private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "enabled": return(UniGridFunctions.ColoredSpanYesNo(parameter, true)); case "scope": { string types = ValidationHelper.GetString(parameter, ""); var typeList = TypeHelper.GetTypes(types); if (typeList.Count == 0) { return(GetString("general.selectall")); } string list = ""; typeList.ForEach(s => list += ResHelper.GetString(ResHelper.GetAPIString(TypeHelper.GetTasksResourceKey(s), s)) + ", "); return(list.Trim().TrimEnd(',')); } } return(parameter); }
/// <summary> /// Deletes selected tasks. /// </summary> protected void DeleteSelected(object parameter) { if (parameter == null) { return; } eventCode = "DELETESELECTEDDATA"; ArrayList list = (ArrayList)parameter; CanceledString = GetString("Tasks.DeletionCanceled"); try { AddLog(GetString("Synchronization.DeletingTasks")); foreach (string taskIdString in list) { int taskId = ValidationHelper.GetInteger(taskIdString, 0); if (taskId > 0) { TaskInfo task = TaskInfoProvider.GetTaskInfo(taskId); if (task != null) { AddLog(string.Format(ResHelper.GetAPIString("deletion.running", "Deleting '{0}' task"), HTMLHelper.HTMLEncode(task.TaskTitle))); // Delete synchronization SynchronizationInfoProvider.DeleteSynchronizationInfo(task, serverId, currentSiteId); } } } CurrentInfo = GetString("Tasks.DeleteOK"); 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.DeletionFailed"); AddErrorLog(CurrentError); } } catch (Exception ex) { CurrentError = GetString("Tasks.DeletionFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!RequestHelper.IsPostBack()) { // Empty string or both documents and object means (all) to be selected if (AllowAll && (String.IsNullOrEmpty(mObjectType) || (mObjectType.Contains(CMSObjectHelper.GROUP_DOCUMENTS) && mObjectType.Contains(CMSObjectHelper.GROUP_OBJECTS)))) { drpType.SelectedIndex = 0; } else { // If value is not already in dropdown list, add it there if (!String.IsNullOrEmpty(mObjectType)) { string value = mObjectType.Trim(';'); if (drpType.Items.FindByValue(value) == null) { var typeList = TypeHelper.GetTypes(value); string list = ""; typeList.ForEach(s => list += ResHelper.GetString(ResHelper.GetAPIString("ObjectTasks." + s.Replace(".", "_"), s)) + ", "); drpType.Items.Add(new ListItem(list.Trim().TrimEnd(','), value)); } drpType.SelectedValue = value; } } } }
protected void btnYes_Click(object sender, EventArgs e) { var worker = new AsyncWorker(); if (worker.Status == AsyncWorkerStatusEnum.Running) { // Preventing parallel deletion of 2 and more sites because of the database transaction deadlocks ShowInformation(GetString("site_delete.alreadyrunning")); return; } SiteDeletionLog.LogDeletionState(LogStatusEnum.Info, String.Format(ResHelper.GetAPIString("Site_Delete.DeletingSite", "Initializing deletion of the site"), mSiteInfo.SiteName)); pnlConfirmation.Visible = false; pnlDeleteSite.Visible = true; // Start the timer for the callbacks ltlScript.Text = ScriptHelper.GetScript("StartStateTimer();"); var deletionSettings = new SiteDeletionSettings { DeleteAttachments = chkDeleteDocumentAttachments.Checked, DeleteMediaFiles = chkDeleteMediaFiles.Checked, DeleteMetaFiles = chkDeleteMetaFiles.Checked, Site = mSiteInfo }; worker.RunAsync(_ => SiteInfoProvider.DeleteSiteInfo(deletionSettings, SiteDeletionLog), WindowsIdentity.GetCurrent()); }
protected void ctrlImport_OnFinished(object sender, EventArgs e) { try { // Convert default culture if (!siteType.SelectTemplate) { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); tree.ChangeSiteDefaultCulture(SiteName, Culture, "en-US"); // Change root GUID TreeNode root = DocumentHelper.GetDocument(SiteName, "/", Culture, false, "cms.root", null, null, 1, false, null, tree); if (root != null) { root.NodeGUID = Guid.NewGuid(); DocumentHelper.UpdateDocument(root, tree); } } } catch (Exception ex) { EventLogProvider ev = new EventLogProvider(); ev.LogEvent("NewSiteWizard", "FINISH", ex); } finally { if (ImportManager.Settings.ProcessCanceled) { NextButton.Enabled = CancelButton.Enabled = false; mImportCanceled = true; lblProgress.Text = "<strong>" + ResHelper.GetAPIString("ImportSite.ImportCanceled", "Import process has been cancelled.") + "</strong>"; } else { if (!ImportManager.Settings.IsWarning() && !ImportManager.Settings.IsError()) { PreviousButton.Visible = false; CultureHelper.SetPreferredCulture(Culture); if (siteType.SelectTemplate) { // Done finishSite.Domain = Domain; wzdImport.ActiveStepIndex = 7; } else { selectMaster.SiteName = SiteName; wzdImport.ActiveStepIndex += 1; selectMaster.ReloadData(); } } } // Stop the timer string script = "StopSelectionTimer();"; ltlScriptAfter.Text += ScriptHelper.GetScript(script); } }
/// <summary> /// Removes selected operator from the ACL. /// </summary> protected void btnRemoveOperator_Click(Object sender, EventArgs e) { // Check permission CheckPermissions(true); if (lstOperators.SelectedItem == null) { return; } string operatorName = lstOperators.SelectedItem.Text; string message; string operatorID = lstOperators.SelectedValue; if (operatorID.StartsWith("U", StringComparison.InvariantCulture)) { int userId = int.Parse(operatorID.Substring(1)); UserInfo ui = UserInfo.Provider.Get(userId); AclItemInfoProvider.RemoveUser(Node.NodeID, ui); message = "security.documentuserpermissionremoved"; } else { RoleInfo ri = RoleInfo.Provider.Get(int.Parse(operatorID.Substring(1))); AclItemInfoProvider.RemoveRole(Node.NodeID, ri); message = "security.documentrolepermissionremoved"; } // Log synchronization task and flush cache DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, Node.TreeProvider); Node.ClearCache(); // Insert information about this event to eventlog. if (Tree.LogEvents) { var logData = new EventLogData(EventTypeEnum.Information, "Content", "DOCPERMISSIONSMODIFIED") { EventDescription = String.Format(ResHelper.GetAPIString(message, "Operator '{0}' has been removed from the page permissions."), operatorName), EventUrl = eventUrl, UserID = Tree.UserInfo.UserID, UserName = Tree.UserInfo.UserName, NodeID = Node.NodeID, DocumentName = Node.GetDocumentName(), IPAddress = ipAddress, SiteID = Node.NodeSiteID }; Service.Resolve <IEventLogService>().LogEvent(logData); } dsAclItems = null; LoadOperators(true); CheckButtonsActiveState(); }
private static string GetDisplayedName(DocumentAttachment attachment) { var displayedName = TextHelper.LimitLength(attachment.AttachmentName, AttachmentsControl.ATTACHMENT_NAME_LIMIT); if (!String.IsNullOrEmpty(attachment.AttachmentVariantDefinitionIdentifier)) { displayedName = ResHelper.GetAPIString("AttachmentVariant." + attachment.AttachmentVariantDefinitionIdentifier, attachment.AttachmentVariantDefinitionIdentifier); } return(displayedName); }
private object GetAttachmentHtml(ISimpleDataContainer container) { // Attachment name string name = ValidationHelper.GetString(container["AttachmentName"], ""); Guid guid = ValidationHelper.GetGuid(container["AttachmentGUID"], Guid.Empty); int siteId = ValidationHelper.GetInteger(container["AttachmentSiteID"], 0); string extension = ValidationHelper.GetString(container["AttachmentExtension"], ""); // File name name = Path.GetFileNameWithoutExtension(name); string url = ResolveUrl("~/CMSPages/GetFile.aspx?guid=") + guid; if (siteId != currentSiteId) { // Add the site name to the URL if not current site SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId); if (si != null) { url += "&sitename=" + si.SiteName; } } string tooltipSpan = name; bool isImage = ImageHelper.IsImage(extension); string variant = ValidationHelper.GetString(container["AttachmentVariantDefinitionIdentifier"], ""); if (isImage) { int imageWidth = ValidationHelper.GetInteger(container["AttachmentImageWidth"], 0); int imageHeight = ValidationHelper.GetInteger(container["AttachmentImageHeight"], 0); string id = guid.ToString(); if (!String.IsNullOrEmpty(variant)) { url += "&variant=" + variant; id += "_" + variant; } string tooltip = UIHelper.GetTooltipAttributes(url, imageWidth, imageHeight, null, name, extension, null, null, 300); tooltipSpan = "<span id=\"" + id + "\" " + tooltip + ">" + name + "</span>"; } var html = UIHelper.GetFileIcon(Page, extension, tooltip: name) + " <a href=\"" + url + "\" target=\"_blank\">" + tooltipSpan + "</a>"; if (!String.IsNullOrEmpty(variant)) { var displayedVariantName = ResHelper.GetAPIString("AttachmentVariant." + variant, variant); html += String.Format(" ({0})", displayedVariantName); } return(html); }
protected void gridTasks_OnAction(string actionName, object actionArgument) { // Parse action argument int taskId = ValidationHelper.GetInteger(actionArgument, 0); eventType = EventLogProvider.EVENT_TYPE_INFORMATION; if (taskId > 0) { TaskInfo task = TaskInfoProvider.GetTaskInfo(taskId); if (task != null) { switch (actionName.ToLower()) { case "delete": // Delete task eventCode = "DELETESELECTEDDATA"; AddEventLog(string.Format(ResHelper.GetAPIString("deletion.running", "Deleting '{0}' task"), HTMLHelper.HTMLEncode(task.TaskTitle))); SynchronizationInfoProvider.DeleteSynchronizationInfo(taskId, serverId, currentSiteId); break; case "synchronize": string result = null; try { // Run task synchronization eventCode = "SYNCSELECTEDDATA"; result = StagingHelper.RunSynchronization(taskId, serverId, true, currentSiteId); if (string.IsNullOrEmpty(result)) { lblInfo.Text = GetString("Tasks.SynchronizationOK"); } else { lblError.Text = GetString("Tasks.SynchronizationFailed"); eventType = EventLogProvider.EVENT_TYPE_ERROR; } } catch (Exception ex) { result = ex.Message; lblError.Text = GetString("Tasks.SynchronizationFailed"); eventType = EventLogProvider.EVENT_TYPE_ERROR; } // Log message AddEventLog(result + string.Format(ResHelper.GetAPIString("synchronization.running", "Processing '{0}' task"), HTMLHelper.HTMLEncode(task.TaskTitle))); break; } } } }
/// <summary> /// Deletes all tasks. /// </summary> protected void DeleteAll(object parameter) { eventCode = "DELETEALLTASKS"; CanceledString = GetString("Tasks.DeletionCanceled"); try { AddLog(GetString("Synchronization.DeletingTasks")); // Get the tasks DataSet ds = StagingTaskInfoProvider.SelectTaskList(currentSiteId, serverId, null, "TaskID", -1, "TaskID, TaskTitle"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow row in ds.Tables[0].Rows) { int taskId = ValidationHelper.GetInteger(row["TaskID"], 0); if (taskId > 0) { string taskTitle = ValidationHelper.GetString(row["TaskTitle"], null); AddLog(string.Format(ResHelper.GetAPIString("deletion.running", "Deleting '{0}' task"), HTMLHelper.HTMLEncode(taskTitle))); // Delete synchronization SynchronizationInfoProvider.DeleteSynchronizationInfo(taskId, serverId, currentSiteId); } } } CurrentInfo = GetString("Tasks.DeleteOK"); 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.DeletionFailed"); AddErrorLog(CurrentError); } } catch (Exception ex) { CurrentError = GetString("Tasks.DeletionFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
private void CheckApplicationState(SiteDeletionLog delLog) { if (ApplicationInstanceGUID == SystemHelper.ApplicationInstanceGUID) { return; } // Restart of the application LogStatusEnum progressLog = delLog.GetProgressState(); if (progressLog != LogStatusEnum.Finish) { delLog.LogDeletionState(LogStatusEnum.UnexpectedFinish, ResHelper.GetAPIString("Site_Delete.Applicationrestarted", "<strong>Application has been restarted and the logging of the site delete process has been terminated. Please make sure that the site is deleted. If it is not, please repeate the deletion process.</strong><br />")); } }
/// <summary> /// Localizes Data.com errors into current UI language, if applicable. /// </summary> private void LocalizeErrors() { if (mErrors != null) { foreach (Error error in mErrors.Where(x => !String.IsNullOrEmpty(x.ErrorCode))) { string name = String.Format("datacom.error.{0}", error.ErrorCode); string message = ResHelper.GetAPIString(name, Thread.CurrentThread.CurrentUICulture.Name, String.Empty); if (!String.IsNullOrEmpty(message)) { error.ErrorMessage = message; } } } }
private string ProcessSynchronization(int connectorId, int taskId) { if ((taskId > 0) && (connectorId > 0)) { // Get connector and task IntegrationConnectorInfo connectorInfo = IntegrationConnectorInfoProvider.GetIntegrationConnectorInfo(connectorId); IntegrationTaskInfo taskInfo = IntegrationTaskInfoProvider.GetIntegrationTaskInfo(taskId); if ((connectorInfo != null) && (taskInfo != null)) { if (connectorInfo.ConnectorEnabled) { // Get connector instance BaseIntegrationConnector connector = IntegrationHelper.GetConnector(connectorInfo.ConnectorName) as BaseIntegrationConnector; if (connector != null) { AddLog(String.Format(ResHelper.GetAPIString("synchronization.running", "Processing '{0}' task"), HTMLHelper.HTMLEncode(taskInfo.TaskTitle))); // Process the task if (TasksAreInbound) { // Always try to process the task when requested from UI taskInfo.TaskProcessType = IntegrationProcessTypeEnum.Default; return(connector.ProcessExternalTask(taskInfo)); } else { return(connector.ProcessInternalTask(taskInfo)); } } else { // Can't load connector AddLog(String.Format(ResHelper.GetAPIString("synchronization.skippingunavailable", "Skipping '{0}' task - failed to load associated connector."), HTMLHelper.HTMLEncode(taskInfo.TaskTitle))); } } else { // Connector is disabled AddLog(String.Format(ResHelper.GetAPIString("synchronization.skippingdisabled", "Skipping '{0}' task - associated connector is disabled."), HTMLHelper.HTMLEncode(taskInfo.TaskTitle))); } } } return(null); }
protected void lnkBreakWithCopy_Click(Object sender, EventArgs e) { // Check permission CheckModifyPermission(true); // Break permission inheritance and copy parent permissions AclInfoProvider.BreakInheritance(Node, true); // Log staging task TaskParameters taskParam = new TaskParameters(); taskParam.SetParameter("copyPermissions", true); DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.BreakACLInheritance, Node.TreeProvider, SynchronizationInfoProvider.ENABLED_SERVERS, taskParam, Node.TreeProvider.AllowAsyncActions); // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents) { var logData = new EventLogData(EventTypeEnum.Information, "Content", "DOCPERMISSIONSMODIFIED") { EventDescription = ResHelper.GetAPIString("security.documentpermissionsbreakcopy", "Inheritance of the parent page permissions have been broken. Parent page permissions have been copied."), EventUrl = currentUrl, UserID = DocumentManager.Tree.UserInfo.UserID, UserName = DocumentManager.Tree.UserInfo.UserName, NodeID = Node.NodeID, DocumentName = DocumentName, IPAddress = ipAddress, SiteID = Node.NodeSiteID }; Service.Resolve <IEventLogService>().LogEvent(logData); } lblInheritanceInfo.Text = GetString("Security.InheritsInfo.DoesNotInherit"); SwitchBackToPermissionsMode(); // Clear and reload securityElem.InvalidateAcls(); securityElem.LoadOperators(true); }
protected void btnDestroy_Click(object sender, EventArgs e) { if (Node == null) { return; } // Check permissions if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn)) { ShowError(GetString("History.ErrorNotAllowedToDestroy")); return; } VersionManager.ClearDocumentHistory(Node.DocumentID); ShowConfirmation(GetString("VersionProperties.VersionsCleared")); var logData = new EventLogData(EventTypeEnum.Information, "Content", "DESTROYHISTORY") { EventDescription = String.Format(ResHelper.GetAPIString("contentedit.documenthistorydestroyed", "History of the page '{0}' has been destroyed."), HTMLHelper.HTMLEncode(Node.NodeAliasPath)), EventUrl = RequestContext.RawURL, UserID = TreeProvider.UserInfo.UserID, UserName = TreeProvider.UserInfo.UserName, NodeID = Node.NodeID, DocumentName = Node.GetDocumentName(), IPAddress = RequestContext.UserHostAddress, SiteID = Node.NodeSiteID }; Service.Resolve <IEventLogService>().LogEvent(logData); InvalidateNode(); ReloadData(); if (AfterDestroyHistory != null) { AfterDestroyHistory(sender, e); } }
/// <summary> /// Gets header text for given table /// </summary> /// <param name="table">Table to get the header for</param> /// <returns>HTML representing header text</returns> private string GetTableHeaderText(DataTable table) { string tableName = table.TableName; string defaultString = null; // ### Special cases if (!string.IsNullOrEmpty(ObjectType)) { if (CustomTableItemProvider.IsCustomTableItemObjectType(ObjectType)) { defaultString = "CustomTableData"; } else if (ObjectType == TreeNode.OBJECT_TYPE) { defaultString = "DocumentData"; } else { defaultString = tableName; } } return("<h4 class=\"listing-title\">" + ResHelper.GetAPIString("ObjectType." + tableName, Thread.CurrentThread.CurrentUICulture.ToString(), GetString("ObjectType." + defaultString)) + "</h4>"); }
protected object UniGridWorkflows_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "type": DataRowView drv = (DataRowView)parameter; bool versioning = ValidationHelper.GetBoolean(drv.Row["WorkflowAutoPublishChanges"], false); int type = ValidationHelper.GetInteger(drv.Row["WorkflowType"], 0); return(WorkflowHelper.GetWorkflowTypeString((WorkflowTypeEnum)type, versioning)); case "scope": string types = ValidationHelper.GetString(parameter, ""); var typeList = TypeHelper.GetTypes(types); if (typeList.Count == 0) { typeList.Add(PredefinedObjectType.GROUP_DOCUMENTS); } string list = ""; typeList.ForEach(s => list += ResHelper.GetString(ResHelper.GetAPIString("ObjectTasks." + s.Replace(".", "_").Replace("#", "_"), s)) + ", "); return(list.Trim().TrimEnd(',')); } return(parameter); }
public void Save() { CheckPermissions(true); int allowed = 0; int denied = 0; string operatorID = null; if (lstOperators.SelectedItem == null) { return; } else { operatorID = lstOperators.SelectedValue; allowed += GetCheckBoxValue(chkReadAllow, NodePermissionsEnum.Read); allowed += GetCheckBoxValue(chkModifyAllow, NodePermissionsEnum.Modify); allowed += GetCheckBoxValue(chkCreateAllow, NodePermissionsEnum.Create); allowed += GetCheckBoxValue(chkDeleteAllow, NodePermissionsEnum.Delete); allowed += GetCheckBoxValue(chkDestroyAllow, NodePermissionsEnum.Destroy); allowed += GetCheckBoxValue(chkExploreTreeAllow, NodePermissionsEnum.ExploreTree); allowed += GetCheckBoxValue(chkManagePermissionsAllow, NodePermissionsEnum.ModifyPermissions); denied += GetCheckBoxValue(chkReadDeny, NodePermissionsEnum.Read); denied += GetCheckBoxValue(chkModifyDeny, NodePermissionsEnum.Modify); denied += GetCheckBoxValue(chkCreateDeny, NodePermissionsEnum.Create); denied += GetCheckBoxValue(chkDeleteDeny, NodePermissionsEnum.Delete); denied += GetCheckBoxValue(chkDestroyDeny, NodePermissionsEnum.Destroy); denied += GetCheckBoxValue(chkExploreTreeDeny, NodePermissionsEnum.ExploreTree); denied += GetCheckBoxValue(chkManagePermissionsDeny, NodePermissionsEnum.ModifyPermissions); string message = null; string operatorName = lstOperators.SelectedItem.Text; if (operatorID.StartsWith("U")) { int userId = int.Parse(operatorID.Substring(1)); UserInfo ui = UserInfoProvider.GetUserInfo(userId); AclProvider.SetUserPermissions(Node, allowed, denied, ui); message = "security.documentuserpermissionschange"; } else { AclProvider.SetRolePermissions(Node, allowed, denied, int.Parse(operatorID.Substring(1))); message = "security.documentrolepermissionschange"; } lblInfo.Text = GetString("general.changessaved"); // Log synchronization task and flush cache DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, Node.TreeProvider); CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(Node, Node.NodeSiteName)); // Insert information about this event to eventlog. if (Tree.LogEvents) { EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", Tree.UserInfo.UserID, Tree.UserInfo.UserName, Node.NodeID, DocumentName, ipAddress, string.Format(ResHelper.GetAPIString(message, "Permissions of the operator '{0}' have been modified for the document."), operatorName), Node.NodeSiteID, eventUrl); } } if (Node != null) { // Invalidate permission data in current request TreeSecurityProvider.InvalidateTreeNodeAuthorizationResults(CMSContext.CurrentUser, NodeID, Node.DocumentCulture); AclProvider.InvalidateACLItems(CMSContext.CurrentUser.UserID, Node); } CheckPermissions(false, true); pnlUpdate.Update(); }
private void DeleteSynchronization(int synchronizationId, string taskTitle) { AddLog(String.Format(ResHelper.GetAPIString("deletion.running", "Deleting '{0}' task"), HTMLHelper.HTMLEncode(taskTitle))); IntegrationSynchronizationInfoProvider.DeleteIntegrationSynchronizationInfo(synchronizationId); }
/// <summary> /// Deletes all tasks. /// </summary> protected void DeleteAll(object parameter) { eventCode = "DELETEALLDATA"; CanceledString = GetString("Tasks.DeletionCanceled"); try { AddLog(GetString("Synchronization.DeletingTasks")); string where = "TaskSiteID IS NULL"; string classWhere = string.Empty; // Ensure only data task selection if (string.IsNullOrEmpty(objectType)) { DataSet dsTables = DataClassInfoProvider.GetCustomTableClasses(currentSiteId, null, null, 0, "ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { foreach (DataRow dr in dsTables.Tables[0].Rows) { classWhere += "N'" + CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString()).Replace("'", "''") + "',"; } classWhere = classWhere.TrimEnd(new char[] { ',' }); } where = SqlHelperClass.AddWhereCondition(where, "TaskObjectType IN (" + classWhere + ")"); } // Get the tasks DataSet ds = TaskInfoProvider.SelectObjectTaskList(currentSiteId, serverId, objectType, where, "TaskID", 0, "TaskID, TaskTitle"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow row in ds.Tables[0].Rows) { int taskId = ValidationHelper.GetInteger(row["TaskID"], 0); if (taskId > 0) { string taskTitle = ValidationHelper.GetString(row["TaskTitle"], null); AddLog(string.Format(ResHelper.GetAPIString("deletion.running", "Deleting '{0}' task"), HTMLHelper.HTMLEncode(taskTitle))); // Delete synchronization SynchronizationInfoProvider.DeleteSynchronizationInfo(taskId, serverId, currentSiteId); } } } CurrentInfo = GetString("Tasks.DeleteOK"); 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.DeletionFailed"); AddErrorLog(CurrentError); } } catch (Exception ex) { CurrentError = GetString("Tasks.DeletionFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
/// <summary> /// Adds GUID field to form definition. /// </summary> private void CreateGUID() { try { // Create GUID field FormFieldInfo ffiGuid = new FormFieldInfo(); // Fill FormInfo object ffiGuid.Name = "ItemGUID"; ffiGuid.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "GUID"); ffiGuid.DataType = FieldDataType.Guid; ffiGuid.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty); ffiGuid.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, String.Empty); ffiGuid.FieldType = FormFieldControlTypeEnum.CustomUserControl; ffiGuid.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe(); ffiGuid.PrimaryKey = false; ffiGuid.System = true; ffiGuid.Visible = false; ffiGuid.Size = 0; ffiGuid.AllowEmpty = false; FormInfo.AddFormItem(ffiGuid); // Update table structure - columns could be added bool old = TableManager.UpdateSystemFields; TableManager.UpdateSystemFields = true; string schema = FormInfo.GetXmlDefinition(); TableManager tm = new TableManager(null); tm.UpdateTableByDefinition(dci.ClassTableName, schema); TableManager.UpdateSystemFields = old; // Update xml schema and form definition dci.ClassFormDefinition = schema; dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName); dci.Generalized.LogEvents = false; // Save the data DataClassInfoProvider.SetDataClassInfo(dci); dci.Generalized.LogEvents = true; // Clear the default queries QueryInfoProvider.ClearDefaultQueries(dci, true, false); // Clear the object type hashtable ProviderStringDictionary.ReloadDictionaries(className, true); // Clear the classes hashtable ProviderStringDictionary.ReloadDictionaries("cms.class", true); // Clear class strucures ClassStructureInfo.Remove(className, true); // Ensure GUIDs for all items using (CMSActionContext ctx = new CMSActionContext()) { ctx.UpdateSystemFields = false; ctx.LogSynchronization = false; DataSet dsItems = CustomTableItemProvider.GetItems(className); if (!DataHelper.DataSourceIsEmpty(dsItems)) { foreach (DataRow dr in dsItems.Tables[0].Rows) { CustomTableItem item = CustomTableItem.New(className, dr); item.ItemGUID = Guid.NewGuid(); item.Update(); } } } // Log event UserInfo currentUser = MembershipContext.AuthenticatedUser; EventLogProvider.LogEvent(EventType.INFORMATION, "Custom table", "GENERATEGUID", string.Format(ResHelper.GetAPIString("customtable.GUIDGenerated", "Field 'ItemGUID' for custom table '{0}' was created and GUID values were generated."), dci.ClassName), null, currentUser.UserID, currentUser.UserName); URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "gen", "1")); } catch (Exception ex) { FieldEditor.ShowError(GetString("customtable.ErrorGUID") + ex.Message); // Log event EventLogProvider.LogException("Custom table", "GENERATEGUID", ex); } }
/// <summary> /// Synchronizes the current object type. /// </summary> private void SynchronizeCurrent(object parameter) { string result = string.Empty; eventCode = "SYNCCURRENTDATA"; CanceledString = GetString("Tasks.SynchronizationCanceled"); try { int sid = serverId; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } AddLog(GetString("Synchronization.LoggingTasks")); // Get the tasks List <ISynchronizationTask> tasks = SynchronizationHelper.LogObjectChange(objectType, 0, DateTimeHelper.ZERO_TIME, TaskTypeEnum.UpdateObject, true, false, false, false, false, currentSiteId, sid); AddLog(GetString("Synchronization.RunningTasks")); // Run the synchronization foreach (TaskInfo task in tasks.OfType <TaskInfo>()) { AddLog(string.Format(ResHelper.GetAPIString("synchronization.running", "Processing '{0}' task"), HTMLHelper.HTMLEncode(task.TaskTitle))); result += StagingHelper.RunSynchronization(task.TaskID, serverId, true, currentSiteId); } // 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) { CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalizes log context FinalizeContext(); } }
/// <summary> /// Adds GUID field to form definition. /// </summary> private void CreateGUID() { bool success; try { if (FormInfo == null) { return; } // Create GUID field FormFieldInfo ffiGuid = new FormFieldInfo(); // Fill FormInfo object ffiGuid.Name = "ItemGUID"; ffiGuid.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "GUID"); ffiGuid.DataType = FieldDataType.Guid; ffiGuid.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty); ffiGuid.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, String.Empty); ffiGuid.PrimaryKey = false; ffiGuid.System = true; ffiGuid.Visible = false; ffiGuid.Size = 0; ffiGuid.AllowEmpty = false; FormInfo.AddFormItem(ffiGuid); // Update definition dci.ClassFormDefinition = FormInfo.GetXmlDefinition(); using (CMSActionContext context = new CMSActionContext()) { // Disable logging into event log context.LogEvents = false; DataClassInfoProvider.SetDataClassInfo(dci); } // Clear the default queries QueryInfoProvider.ClearDefaultQueries(dci, true); // Clear the object type hashtable AbstractProviderDictionary.ReloadDictionaries(className, true); // Clear the classes hashtable AbstractProviderDictionary.ReloadDictionaries("cms.class", true); // Clear class strucures ClassStructureInfo.Remove(className, true); // Ensure GUIDs for all items using (CMSActionContext ctx = new CMSActionContext()) { ctx.UpdateSystemFields = false; ctx.LogSynchronization = false; DataSet dsItems = CustomTableItemProvider.GetItems(className); if (!DataHelper.DataSourceIsEmpty(dsItems)) { foreach (DataRow dr in dsItems.Tables[0].Rows) { CustomTableItem item = CustomTableItem.New(className, dr); item.ItemGUID = Guid.NewGuid(); item.Update(); } } } // Log event UserInfo currentUser = MembershipContext.AuthenticatedUser; var logData = new EventLogData(EventTypeEnum.Information, "Custom table", "GENERATEGUID") { EventDescription = String.Format(ResHelper.GetAPIString("customtable.GUIDGenerated", "Field 'ItemGUID' for custom table '{0}' was created and GUID values were generated."), dci.ClassName), UserID = currentUser.UserID, UserName = currentUser.UserName, }; Service.Resolve <IEventLogService>().LogEvent(logData); success = true; } catch (Exception ex) { success = false; FieldEditor.ShowError(GetString("customtable.ErrorGUID")); // Log event Service.Resolve <IEventLogService>().LogException("Custom table", "GENERATEGUID", ex); } if (success) { URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "gen", "1")); } }
/// <summary> /// Complete synchronization. /// </summary> public void SynchronizeComplete(object parameter) { string result = null; eventCode = "SYNCCOMPLETEDATA"; CanceledString = GetString("Tasks.SynchronizationCanceled"); try { int sid = serverId; if (sid <= 0) { sid = SynchronizationInfoProvider.ENABLED_SERVERS; } AddLog(GetString("Synchronization.LoggingTasks")); // Get custom tables object types string objectTypes = string.Empty; DataSet dsTables = DataClassInfoProvider.GetCustomTableClasses(currentSiteId, null, null, 0, "ClassName"); if (!DataHelper.DataSourceIsEmpty(dsTables)) { DataTable table = dsTables.Tables[0]; foreach (DataRow dr in table.Rows) { objectTypes += CustomTableItemProvider.GetObjectType(dr["ClassName"].ToString()) + ";"; } } // Get the tasks List <ISynchronizationTask> tasks = SynchronizationHelper.LogObjectChange(objectTypes.Trim(';'), 0, DateTimeHelper.ZERO_TIME, TaskTypeEnum.UpdateObject, true, false, false, false, false, currentSiteId, sid); AddLog(GetString("Synchronization.RunningTasks")); // Run the synchronization foreach (TaskInfo task in tasks.OfType <TaskInfo>()) { AddLog(string.Format(ResHelper.GetAPIString("synchronization.running", "Processing '{0}' task"), HTMLHelper.HTMLEncode(task.TaskTitle))); result += StagingHelper.RunSynchronization(task.TaskID, serverId, true, currentSiteId); } // 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) { CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
/// <summary> /// Synchronization of selected items. /// </summary> /// <param name="parameter">ArrayList of selected items</param> public void SynchronizeSelected(object parameter) { if (parameter == null) { return; } string result = string.Empty; eventCode = "SYNCSELECTEDDATA"; ArrayList list = (ArrayList)parameter; CanceledString = GetString("Tasks.SynchronizationCanceled"); try { AddLog(GetString("Synchronization.RunningTasks")); foreach (string taskIdString in list) { int taskId = ValidationHelper.GetInteger(taskIdString, 0); if (taskId > 0) { // Synchronize the task TaskInfo task = TaskInfoProvider.GetTaskInfo(taskId); if (task != null) { AddLog(string.Format(ResHelper.GetAPIString("synchronization.running", "Processing '{0}' task"), HTMLHelper.HTMLEncode(task.TaskTitle))); result += StagingHelper.RunSynchronization(taskId, serverId, true, currentSiteId); } } } // Log possible error if (result != string.Empty) { 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) { CurrentError = GetString("Tasks.SynchronizationFailed") + ": " + ex.Message; AddErrorLog(CurrentError); } finally { // Finalize log context FinalizeContext(); } }
/// <summary> /// On click OK save secured settings. /// </summary> protected void btnRadOk_Click(object sender, EventArgs e) { // Check permission CheckModifyPermission(true); if (Node != null) { string message = null; bool clearCache = false; // Authentication if (!pnlUIAuth.IsHidden) { int isSecuredNode = Node.IsSecuredNode; if (radYes.Checked) { isSecuredNode = 1; } else if (radNo.Checked) { isSecuredNode = 0; } else if (radParent.Checked) { isSecuredNode = -1; } // Set secured areas settings if (isSecuredNode != Node.IsSecuredNode) { Node.IsSecuredNode = isSecuredNode; clearCache = true; message += ResHelper.GetAPIString("security.documentaccessauthchanged", "Document authentication settings have been modified."); } } // SSL if (!pnlUISsl.IsHidden) { int requiresSSL = Node.RequiresSSL; if (radYesSSL.Checked) { requiresSSL = 1; } else if (radNoSSL.Checked) { requiresSSL = 0; } else if (radParentSSL.Checked) { requiresSSL = -1; } else if (radNeverSSL.Checked) { requiresSSL = 2; } // Set SSL settings if (requiresSSL != Node.RequiresSSL) { Node.RequiresSSL = requiresSSL; clearCache = true; if (message != null) { message += "<br />"; } message += ResHelper.GetAPIString("security.documentaccesssslchanged", "Document SSL settings have been modified."); } } DocumentManager.UpdateDocument(false); // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents && (message != null)) { EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCACCESSMODIFIED", currentUser.UserID, currentUser.UserName, Node.NodeID, DocumentName, ipAddress, message, Node.NodeSiteID, eventUrl); } // Clear cache if security settings changed if (clearCache) { CacheHelper.ClearPageInfoCache(Node.NodeSiteName); CacheHelper.ClearFileNodeCache(Node.NodeSiteName); } } }
/// <summary> /// OnSaveData event handler. Sets security properties. /// </summary> protected void DocumentManager_OnSaveData(object sender, DocumentManagerEventArgs e) { TreeNode node = e.Node; if (node != null) { string message = null; bool clearCache = false; // Authentication if (pnlAccessPart.Visible) { if (!pnlAuth.IsHidden) { bool?isSecuredNode = node.IsSecuredNode; if (radYes.Checked) { isSecuredNode = true; } else if (radNo.Checked) { isSecuredNode = false; } else if (radParent.Checked) { isSecuredNode = null; } // Set secured areas settings if (isSecuredNode != node.IsSecuredNode) { node.IsSecuredNode = isSecuredNode; clearCache = true; message += ResHelper.GetAPIString("security.documentaccessauthchanged", "Page authentication settings have been modified."); } } // SSL if (!pnlSSL.IsHidden) { int?requiresSSL = node.RequiresSSL; if (radYesSSL.Checked) { requiresSSL = 1; } else if (radNoSSL.Checked) { requiresSSL = 0; } else if (radParentSSL.Checked) { requiresSSL = null; } else if (radNeverSSL.Checked) { requiresSSL = 2; } // Set SSL settings if (requiresSSL != node.RequiresSSL) { node.RequiresSSL = requiresSSL; clearCache = true; if (message != null) { message += "<br />"; } message += ResHelper.GetAPIString("security.documentaccesssslchanged", "Page SSL settings have been modified."); } } } // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents && (message != null)) { EventLogProvider.LogEvent(EventType.INFORMATION, "Content", "DOCACCESSMODIFIED", message, eventUrl, currentUser.UserID, currentUser.UserName, node.NodeID, DocumentName, ipAddress, node.NodeSiteID); } // Clear cache if security settings changed if (clearCache) { PageInfoCacheHelper.ClearCache(node.NodeSiteName); CacheHelper.ClearFileNodeCache(node.NodeSiteName); } // Clear ACL settings securityElem.InvalidateAcls(); } }
/// <summary> /// Resets permission inheritance of node and its children. /// </summary> /// <param name="siteName">Name of site</param> /// <param name="nodeAliasPath">Alias path</param> /// <param name="recursive">Indicates whether to recursively reset all nodes below the current node</param> /// <param name="user">Current user</param> /// <param name="tr">Tree provider</param> /// <returns>Whether TRUE if no permission conflict has occurred</returns> private bool ResetNodePermission(string siteName, string nodeAliasPath, bool recursive, UserInfo user, TreeProvider tr) { // Check permissions bool permissionsResult = false; try { if (tr == null) { tr = new TreeProvider(user); } // Get node by alias path TreeNode treeNode = tr.SelectSingleNode(siteName, nodeAliasPath, null, true, null, false); permissionsResult = CanModifyPermission(!recursive, treeNode, user); if (treeNode != null) { // If user has permissions if (permissionsResult) { // Break inheritance of a node if (!AclInfoProvider.DoesNodeInheritPermissions(treeNode)) { // Restore inheritance of a node AclInfoProvider.RestoreInheritance(treeNode); // Log current encoded alias path AddLog(HTMLHelper.HTMLEncode(nodeAliasPath)); // Log staging task and flush cache DocumentSynchronizationHelper.LogDocumentChange(treeNode, TaskTypeEnum.RestoreACLInheritance, treeNode.TreeProvider, SynchronizationInfoProvider.ENABLED_SERVERS, null, treeNode.TreeProvider.AllowAsyncActions); Node.ClearCache(); // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents) { if (recursive) { LogContext.LogEventToCurrent(EventType.INFORMATION, "Content", "DOCPERMISSIONSMODIFIED", string.Format(ResHelper.GetAPIString("security.documentpermissionsrestoredfordoc", "Permissions of the page '{0}' have been restored to the parent page permissions."), nodeAliasPath), null, user.UserID, user.UserName, treeNode.NodeID, treeNode.GetDocumentName(), ipAddress, Node.NodeSiteID, null, null, null, DateTime.Now); } else { EventLogProvider.LogEvent(EventType.INFORMATION, "Content", "DOCPERMISSIONSMODIFIED", ResHelper.GetAPIString("security.documentpermissionsrestored", "Permissions have been restored to the parent page permissions."), eventUrl, user.UserID, user.UserName, treeNode.NodeID, treeNode.GetDocumentName(), ipAddress, Node.NodeSiteID); } } } else { AddLog(string.Format(GetString("cmsdesk.skippingrestoring"), HTMLHelper.HTMLEncode(nodeAliasPath))); } } // Recursively reset node inheritance if (recursive) { // Get child nodes of current node DataSet ds = DocumentManager.Tree.SelectNodes(siteName, treeNode.NodeAliasPath.TrimEnd('/') + "/%", TreeProvider.ALL_CULTURES, true, null, null, null, 1, false, -1, DocumentColumnLists.SELECTNODES_REQUIRED_COLUMNS + ",NodeAliasPath"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { string childNodeAliasPath = ValidationHelper.GetString(dr["NodeAliasPath"], string.Empty); if (!string.IsNullOrEmpty(childNodeAliasPath)) { bool tempPermissionsResult = ResetNodePermission(siteName, childNodeAliasPath, true, user, tr); permissionsResult = tempPermissionsResult && permissionsResult; } } } } } } catch (ThreadAbortException ex) { if (CMSThread.Stopped(ex)) { // When canceled CurrentInfo = GetString("cmsdesk.restoringcanceled"); AddLog(CurrentInfo); } else { // Log error CurrentError = GetString("cmsdesk.restoringfailed") + ": " + ex.Message; AddLog(CurrentError); } } catch (Exception ex) { // Log error CurrentError = GetString("cmsdesk.restoringfailed") + ": " + ex.Message; AddLog(CurrentError); } return(permissionsResult); }
protected void lnkBreakWithClear_Click(Object sender, EventArgs e) { // Check permission CheckModifyPermission(true); // Break permission inheritance and clear permissions AclInfoProvider.BreakInheritance(Node, false); // Log staging task and flush cache DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.BreakACLInheritance, Node.TreeProvider, SynchronizationInfoProvider.ENABLED_SERVERS, null, Node.TreeProvider.AllowAsyncActions); Node.ClearCache(); // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents) { EventLogProvider.LogEvent(EventType.INFORMATION, "Content", "DOCPERMISSIONSMODIFIED", ResHelper.GetAPIString("security.documentpermissionsbreakclear", "Inheritance of the parent page permissions have been broken."), eventUrl, currentUser.UserID, currentUser.UserName, Node.NodeID, DocumentName, ipAddress, Node.NodeSiteID); } lblInheritanceInfo.Text = GetString("Security.InheritsInfo.DoesNotInherit"); SwitchBackToPermissionsMode(); // Clear and reload securityElem.InvalidateAcls(); securityElem.LoadOperators(true); }
/// <summary> /// OnSaveData event handler. Sets security properties. /// </summary> protected void DocumentManager_OnSaveData(object sender, DocumentManagerEventArgs e) { TreeNode node = e.Node; if (node != null) { string message = null; bool clearCache = false; // Authentication if (pnlAccessPart.Visible) { if (!pnlAuth.IsHidden) { bool?isSecuredNode = node.IsSecuredNode; if (radYes.Checked) { isSecuredNode = true; } else if (radNo.Checked) { isSecuredNode = false; } else if (radParent.Checked) { isSecuredNode = null; } // Set secured areas settings if (isSecuredNode != node.IsSecuredNode) { node.IsSecuredNode = isSecuredNode; clearCache = true; message += ResHelper.GetAPIString("security.documentaccessauthchanged", "Page authentication settings have been modified."); } } } // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents && (message != null)) { var logData = new EventLogData(EventTypeEnum.Information, "Content", "DOCPERMISSIONSMODIFIED") { EventDescription = message, EventUrl = currentUrl, UserID = currentUser.UserID, UserName = currentUser.UserName, NodeID = node.NodeID, DocumentName = DocumentName, IPAddress = ipAddress, SiteID = node.NodeSiteID }; Service.Resolve <IEventLogService>().LogEvent(logData); } // Clear cache if security settings changed if (clearCache) { CacheHelper.ClearFileNodeCache(node.NodeSiteName); } // Clear ACL settings securityElem.InvalidateAcls(); } }