public void OnAfterDeploy(IEnumerable <IEntity> entities, IDictionary <string, object> state) { // we need to create our own scheduler so we can shut it down after deployment. If we don't do this then during installation // error messages will appear in the log. var scheduler = SchedulingHelper.Instance; var tenant = RequestContext.GetContext().Tenant; var tenantName = tenant.Name; ISet <string> solutionAliases = new HashSet <string>(); foreach (IEntity entity in entities) { var solution = entity.Cast <Solution>(); if (solution != null && !string.IsNullOrWhiteSpace(solution.Alias)) { solutionAliases.Add(solution.Alias); } foreach (var schedItem in Entity.GetInstancesOfType <ScheduledItem>(true, "inSolution.isOfType.id")) // ok to use this rather than a report as there are unlikely to be many inboxes in the system { if (solution != null && schedItem.InSolution != null && schedItem.InSolution.Id == solution.Id) { EventLog.Application.WriteTrace(string.Format("Post install updating updating ScheduledItems '{0}' in Tenant '{1}'.", schedItem.Name, tenantName)); SchedulingSyncHelper.UpdateScheduledJob(schedItem, scheduler); } } } ResyncSchedulesForGlobalTenant(solutionAliases, scheduler); scheduler.Shutdown(true); // We need to shutdown the scheduler otherwise deployment won't complete }
/// <summary> /// Resync the schedules for the global tenant. /// </summary> /// <param name="solutionAliases"></param> /// <param name="scheduler"></param> private void ResyncSchedulesForGlobalTenant(ISet <string> solutionAliases, Quartz.IScheduler scheduler) { if (solutionAliases.Count == 0) { return; } using (new GlobalAdministratorContext()) { foreach (var schedItem in Entity.GetInstancesOfType <ScheduledItem>(true, "inSolution.{isOfType.id, alias}, isOfType.{systemTenantOnly}")) { var itemSolutions = new List <string>(); if (schedItem.InSolution != null) { itemSolutions.Add(schedItem.InSolution.Alias); } if (solutionAliases.Overlaps(itemSolutions) && schedItem.IsOfType.Any(t => t.SystemTenantOnly ?? false)) { EventLog.Application.WriteTrace(string.Format("Post install updating updating ScheduledItems '{0}' in Global Tenant.", schedItem.Name)); SchedulingSyncHelper.UpdateScheduledJob(schedItem, scheduler); } } } }
/// <summary> /// Called after saving of the specified enumeration of entities has taken place. /// </summary> /// <param name="entities">The entities.</param> /// <param name="state">The state passed between the before save and after save callbacks.</param> public void OnAfterSave(IEnumerable <IEntity> entities, IDictionary <string, object> state) { var changedSchedules = (List <ScheduledItem>)state[ChangedScheduleKey]; foreach (var triggerOnSch in changedSchedules) { SchedulingSyncHelper.UpdateScheduledJob(triggerOnSch, SchedulingHelper.Instance); } }
/// <summary> /// Called after saving of the specified enumeration of entities has taken place. /// </summary> /// <param name="entities">The entities.</param> /// <param name="state">The state passed between the before save and after save callbacks.</param> public void OnAfterSave(IEnumerable <IEntity> entities, IDictionary <string, object> state) { if (entities == null) { return; } foreach (var entity in entities) { var schedule = entity.As <Schedule>(); if (schedule != null) { foreach (var trigger in schedule.TriggersForSchedule) { SchedulingSyncHelper.UpdateScheduledJob(trigger, SchedulingHelper.Instance); } } } }