public IList <Email> GetEmailsBy(string sender, string recipient, EmailState state, int maxTryTime, bool immediatelyMailOnly, int pageIndex, int pageSize, out int recordCount) { Conditions conditions = new Conditions(); if (sender != null && sender != "") { conditions.ConditionExpressions.Add(new Condition("Sender", Operator.Like, sender)); } if (recipient != null && recipient != "") { conditions.ConditionExpressions.Add(new Condition("Recipients", Operator.Like, recipient)); } conditions.ConditionExpressions.Add(new Condition("State", Operator.EqualTo, state)); if (maxTryTime != -1) { conditions.ConditionExpressions.Add(new Condition("TryTime", Operator.SmallerOrEqualTo, maxTryTime)); } if (immediatelyMailOnly) { conditions.ConditionExpressions.Add(new Condition("NextTryTime", Operator.SmallerOrEqualTo, DateTime.Now)); } conditions.Connector = Connector.AND; OrderExpression orderExpression = new OrderExpression("Priority", false); return(this.dbGateway.getRecords(pageIndex, pageSize, conditions, orderExpression, null, Connector.AND, out recordCount)); }
internal User(Guid id, string email, string passwordHash) { Id = id; Email = email ?? throw new ArgumentNullException(nameof(email)); PasswordHash = passwordHash ?? throw new ArgumentNullException(nameof(passwordHash)); CreateDate = DateTime.UtcNow; EmailState = EmailState.Unconfirmed; _concurrencyToken = Guid.NewGuid(); }
public void Confirm() { if (EmailState != EmailState.Unconfirmed) { throw new UserEmailAlreadyConfirmedException(); } EmailState = EmailState.Confirmed; _concurrencyToken = Guid.NewGuid(); }
public virtual void EnqueueEmailToBeSent(string fromAddress, HashSet <Recipient> recipients, string subject) { Guard.Hope(State.CanSend, "cannot enqeue email in the current state: " + State.Name); Guard.Hope(_emailRecipients.Count == 0, "recipients must be empty"); State = EmailState.ToBeSent; FromAddress = fromAddress; Subject = subject; recipients.Each(r => _emailRecipients.Add(new EmailRecipient(this, r))); DomainEvents.RaiseEvent(new EmailEnqueuedToBeSentDomainEvent { EmailId = Id }); }
public EmailItem( Guid key, DateTime createdAt, EmailState state, DateTime?deliveredAt, string text, Email dstAddress, string subject) { Key = key; CreatedAt = createdAt; State = state; DeliveredAt = deliveredAt; Text = text; DstAddress = dstAddress; Subject = subject; }
public EmailBuilder WithState(EmailState state) { _state = state; return(this); }
public Email GetById(int emailId) { EmailState emailState = _context.Emails.Single(x => x.Id == emailId); return(new Email(emailState)); }
internal Email(EmailState state) { this.State = state; }
public async Task Handle(HandlerContext <TCommand> context) { (string key, int rate, int perSeconds) = GetRate(context); // check cache if (CurrentHttpContext.Instance().Cache.Get(key) is not RateLimit cacheItem) { cacheItem = RateLimit.Create(key, 1, rate, perSeconds); Logger.InfoFormat( "add {key} to cache: {@cacheItem}", key, cacheItem); CurrentHttpContext.Instance().Cache.Insert( key, cacheItem, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, (key, item, reason) => Logger.InfoFormat( "cache item '{key}' removed due to '{reason}'", key, reason)); } // check database KeyValueProperty?rateLimitProperty = await CompositionRoot.Databases.Snittlistan.KeyValueProperties .SingleOrDefaultAsync(x => x.Key == key); if (rateLimitProperty == null) { KeyValueProperty keyValueProperty = new( context.Tenant.TenantId, key, RateLimit.Create(key, 1, rate, perSeconds)); rateLimitProperty = CompositionRoot.Databases.Snittlistan.KeyValueProperties.Add(keyValueProperty); } else { rateLimitProperty.ModifyValue <RateLimit>( r => r.SetRate(rate).SetPerSeconds(perSeconds), x => Logger.InfoFormat("before: {@x}", x), x => Logger.InfoFormat("after: {@x}", x)); } DateTime now = DateTime.Now; rateLimitProperty.ModifyValue <RateLimit>( x => x.UpdateAllowance(now), x => Logger.InfoFormat("before: {@x}", x), x => Logger.InfoFormat("after: {@x}", x)); _ = cacheItem.UpdateAllowance(now); double allowance = rateLimitProperty.GetValue <RateLimit, double>(x => x.Allowance); if (allowance < 1 || cacheItem.Allowance < 1) { string message = $"(db) allowance = {allowance:N2}, (cache) allowance = {cacheItem.Allowance:N2}, wait to reach 1"; throw new HandledException(message); } TEmail email = await CreateEmail(context); EmailState state = email.State; _ = CompositionRoot.Databases.Snittlistan.SentEmails.Add(new( email.From, email.To, email.Bcc, email.Subject, state)); Logger.InfoFormat("sending email {@email}", email); await CompositionRoot.EmailService.SendAsync(email); rateLimitProperty.ModifyValue <RateLimit>( x => x.DecreaseAllowance(), x => Logger.InfoFormat("before: {@x}", x), x => Logger.InfoFormat("after: {@x}", x)); _ = cacheItem.DecreaseAllowance(); }
public static Email ToEmail(EmailState state) { return(new Email(state)); }