小编All*_*ool的帖子

Angular 5 Form脏支票

我有一些表格和按钮来保存它。仅当表单上有未保存的更改(输入)时,才必须启用该按钮。

<form>
    <div>
    ... (inputs)
        <span (click)="save()"> Save </span>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

Angular 5中有一些内置的表单脏检查机制吗?实施此方案的最简单方法是什么?

html javascript angular angular5

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

阻止 Google Chrome 发送 Sec-Fetch 标头

我想在我的 Web API 2(net.framework 4.6.2 应用程序)中缓存静态内容(index.html)

我编写了 OWIN 中间件,它cache-control向响应添加了标头,从而允许从浏览器缓存中检索后续请求。

OWIN 上下文扩展:

public static class BrowserCacheOwinContextExtensions {
  public static IOwinContext SetCacheControlHeader(this IOwinContext context, int maxAge) {
    context.Response.Headers["Cache-Control"] = $"public, max-age={maxAge}";
    context.Response.Headers["Vary"] = "User-Agent";
        
    return context;
  } 
}
Run Code Online (Sandbox Code Playgroud)

中间件的片段:

if (browserCacheOptions.IsEnable) {
  context.SetCacheControlHeader(browserCacheOptions.MaxAge);
}

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

它在 Mozilla 浏览器中工作正常,但在 Chrome 中却不行。

来自 Mozilla 的片段:

在此输入图像描述 在此输入图像描述

我相信其根本原因是 Chrome自动向请求添加了额外的Sec-Fetchheaders + 。cache-control: max-age=0

在此输入图像描述

Chrome 自动添加 Sec-Fetch 标头:

在此输入图像描述 在此输入图像描述

注意:如果在单独的浏览器选项卡中打开相同的请求,则它在 Chrome 中工作正常(sec-fetch请求中没有标头)

问:是否可以以某种方式禁用此类行为,并且不自动将 sec-fetch 标头添加到请求中?

或者如果您有其他建议,请分享。

caching http-headers asp.net-web-api owin owin-middleware

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

单元测试异步方法C#

我有一个问题)

我尝试在我的c#代码中重现类似几个sp(存储过程)调用的东西,但我想以异步方式执行它.

TSQL示例:( Execute sp @key = 15072000173475; Execute sp @key = 15072000173571; ... Execute sp @key = n;)

[TestClass]
public class UnitTestNomenclature {
    [TestMethod]
    public void ParallelSQLMethod() {
        Task scropeTasks = null;
        //real amount is more then 1500
        long[] keys = new long[] {15072000173475,15072000173571 ... n };

        try {
            var tasks = keys.Select( i =>  Task.Run(async () => { await RunStoredProc(i); }));
            scropeTasks =  Task.WhenAll(tasks);

            scropeTasks.Wait();
        } catch (Exception ex) {
            Debug.WriteLine("Exception: " + ex.Message);

            Debug.WriteLine("IsFaulted: " + …
Run Code Online (Sandbox Code Playgroud)

c# ado.net unit-testing asynchronous async-await

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

适当的c#集合,可通过multy键快速搜索

您好我正在努力重构一些遗留代码.有些代码表示从自定义类型到c#类型的"转换器".

          ...
           if (dataType == CustomType.Bit)
            {
                return typeof(bool);
            }
            else if (dataType == CustomType.Bittype ||
                dataType == CustomType.Char ||
                dataType == CustomType.Fromtotype ||
                dataType == CustomType.Mdcintervaltype ||
                dataType == CustomType.Nclob ||
                dataType == CustomType.Nchar ||
                dataType == CustomType.Ntext ||
                dataType == CustomType.Nvarchar ||
                dataType == CustomType.Nvarchar2 ||
                dataType == CustomType.Varchar ||
                dataType == CustomType.Varchar2)
            {
                return typeof(string);
            }
            else if (dataType == CustomType.Date ||
                dataType == CustomType.Datetime ||
                dataType == CustomType.Timestamp3 ||
                dataType == CustomType.Timestamp6)
            {
                return typeof(DateTime);
            } …
Run Code Online (Sandbox Code Playgroud)

c# algorithm collections design-patterns data-structures

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

将应用程序功能服务总线触发器切换为 ReceiveAndDelete 模式而不是 PeekLock

我有一个.net core后台代理(托管服务)

它使用 Web 作业触发功能处理 Azure 服务总线消息

public async Task ProcessSyncResponseMessage(
            [ServiceBusTrigger(ServiceBusTriggers.SyncResponses, ServiceBusTriggers.SubscriptionName)] Message message)
        {
            // some actions
        }
Run Code Online (Sandbox Code Playgroud)

正如我所看到的,它在PeekLock 模式下工作,但我想切换到ReceiveAndDelete 模式,从而在收到消息后立即从服务总线中删除消息。

我想知道是否可以使用 .net core web 作业触发功能。

问:如果是这样,您能给我一些提示吗?我该如何设置?

servicebus azure .net-core

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

利用流写入器 WriteLineAsync 和 WhenAll 是否正确

我有一段代码以异步方式写入内存流(.NET Standard 2.1)

  • 创建热任务列表,每行一个
  • 然后等待全部完成
  • 最后将写入器缓冲区刷新到内存流

代码:

await using var memoryStream = new MemoryStream();
await using var writer = new StreamWriter(memoryStream);

var recordTasks = stringRecordsToWrite.Select(r => writer.WriteLineAsync(r));

await Task.WhenAll(recordTasks);

await writer.FlushAsync();

var result = memoryStream.ToArray();
Run Code Online (Sandbox Code Playgroud)

问题

有几个问题困扰着我:

  1. 有报道称,一些记录有时会被跳过。因此,我想知道这样的实施是否是根本原因。我尝试在本地重现该问题,但不幸的是没有成功
  2. Resharper 还强调,“writer”(在 SELECT 语句内)是一个捕获的变量,并在外部作用域中进行处理。这会是一个问题吗?

或者那些都是假痕迹,而且实现得很好,我应该尝试在其他地方找到原因

Ps代码片段,用于尝试重现该问题,但是,结果文件大小约为 250 MB,并且仍然没有该问题的证据......

 internal class Program
    {
        public static async Task Main(string[] args)
        {
            var records = new Dictionary<string, IEnumerable<RecordsToWrite>>();

            for (var i = 0; i < 200; i++)
            {
                var recordKey = $"test-{i}";

                records.Add(recordKey, default); …
Run Code Online (Sandbox Code Playgroud)

c# asynchronous streamwriter async-await

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