小编Ber*_*ken的帖子

检查C#中的图像是否为空

我到处都看,但似乎没有一个标准(我可以看到)如何检查图像是否为空白.在C#中

我有办法做到这一点,但很想知道检查图像是否为空白的正确方法是什么,所以每个人都可以在将来知道.

我不会复制粘贴一堆代码,如果你想要我,这将是我的荣幸,但我首先要解释我如何检查图像是否为空白.

你拍一张.jpg图片,获取它的宽度.例如500像素然后你将它除以2给你250

然后你检查每个像素的颜色在(250宽度和高度)的位置(你迭代的地方是想象图像的高度).

这样做只是垂直检查图像的中间像素线.它通过所有像素检查,看看颜色是否是白色除外.我已经这样做了,所以你不必搜索所有500*像素的高度,因为你几乎总是会遇到页面中间的颜色.

它的工作......有点慢......必须有更好的方法来做到这一点?您可以将其更改为垂直搜索2/3/4行,以增加发现非空白页面的机会,但这将花费更长时间.

(另请注意,使用图像的大小来检查它是否包含某些内容在这种情况下不起作用,因为打开两个句子的页面和空白页面的大小彼此太靠近)

添加解决方案后.

帮助实施和理解解决方案的资源.

(请注意,在第一个网站上,所声明的Pizelformat实际上是Pixelformat) - 我知道的小错误,只是提到,可能会引起一些混淆.

在我实施该方法以加速像素搜寻之后,速度没有增加那么多.所以我认为我做错了什么.

40个图像的旧时间= 15.63.

40张图片的新时间= 15.43

我看到DocMax 引用的伟大文章,代码"锁定"在一组像素中.(或者多数民众赞成我是如何理解的)所以我所做的就是锁定每页的像素中间行.这是正确的举动吗?

private int testPixels(String sourceDir)
    {
         //iterate through images
        string[] fileEntries = Directory.GetFiles(sourceDir).Where(x => x.Contains("JPG")).ToArray();

        var q = from string x in Directory.GetFiles(sourceDir)
                where x.ToLower().EndsWith(".jpg")
                select new FileInfo(x);

        int holder = 1;
        foreach (var z in q)
        {
            Bitmap mybm= Bitmap.FromFile(z.FullName) as Bitmap;
            int blank = getPixelData2(mybm);

            if (blank == 0)
            {
                holder …
Run Code Online (Sandbox Code Playgroud)

c# image pixel

7
推荐指数
1
解决办法
7613
查看次数

为什么 puppeteer page.goto() 会抛出超时错误?

下面的代码会报错,为什么呢?

超出导航超时:超出 60000ms

我使用的是 puppeteer 版本 1.19.0

const puppeteer = require("puppeteer");

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.setCacheEnabled(false);

  try {
    const response = await page.goto("https://www.gatsbyjs.com", {
      waitUntil: "networkidle0",
      timeout: 60000
    });

    console.log("Status code:", response.status());
  } catch (error) {
    console.log(error.message);
  }

  await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)

其他一些 URL 工作正常,所以我想知道这个特定 URL 是否有什么特别之处?

node.js puppeteer serverless

7
推荐指数
1
解决办法
6773
查看次数

Kubernetes:hostPort 和 hostIp 有何用途?

我尝试了解 Kubernetes 中的 hostIP 和 hostPort。

这是我的集群配置:

3个流浪节点:

nodes = [
  { :hostname => 'k8s-master', :ip => '192.168.150.200', :ram => 4096 },
  { :hostname => 'k8s-minion1', :ip => '192.168.150.201', :ram => 4096 },
  { :hostname => 'k8s-minion2', :ip => '192.168.150.202', :ram => 4096 },
]
Run Code Online (Sandbox Code Playgroud)

我编写以下清单来测试它:

apiVersion: v1
kind: Pod
metadata:
  name: firstpod
spec:
  containers:
  - name: container
    image: nginx
    ports:
    - containerPort: 80
      hostIP: 10.0.0.1
      hostPort: 8080
Run Code Online (Sandbox Code Playgroud)

我部署的是kubectl apply -f port.yml pod 在 k8s-minion2 上运行

kubectl get pods …
Run Code Online (Sandbox Code Playgroud)

port cluster-computing kubernetes kubernetes-pod

7
推荐指数
2
解决办法
4万
查看次数

Microsoft安全通报(2269637)对.NET编码的影响

Microsoft发布安全通报(2269637)不安全的库加载可能允许远程执行代码.

该注释指的是有助于检测此问题的工具和动态链接库安全性的编程指南.

这些指南如何转换为.NET开发?我认为这只影响平台调用.

这仍然是导入系统库的推荐方法吗?

DllImport("user32.dll")]
Run Code Online (Sandbox Code Playgroud)

.net security dll pinvoke loadlibrary

6
推荐指数
1
解决办法
301
查看次数

使用XSLT更改节点的位置

我正在使用身份转换,在此期间,我需要使用XSLT更改节点的位置.假设,我有一个像这样的XML:

<root>
    <a>
        <b1>SampleB1</b1>
        <b2>
            <c1>zyx</c1>
            <c2>wvu</c2>
            <c3>tsr</c3>
            <c4>dtg</c4>
            <c5>hkj</c5>
        </b2>
        <b3>SampleB3</b3>
    </a>
</root>
Run Code Online (Sandbox Code Playgroud)

然后我想改变节点'c4'和'c5'的位置,并希望输出为:

<root>
    <c4>dtg</c4>
    <c5>hkj</c5>
    <a>
        <b1>SampleB1</b1>
        <b2>
            <c1>zyx</c1>
            <c2>wvu</c2>
            <c3>tsr</c3>
        </b2>
        <b3>SampleB3</b3>
    </a>
</root>
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我,我们怎么做到这一点.

谢谢 !!!

xslt

6
推荐指数
1
解决办法
3666
查看次数

Swagger中的参数输出重复

更新:我开始怀疑这是否是由于一个错误:

https://github.com/domaindrivendev/Swashbuckle/issues/590

但是解决方法表明似乎没有解决我的问题.


我正在使用Swashbuckle为C#ASP.NET Web API项目生成API文档.

我的目标是允许以下作为有效的URL:

/endpoint/items/123/foo?param2=bar
Run Code Online (Sandbox Code Playgroud)

将所需参数(param1)设置为"foo",将可选参数(param2)设置为"bar".我希望两个参数都包含在一个C#参数对象中.(使用其他可选参数,如param3等).几个端点将使用相同的参数,我希望有一个表示参数的对象.

Swagger/Swashbuckle的细节大多是黑盒子,我无法弄明白.我在参数列表中得到了重复项.

重现问题的示例代码:

    // This endpoint is generating documentation the way I would like.
    [HttpGet]
    [Route("endpoint1/items/{id}/{param1}")]
    public string GetDataForParameters(int id, string param1, string param2 = null, string param3 = null)
    {
        return string.Format("Params: {1}, {2}, {3}", id, param1, param2, param3);
    }

    // This endpoint has the structure I would like, but I get duplicates for param1 in the documentation.
    [HttpGet]
    [Route("endpoint2/items/{id}/{param1}")]
    public string GetDataForParameters(int id, [FromUri(Name = "")]MyParams myParams)
    {
        return string.Format("Params: …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-web-api swagger swashbuckle

6
推荐指数
1
解决办法
1379
查看次数

angular 通用中的应用洞察

我有一个 Angular 项目,我想使用Application Insights进行日志记录。
我试过这个教程,它工作得很好,但不是在 SSR 模式下。

当我在 SSR 模式下运行应用程序时,我收到此错误:

RerefenceError: XmlHttpRequest is not defined
Run Code Online (Sandbox Code Playgroud)

我找到了这个SO post,这似乎与我的问题相同。按照它的一个答案,我已经安装了XMLHttpRequest库并将这一行添加到server.ts:

(global as any).XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;    
Run Code Online (Sandbox Code Playgroud)

不为我工作。Angular Universal 尚未响应http 请求。另外,我尝试使用“xhr2”库而不是“xmlhttprequest”,它也不起作用。

如何获得应用程序洞察以在 Angular SSR 模式下工作?


更多详情

这就是我将应用程序洞察添加到我的项目的方式。

monitoring.service.ts:aiAPI的包装器:

RerefenceError: XmlHttpRequest is not defined
Run Code Online (Sandbox Code Playgroud)

然后像这样调用aiat的初始化代码app.component.ts:

(global as any).XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;    
Run Code Online (Sandbox Code Playgroud)

更新:

我把它通过周围的所有相关应用的见解API的方法调用,如工作trackException()和this.appInsights.loadAppInsights()一个if statememt内:

import { ApplicationInsights } from "@microsoft/applicationinsights-web";

class MonitoringService …
Run Code Online (Sandbox Code Playgroud)

azure-application-insights server-side-rendering angular-universal angular

6
推荐指数
0
解决办法
493
查看次数

更改 System.Web.Security.MembershipProvider (EPiServer) 中密码策略验证的错误消息

这是我的情况。

我正在使用 EPiServer 9 并且我已经配置了一个 SqlServerMembershipProvider 如下:

<add name="SqlServerMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                     connectionStringName="EPiServerXYZ"
                     enablePasswordRetrieval="false"
                     enablePasswordReset="true"
                     requiresQuestionAndAnswer="false"
                     requiresUniqueEmail="false"
                     maxInvalidPasswordAttempts="5"
                     minRequiredPasswordLength="8"
                     minRequiredNonalphanumericCharacters="1"
                     passwordAttemptWindow="10"
                     applicationName="/"
                     passwordStrengthRegularExpression="^.*(?=.{8,})(?=.*\d)(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^\w\d\s]).*$" />
Run Code Online (Sandbox Code Playgroud)

一切正常,验证和不同的场景。

我们的问题是会员提供者显示的错误消息是通过使用配置创建的,它最终给出了用户不友好的消息,例如:

  • '无效密码,最小长度:8,最小非字母数字字符:1'
  • 'newPassword' 中的非字母数字字符需要大于或等于 '1'。参数名称:newPassword'
  • '参数'newPassword' 与配置文件中指定的正则表达式不匹配。参数名称:newPassword'

在episerver中创建用户时的错误消息密码验证

我很想设置一个自定义错误消息,它真正向用户解释了我们在用于验证密码的正则表达式中的所有要求。

到目前为止,我可以考虑这样做的唯一方法是实现/扩展我们正在使用的当前提供程序,以便在验证出现问题时设置自定义错误消息,但我想可能有另一种更好/更简单的方法来做到这一点.

提前致谢!

.net asp.net security asp.net-membership episerver

5
推荐指数
1
解决办法
1038
查看次数

如何将 WebDeploy 与 ASP.Net core 结合使用

我们有一个更新程序,可以自动将 WebDeploy 包发布到 IIS 服务器。该程序适用于 MVC 5 - 应用程序,但不适用于 .Net Core 应用程序。我们使用 Microsoft.Web.Deployment - API,我的发布方法如下所示:

private void UpdateIIS(DTOs.ApplicationConfiguration.ApplicationServer applicationServer, DTOs.Update.Update update) {
    // SSL-Zertifikatsfehler ignorieren
    System.Net.ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(
        (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return true; });
    var sourceBaseOptions = new DeploymentBaseOptions();
    var destBaseOptions = new DeploymentBaseOptions() {
        ComputerName = string.Format("https://{0}:{1}/msdeploy.axd?site={2}", applicationServer.Adresse, applicationServer.MSDeployPort, applicationServer.SiteName),
        UserName = applicationServer.User,
        Password = applicationServer.Passwort,
        AuthenticationType = "Basic"
    };
    string updatePackage = Directory.GetFiles(update.UpdateDirectory, "*.zip").FirstOrDefault();
    if (!File.Exists(updatePackage)) {
        throw new Exception("Update-Paketdatei …
Run Code Online (Sandbox Code Playgroud)

iis msdeploy webdeploy asp.net-core

5
推荐指数
1
解决办法
3598
查看次数

ASP.NET Core 中的响应类型

我刚刚将项目从 ASP.Net 4.5 迁移到 ASP.Net Core。我有一个 REST API get,过去用于返回 blob,但现在返回 JSON。

这是旧代码:

[HttpGet]
[ResponseType(typeof(HttpResponseMessage))]
[Route("Download/{documentId}")]
public async Task<HttpResponseMessage> DownloadDocument(string documentId)
{
    try
    {
        var result = await TheDocumentService.DownloadDocument(documentId);

        return result;
    }
    catch (Exception ex)
    {
        return new HttpResponseMessage
        {
            StatusCode = HttpStatusCode.InternalServerError,
            Content = new StringContent(ex.Message)
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

ASP.net Core 中的代码除了[ResponseType(typeof(HttpResponseMessage))]在 ASP.Net Core 中不起作用之外是相同的,并且两种解决方案的返回结果也相同。

但是当在客户端查看服务器的响应时,它们是不同的。

在此输入图像描述

因此,它们之间唯一的区别是[ResponseType(typeof(HttpResponseMessage))]. ASP.NET Core 中有类似的东西吗?

c# asp.net asp.net-mvc asp.net-core

5
推荐指数
2
解决办法
1万
查看次数