小编kar*_*ara的帖子

如何在不等待的情况下等待其他服务在后台完成任务?

我正在创建一个ASP.NET Core WebApi,它使用Autodesk Model Derivative API将Revit文件转换为另一种文件格式。上传文件后,Autodesk API将在后台开始工作,可能需要几分钟才能完成其工作。

我想监视Autodesk API的状态,以了解转换是否已经完成并通知用户。我正在寻找监视作业状态的最佳方法,而无需“等待”并使请求挂起几分钟。

我试过只是异步运行任务而不等待结果。直到我想要在数据库上下文中更新一个值的时候,该方法才起作用,因为由于请求结束,该值已被删除。

我还研究了实现后台服务的几种方法,但是还没有找到一种清晰的方法。

public async Task<ActionResult<Response<JobResponse>>> UploadFile(string bucketKey, IFormFile file)
{
    // ....
    // File has been uploaded 
    Response<JobResponse> response
        = await NetworkManager.PostAsync<JobResponse>(URI.Job.Url, JsonConvert.SerializeObject(jobData));

    // The job has been created in the Autodesk API, so I create a record in my own database
    var job = new Job(urn, file.FileName);
    context.Jobs.Add(job);
    await context.SaveChangesAsync();

    // This method is what I want to do in the background 
    MonitorStatus(job);

    return Respond(response);
}

