小编Gri*_*der的帖子

如何限制并发异步I/O操作的数量?

// let's say there is a list of 1000+ URLs
string[] urls = { "http://google.com", "http://yahoo.com", ... };

// now let's send HTTP requests to each of these URLs in parallel
urls.AsParallel().ForAll(async (url) => {
    var client = new HttpClient();
    var html = await client.GetStringAsync(url);
});
Run Code Online (Sandbox Code Playgroud)

这是问题所在,它会同时启动1000多个Web请求.有没有一种简单的方法来限制这些异步http请求的并发数量?这样在任何给定时间都不会下载超过20个网页.如何以最有效的方式做到这一点?

c# asynchronous task-parallel-library async-await async-ctp

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

使用T-SQL生成MD5哈希字符串

有没有办法生成类型为varchar(32)的MD5哈希字符串,而不使用fn_varbintohexstr

SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', 'email@dot.com')), 3, 32)
Run Code Online (Sandbox Code Playgroud)

所以它可以在带有SCHEMABINDING的视图中使用

t-sql sql-server sql-server-2008

92
推荐指数
6
解决办法
22万
查看次数

统一成本搜索和Dijkstra算法之间有什么区别?

我想知道统一成本搜索Dijkstra算法之间有什么区别.它们似乎是相同的算法.

artificial-intelligence graph

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

为什么DbContext没有实现IDbContext接口?

为什么IDbContext实体框架中没有接口?如果现有的接口有类似SaveChanges()等的方法来测试,那么你可以从中导出自定义数据库上下文接口吗?

public interface ICustomDbContext : IDbContext
{
    // add entity set properties to existing set of methods in IDbContext
    IDbSet<SomeEntity> SomeEntities { get; }
}
Run Code Online (Sandbox Code Playgroud)

testing unit-testing entity-framework moq mocking

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

如何从ModelState键中删除前缀?

例如,有一个Web Api动作方法:

public HttpMessageResponse Post(UserDto userDto)
{
    if (!this.ModelState.IsValid)
    {
        return this.Request.CreateErrorResponse(
            HttpStatusCode.BadRequest, this.ModelState);
    }

    // ...
}
Run Code Online (Sandbox Code Playgroud)

客户端发送以下请求:

HTTP POST: /api/user
{ "username": "me", "password": "Pa$sw0rd" }
Run Code Online (Sandbox Code Playgroud)

得到回应:

HTTP 201/Created:
{ "message": "Your request is invalid.",
  "modelState": { "userDto.Password": "Your password is too strong." } }
Run Code Online (Sandbox Code Playgroud)

默认情况下,action方法通过在模型错误前加上action方法中使用的参数名称来公开实现细节.如果客户端应用程序在清理模型错误时硬编码此前缀名称,然后服务器端代码更改(例如,您更换了Post(UserDto userDto)签名Post(UserDto dto))并且所有客户端应用程序停止工作,该怎么办?

这就是为什么你需要确保在服务器端删除这个前缀.问题是,如何正确地做到这一点,而不会使事情复杂化.例如,您可以创建自定义序列化程序并在序列化期间删除这些前缀.但是为了做到这一点,你需要知道模型参数的名称,调用代码可能看起来像这样:

public HttpMessageResponse Post(UserDto userDto)
{
    if (!this.ModelState.IsValid)
    {
        return this.Request.CreateCustomErrorResponse(
            HttpStatusCode.BadRequest, this.ModelState, modelName: "userDto");
    }

    // ...
}
Run Code Online (Sandbox Code Playgroud)

.net asp.net-web-api

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

如何根据最佳实践在C#4中创建异步方法?

请考虑以下代码段:

public static Task<string> FetchAsync()
{
    string url = "http://www.example.com", message = "Hello World!";

    var request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = WebRequestMethods.Http.Post;

    return Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream, request.EndGetRequestStream, null)
        .ContinueWith(t =>
        {
            var stream = t.Result;
            var data = Encoding.ASCII.GetBytes(message);
            Task.Factory.FromAsync(stream.BeginWrite, stream.EndWrite, data, 0, data.Length, null, TaskCreationOptions.AttachedToParent)
                .ContinueWith(t2 => { stream.Close(); });
        })
        .ContinueWith<string>(t =>
        {
            var t1 =
                Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null)
                .ContinueWith<string>(t2 =>
                {
                    var response = (HttpWebResponse)t2.Result;
                    var stream = response.GetResponseStream();
                    var buffer = new byte[response.ContentLength > 0 ? response.ContentLength : 0x100000]; …
Run Code Online (Sandbox Code Playgroud)

c# parallel-processing task

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

如何在.csproj文件中设置MSDeploy设置

有没有办法在ASP.NET MVC项目的.csproj文件中设置MSDeploy参数?特别是"skip"参数,它应该跳过"Temp"文件夹.

-skip:objectName=dirPath,absolutePath="\\temp"
Run Code Online (Sandbox Code Playgroud)

..或者如何将此参数传递到MSBuild.exe参数列表?

c# asp.net deployment msdeploy asp.net-mvc-3

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

如何在ASP.NET Web Api中从绑定中排除某些属性

如何排除某些属性,或明确指定Web Api模型绑定器应绑定哪些模型属性?类似于CreateProduct([Bind(Include = "Name,Category") Product product)ASP.NET MVC的东西,没有创建另一个模型类,然后从原始模型复制它的所有验证属性.

// EF entity model class
public class User
{
    public int Id { get; set; }       // Exclude
    public string Name { get; set; }  // Include
    public string Email { get; set; } // Include
    public bool IsAdmin { get; set; } // Include for Admins only
}

// HTTP POST: /api/users | Bind Name and Email properties only
public HttpResponseMessage Post(User user)
{
    if (this.ModelState.IsValid)
    {
        return this.Request.CreateErrorResponse(this.ModelState);
    } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc asp.net-web-api asp.net-web-api2

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

将SQLite数据库文件放在Azure App Service中的位置?

问题1:您认为在Azure Web App文件系统中放置SQLite数据库文件(database.sqlite)的正确位置在哪里?例如:

  1. D:\home\data\database.sqlite
  2. D:\home\site\database.sqlite
  3. D:\home\site\wwwroot\database.sqlite
  4. 其他?

Q2:为了确保公共用户无法访问数据库文件以及在部署期间或应用程序按比例放大/缩小时不会被意外覆盖,还应考虑哪些因素?(Web App配置为从本地Git存储库进行部署)

问题3:在哪里可以了解有关Azure App Service中使用的文件系统的更多信息,官方源URL?例如,它是如何在单个Web应用程序中的多个VM之间共享的,当应用程序按比例放大/缩小时它是如何工作的,D:\home(持久性)与D:\local(非持久性)之间有什么区别......

请注意,SQLiteAzure Blob存储中不起作用,因此不能选择.请不要建议替代存储解决方案,这个问题具体是关于SQLite的.

参考

database sqlite azure azure-web-sites

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

如何从Visual Studio 2012检测到的更改列表中排除某些文件夹?

在Visual Studio 2012 /团队资源管理器/待定更改中,有一个指向解决方案中检测到的更改的文件列表的链接.

如何使Visual Studio不检测_ReSharper.*Packages文件夹中的挂起更改?

在此输入图像描述

.net visual-studio team-explorer visual-studio-2012

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