小编Sze*_*eki的帖子

VSTS创建新的WorkItem

我正在使用VSTS REST API,我正在尝试创建一个新的WorkItem.但我只能从VSTS获取现有的WorkItem并更新WorkItem.

        var listDoNotUpdate = new List<string>();
        listDoNotUpdate.Add("System.BoardColumn");
        listDoNotUpdate.Add("System.BoardColumnDone");
        var wi = await this.Client.GetWorkItemAsync(4000);
        wi.Fields["System.Title"] = "Test";
        wi.Fields["System.Description"] = "Test";
        wi.Fields["Microsoft.VSTS.Common.AcceptanceCriteria"] = "Test";
        var doc = new JsonPatchDocument();
        foreach (var field in wi.Fields)
        {
            if (!listDoNotUpdate.Contains(field.Key))
            {
                doc.Add(new JsonPatchOperation
                {
                    Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Replace,
                    Path = string.Concat("/fields/", field.Key),
                    Value = field.Value
                });
            }
        }

        await this.Client.UpdateWorkItemAsync(doc, 4000);
Run Code Online (Sandbox Code Playgroud)

但是,我如何创建一个新的WorkItem并上传它?

azure-devops

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

.NET Core 3.1 在命中中间件之前记录控制器中抛出的异常

我向我的 中添加了一个异常处理中间件.net core 3.1 api,但它的行为不符合预期。我看到大量未处理异常的日志消息。

我做了一个简单的骨架来重现它。我没有配置日志记录,但行为是相同的。

启动.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.ConfigureExceptionHandler();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });
}
Run Code Online (Sandbox Code Playgroud)

ExceptionHandlerMiddleware.cs

public static class ExceptionHandlerMiddleware
{
    public static void ConfigureExceptionHandler(this IApplicationBuilder app)
    {
        app.UseExceptionHandler(applicationBuilder =>
        {
            applicationBuilder.Run(async httpContext => await ExceptionHandlerAsync(httpContext));
        });
    }

    private static async Task ExceptionHandlerAsync(HttpContext context)
    {
        var contextFeature = context.Features.Get<IExceptionHandlerFeature>();

        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
        var message = contextFeature?.Error.Message ?? "Internal Server Error with no inner exception";

        await context.Response.WriteAsync(message);
    }
}
Run Code Online (Sandbox Code Playgroud)

异常控制器.cs

[ApiController] …
Run Code Online (Sandbox Code Playgroud)

c# logging middleware exception .net-core

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

TPL 完成与完成

我需要从旧数据库导入客户相关数据,并在此过程中执行多次转换。这意味着单个条目需要执行额外的“事件”(同步产品、创建发票等)。

我最初的解决方案是一种简单的并行方法。它工作正常,但有时会出现问题。如果当前处理的客户需要等待相同类型的事件,他们的处理队列可能会被卡住并最终超时,导致每个底层事件也失败(它们依赖于失败的事件)。这种情况并不总是发生,但还是很烦人。

于是我有了另一个想法,分批工作。我的意思是不仅限制同时处理的客户数量,还限制广播到队列的事件数量。在四处寻找想法时,我找到了这个答案,它指向TPL DataFlow

我做了一个骨架来熟悉它。Complete()我设置了一个简单的管道,但我对和 waiting的用法有点困惑Completion()

步骤如下

  1. 制作一个数字列表(要导入的客户的 ID) - 这是导入逻辑之外的,它只是为了能够触发其余的逻辑
  2. 创建一个BatchBlock(能够限制同时处理的客户数量)
  3. MyClass1根据 id ( TransformBlock<int, MyClass1>)创建单个项目
  4. MyClass2执行一些逻辑并生成( )的集合TransformManyBlock<MyClass1, MyClass2>- 例如,睡眠 1 秒
  5. 对集合中的每个项目执行一些逻辑 ( ActionBlock<MyClass2>) - 例如,休眠 1 秒

这是完整的代码:

public static class Program
{
    private static void Main(string[] args)
    {
        var batchBlock = new BatchBlock<int>(2);
        for (var i = 1; i < 10; i++)
        {
            batchBlock.Post(i);
        }


        batchBlock.Complete();
        while (batchBlock.TryReceive(null, …
Run Code Online (Sandbox Code Playgroud)

c# parallel-processing multithreading task-parallel-library tpl-dataflow

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

使用 RestSharp 将 JSON 数组反序列化为 C# 结构

我使用 RestSharp 和IRestResponse<T> response = client.Execute<T>(request). 但是,一个特定的 JSON 结果给我带来了麻烦,它以方括号开头和结尾......

我的 JSON 以“[”和“]”字符开头和结尾:

[
  {
    "first": "Adam",
    "last": "Buzzo"
  },
  {
    "first": "Jeffrey",
    "last": "Mosier"
  }
]
Run Code Online (Sandbox Code Playgroud)

我创建了这个类结构:

public class Person
{
    public string first { get; set; }
    public string last { get; set; }
}
public class Persons
{
    public List<Person> person { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我在方法中使用 RestSharp 动态反序列化为我的Persons类型 T...

IRestResponse<T> response = client.Execute<T>(request);
return response;
Run Code Online (Sandbox Code Playgroud)

问题是,当 T 是Persons时,我在客户端上收到此错误。执行行:

无法将“RestSharp.JsonArray”类型的对象转换为“System.Collections.Generic.IDictionary`2[System.String,System.Object]”类型。

我也尝试使用 Json.Net …

c# json restsharp deserialization json-deserialization

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

连接数过多异常

我尝试SELECT在表上运行MySql,但收到​​此错误:

Server Error in '/MyApp' Application.
Too many connections
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: MySql.Data.MySqlClient.MySqlException: Too many connections
Run Code Online (Sandbox Code Playgroud)

来源错误:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack …
Run Code Online (Sandbox Code Playgroud)

.net c# mysql

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