private async Task MonitorStatus(Job …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core autodesk-forge asp.net-core-webapi

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

运行 xunit 测试时无法将输出打印到控制台窗口

public class test2InAnotherProject
{
    private readonly ITestOutputHelper output;

    public test2InAnotherProject(ITestOutputHelper output)
    {
        this.output = output;
    }
    int Diff(int a, int b)
    {
        return (a - b);
    }
    int Div(int a, int b)
    {
        return (b / a);
    }

    [Fact]
    public void Test2()
    {
        int a = 2, b = 4;

        output.WriteLine("Test1: Project 2 in old library");
        int c = Diff(a, b);
        Assert.Equal(c, (a - b));
        output.WriteLine("Test1: Asssert done Project 2 in old library");
    }

    [Fact]
    public void Test3()
    {
        int …
Run Code Online (Sandbox Code Playgroud)

c# xunit

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

多列索引如何在oracle中运行?

我正在构建一个表来管理一些文章:

| Company | Store | Sku | ..OtherColumns.. | 
|       1 |     1 | 123 | ..               | 
|       1 |     2 | 345 | ..               | 
|       3 |     1 | 123 | ..               |
Run Code Online (Sandbox Code Playgroud)

脚本

大多数时候company,store和sku将用于SELECT行:

SELECT * FROM stock s WHERE s.company = 1 AND s.store = 1 AND s.sku = 123;
Run Code Online (Sandbox Code Playgroud)

..但有时候公司在访问桌子时将无法使用.

SELECT * FROM stock s WHERE s.store = 1 AND s.sku = 123;
Run Code Online (Sandbox Code Playgroud)

..有时所有文章都会被选中用于商店.

SELECT * FROM stock s WHERE s.company = …
Run Code Online (Sandbox Code Playgroud)

oracle indexing

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

有没有办法使用 NPOI 在我的 Excel 文档中从十六进制值(例如“#72fe9c”)向单元格添加颜色

由于我是 NPOI 新手,我想向 Excel 工作表中的单元格添加颜色。我有一个像“#ffeeff”这样的十六进制值,并且ICellStyle.FillForegroundColor只能分配短整型值。

System.OverflowException:对于 Int16 来说值太大或太小。

我已经尝试过这样的代码并且它正在工作

style.FillForegroundColor = HSSFColor.Grey25Percent.Index;
Run Code Online (Sandbox Code Playgroud)

但我只有可以转换为 int 的十六进制值,但它仅支持短 int 值。

//it is working
style.FillForegroundColor = HSSFColor.Grey25Percent.Index;

// not working for me as '#ffeeff' canot be converted to short, it can only be converted to int
style.FillForegroundColor = short.Parse(fontcolorCode.Substring(1), NumberStyles.HexNumber)

style.FillForegroundColor = short.Parse(fontcolorCode.Substring(1), NumberStyles.HexNumber) 
Run Code Online (Sandbox Code Playgroud)

它不应该抛出错误,并且在 Excel 工作表中,必须将相同的颜色(fontcolorCode)应用于单元格

c# excel npoi

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

使用函数计算c#中数组之间的欧几里得距离

我想计算用户输入的点之间的欧式距离,因此您可以在这里看到:

static void Main(string[] args)
{
    int numtest = int.Parse(Console.ReadLine());
    int[,] points=new int[10,2];
    for (int i = 0; i < numtest; i++)
    {
        Console.WriteLine("point " +(i+1).ToString()+" x: ");
        points[i, 0] = int.Parse(Console.ReadLine());
        Console.WriteLine("point " + (i + 1).ToString() + " y: ");
        points[i, 1] = int.Parse(Console.ReadLine());
    }
}

public float[] calculate(int[,] points)
{
    for (int i = 0; i <points.Length ; i++)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

C#中有任何功能可以做到这一点吗?

我需要数组中所有点之间的每个距离值

c# distance

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

为什么Hashmap允许空键?

实际上我读了很多关于这个问题的帖子,但没有得到确切原因/答案为什么Hashmap允许空键?.请问任何人都可以通过一个例子向我解释确切的答案.提前致谢.

java collections hashmap

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

如何使用 NUnit “Assert.That()”列表中的项目匹配某些条件?

我正在编写一些单元测试并想检查结果列表。

这是我正在做的一个简单的例子:

[Test]
public void FilterSomething_Test()
{
    List<MyClass> testdata = new List<MyClass>
    {
        new MyClass { SomeProperty = "expectedValue" },
        new MyClass { SomeProperty = "expectedValue" },
        new MyClass { SomeProperty = "unexpectedValue" },
        new MyClass { SomeProperty = "unexpectedValue" },
        new MyClass { SomeProperty = null },
    }

    List<MyClass> result = FilterSomething(testdata);

    Assert.That(
        result.Where(r => r.SomeProperty == "expectedValue"),
        Has.Exactly(2).Items,
        "Two Items should match this..");
}
Run Code Online (Sandbox Code Playgroud)

失败测试的输出:

两个项目应该与此匹配..

预期:正好 2 件

但是是:没有项目

输出并没有解释出了什么问题。

说明:我有多个测试的测试数据。这就是为什么我想在每次测试中检查特定项目。

我的问题:

有没有办法检查列表中的项目计数并从中获取正确的消息NUnit? …

c# nunit unit-testing assert

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

是否有可能看到我的应用程序扔了多少"异常"?

我有一些(旧的,旧的)控制台应用程序,它们可以处理大型数据库并处理一些数据.在处理数据时,抛出并捕获异常.不幸的是,如果记录无效,这在某些情况下是有意的.

我想测量异常的数量是否在可接受的范围内.

处理100.000条记录,20条Exceptions捕获=>正常运行.

处理100.000条记录,10.000 Exceptions捕获=>这是一个问题.

例如,代码

static void Main(string[] args)
{
    DoSomething();

    int x = HowMuchErrorsDidICatch(); // This is where 

    Console.WriteLine("This run catched {0} Exception.", x);
}

// Some work to do..
static void DoSomething()
{
    for (int i = 0; i < 1001; i++)
    {
        try
        {
            // .. Processing some Data
            if (i % 10 == 0)
                throw new Exception("Something went wrong.");
        }
        catch (Exception ex)
        {
            errorCount++;
            // Handling the Exception
        }
    } …
Run Code Online (Sandbox Code Playgroud)

.net c# exception-handling exception

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