我正在尝试使这段代码工作:
protected async Task RunIsolated<TServ1, TServ2>(Action<TServ1, TServ2> action)
{
await RunInScope(action, typeof(TServ1), typeof(TServ2));
}
protected async Task<TResult> RunIsolatedForResult<TService, TResult>(Func<TService, TResult> func)
{
return (TResult) await RunInScope(func, typeof(TService));
}
private Task<object> RunInScope(Delegate d, params object[] args)
{
using (var scope = _serviceProvider.CreateScope())
{
object[] parameters = args.Cast<Type>().Select(t => scope.ServiceProvider.GetService(t)).ToArray();
return Task.FromResult(d.DynamicInvoke(parameters));
}
}
Run Code Online (Sandbox Code Playgroud)
这项工作用于同步版本的代码,如下所示:
await RunIsolated<Service>(serv => serv.SaveAsync(item).Wait());
Run Code Online (Sandbox Code Playgroud)
但是对于相同代码的异步版本,不起作用(db操作抛出异常)
await RunIsolated<Service>(async serv => await serv.SaveAsync(item));
Run Code Online (Sandbox Code Playgroud)
是它在某种程度上可能转换异步Action或Func到Delegate并调用它没有松动的异步状态?
我需要有功能,允许我序列化Map<CustomType1, CustomType2>.我创建了继承自JsonSerializer的自定义Serializer.我也创建了简单的模块并在我的mapper中注册它;
SimpleModule myModule = new SimpleModule("myModule");
myModule.addKeySerializer(CustomType1.class, new CustomType1Serializer());
myModule.addSerializer(CustomType1.class, new CustomType1Serializer());
mapperInstance.registerModule(myModule);
Run Code Online (Sandbox Code Playgroud)
当我只是序列化CustomType1的一个实例时它工作得很好,但是当我创建map并尝试序列化它时,jackson跳过我的序列化器并使用它StdKeySerializer.怎么解决???
感谢您的关注.
我正在尝试使用基本表单身份验证实现ASP.NET MVC5应用程序.所以有我的登录方法:
[HttpPost]
[AllowAnonymous]
public ActionResult Login(string email, string password, bool? rememberMe)
{
if (email.IsNullOrWhiteSpace() || password.IsNullOrWhiteSpace())
{
return RedirectToAction("Index");
}
UserEntity user = new UserEntity() {Email = email, PasswordHash = password};
var userFromDb = _userService.FindUser(user);
if (userFromDb != null)
{
FormsAuthentication.SetAuthCookie(userFromDb.Name, rememberMe.GetValueOrDefault());
var a = HttpContext.User.Identity.IsAuthenticated; //This is still false for some reson
return RedirectToAction("Index", "User");
}
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
但是在重定向这个方法后,它给了我401 Unauthorized错误.似乎也像HttpContext.User.Identity.IsAuthenticated是假的.
你有什么想法/建议为什么会这样,以及如何解决它?
UPD:我也有来自auth的行webconfig概念,所以这不是原因
<authentication mode="Forms">
<forms loginUrl="~/Login/Index" />
</authentication>
我在 Ubuntu 16.04 上的 Nginx 后面托管了一个 asp.net net core 2.0 应用程序。
我的设置看起来像这样:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
...
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-Proto-Version $http2;
client_max_body_size 32m;
keepalive_timeout 200;
send_timeout 20;
client_body_timeout 50;
}
}
Run Code Online (Sandbox Code Playgroud)
我也有这些设置 Startup.cs
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto
});
Run Code Online (Sandbox Code Playgroud)
但仍然每次当我试图得到HttpContext.Connection.RemoteIpAddress它的回报127.0.0.1
我应该怎么做才能解决这个问题并获得真实的 IP 地址?
我有一个标记:
<table cellpadding="0" cellspacing="0" class="table_report_line">
<tbody>
<tr>
<td>
<div class="dvlefttable">
</div>
</td>
<td class="dvtoptable" colspan="4" width="100%">
Test
</td>
<td>
<div class="dvrighttable">
</div>
</td>
</tr>
<tr>
<canvas id="chartId" width="400" height="400" style="margin: 30px;">
</canvas>
</tr>
<tr>
<td>
</td>
<td colspan="4">
<br style="line-height: 15px;" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="6" class="bg_bottom_table">
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
但是当Firefox渲染页面时,我看到它将画布放在桌子外面
<canvas id="chartId" style="margin: 30px;" height="400" width="400"> </canvas>
<table cellspacing="0" cellpadding="0" class="table_report_line">
<tbody>
<tr>
<td class="">
<div class="dvlefttable">
</div>
</td>
<td width="100%" colspan="4" class="dvtoptable">
Test
</td> …Run Code Online (Sandbox Code Playgroud) 我有一个任务
def task():
a = worker()
a.do_some_work()
Run Code Online (Sandbox Code Playgroud)
Worker本身是一个单独的类,在单独的模块中,谁使用这样的Driver类,
class Worker(object):
def __init__(self):
self.driver = Driver(args)
...
Run Code Online (Sandbox Code Playgroud)
并且再次Driver是单独模块中的单独类
所以,当我尝试类似的东西
with patch('package.module.Driver', new=Mock(return_value=999)):
task()
Run Code Online (Sandbox Code Playgroud)
在任务中仍然有一个Driver类实例,但不是模拟.那是错的.如何解决?
UPD1:
Driver与Worker住在不同的模块和Worker进口Driver
我使用一些JavaScript库来绘制图表.它需要将带坐标的数组传递给图表初始值设定项.但是图表初始化函数的签名看起来像新函数([arr1],[arr2],[arr3]),但我不知道我将传入多少数组,但不可能以另一种方式初始化它.怎么可能解决这个问题?谢谢.
UPD:调用的函数是构造函数,因此使用apply无法正常工作.问题是如何传递数据,而不是如何获取传递数据的计数
是否可以在C#中创建通用限制,使用where仅选择具有某个名称的Field的类.
例如,我AbstractService<T>
有一个方法IEnumerable<T> ProvideData(userId);
在内部提供数据我应该只选择具有相同用户bla-bla-bla.Where的实例(d => d.UserId == userId).但是d.UserId无法解决.怎么可能解决这个问题?
重要提示:我无法从具有UserID字段的类或接口继承T.
我从现有数据库中消耗数据.这个数据库存储系统事件.我的服务应该通过计时器检查这个数据库,检查是否创建了一些新事件,然后上传并处理.像简单的队列实现.
问题是 - 每次检查数据库时,我怎样才能获得新的文档.我无法使用时间戳,因为事件从不同的源传递到数据库,并且没有任何事件顺序.所以我只需要使用插入顺序.
var v1 = _questionRepository.GetQuery().Where(q =>
q.EvaluationGroupId == evaluationGroupId &&
((q.TopicValue == questionTopic &&
q.Index > currentQuestionIndex) ||
(q.TopicValue > (questionTopic) &&
q.Index >= 0 && q.Id != currentQuestionIndex)))
.OrderBy(q => q.Index).OrderBy(a => a.TopicValue).FirstOrDefault();
var v2 = _questionRepository.GetQuery().Where(q =>
q.EvaluationGroupId == evaluationGroupId &&
((q.TopicValue == questionTopic &&
q.Index > currentQuestionIndex) ||
(q.TopicValue > (questionTopic) &&
q.Index >= 0 && q.Id != currentQuestionIndex)))
.OrderBy(q => q.Index).OrderBy(a => a.TopicValue).ToList().FirstOrDefault()
Run Code Online (Sandbox Code Playgroud)
v1 != v2 ENTITIES不同 如何可能?(db中的数据相同)
存储库与EF实体一起运行
我需要实现SVM数字分类器的概念.它应该是我在画布中写入的分类输入的简单.但我需要从头开始实施.语言并不重要.
任何人都可以一步一步地指导我如何做到这一点.任何材料链接都会有所帮助.但我需要一些与实践相关的东西而不是理论.因为我已经阅读了一些关于它的理论文章.并且有基本的想法它应该如何工作,但仍然有一些麻烦如何将这些想法转换为现实生活中的例子.
非常感谢.
c# ×4
.net ×2
asp.net-core ×1
asp.net-mvc ×1
async-await ×1
asynchronous ×1
canvas ×1
delegates ×1
generics ×1
html ×1
html-table ×1
html5 ×1
http2 ×1
inheritance ×1
ip-address ×1
jackson ×1
java ×1
javascript ×1
json ×1
linq ×1
mongodb ×1
nginx ×1
parameters ×1
python ×1
python-2.7 ×1
python-mock ×1
svm ×1
unit-testing ×1