小编Pin*_*ong的帖子

如何在.NET中以编程方式为图像的透明部分着色

我创建了一个图像并手动保存为文件,该图像具有在图像中透明的形状(例如心脏),而图像的其余部分具有其他颜色.如何在.NET中以编程方式使用指定颜色制作透明形状,使图像的其余部分保持不变?

例如,提供的是一个图像,我想用颜色填充透明部分.

http://www.sendspace.com/file/an53a1

.net c# drawing transparent

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

UML帮助C#设计原则

任何人都可以请指出下图的含义:

在此输入图像描述

  1. PolicyLayer和PolicyServiceInterface之间的关系是什么
  2. PolicyServiceInterface和MachanismLayer之间有什么关系.

C#代码也将不胜感激!

请注意,UML来自C#中的敏捷原则,模式和实践.作者:Martin C. Robert,Martin Micah 2006.

添加于2011年6月15日

请执行以下相同的含义:1)一端带三角形的实线2)一端带三角形的虚线

添加于2011年6月3日1日

有什么区别:1)一端带箭头的实线2)一端带箭头的虚线

以下链接中的示例和PersistentObject和ThirdPartyPersistentSet中的示例:

UML帮助C#设计原则

添加于2011年6月3日2日

PolicyLayer和PolicyServiceInterface之间的关系如下:

public class PolicyLayer

{
    private PolicyServiceInterface policyServiceInterface = new PolicyServiceInterfaceImplementation();
}

class PolicyServiceInterfaceImplementation:PolicyServiceInterface {}
Run Code Online (Sandbox Code Playgroud)

关于

c# oop uml design-principles

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

在C#中实现anagram函数

可能重复:
什么是一种简单的方法来判断一个单词列表是否是彼此的字谜?

在C#中编写函数的最佳方法(性能范围广)是什么,它接受两个字符串,当字符串是彼此的字符串时返回true,否则返回false.字谜的例子是:

abet beat beta bate
abides biased
Run Code Online (Sandbox Code Playgroud)

字谜链接

在实现这一点时,每个字符串中是否有空格?

任何想法都将非常感谢!

c#

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

服务器关闭时出现什么异常或http状态代码

我想监视WCF服务器,并在服务器关闭时发送电子邮件通知。为此,我正在编写一个控制台应用程序,以定期向服务器发送虚拟请求,并检查是否将响应发送回去。控制台应用程序收到异常后,服务器将出现问题,包括服务器已关闭。

但是,问题是我在服务器的不同状态下收到了不同的异常。以下是服务器处于不同状态时从服务器返回的异常。但是,所有这些似乎都属于服务器故障类别。任何的想法??:

IIS关闭时

System.ServiceModel.EndpointNotFoundException,

消息:
http://localhost/service.svc上没有侦听终结点的端点可以接受该消息。这通常是由不正确的地址或SOAP操作引起的。有关更多详细信息,请参见InnerException(如果存在)。

内部异常消息:远程服务器返回错误:(404)找不到

当一个Web.config文件被故意更改为错误的名称:

System.ServiceModel.ServiceActivationException
链接: http://localhost/service.svc
消息:
无法激活请求的服务'http://localhost/service.svc'。请参阅服务器的诊断跟踪日志以获取更多信息。

由于其他未知原因

System.ServiceModel.ServerTooBusyException
消息:
位于http://localhost/service.svc ' 的HTTP服务太忙。
消息:
远程服务器返回错误:(503)服务器不可用。

更新1

异常并不总是返回http状态代码。

更新2 除了使用WCF代理调用服务之外,我还必须使用WebRequest,如下所示:

       try
        {
            WebRequest webRequest = WebRequest.Create(uri);
            webRequest.Method = "GET";

            HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse();                             

        }
        catch ()  //what excpetion will tell me server is down??
        {
           ...
        }
Run Code Online (Sandbox Code Playgroud)

.net c# wcf exception-handling http-error

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

单例 Azure Cosmos DB 客户端

在应用程序的生命周期内使用单例 Azure Cosmos DB 客户端

每个 DocumentClient 实例都是线程安全的,并且在直接模式下操作时执行高效的连接管理和地址缓存。为了通过 DocumentClient 实现高效的连接管理和更好的性能,建议在应用程序的生命周期中为每个 AppDomain 使用单个 DocumentClient 实例。

https://learn.microsoft.com/en-us/azure/cosmos-db/performance-tips

services.AddSingleton<IDocumentClient>(x => new DocumentClient(UriEndpoint, MasterKey));

private readonly IDocumentClient _documentClient;
public HomeController(IDocumentClient documentClient){
    _documentClient = documentClient;
}
Run Code Online (Sandbox Code Playgroud)

这是否意味着客户端可以用于多个数据库(即任何数据库中的任何容器)?

如何在 dotnet 核心应用程序中将 DocumentDB 客户端初始化为单例

azure azure-cosmosdb azure-cosmosdb-sqlapi

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

使用 Xamarin Android 版本 8、.net 标准运行或不运行包含服务和活动的 ConfigureAwait(false)

我遇到了以下有关何时何地使用的文章ConfigureAwait(false),但无法得到答案。

您不需要 ConfigureAwait(false),但仍可在库和 UI 应用程序中使用它。(例如 Xamarin、WinForms 等)

https://blog.stephencleary.com/2017/03/aspnetcore-synchronization-context.html

此链接说相反的答案

