/// <summary> /// When exception occurs, log it to event log and add message to asnyc log. /// </summary> /// <param name="errorTitle">Error to add to async log</param> /// <param name="nodeId">ID of node which caused operation to fail</param> /// <param name="ex">Exception to log</param> /// <param name="siteId">Site identifier</param> /// <param name="eventCode">Code of event</param> private void LogExceptionToEventLog(string eventCode, string errorTitle, int nodeId, Exception ex, int siteId) { LogContext.LogEvent(EventType.ERROR, "Content", eventCode, EventLogProvider.GetExceptionLogMessage(ex), RequestContext.RawURL, CurrentUser.UserID, CurrentUser.UserName, nodeId, null, RequestContext.UserHostAddress, siteId, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); AddError(GetString(errorTitle) + " : " + EventLogProvider.GetExceptionLogMessage(ex)); }
/// <summary> /// Logs successful delete. /// </summary> /// <param name="logProgress">Log where successful delete will be recorded</param> /// <param name="displayableName">Name of successfully deleted item</param> private void AddSuccessLog(LogContext logProgress, string displayableName) { AddLog(displayableName); string deletedMessage = String.Format(GetString("massdelete.wasdeleted"), ObjectTypeDisplayableName, displayableName); logProgress.LogEvent(EventType.INFORMATION, ObjectTypeDisplayableName, "DELETEOBJ", deletedMessage, RequestContext.RawURL, CurrentUser.UserID, CurrentUser.UserName, 0, null, RequestContext.UserHostAddress, SiteContext.CurrentSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); }
/// <summary> /// Adds message to event log object and updates event type. /// </summary> /// <param name="logMessage">Message to log</param> protected void AddEventLog(string logMessage) { // Log event to event log LogContext.LogEvent(eventType, "Staging", eventCode, logMessage, RequestContext.RawURL, currentUser.UserID, currentUser.UserName, 0, null, RequestContext.UserHostAddress, currentSiteId, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); }
/// <summary> /// When exception occurs, log it to event log. /// </summary> /// <param name="eventCode">Code of event</param> /// <param name="errorTitle">Message to log to asynchronous log</param> /// <param name="ex">Exception to log</param> /// <param name="siteId">ID of site</param> private void LogExceptionToEventLog(string eventCode, string errorTitle, Exception ex, int siteId) { AddError(ResHelper.GetString(errorTitle, currentCulture) + ": " + ex.Message); LogContext.LogEvent(EventLogProvider.EVENT_TYPE_ERROR, DateTime.Now, "Content", eventCode, currentUser.UserID, currentUser.UserName, 0, null, HTTPHelper.UserHostAddress, EventLogProvider.GetExceptionLogMessage(ex), siteId, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent()); }
/// <summary> /// Adds message to event log object and updates event type. /// </summary> /// <param name="logMessage">Message to log</param> protected void AddEventLog(string logMessage) { // Log event to event log LogContext.LogEvent(eventType, DateTime.Now, "Staging", eventCode, currentUser.UserID, currentUser.UserName, 0, null, HTTPHelper.UserHostAddress, logMessage, currentSiteId, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent()); }
/// <summary> /// When exception occures, log it to event log. /// </summary> /// <param name="messageTitle">Title message</param> /// <param name="ex">Exception to log</param> private void LogExceptionToEventLog(string messageTitle, Exception ex) { AddError(messageTitle + ": " + ex.Message); LogContext.LogEvent(EventLogProvider.EVENT_TYPE_ERROR, DateTime.Now, "Content", "PUBLISHDOC", currentUser.UserID, currentUser.UserName, 0, null, HTTPHelper.UserHostAddress, EventLogProvider.GetExceptionLogMessage(ex), currentSiteId, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent()); }
/// <summary> /// Adds error message to the <paramref name="errorLog"/> /// and either accumulates permission-related exceptions to the <paramref name="logPermissionError"/> /// or logs other <see cref="Exception"/> directly to the event log. /// </summary> private void HandleException(StringBuilder errorLog, LogContext logPermissionError, string displayableName, Exception exception) { AddErrorLog(errorLog, displayableName); if (IsPermissionRelated(exception)) { logPermissionError.LogEvent(EventType.ERROR, ObjectTypeDisplayableName, "DELETEOBJ", exception.Message, RequestContext.RawURL, CurrentUser.UserID, CurrentUser.UserName, 0, null, RequestContext.UserHostAddress, SiteContext.CurrentSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); } else { EventLogProvider.LogException("Application_Error", "DELETEOBJ", exception); } }
/// <summary> /// Empties recycle bin. /// </summary> private void EmptyBin(object parameter) { // Begin log AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", currentCulture)); BinSettingsContainer settings = (BinSettingsContainer)parameter; CurrentUserInfo currentUserInfo = settings.User; SiteInfo currentSite = settings.Site; DataSet recycleBin = null; string where = IsSingleSite ? "VersionObjectSiteID IS NULL" : null; switch (settings.CurrentWhat) { case What.AllObjects: if (currentSite != null) { where = SqlHelper.AddWhereCondition(where, "VersionObjectSiteID = " + currentSite.SiteID, "OR"); } where = GetWhereCondition(where); where = SqlHelper.AddWhereCondition(where, filter.WhereCondition); break; case What.SelectedObjects: List <string> toRestore = ugRecycleBin.SelectedItems; // Restore selected objects if (toRestore.Count > 0) { where = SqlHelper.GetWhereCondition("VersionID", toRestore); } break; } recycleBin = ObjectVersionHistoryInfoProvider.GetRecycleBin(where, null, -1, "VersionID, VersionObjectType, VersionObjectID, VersionObjectDisplayName, VersionObjectSiteID"); try { if (!DataHelper.DataSourceIsEmpty(recycleBin)) { foreach (DataRow dr in recycleBin.Tables[0].Rows) { int versionHistoryId = Convert.ToInt32(dr["VersionID"]); string versionObjType = Convert.ToString(dr["VersionObjectType"]); string objName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dr["VersionObjectDisplayName"], string.Empty))); string siteName = null; if (currentSite != null) { siteName = currentSite.SiteName; } else { int siteId = ValidationHelper.GetInteger(dr["VersionObjectSiteID"], 0); siteName = SiteInfoProvider.GetSiteName(siteId); } // Check permissions if (!currentUserInfo.IsAuthorizedPerObject(PermissionsEnum.Destroy, versionObjType, siteName)) { CurrentError = String.Format(ResHelper.GetString("objectversioning.Recyclebin.DestructionFailedPermissions", currentCulture), objName); AddLog(CurrentError); } else { AddLog(ResHelper.GetString("general.object", currentCulture) + " '" + objName + "'"); // Destroy the version int versionObjId = ValidationHelper.GetInteger(dr["VersionObjectID"], 0); ObjectVersionManager.DestroyObjectHistory(versionObjType, versionObjId); LogContext.LogEvent(EventType.INFORMATION, "Objects", "DESTROYOBJECT", ResHelper.GetString("objectversioning.Recyclebin.objectdestroyed"), RequestContext.RawURL, currentUserInfo.UserID, currentUserInfo.UserName, 0, null, RequestContext.UserHostAddress, (currentSite != null) ? currentSite.SiteID : 0, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); } } if (!String.IsNullOrEmpty(CurrentError)) { CurrentError = ResHelper.GetString("objectversioning.recyclebin.errorsomenotdestroyed", currentCulture); AddLog(CurrentError); } else { CurrentInfo = ResHelper.GetString("ObjectVersioning.Recyclebin.DestroyOK", currentCulture); AddLog(CurrentInfo); } } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state != CMSThread.ABORT_REASON_STOP) { // Log error CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", currentCulture); AddLog(CurrentError); // Log to event log LogException("EMPTYINGBIN", ex); } } catch (Exception ex) { // Log error CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", currentCulture); AddLog(CurrentError); // Log to event log LogException("EMPTYINGBIN", ex); } }
private void RemoveWorkflow(object parameter) { VersionManager verMan = VersionManager.GetInstance(Tree); TreeNode node = null; // Custom logging Tree.LogEvents = false; Tree.AllowAsyncActions = false; CanceledString = ResHelper.GetString("workflowdocuments.removingcanceled", currentCulture); try { // Begin log AddLog(ResHelper.GetString("content.preparingdocuments", currentCulture)); string where = parameter as string; // Get the documents DataSet documents = GetDocumentsToProcess(where); if (!DataHelper.DataSourceIsEmpty(documents)) { // Begin log AddLog(ResHelper.GetString("workflowdocuments.removingwf", currentCulture)); foreach (DataTable classTable in documents.Tables) { foreach (DataRow nodeRow in classTable.Rows) { // Get the current document string className = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty); string aliasPath = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty); string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty); string siteName = ValidationHelper.GetString(nodeRow["SiteName"], string.Empty); // Get published version node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false); string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")"); // Destroy document history verMan.DestroyDocumentHistory(node.DocumentID); // Clear workflow DocumentHelper.ClearWorkflowInformation(node); node.Update(); // Add log record AddLog(encodedAliasPath); // Add record to eventlog LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "REMOVEDOCWORKFLOW", currentUser.UserID, currentUser.UserName, node.NodeID, node.GetDocumentName(), HTTPHelper.UserHostAddress, string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath), node.NodeSiteID, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent()); } } CurrentInfo = GetString("workflowdocuments.removecomplete"); } else { AddError(ResHelper.GetString("workflowdocuments.nodocumentstoclear", currentCulture)); } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // When canceled CurrentInfo = CanceledString; } else { int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID; // Log error LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId); } } catch (Exception ex) { int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID; // Log error LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId); } }
/// <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, CurrentUserInfo 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 (!AclProvider.DoesNodeInheritPermissions(treeNode.NodeID)) { // Restore inheritance of a node AclProvider.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); CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(Node, Node.NodeSiteName)); // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents) { if (recursive) { LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", user.UserID, user.UserName, treeNode.NodeID, treeNode.GetDocumentName(), ipAddress, string.Format(ResHelper.GetAPIString("security.documentpermissionsrestoredfordoc", "Permissions of document '{0}' have been restored to the parent document permissions."), nodeAliasPath), Node.NodeSiteID, null, null, null, null); } else { EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", user.UserID, user.UserName, treeNode.NodeID, treeNode.GetDocumentName(), ipAddress, ResHelper.GetAPIString("security.documentpermissionsrestored", "Permissions have been restored to the parent document permissions."), Node.NodeSiteID, eventUrl); } } } else { AddLog(string.Format(ResHelper.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, TreeProvider.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) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // When canceled CurrentInfo = ResHelper.GetString("cmsdesk.restoringcanceled"); AddLog(CurrentInfo); } else { // Log error CurrentError = ResHelper.GetString("cmsdesk.restoringfailed") + ": " + ex.Message; AddLog(CurrentError); } } catch (Exception ex) { // Log error CurrentError = ResHelper.GetString("cmsdesk.restoringfailed") + ": " + ex.Message; AddLog(CurrentError); } return(permissionsResult); }
/// <summary> /// Empties recycle bin. /// </summary> private void EmptyBin(object parameter) { // Begin log AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", currentCulture)); BinSettingsContainer settings = (BinSettingsContainer)parameter; CurrentUserInfo currentUserInfo = settings.User; DataSet recycleBin = null; string where = null; DateTime modifiedFrom = DateTimeHelper.ZERO_TIME; DateTime modifiedTo = DateTimeHelper.ZERO_TIME; switch (settings.CurrentWhat) { case What.AllDocuments: SetDocumentAge(ref modifiedFrom, ref modifiedTo); where = GetWhereCondition(filter.WhereCondition); break; case What.SelectedDocuments: List <string> toRestore = ugRecycleBin.SelectedItems; // Restore selected documents if (toRestore.Count > 0) { where = SqlHelper.GetWhereCondition("VersionHistoryID", toRestore); } break; } recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, where, "DocumentNamePath ASC", -1, null, modifiedFrom, modifiedTo); try { if (!DataHelper.DataSourceIsEmpty(recycleBin)) { TreeProvider tree = new TreeProvider(currentUserInfo); tree.AllowAsyncActions = false; VersionManager verMan = VersionManager.GetInstance(tree); foreach (DataRow dr in recycleBin.Tables[0].Rows) { int versionHistoryId = Convert.ToInt32(dr["VersionHistoryID"]); string documentNamePath = ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty); // Check permissions TreeNode tn = null; if (!IsAuthorizedPerDocument(versionHistoryId, "Destroy", currentUser, out tn, verMan)) { CurrentError = String.Format(ResHelper.GetString("Recyclebin.DestructionFailedPermissions", currentCulture), documentNamePath); AddLog(CurrentError); } else { AddLog(ResHelper.GetString("general.document", currentCulture) + "'" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty)) + "'"); // Destroy the version verMan.DestroyDocumentHistory(ValidationHelper.GetInteger(dr["DocumentID"], 0)); LogContext.LogEvent(EventType.INFORMATION, "Content", "DESTROYDOC", string.Format(ResHelper.GetString("Recyclebin.documentdestroyed"), documentNamePath), RequestContext.RawURL, currentUser.UserID, currentUser.UserName, 0, null, RequestContext.UserHostAddress, SiteContext.CurrentSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); } } if (!String.IsNullOrEmpty(CurrentError)) { CurrentError = ResHelper.GetString("recyclebin.errorsomenotdestroyed", currentCulture); AddLog(CurrentError); } else { CurrentInfo = ResHelper.GetString("recyclebin.destroyok", currentCulture); AddLog(CurrentInfo); } } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state != CMSThread.ABORT_REASON_STOP) { // Log error CurrentError = "Error occurred: " + ex.Message; AddLog(CurrentError); } } catch (Exception ex) { // Log error CurrentError = "Error occurred: " + ex.Message; AddLog(CurrentError); } }
/// <summary> /// Empties recycle bin. /// </summary> private void EmptyBin(BinSettingsContainer settings) { // Begin log AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", mCurrentCulture)); try { DataSet recycleBin = GetRecycleBinSeletedItems(settings, "VersionID, VersionObjectType, VersionObjectID, VersionObjectDisplayName, VersionObjectSiteID"); if (!DataHelper.DataSourceIsEmpty(recycleBin)) { foreach (DataRow dr in recycleBin.Tables[0].Rows) { string versionObjType = Convert.ToString(dr["VersionObjectType"]); string objName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dr["VersionObjectDisplayName"], string.Empty))); SiteInfo currentSite = settings.Site; string siteName; if (currentSite != null) { siteName = currentSite.SiteName; } else { int siteId = ValidationHelper.GetInteger(dr["VersionObjectSiteID"], 0); siteName = SiteInfoProvider.GetSiteName(siteId); } // Check permissions UserInfo currentUserInfo = settings.User; if (!currentUserInfo.IsAuthorizedPerObject(PermissionsEnum.Destroy, versionObjType, siteName)) { CurrentError = String.Format(ResHelper.GetString("objectversioning.Recyclebin.DestructionFailedPermissions", mCurrentCulture), objName); AddLog(CurrentError); } else { AddLog(ResHelper.GetString("general.object", mCurrentCulture) + " '" + objName + "'"); // Destroy the version int versionObjId = ValidationHelper.GetInteger(dr["VersionObjectID"], 0); ObjectVersionManager.DestroyObjectHistory(versionObjType, versionObjId); LogContext.LogEvent(EventType.INFORMATION, "Objects", "DESTROYOBJECT", ResHelper.GetString("objectversioning.Recyclebin.objectdestroyed"), RequestContext.RawURL, currentUserInfo.UserID, currentUserInfo.UserName, 0, null, RequestContext.UserHostAddress, (currentSite != null) ? currentSite.SiteID : 0, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); } } if (!String.IsNullOrEmpty(CurrentError)) { CurrentError = ResHelper.GetString("objectversioning.recyclebin.errorsomenotdestroyed", mCurrentCulture); AddLog(CurrentError); } else { CurrentInfo = ResHelper.GetString("ObjectVersioning.Recyclebin.DestroyOK", mCurrentCulture); AddLog(CurrentInfo); } } } catch (ThreadAbortException ex) { if (!CMSThread.Stopped(ex)) { // Log error CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", mCurrentCulture); AddLog(CurrentError); // Log to event log LogException("EMPTYINGBIN", ex); } } catch (Exception ex) { // Log error CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", mCurrentCulture); AddLog(CurrentError); // Log to event log LogException("EMPTYINGBIN", ex); } }
/// <summary> /// When exception occures, log it to event log. /// </summary> /// <param name="messageTitle">Title message</param> /// <param name="ex">Exception to log</param> private void LogExceptionToEventLog(string messageTitle, Exception ex) { AddError(messageTitle + ": " + ex.Message); LogContext.LogEvent(EventType.ERROR, "Content", "PUBLISHDOC", EventLogProvider.GetExceptionLogMessage(ex), RequestContext.RawURL, currentUser.UserID, currentUser.UserName, 0, null, RequestContext.UserHostAddress, currentSiteId, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); }