private string CreateUpdateTasksAndRunTasksInternal(string action) { string result; int sid = SelectedServerID; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } EventCode = "SYNCHRONIZE"; AddLog(String.Format(GetString("Synchronization.LoggingTasks"), PredefinedObjectType.DOCUMENT)); // Prepare settings for current node var settings = new LogMultipleDocumentChangeSettings { EnsurePublishTask = true, NodeAliasPath = aliasPath, TaskType = TaskTypeEnum.UpdateDocument, ServerID = sid, KeepTaskData = false, RunAsynchronously = false, SiteName = CurrentSiteName }; // Create update task for current node var currentNodeUpdateTask = DocumentSynchronizationHelper.LogDocumentChange(settings); // Create update tasks for subtree or for the whole tree, depends on sync action if (action != SYNCHRONIZE_CURRENT) { settings.NodeAliasPath = action == SYNCHRONIZE_COMPLETE ? "/%" : aliasPath.TrimEnd('/') + "/%"; DocumentSynchronizationHelper.LogDocumentChange(settings); } AddLog(GetString("Synchronization.RunningTasks")); if (action == SYNCHRONIZE_CURRENT) { // Run sync for the current node only result = StagingTaskRunner.RunSynchronization(currentNodeUpdateTask.Select(t => t.TaskID)); } else { // Get all tasks for given path, depends on the sync action and run them string path = action == SYNCHRONIZE_COMPLETE ? "/" : aliasPath; DataSet ds = StagingTaskInfoProvider.SelectDocumentTaskList(CurrentSiteID, SelectedServerID, path, null, "TaskID", -1, "TaskID"); result = StagingTaskRunner.RunSynchronization(ds); } return(result); }
private string CreateUpdateTasksAndRunTasksInternal(string action) { string result; int sid = SelectedServerID; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } EventCode = "SYNCHRONIZE"; AddLog(GetString("Synchronization.LoggingTasks")); // Prepare settings for current node var settings = new LogMultipleDocumentChangeSettings { EnsurePublishTask = true, NodeAliasPath = aliasPath, TaskType = TaskTypeEnum.UpdateDocument, ServerID = sid, KeepTaskData = false, RunAsynchronously = false, SiteName = CurrentSiteName }; // Create update task for current node var currentNodeUpdateTask = DocumentSynchronizationHelper.LogDocumentChange(settings); // Create update tasks for subtree or for the whole tree, depends on sync action if (action != SYNCHRONIZE_CURRENT) { settings.NodeAliasPath = action == SYNCHRONIZE_COMPLETE ? "/%" : aliasPath.TrimEnd('/') + "/%"; DocumentSynchronizationHelper.LogDocumentChange(settings); } AddLog(GetString("Synchronization.RunningTasks")); if (action == SYNCHRONIZE_CURRENT) { // Run sync for the current node only result = StagingHelper.RunSynchronization(currentNodeUpdateTask, SelectedServerID, true, CurrentSiteID, AddLog); } else { // Get all tasks for given path, depends on the sync action and run them string path = action == SYNCHRONIZE_COMPLETE ? "/" : aliasPath; DataSet ds = StagingTaskInfoProvider.SelectDocumentTaskList(CurrentSiteID, SelectedServerID, path, null, "TaskID", -1, "TaskID, TaskTitle"); result = StagingHelper.RunSynchronization(ds, SelectedServerID, true, CurrentSiteID, AddLog); } return result; }
/// <summary> /// Handles the logic of assigning categories to the document. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveToDocumentCategories() { SetPossibleAndSelectedCategories(); // Do check of min/max here // Do check of min/max here if (MinimumCategories > 0 && SelectedCategories.Count() < MinimumCategories) { AddError("Must select at least " + MinimumCategories + " " + (MinimumCategories == 1 ? "category" : "categories")); return; } if (MaximumCategories > 0 && SelectedCategories.Count() > MaximumCategories) { AddError("Can select no more than " + MaximumCategories + " " + (MaximumCategories == 1 ? "category" : "categories")); return; } int DocumentID = ValidationHelper.GetInteger(PageDocument.GetValue("DocumentID"), -1); // Can only do Document/Category if there is a DocumentID on the current object. if (DocumentID > 0) { // Get selected categories, except only those in the possible categories List <int> DocumentCategoryIds = new List <int>(); foreach (var DocCategory in DocumentCategoryInfoProvider.GetDocumentCategories(DocumentID)) { DocumentCategoryIds.Add(DocCategory.CategoryID); } // Find IDs we need to add and remove. List <int> NotSelectedIds = PossibleCategoryIDs.Except(SelectedCategoryIDs).ToList(); List <int> DeselectIds = DocumentCategoryIds.Intersect(NotSelectedIds).ToList(); List <int> SelectIds = SelectedCategoryIDs.Except(DocumentCategoryIds).ToList(); bool CategoriesChanged = false; foreach (int DeselectId in DeselectIds) { DocumentCategoryInfo.Provider.Remove(DocumentID, DeselectId); CategoriesChanged = true; } foreach (int SelectId in SelectIds) { DocumentCategoryInfo.Provider.Add(DocumentID, SelectId); CategoriesChanged = true; } // Page changes require custom logic for staging if (CategoriesChanged && LicenseHelper.CheckFeature(Request.Url.AbsoluteUri, FeatureEnum.Staging)) { TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); List <ServerInfo> targetServers = ServerInfo.Provider.Get().Where(x => x.ServerSiteID == SiteContext.CurrentSiteID && x.ServerEnabled).ToList(); foreach (ServerInfo targetServer in targetServers) { var docObj = DocumentHelper.GetDocument(DocumentID, tree); var settings = new LogMultipleDocumentChangeSettings() { EnsurePublishTask = true, NodeAliasPath = docObj.NodeAliasPath, TaskType = TaskTypeEnum.UpdateDocument, ServerID = targetServer.ServerID, KeepTaskData = false, RunAsynchronously = false, SiteName = docObj.Site.SiteName }; // Logs parent task, which will run through the task on insert event and do the same check. var currentNodeUpdateTask = DocumentSynchronizationHelper.LogDocumentChange(settings); } } AddConfirmation(string.Format("{0} Categories Added, {1} Categories Removed.", SelectIds.Count, DeselectIds.Count)); } }
/// <summary> /// Internal method for synchronizing current document. /// </summary> /// <param name="parameter">Parameter</param> /// <param name="eventCodeForLog">Event code to set</param> /// <param name="finalizeEventLog">Indicates whether to finalize eventlog</param> /// <returns>Result of synchronization</returns> private string SynchronizeCurrentInternal(object parameter, string eventCodeForLog, bool finalizeEventLog) { string result = string.Empty; eventCode = eventCodeForLog; bool finish = ValidationHelper.GetBoolean(parameter, true); CanceledString = GetString("Tasks.SynchronizationCanceled"); int sid = serverId; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } AddLog(GetString("Synchronization.LoggingTasks")); try { // Get the tasks var settings = new LogMultipleDocumentChangeSettings() { EnsurePublishTask = true, NodeAliasPath = aliasPath, TaskType = TaskTypeEnum.UpdateDocument, ServerID = sid, KeepTaskData = false, RunAsynchronously = false, SiteName = currentSiteName }; IEnumerable<ISynchronizationTask> tasks = DocumentSynchronizationHelper.LogDocumentChange(settings); AddLog(GetString("Synchronization.RunningTasks")); // Run the synchronization result = StagingHelper.RunSynchronization(tasks, serverId, true, currentSiteId, AddLog); if (finish) { // Log possible error if (!String.IsNullOrEmpty(result)) { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, null); } else { CurrentInfo = GetString("Tasks.SynchronizationOK"); AddLog(CurrentInfo); } } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // Canceled by user CurrentInfo = CanceledString; AddLog(CurrentInfo); } else { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, result); } } catch (Exception ex) { EventLogProvider.LogException("Staging", "SYNCHRONIZE", ex); CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { if (finalizeEventLog) { // Finalize log context FinalizeContext(); } } return result; }
/// <summary> /// Internal method for synchronizing current document. /// </summary> /// <param name="parameter">Parameter</param> /// <param name="eventCodeForLog">Event code to set</param> /// <param name="finalizeEventLog">Indicates whether to finalize eventlog</param> /// <returns>Result of synchronization</returns> private string SynchronizeCurrentInternal(object parameter, string eventCodeForLog, bool finalizeEventLog) { string result = string.Empty; eventCode = eventCodeForLog; bool finish = ValidationHelper.GetBoolean(parameter, true); CanceledString = GetString("Tasks.SynchronizationCanceled"); int sid = serverId; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } AddLog(GetString("Synchronization.LoggingTasks")); try { // Get the tasks var settings = new LogMultipleDocumentChangeSettings() { EnsurePublishTask = true, NodeAliasPath = aliasPath, TaskType = TaskTypeEnum.UpdateDocument, ServerID = sid, KeepTaskData = false, RunAsynchronously = false, SiteName = currentSiteName }; IEnumerable <ISynchronizationTask> tasks = DocumentSynchronizationHelper.LogDocumentChange(settings); AddLog(GetString("Synchronization.RunningTasks")); // Run the synchronization result = StagingHelper.RunSynchronization(tasks, serverId, true, currentSiteId, AddLog); if (finish) { // Log possible error if (!String.IsNullOrEmpty(result)) { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, null); } else { CurrentInfo = GetString("Tasks.SynchronizationOK"); AddLog(CurrentInfo); } } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // Canceled by user CurrentInfo = CanceledString; AddLog(CurrentInfo); } else { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, result); } } catch (Exception ex) { EventLogProvider.LogException("Staging", "SYNCHRONIZE", ex); CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { if (finalizeEventLog) { // Finalize log context FinalizeContext(); } } return(result); }
/// <summary> /// Prepares staging update tasks for documents by given event code and run all tasks /// update, delete, create etc. on given subtree. /// </summary> /// <param name="eventCode">Which action has been chosen and what tasks should be created.</param> private void CreateUpdateTasksAndRunTasks(string eventCode) { string result = null; CanceledString = GetString("Tasks.SynchronizationCanceled"); try { int sid = serverId; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } AddLog(GetString("Synchronization.LoggingTasks")); // Prepare settings for current node var settings = new LogMultipleDocumentChangeSettings() { EnsurePublishTask = true, NodeAliasPath = aliasPath, TaskType = TaskTypeEnum.UpdateDocument, ServerID = sid, KeepTaskData = false, RunAsynchronously = false, SiteName = currentSiteName }; // Create update task for current node var currentNodeUpdateTask = DocumentSynchronizationHelper.LogDocumentChange(settings); // Create update tasks for subtree or for the whole tree, depends on sync action if (eventCode != SYNCHRONIZE_CURRENT) { settings.NodeAliasPath = eventCode == SYNCHRONIZE_COMPLETE ? "/%" : aliasPath.TrimEnd('/') + "/%"; DocumentSynchronizationHelper.LogDocumentChange(settings); } AddLog(GetString("Synchronization.RunningTasks")); if (eventCode == SYNCHRONIZE_CURRENT) { // Run sync for the current node only result = StagingHelper.RunSynchronization(currentNodeUpdateTask, serverId, true, currentSiteId, AddLog); } else { // Get all tasks for given path, depends on the sync action and run them string path = eventCode == SYNCHRONIZE_COMPLETE ? "/" : aliasPath; DataSet ds = StagingTaskInfoProvider.SelectDocumentTaskList(currentSiteId, serverId, path, null, "TaskID", -1, "TaskID, TaskTitle"); result = StagingHelper.RunSynchronization(ds, serverId, true, currentSiteId, AddLog); } // Log possible errors if (!string.IsNullOrEmpty(result)) { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, null); } else { CurrentInfo = GetString("Tasks.SynchronizationOK"); AddLog(CurrentInfo); } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // Canceled by user CurrentInfo = CanceledString; AddLog(CurrentInfo); } else { CurrentError = GetString("Tasks.SynchronizationFailed"); AddErrorLog(CurrentError, result); } } catch (Exception ex) { EventLogProvider.LogException("Staging", "SYNCHRONIZE", ex); CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }