public override void DoWork(IlluminateDatabase database) { var status = "success"; logger.Information("RefreshUserState started"); foreach (var orgdb in database.GetAllOrgStores()) { logger.Information("RefreshUserState on {0}", orgdb); try { RefreshUserStateFor(orgdb); } catch (Exception ex) { logger.Exception(ex); status = "errors"; } } logger.Information("RefreshUserState completed with {0}", status); }
protected override void OnApplicationStarted() { //hook into the fed auth config created event do we can do some extra steps FederatedAuthentication.FederationConfigurationCreated += FederatedAuthentication_FederationConfigurationCreated; XmlConfigurator.Configure(); //configure logging Logger = LogManager.GetLogger("Illuminate"); Logger.Information("Illuminate Web Application Started"); AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteTable.Routes.MapHubs(); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Logger.Information("About to create master store when starting Illuminate"); DataBase = IlluminateDatabase.Create(new DocumentStore { ConnectionStringName = "RavenServer" }); Logger.Information("Created master store when starting Illuminate"); Mappings.Initialise(); BinderConfig.RegisterBinders(); var accountRepoStore = new DocumentStore {ConnectionStringName = "RavenServer"}; accountRepoStore.Initialize(); var accountRepo = new RavenUserAccountRepository(accountRepoStore); UserAccountService = new UserAccountService(accountRepo) { Configuration = MembershipRebootConfig.Create() }; RebootAuthenticationService = new SamAuthenticationService(UserAccountService); //in DEBUG mode attach raven profiler so we can profile all org stores if needed #if DEBUG foreach (var store in DataBase.GetAllOrgStores().Where(store => store.Identifier.EndsWith("halethorpe"))) { Raven.Client.MvcIntegration.RavenProfiler.InitializeFor(store); } //Raven.Client.MvcIntegration.RavenProfiler.InitializeFor(DataBase.MasterStore); #endif //task manager does some stuff as background processes Logger.Information("about to initialize taskmanager when starting Illuminate"); TaskManager.Initialize(new IlluminateRegistry()); Logger.Information("Initialized taskmanager when starting Illuminate"); }
public void DoWork(IlluminateDatabase database,IEmailSender emailSender) { Logger.Information("EmailDailyTasks started"); //we need to get a list of tasks that are Overdue, duetoday or due tomorrow. foreach (var db in database.GetAllOrgStores()) { Currentstore = db; List<User> users; using (var session = db.OpenSession()) { users = session.Query<User>().ToList(); } //get the tasks etc for this user. foreach (var user in users) { Currentuser = user; //set culture Thread.CurrentThread.CurrentCulture = user.Culture; var bodyBuilder = new StringBuilder(); using (var session = db.OpenSession()) //smaller sessions { var targetuser = user; var tasks = session.Query<Task>() .Where( x => x.ConsolidatedAssignees.Any(a => a.UserId == targetuser.Id) && x.DueDate <= DateTime.Today.AddDays(3) && x.CompletedDate == null); var meetings = session.Query<Meeting>() .Where( x => x.Invitees.Any(i => i.UserId == targetuser.Id) && x.DueDate <= DateTime.Today.AddDays(3) && x.DueDate >= DateTime.Today); var items = new List<TimelineItem>(); items.AddRange(tasks.ToList().ToTimelineItems()); items.AddRange(meetings.ToList().ToTimelineItems()); Logger.Information("{0} items for {1}", items.Count, targetuser.Name); var sectionbuilder = new StringBuilder(); if (items.Count > 0) { var overduelines = (from i in items where i.start.Date < DateTime.Today orderby i.start ascending select FormatItem(i)); sectionbuilder.AppendLine(SubHeader("Overdue tasks")); if (overduelines.Any()) { sectionbuilder.Append(String.Join("\n", overduelines.ToList())); } else { sectionbuilder.AppendLine("No items to show<br/>"); } sectionbuilder.AppendLine("<br/>"); var todaylines = (from i in items where i.start.Date == DateTime.Today orderby i.start ascending select FormatItem(i)); sectionbuilder.AppendLine(SubHeader("Today's tasks")); if (todaylines.Any()) { sectionbuilder.Append(String.Join("\n", todaylines.ToList())); } else { sectionbuilder.AppendLine("No items to show<br/>"); } sectionbuilder.AppendLine("<br/>"); var futurelines = (from i in items where i.start.Date > DateTime.Today orderby i.start ascending select FormatItem(i)); sectionbuilder.AppendLine(SubHeader("Upcoming tasks")); if (futurelines.Any()) { sectionbuilder.Append(String.Join("\n", futurelines.ToList())); } else { sectionbuilder.AppendLine("No items to show<br/>"); } } //TODO: Add Insights //TODO: Add Messages //render section bodyBuilder.Append(Email.WrapSection(sectionbuilder.ToString())); //clear section builder. sectionbuilder.Clear(); //TODO: Add KPIs if (targetuser.CanManageOthers) //TODO: no point if they don't have any managees. { //TODO: Add Team KPIs //TODO: Add Team HIG } var stuffToSend = (targetuser.EmailAddress == "*****@*****.**"); //Done if (stuffToSend)//only send if stuff to send? { var email = new Email(); email.To.Add(new EmailRecipient { Name = targetuser.Name, Email = targetuser.EmailAddress }); const string headertemplate = "<table style='text-align:left;width:100%;padding:0px; margin-top:0px;' cellpadding='0' cellspacing='0'><tr><td style='width:0px;'>{0} </td><td style='font-family: Helvetica,Arial,sans-serif; line-height: 1.3; text-decoration: none; font-size: 18px; font-weight: bold; color: #FFF; padding: 0'>{1}</td></tr></table>"; var headername = new StringBuilder(); headername.AppendLine(targetuser.Name + "<br/>"); headername.AppendLine(String.Format("<div style='font-size:14px;'>{0}</div>", DateTime.Today.ToShortDateString())); var headeravatar = String.Format(AvatarImageString, ImageHelper.GetAvatarUrl(user.Avatar.PublicID, 50), user.Name); email.Subject = "Your Illuminate Daily Update"; email.Body = Email.WrapBody(HostName, "Illuminate Daily Update", String.Format(headertemplate, headeravatar, headername), bodyBuilder.ToString()); emailSender.Send(email); } } } } }