为所有服务器端代码调用 ConfigureAwait 的最佳实践

正确使用 Task.Run 和 async-await 时

我的问题:

场景 1:下面的代码作为后台服务运行。

我的问题:ConfigureAwait(false)无论何时await都需要像下面的 A 和 B 一样使用:

    [Service(Name = "com.MainApplicationService", Label = "Main Application Service", Exported = false)]
    public class MainApplicationService : Android.App.Service
    {

        public override IBinder OnBind(Intent intent)
        {
            return null;
        }

        [return: GeneratedEnum]
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            await InitAsync().ConfigureAwait(false);   //line A

            Task.Run(async () => await …
Run Code Online (Sandbox Code Playgroud)

c# task-parallel-library xamarin.android async-await xamarin

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

读取XML文件的内容而不必删除XML声明

我想从文件中读取所有XML内容.下面的代码仅在<?xml version="1.0" encoding="UTF-8"?>删除XML声明()时有效.在不删除XML声明的情况下读取文件的最佳方法是什么?

XmlTextReader reader = new XmlTextReader(@"c:\my path\a.xml");
            reader.Read();
            string rs = reader.ReadOuterXml();
Run Code Online (Sandbox Code Playgroud)

在不删除XML声明的情况下,reader.ReadOuterXml()返回一个空字符串.

<?xml version="1.0" encoding="UTF-8"?>  
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://www.as.com/ver/ver.IClaimver/Car</a:Action>
    <a:MessageID>urn:uuid:b22149b6-2e70-46aa-8b01-c2841c70c1c7</a:MessageID>
    <ActivityId CorrelationId="16b385f3-34bd-45ff-ad13-8652baeaeb8a" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">04eb5b59-cd42-47c6-a946-d840a6cde42b</ActivityId>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">http://localhost/ver.Web/ver2011.svc</a:To>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Car xmlns="http://www.as.com/ver">
      <carApplication>
        <HB_Base xsi:type="HB" xmlns="urn:core">
          <Header>
            <Advisor>
              <AdvisorLocalAuthorityCode>11</AdvisorLocalAuthorityCode>
              <AdvisorType>1</AdvisorType>
            </Advisor>
          </Header>
          <General>
            <ApplyForHB>yes</ApplyForHB>
            <ApplyForCTB>yes</ApplyForCTB>
            <ApplyForFSL>yes</ApplyForFSL>
            <ConsentSupplied>no</ConsentSupplied>
            <SupportingDocumentsSupplied>no</SupportingDocumentsSupplied>
          </General>
        </HB_Base>
      </carApplication>
    </Car>
  </s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)

更新

我知道其他使用NON-xml阅读器的方法(例如使用File.ReadAllText()).但我需要知道一种使用xml方法的方法.

c# xml xml-declaration

4
推荐指数
1
解决办法
9203
查看次数

通过 Azure API 管理的 C# 表达式出现 ToString() 错误

我在尝试将类型转换为字符串时遇到错误,如下所示:

  <set-variable name="a" value="@(context.Variables["a"].ToString())" />
Error in element 'set-variable' on line 16, column 10: Usage of member 'ToString' of type 'System.Object' is not supported within expressions


 <set-variable name="a" value="@(context.Variables["a"])" />
    Error in element 'set-variable' on line 16, column 10: Expression return type 'System.Object' is not allowed
Run Code Online (Sandbox Code Playgroud)

https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions

azure azure-api-management

4
推荐指数
1
解决办法
2374
查看次数

使用 Azure APIM 策略获取策略中指定的 url 部分

是否可以在策略内获取下面指定的 url 部分:

<policies>
        <inbound>
            <base />    
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
            <find-and-replace from="https://thirdparty/certs" 
                 to="@(specified url part)" />        
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>
Run Code Online (Sandbox Code Playgroud)

请注意,整个 URL 可能包含版本控制和前缀。

azure azure-api-management

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

记录 Polly 等待和重试策略 ASP.NET CORE 2.1

我需要在 APS.NET CORE 2.1+ 中记录通过 Polly 定义的重试策略。

我的代码如下所示,显示 Polly 重试 polly 并使用 HttpClient。

public IServiceProvider ConfigureServices(IServiceCollection services)
        {
          //...

            //https://github.com/App-vNext/Polly/wiki/Polly-and-HttpClientFactory            
            Random jitterer = new Random();
            services.AddHttpClient<SimpleCastClient>()
                //TransientErrors:
                //Network failures(System.Net.Http.HttpRequestException)
                //HTTP 5XX status codes(server errors)
                //HTTP 408 status code(request timeout)
                .AddTransientHttpErrorPolicy(policyBuilder =>
                    //Exponential backoff with Randomisation
                    policyBuilder.WaitAndRetryAsync(10,
                        retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                                        + TimeSpan.FromMilliseconds(jitterer.Next(1, 100))
                    ));
}

  [ApiVersion("1")]
    [Route("api/v{version:apiVersion}/[controller]")]
    [ApiController]
    public class MyController : ControllerBase
    {
        ILog _logger;
        private SimpleCastClient _simpleCastClient;

        public MyController(ILog logger, SimpleCastClient simpleCastClient)
        {
            _logger = logger;
            _simpleCastClient = …
Run Code Online (Sandbox Code Playgroud)

c# .net-core polly asp.net-core asp.net-core-webapi

3
推荐指数
1
解决办法
4624
查看次数