/// <summary> /// Executes the UnsetTragetLayout client action using parameters passed in hidden fields. /// </summary> private void UnsetTargetLayout() { int sourceLayoutId = ValidationHelper.GetInteger(SourceLayoutIdentifierHiddenField.Value, 0); using (var scope = new CMSTransactionScope()) { LayoutInfo sourceLayout = LayoutInfoProvider.GetLayoutInfo(sourceLayoutId); if (sourceLayout == null) { throw new ApplicationException(GetString("device_profile.layoutmapping.errors.nosourcelayout")); } InfoObjectCollection <DeviceProfileLayoutInfo> bindings = DeviceProfileLayoutInfoProvider.GetDeviceProfileLayouts() .WhereEquals("DeviceProfileID", DeviceProfile.ProfileID) .WhereEquals("SourceLayoutID", sourceLayout.LayoutId) .TypedResult .Items; if (bindings.Count > 0) { DeviceProfileLayoutInfoProvider.DeleteDeviceProfileLayoutInfo(bindings[0]); } scope.Commit(); } }
/// <summary> /// Refreshes macro signatures in all object which can contain macros. /// </summary> private static void RefreshMacroSignatures() { // Get object types var objectTypes = new List <string> { TransformationInfo.OBJECT_TYPE, UIElementInfo.OBJECT_TYPE, FormUserControlInfo.OBJECT_TYPE, SettingsKeyInfo.OBJECT_TYPE, AlternativeFormInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE_SYSTEMTABLE, DataClassInfo.OBJECT_TYPE_CUSTOMTABLE, DataClassInfo.OBJECT_TYPE_DOCUMENTTYPE, PageTemplateInfo.OBJECT_TYPE, LayoutInfo.OBJECT_TYPE, CssStylesheetInfo.OBJECT_TYPE, WorkflowActionInfo.OBJECT_TYPE, }; foreach (string type in objectTypes) { try { using (var context = new CMSActionContext()) { context.DisableLogging(); context.CreateVersion = false; context.LogIntegration = false; var infos = new InfoObjectCollection(type); foreach (var info in infos) { MacroSecurityProcessor.RefreshSecurityParameters(info, "administrator", true); } } } catch (Exception ex) { EventLogProvider.LogException(EventLogSource, "REFRESHMACROSIGNATURES", ex, 0, "Type: " + type); } } }
/// <summary> /// Executes the SetTragetLayout client action using parameters passed in hidden fields. /// </summary> private void SetTargetLayout() { int sourceLayoutId = ValidationHelper.GetInteger(SourceLayoutIdentifierHiddenField.Value, 0); int targetLayoutId = ValidationHelper.GetInteger(TargetLayoutIdentifierHiddenField.Value, 0); using (var scope = new CMSTransactionScope()) { LayoutInfo sourceLayout = LayoutInfoProvider.GetLayoutInfo(sourceLayoutId); if (sourceLayout == null) { throw new ApplicationException(GetString("device_profile.layoutmapping.errors.nosourcelayout")); } LayoutInfo targetLayout = LayoutInfoProvider.GetLayoutInfo(targetLayoutId); if (targetLayout == null) { throw new ApplicationException(GetString("device_profile.layoutmapping.errors.notargetlayout")); } InfoObjectCollection <DeviceProfileLayoutInfo> bindings = DeviceProfileLayoutInfoProvider.GetDeviceProfileLayouts() .Where("DeviceProfileID", QueryOperator.Equals, DeviceProfile.ProfileID) .Where("SourceLayoutID", QueryOperator.Equals, sourceLayout.LayoutId) .TypedResult .Items; DeviceProfileLayoutInfo binding = null; if (bindings.Count > 0) { binding = bindings[0]; } else { binding = new DeviceProfileLayoutInfo { DeviceProfileID = DeviceProfile.ProfileID, SourceLayoutID = sourceLayout.LayoutId }; } binding.TargetLayoutID = targetLayout.LayoutId; DeviceProfileLayoutInfoProvider.SetDeviceProfileLayoutInfo(binding); scope.Commit(); } }
private void SaveToExternalStorage(InfoObjectCollection collection) { if (collection == null) { return; } foreach (BaseInfo info in collection) { AddLog(string.Format(GetString("Deployment.Deploying"), GetString("objecttype." + collection.ObjectType.Replace(".", "_")), info.Generalized.ObjectDisplayName)); try { info.Generalized.SaveExternalColumns(); } catch (Exception ex) { AddError(ex.Message); } } }
/// <summary> /// Executes the UnsetTragetLayout client action using parameters passed in hidden fields. /// </summary> private void UnsetTargetLayout() { int sourceLayoutId = ValidationHelper.GetInteger(SourceLayoutIdentifierHiddenField.Value, 0); using (CMSTransactionScope scope = new CMSTransactionScope()) { LayoutInfo sourceLayout = LayoutInfoProvider.GetLayoutInfo(sourceLayoutId); if (sourceLayout == null) { throw new ApplicationException(GetString("device_profile.layoutmapping.errors.nosourcelayout")); } string condition = String.Format("DeviceProfileID = {0:D} AND SourceLayoutID = {1:D}", DeviceProfile.ProfileID, sourceLayout.LayoutId); InfoObjectCollection <DeviceProfileLayoutInfo> bindings = DeviceProfileLayoutInfoProvider.GetDeviceProfileLayouts(condition, null).Items; if (bindings.Count > 0) { DeviceProfileLayoutInfoProvider.DeleteDeviceProfileLayoutInfo(bindings[0]); } scope.Commit(); } }
/// <summary> /// Refreshes macro signatures in all object which can contain macros. /// </summary> private static void RefreshMacroSignatures() { // Get object types var objectTypes = new List <string> { TransformationInfo.OBJECT_TYPE, UIElementInfo.OBJECT_TYPE, FormUserControlInfo.OBJECT_TYPE, SettingsKeyInfo.OBJECT_TYPE, AlternativeFormInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE, // Process all data classes just through general object type to avoid duplicities PageTemplateInfo.OBJECT_TYPE, LayoutInfo.OBJECT_TYPE, CssStylesheetInfo.OBJECT_TYPE, WorkflowActionInfo.OBJECT_TYPE, }; var adminIdentityOption = MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser); foreach (string type in objectTypes) { try { using (var context = new CMSActionContext()) { context.DisableLogging(); context.CreateVersion = false; context.LogIntegration = false; var infos = new InfoObjectCollection(type); foreach (var info in infos) { MacroSecurityProcessor.RefreshSecurityParameters(info, adminIdentityOption, true); } } } catch (Exception ex) { EventLogProvider.LogException(EventLogSource, "REFRESHMACROSIGNATURES", ex, 0, "Type: " + type); } } }
/// <summary> /// Tests compilation of the given list of objects /// </summary> /// <param name="collection">Collection of objects</param> private void TestCompilation(InfoObjectCollection collection) { if (collection == null) { return; } foreach (BaseInfo info in collection) { var name = info.Generalized.ObjectFullName ?? info.Generalized.ObjectDisplayName; if (SystemContext.DevelopmentMode && (info.Generalized.ObjectCodeName.StartsWithCSafe("test", true) || name.StartsWithCSafe("test", true))) { // Skip testing objects continue; } AddLog(string.Format(GetString("Deployment.Testing"), GetString("objecttype." + collection.ObjectType.Replace(".", "_")), name)); try { var path = info.Generalized.GetVirtualFileRelativePath(info.TypeInfo.CodeColumn, info.Generalized.ObjectVersionGUID.ToString()); if (path.EndsWithCSafe(".ascx", true)) { // Try to load the control var c = Page.LoadUserControl(path); c.Dispose(); } } catch (ThreadAbortException) { // Cancel } catch (Exception ex) { string message = string.Format(GetString("Deployment.TestingFailed"), GetString("objecttype." + collection.ObjectType.Replace(".", "_")), name, ex.Message); AddError(message); } } }
/// <summary> /// Refreshes the security parameters in macros for all the objects of the specified object types. /// Signs all the macros with the current user if the old salt is not specified. /// </summary> /// <param name="objectTypes">Object types</param> /// <param name="oldSalt">Old salt </param> /// <param name="newSalt">New salt</param> private void RefreshSecurityParams(IEnumerable<string> objectTypes, string oldSalt, string newSalt) { var oldSaltSpecified = !string.IsNullOrEmpty(oldSalt) && !chkRefreshAll.Checked; var newSaltSpecified = !string.IsNullOrEmpty(newSalt) && !chkUseCurrentSalt.Checked; processedObjects.Clear(); using (var context = new CMSActionContext()) { context.LogEvents = false; context.LogSynchronization = false; foreach (var objectType in objectTypes) { var niceObjectType = GetNiceObjectTypeName(objectType); AddLog(string.Format(GetString("macros.refreshsecurityparams.processing"), niceObjectType)); try { var infos = new InfoObjectCollection(objectType); // Skip object types derived from general data class object type to avoid duplicities if ((infos.TypeInfo.OriginalObjectType == DataClassInfo.OBJECT_TYPE) && (infos.TypeInfo.ObjectType != DataClassInfo.OBJECT_TYPE)) { continue; } foreach (var info in infos) { try { bool refreshed; if (oldSaltSpecified) { refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, oldSalt, newSaltSpecified ? newSalt : ValidationHelper.HashStringSalt, true); } else { if (chkRefreshAll.Checked && newSaltSpecified) { // Do not check integrity, but use new salt refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, MembershipContext.AuthenticatedUser.UserName, true, newSalt); } else { // Do not check integrity, sign everything with current user refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, MembershipContext.AuthenticatedUser.UserName, true); } } if (refreshed) { var objectName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(info.Generalized.ObjectDisplayName)); processedObjects.Add(niceObjectType, objectName); } } catch (Exception ex) { string message = "Signing " + TypeHelper.GetNiceObjectTypeName(info.TypeInfo.ObjectType) + " " + info.Generalized.ObjectDisplayName + " failed: " + ex.Message; EventLogProvider.LogEvent(EventType.ERROR, "Import", "MACROSECURITY", message); } } } catch (Exception e) { AddLog(e.Message); EventLogProvider.LogException(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "ERROR", e); } } } EventLogProvider.LogEvent(EventType.INFORMATION, EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "PROCESSEDOBJECTS", GetProcessedObjectsForEventLog()); }
/// <summary> /// Refreshes the security parameters in macros for all the objects of the specified object types. /// Signs all the macros with the current user if the old salt is not specified. /// </summary> /// <param name="objectTypes">Object types</param> /// <param name="oldSalt">Old salt </param> /// <param name="newSalt">New salt</param> private void RefreshSecurityParams(IEnumerable<string> objectTypes, string oldSalt, string newSalt) { var oldSaltSpecified = !string.IsNullOrEmpty(oldSalt) && !chkRefreshAll.Checked; var newSaltSpecified = !string.IsNullOrEmpty(newSalt) && !chkUseCurrentSalt.Checked; processedObjects.Clear(); using (CMSActionContext context = new CMSActionContext()) { context.LogEvents = false; context.LogSynchronization = false; foreach (var objectType in objectTypes) { var objectTypeResourceKey = TypeHelper.GetObjectTypeResourceKey(objectType); var niceObjectType = GetString(objectTypeResourceKey); if (niceObjectType == objectTypeResourceKey) { if (objectType.StartsWithCSafe("bizformitem.bizform.", true)) { DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(objectType.Substring("bizformitem.".Length)); if (dci != null) { niceObjectType = "on-line form " + dci.ClassDisplayName; } } else { niceObjectType = objectType; } } LogContext.AppendLine(string.Format(GetString("macros.refreshsecurityparams.processing"), niceObjectType)); try { var infos = new InfoObjectCollection(objectType); foreach (var info in infos) { try { bool refreshed = false; if (oldSaltSpecified) { refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, oldSalt, newSaltSpecified ? newSalt : ValidationHelper.HashStringSalt, true); } else { if (chkRefreshAll.Checked && newSaltSpecified) { // Do not check integrity, but use new salt refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, MembershipContext.AuthenticatedUser.UserName, true, newSalt); } else { // Do not check integrity, sign everything with current user refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, MembershipContext.AuthenticatedUser.UserName, true); } } if (refreshed) { var objectName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(info.Generalized.ObjectDisplayName)); processedObjects.Add(niceObjectType, objectName); } } catch (Exception ex) { string message = "Signing " + TypeHelper.GetNiceObjectTypeName(info.TypeInfo.ObjectType) + " " + info.Generalized.ObjectDisplayName + " failed: " + ex.Message; EventLogProvider.LogEvent(EventType.ERROR, "Import", "MACROSECURITY", message); } } } catch (Exception e) { LogContext.AppendLine(e.Message); EventLogProvider.LogException(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "ERROR", e); } } } EventLogProvider.LogEvent(EventType.INFORMATION, EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "PROCESSEDOBJECTS", GetProcessedObjectsForEventLog()); }
/// <summary> /// Refreshes macro signatures in all object which can contain macros. /// </summary> private static void RefreshMacroSignatures() { // Get object types var objectTypes = new List<string> { TransformationInfo.OBJECT_TYPE, UIElementInfo.OBJECT_TYPE, FormUserControlInfo.OBJECT_TYPE, SettingsKeyInfo.OBJECT_TYPE, AlternativeFormInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE_SYSTEMTABLE, DataClassInfo.OBJECT_TYPE_CUSTOMTABLE, DataClassInfo.OBJECT_TYPE_DOCUMENTTYPE, PageTemplateInfo.OBJECT_TYPE, LayoutInfo.OBJECT_TYPE, CssStylesheetInfo.OBJECT_TYPE, WorkflowActionInfo.OBJECT_TYPE, }; foreach (string type in objectTypes) { try { using (var context = new CMSActionContext()) { context.DisableLogging(); context.CreateVersion = false; context.LogIntegration = false; var infos = new InfoObjectCollection(type); foreach (var info in infos) { MacroSecurityProcessor.RefreshSecurityParameters(info, "administrator", true); } } } catch (Exception ex) { EventLogProvider.LogException(EventLogSource, "REFRESHMACROSIGNATURES", ex, 0, "Type: " + type); } } }
private void RefreshSecurityParams(IEnumerable <string> objectTypes, string oldSalt, string newSalt) { var oldSaltSpecified = !string.IsNullOrEmpty(oldSalt) && !chkRefreshAll.Checked; var newSaltSpecified = !string.IsNullOrEmpty(newSalt) && !chkUseCurrentSalt.Checked; processedObjects.Clear(); using (var context = new CMSActionContext()) { context.LogEvents = false; context.LogSynchronization = false; var processingString = GetString("macros.refreshsecurityparams.processing"); foreach (var objectType in objectTypes) { var niceObjectType = GetNiceObjectTypeName(objectType); AddLog(string.Format(processingString, niceObjectType)); try { var infos = new InfoObjectCollection(objectType) { PageSize = 1000 }; var csi = infos.TypeInfo.ClassStructureInfo; var orderByIndex = FindOrderByIndex(csi); if (orderByIndex != null) { infos.OrderByColumns = orderByIndex.GetOrderBy(); } // Skip object types derived from general data class object type to avoid duplicities if ((infos.TypeInfo.OriginalObjectType == DataClassInfo.OBJECT_TYPE) && (infos.TypeInfo.ObjectType != DataClassInfo.OBJECT_TYPE)) { continue; } foreach (var info in infos) { try { bool refreshed; if (oldSaltSpecified) { refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, oldSalt, newSaltSpecified ? newSalt : ValidationHelper.HashStringSalt, true); } else { var identityOption = MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser); if (chkRefreshAll.Checked && newSaltSpecified) { // Do not check integrity, but use new salt refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, identityOption, true, newSalt); } else { // Do not check integrity, sign everything with current user refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, identityOption, true); } } if (refreshed) { var objectName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(info.Generalized.ObjectDisplayName)); processedObjects.Add(niceObjectType, objectName); } } catch (Exception ex) { string message = "Signing " + TypeHelper.GetNiceObjectTypeName(info.TypeInfo.ObjectType) + " " + info.Generalized.ObjectDisplayName + " failed: " + ex.Message; using (var exceptionContext = new CMSActionContext()) { exceptionContext.LogEvents = true; EventLogProvider.LogEvent(EventType.ERROR, "Import", "MACROSECURITY", message); } } } } catch (Exception ex) { AddLog(ex.Message); using (var exceptionContext = new CMSActionContext()) { exceptionContext.LogEvents = true; EventLogProvider.LogException(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "ERROR", ex); } } } } EventLogProvider.LogEvent(EventType.INFORMATION, EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "PROCESSEDOBJECTS", GetProcessedObjectsForEventLog()); }
/// <summary> /// Refreshes the security parameters in macros for all the objects of the specified object types. /// Signs all the macros with the current user if the old salt is not specified. /// </summary> /// <param name="objectTypes">Object types</param> /// <param name="oldSalt">Old salt </param> /// <param name="newSalt">New salt</param> private void RefreshSecurityParams(IEnumerable <string> objectTypes, string oldSalt, string newSalt) { var oldSaltSpecified = !string.IsNullOrEmpty(oldSalt) && !chkRefreshAll.Checked; var newSaltSpecified = !string.IsNullOrEmpty(newSalt) && !chkUseCurrentSalt.Checked; processedObjects.Clear(); using (CMSActionContext context = new CMSActionContext()) { context.LogEvents = false; context.LogSynchronization = false; foreach (var objectType in objectTypes) { var objectTypeResourceKey = TypeHelper.GetObjectTypeResourceKey(objectType); var niceObjectType = GetString(objectTypeResourceKey); if (niceObjectType == objectTypeResourceKey) { if (objectType.StartsWithCSafe("bizformitem.bizform.", true)) { DataClassInfo dci = DataClassInfoProvider.GetDataClass(objectType.Substring("bizformitem.".Length)); if (dci != null) { niceObjectType = "on-line form " + dci.ClassDisplayName; } } else { niceObjectType = objectType; } } LogContext.AppendLine(string.Format(GetString("macros.refreshsecurityparams.processing"), niceObjectType)); try { var infos = InfoObjectCollection.New(objectType); foreach (var info in infos) { bool refreshed = false; if (oldSaltSpecified) { refreshed = MacroResolver.RefreshSecurityParameters(info, oldSalt, newSaltSpecified ? newSalt : ValidationHelper.HashStringSalt, true); } else { if (chkRefreshAll.Checked && newSaltSpecified) { // Do not check integrity, but use new salt refreshed = MacroResolver.RefreshSecurityParameters(info, CMSContext.CurrentUser.UserName, true, newSalt); } else { // Do not check integrity, sign everything with current user, current salt refreshed = MacroResolver.RefreshSecurityParameters(info, CMSContext.CurrentUser.UserName, true); } } if (refreshed) { var objectName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(info.Generalized.ObjectDisplayName)); processedObjects.Add(niceObjectType, objectName); } } } catch (Exception e) { LogContext.AppendLine(e.Message); EventLogProvider.LogException(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "ERROR", e); } } } EventLogProvider.LogInformation(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "PROCESSEDOBJECTS", GetProcessedObjectsForEventLog()); }