小编Spe*_*527的帖子

Asp.Net Core:在控制器外部使用内存缓存

在ASP.NET Core中,它很容易从控制器访问您的内存缓存

在你的创业公司中你添加:

public void ConfigureServices(IServiceCollection services)
        {
             services.AddMemoryCache();
        }
Run Code Online (Sandbox Code Playgroud)

然后从你的控制器

[Route("api/[controller]")]
public class MyExampleController : Controller
{
    private IMemoryCache _cache;

    public MyExampleController(IMemoryCache memoryCache)
    {
        _cache = memoryCache;
    }

    [HttpGet("{id}", Name = "DoStuff")]
    public string Get(string id)
    {
        var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(1));
        _cache.Set("key", "value", cacheEntryOptions);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,如何在控制器外部访问相同的内存缓存.例如.我有一个由HangFire发起的计划任务,如何从我的代码中通过HangFire计划任务访问内存缓存?

public class ScheduledStuff
{
    public void RunScheduledTasks()
    {
        //want to access the same memorycache here ...
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net memorycache .net-core asp.net-core

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

AngleSharp解析

当您没有要使用的类名或ID时,找不到使用AngleSharp进行解析的许多示例.

HTML

<span><a href="google.com" title="Google"><span class="icon icon_none"></span></a></span>
<span><a href="bing.com" title="Bing"><span class="icon icon_none"></span></a></span>
<span><a href="yahoo.com" title="Yahoo"><span class="icon icon_none"></span></a></span>
Run Code Online (Sandbox Code Playgroud)

我想从任何<a>标题= Bing的标签中找到href

在Python BeautifulSoup我会用

item_needed = a_row.find('a', {'title': 'Bing'})
Run Code Online (Sandbox Code Playgroud)

然后抓住href属性

或jQuery

a[title='Bing']
Run Code Online (Sandbox Code Playgroud)

但是,我坚持使用AngleSharp,例如.以下示例 https://github.com/AngleSharp/AngleSharp/wiki/Examples#getting-certain-elements

c#AngleSharp

var parser = new AngleSharp.Parser.Html.HtmlParser();
var document = parser.Parse(@"<span><a href=""google.com"" title=""Google""><span class=""icon icon_none""></span></a></span>< span >< a href = ""bing.com"" title = ""Bing"" >< span class=""icon icon_none""></span></a></span><span><a href = ""yahoo.com"" title=""Yahoo""><span class=""icon icon_none""></span></a></span>");

//Do something with LINQ
var blueListItemsLinq = document.All.Where(m => m.LocalName == "a" && //stuck);
Run Code Online (Sandbox Code Playgroud)

c# html-parsing anglesharp

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

如何透视日志分析数据 (Kusto)

在这件事上我一直在用头撞墙。我有以下数据(有点像键值对),我需要将设置命名为列而不是行

let settings = datatable (Location:int , SettingName:string, SettingValue:string)
    [1, "PaperSize", "A4",
     1, "Orientation", "Vertical",
     1, "Colour", "False",
     2, "PaperSize", "A3",
     2, "Orientation", "Vertical",
     2, "Colour", "False",
     3, "PaperSize", "A4",
     3, "Orientation", "Horizontal",
     3, "Colour", "True"];
settings
| evaluate pivot(SettingName)
Run Code Online (Sandbox Code Playgroud)

我期望 3 行,每个位置一行,以及每个设置(纸张大小、方向、颜色)和位置的一列。但我最终得到了九行和没有多大意义的数据。我想要得到的输出是:


+----------+-----------+-------------+--------+
| Location | PaperSize | Orientation | Colour |
+----------+-----------+-------------+--------+
|        1 | A4        | Vertical    | False  |
|        2 | A3        | Vertical    | False  |
|        3 | A4        | Horizontal  | True …
Run Code Online (Sandbox Code Playgroud)

azure-log-analytics kql azure-data-explorer

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