예제 #1
0
        public async Task OnResourceExecutionAsync(ResourceExecutingContext before, ResourceExecutionDelegate next)
        {
            var modifying = false;

            if (before.ActionDescriptor is ControllerActionDescriptor action)
            {
                modifying = action.MethodInfo.GetCustomAttributes <DatabaseUpdateAttribute>().Any();
            }

            if (modifying)
            {
                using (var handle = await access.Write())
                {
                    var after = await next();

                    var status = after.HttpContext.Response.StatusCode;

                    if (status < 400)
                    {
                        await SaveChanges(handle);
                    }
                }
            }
            else
            {
                using (await access.Read())
                {
                    await next();
                }
            }
        }
예제 #2
0
        public override async Task Submit(IContextLock access)
        {
            if (pairing.Type != PairingType.Manual)
            {
                throw new InvalidEnumArgumentException("CreateManualPairs: pairing");
            }

            using (var handle = await access.Write())
            {
                entries.Entry(pairing)
                .LoadRelations(p => p.Pairs)
                .LoadRelations(p => p.World.Members, m => m.Pairs1)
                .LoadRelations(p => p.World.Members, m => m.Pairs2)
                .LoadRelations(p => p.World.Pairs)
                .LoadRelations(p => p.World.BackupUser);

                foreach (var pair in pairing.Pairs)
                {
                    emails.Send(Emails.PairingReceiver, pair);
                    emails.Send(Emails.PairingInitiator, pair);
                }

                pairing.IsComplete = true;

                await handle.Finish();
            }
        }
예제 #3
0
        public override async Task Submit(IContextLock access)
        {
            using (var handle = await access.Write())
            {
                var repo = pairings.Pairs(pairing);

                foreach (var pair in pairs)
                {
                    pair.Outcome = PairOutcome.Unknown;

                    repo.Add(pair);

                    emails.Send(Emails.PairingReceiver, pair);
                    emails.Send(Emails.PairingInitiator, pair);
                }

                foreach (var member in optOuts)
                {
                    member.OptOut = false;

                    emails.Send(Emails.OptOut, member);
                }

                if (unpaired != null)
                {
                    if (pairing.World.BackupUser != null)
                    {
                        emails.Send(Emails.PairingInitiator, unpaired, pairing.World.BackupUser);
                        emails.Send(Emails.PairingReceiver, unpaired, pairing.World.BackupUser);
                    }
                    else
                    {
                        emails.Send(Emails.UnpairedMember, unpaired);
                    }
                }

                pairing.IsComplete = true;

                await handle.Finish();
            }
        }
예제 #4
0
        public async Task Flush(int maxMillis)
        {
            var timer = new Stopwatch();

            timer.Start();

            while (timer.ElapsedMilliseconds < maxMillis)
            {
                var email = await Next();

                if (email == null)
                {
                    break;
                }

                var mime = new MailMessage {
                    Subject    = email.Subject,
                    IsBodyHtml = true,
                    Body       = email.Body,
                    From       = new MailAddress(options.Smtp.Email, options.Smtp.Name),
                };

                foreach (var recipient in email.Recipients)
                {
                    mime.To.Add(new MailAddress(recipient.Address.Value, recipient.Name.Value));
                }

                Send(mime);

                using (var handle = await access.Write())
                {
                    email.IsSent = true;
                    email.Sent   = DateTime.UtcNow;
                    await handle.Finish();
                }
            }
        }