小编Kor*_*ijn的帖子

如何在Azure Web作业中实例化OWIN IDataProtectionProvider?

我需要一个IDataProtectionProvider使用UserManagerAzure Web Jobs工作者中的Identity Framework生成电子邮件确认令牌的实例:

var confirmToken = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
Run Code Online (Sandbox Code Playgroud)

这会崩溃,因为null IUserTokenProvider<User, int>被传递给UserManager<User, int>on constru.

在MVC应用程序中,实例创建如下:

public class OWINStartup
{
    public void Configuration(IAppBuilder app)
    {
        var dataProtectionProvider = app.GetDataProtectionProvider();
Run Code Online (Sandbox Code Playgroud)

但是,Azure Web Jobs当然没有OWINStartup钩子.有什么建议?

azure owin asp.net-identity azure-webjobs

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

如何处理事件处理程序引发的域事件?

我已经通过jbogard实现了以下模式:

http://lostechies.com/jimmybogard/2014/05/13/a-better-domain-events-pattern/

想象一下以下实体Coupon和事件CouponActivatedEvent:

public class Coupon : DomainEntity
{
    public virtual User User { get; private set; }

    // ...omitted...

    public void Activate(User user)
    {
        if (User != null)
            throw new InvalidOperationException("Coupon already activated");

        User = user;

        Events.Add(new CouponActivatedEvent(this));
    }
}
Run Code Online (Sandbox Code Playgroud)

以下事件处理程序CouponActivatedHandler:

public class CouponActivatedHandler : IDomainEventHandler<CouponActivatedEvent>
{
    public void Handle(CouponActivatedEvent e)
    {
        // user gets 5 credits because coupon was activated
        for (int i = 0; i < 5; i++)
        {
            e.Coupon.User.AddCredit(); // …
Run Code Online (Sandbox Code Playgroud)

c# domain-driven-design entity-framework

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

Django 查询对象以及所有满足条件的相关对象

鉴于这些 Django 模型:

class Job(models.Model):
    pass

class Task(models.Model):
    job = models.ForeignKey('Job', related_name='tasks')
    status = models.CharField(choices=TaskStatus.CHOICES, max_length=30)
    dependencies = models.ManyToManyField("self", related_name="dependents", symmetrical=False)
Run Code Online (Sandbox Code Playgroud)

我想查询单个作业的所有状态为“待处理”的任务以及状态为“已完成”的所有依赖项。

我编写了以下查询,但它返回至少具有一个依赖项且状态已完成的任务,这显然不是我想要的。

tasks_that_can_be_executed = Task.objects.filter(
    job__pk=job_id,
    status=TaskStatus.PENDING,
    dependencies__status=TaskStatus.COMPLETED
)
Run Code Online (Sandbox Code Playgroud)

有什么建议么?

django orm model

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

Windows Azure Queue返回403 Forbidden

使用以下代码(我已经模糊了实际的凭据):

CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(new StorageCredentials(username, key), true);
CloudQueueClient clnt = cloudStorageAccount.CreateCloudQueueClient();

string logQueueReference = "log2";
CloudQueue queue = clnt.GetQueueReference(logQueueReference);

queue.CreateIfNotExists();
Run Code Online (Sandbox Code Playgroud)

生成以下请求:

HEAD /log2?comp=metadata&timeout=90 HTTP/1.1
x-ms-version: 2012-02-12
User-Agent: WA-Storage/2.0.6.0
x-ms-date: Tue, 29 Apr 2014 13:26:29 GMT
Authorization: SharedKey username:transformedkey
Host: username.queue.core.windows.net
Run Code Online (Sandbox Code Playgroud)

并返回以下响应:

HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Transfer-Encoding: chunked
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 0cc84a81-73e1-4a8c-bf16-098af2b21149
Date: Tue, 29 Apr 2014 15:26:29 GMT
Run Code Online (Sandbox Code Playgroud)

我双重检查了凭证.它们是从manage.windowsazure.com的对话框中复制粘贴的.我在这里错过了什么?

message-queue azure

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