public void SynchroniseOutstanding() { var thisServer = db.Get <MyMood.Domain.MoodServer>().Where(s => s.Name == Configuration.WebConfiguration.ServerName).FirstOrDefault(); if (thisServer != null) { var otherServers = (from s in db.Get <MyMood.Domain.MoodServer>() where s.Id != thisServer.Id && (!s.LastSuccessfulSync.HasValue || s.LastSuccessfulSync.Value.AddMinutes(Configuration.WebConfiguration.ServerSyncIntervalMinutes) < DateTime.UtcNow) select s) .ToArray(); var eventsToSync = (from e in db.Get <Event>() select e) .ToArray(); var client = new HttpClient(); foreach (var otherServer in otherServers) { client.BaseAddress = new Uri(otherServer.BaseAddress); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); foreach (var evt in eventsToSync) { try { var outgoingChanges = this.GetChangesNewerThan(evt, otherServer.LastSuccessfulSync ?? DateTime.MinValue); var response = client.PostAsJsonAsync <DataSyncChangeSet>("api/datasync?eventName=" + evt.Name, outgoingChanges).Result; if (response.IsSuccessStatusCode) { var incomingChanges = response.Content.ReadAsAsync <DataSyncChangeSet>().Result; this.SyncEntityChanges(evt, incomingChanges, null); } else { this.logger.Error(this.GetType(), string.Format("Failed during data sync between {0} and {1} for event {2} - HTTP {3} {4}", thisServer.Name, otherServer.Name, (int)response.StatusCode, response.ReasonPhrase)); } otherServer.LastSuccessfulSync = DateTime.UtcNow; db.Add(new MoodServerSyncReport(thisServer, otherServer, DateTime.UtcNow)); db.SaveChanges(); } catch (Exception ex) { this.logger.Error(this.GetType(), ex, string.Format("Failed during data sync between {0} and {1}", thisServer.Name, otherServer.Name)); } } } } }
public Guid Send(MailMessage message, MailOptions options) { var messageForDispatch = new SentMailMessage(message) { IsSigned = options.Sign, IsEncrypted = options.Encrypt, DeliveryStatus = options.Suspend ? DeliveryStatus.Suspended : DeliveryStatus.Pending, DelayUntil = options.DelayUntil }; db.Add(messageForDispatch); return(messageForDispatch.Id); }
public static User RegisterNewUser(IDomainDataContext db, string userName, string password, string emailAddress, string displayName, bool isApproved, params string[] roleNames) { if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentException("User Name cannot be blank/empty"); } if (db.Get <User>().Any(u => u.UserName.Equals(userName, StringComparison.InvariantCultureIgnoreCase))) { throw new ArgumentException("User Name is already in use"); } if (!string.IsNullOrWhiteSpace(emailAddress) && !emailAddress.IsValidEmailAddress()) { throw new ArgumentException("Email Address does not appear to be valid"); } var user = new User(userName, password, emailAddress, displayName, isApproved); db.Add(user); DomainEvents.Raise(new Events.UserRegistered(user, password)); return(user); }