// Helper internal static bool EnsureUpdateStore(Type interfaceType, string providerName, bool makeAFlush) { using (TimerProfilerFacade.CreateTimerProfiler(interfaceType.ToString())) { var newDataTypeDescriptor = BuildNewDataTypeDescriptor(interfaceType); var oldDataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(newDataTypeDescriptor.DataTypeId); if (oldDataTypeDescriptor == null) { DataMetaDataFacade.PersistMetaData(newDataTypeDescriptor); return(false); } var dataTypeChangeDescriptor = new DataTypeChangeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor); if (!dataTypeChangeDescriptor.AlteredTypeHasChanges) { return(false); } Log.LogVerbose("DynamicTypeManager", "Updating the store for interface type '{0}' on the '{1}' data provider", interfaceType, providerName); var updateDataTypeDescriptor = new UpdateDataTypeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor, providerName); AlterStore(updateDataTypeDescriptor, makeAFlush); return(true); } }
// Helper internal static bool EnsureUpdateStore(Type interfaceType, string providerName, bool makeAFlush) { using (TimerProfilerFacade.CreateTimerProfiler(interfaceType.ToString())) { var newDataTypeDescriptor = BuildNewDataTypeDescriptor(interfaceType); var oldDataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(newDataTypeDescriptor.DataTypeId); if (interfaceType.IsGenerated()) { var customFields = oldDataTypeDescriptor.Fields.Where(f => !f.Inherited && !oldDataTypeDescriptor.KeyPropertyNames .Contains(f.Name)); foreach (var field in customFields) { newDataTypeDescriptor.Fields.Remove(newDataTypeDescriptor.Fields[field.Name]); newDataTypeDescriptor.Fields.Add(field); } } if (oldDataTypeDescriptor == null) { DataMetaDataFacade.PersistMetaData(newDataTypeDescriptor); return(false); } var dataTypeChangeDescriptor = new DataTypeChangeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor); if (!dataTypeChangeDescriptor.AlteredTypeHasChanges) { if (dataTypeChangeDescriptor.TypeHasMetaDataChanges) { Log.LogInformation(nameof(DynamicTypeManager), $"Updating data type descriptor for type '{newDataTypeDescriptor.GetFullInterfaceName()}'"); DataMetaDataFacade.PersistMetaData(newDataTypeDescriptor); } return(false); } Log.LogVerbose(nameof(DynamicTypeManager), "Updating the store for interface type '{0}' on the '{1}' data provider", interfaceType, providerName); var updateDataTypeDescriptor = new UpdateDataTypeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor, providerName); AlterStore(updateDataTypeDescriptor, makeAFlush); return(true); } }
/// <exclude /> public void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, bool forceCompile) { DataTypeChangeDescriptor dataTypeChangeDescriptor = updateDataTypeDescriptor.CreateDataTypeChangeDescriptor(); dataTypeChangeDescriptor.AlteredType.Validate(); using (var transactionScope = TransactionsFacade.CreateNewScope()) { DataMetaDataFacade.PersistMetaData(dataTypeChangeDescriptor.AlteredType); if (dataTypeChangeDescriptor.AlteredTypeHasChanges) { DataProviderPluginFacade.AlterStore(updateDataTypeDescriptor, forceCompile); } transactionScope.Complete(); } }
public void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, bool forceCompile) { var dataTypeChangeDescriptor = updateDataTypeDescriptor.CreateDataTypeChangeDescriptor(); using (TimerProfilerFacade.CreateTimerProfiler()) { SqlStoreManipulator.AlterStoresForType(updateDataTypeDescriptor); bool localizationChanged = dataTypeChangeDescriptor.AlteredType.Localizeable != dataTypeChangeDescriptor.OriginalType.Localizeable; var oldElement = _interfaceConfigurationElements.Single(f => f.DataTypeId == updateDataTypeDescriptor.OldDataTypeDescriptor.DataTypeId); var newElement = InterfaceConfigurationManipulator.Change(_dataProviderContext.ProviderName, dataTypeChangeDescriptor, localizationChanged); if (newElement != null) { _interfaceConfigurationElements.Remove(oldElement); _interfaceConfigurationElements.Add(newElement); } if (forceCompile) { Dictionary<DataTypeDescriptor, IEnumerable<SqlDataTypeStoreDataScope>> allSqlDataTypeStoreDataScopes = BuildAllExistingDataTypeStoreDataScopes(); InitializeStoreResult initializeStoreResult = InitializeStore(newElement ?? oldElement, allSqlDataTypeStoreDataScopes, true); if (!updateDataTypeDescriptor.NewDataTypeDescriptor.IsCodeGenerated) { var interfaceType = updateDataTypeDescriptor.NewDataTypeDescriptor.GetInterfaceType(); if (!DataTypeValidationRegistry.IsValidForProvider(interfaceType, _dataProviderContext.ProviderName)) { // Revalidating alternated static data type _sqlDataTypeStoresContainer.RemoveKnownInterface(interfaceType); DataTypeValidationRegistry.ClearValidationError(interfaceType, _dataProviderContext.ProviderName); AddDataTypeStore(initializeStoreResult); } } } } }
public static XmlProviderInterfaceConfigurationElement Change(UpdateDataTypeDescriptor updateDataTypeDescriptor) { DataTypeChangeDescriptor changeDescriptor = updateDataTypeDescriptor.CreateDataTypeChangeDescriptor(); var xmlDataProviderConfiguration = new XmlDataProviderConfiguration(updateDataTypeDescriptor.ProviderName); object key = xmlDataProviderConfiguration.Section.Interfaces.GetKey(changeDescriptor.OriginalType); var oldConfigurationElement = xmlDataProviderConfiguration.Section.Interfaces.Get(key); var newConfigurationElement = BuildXmlProviderInterfaceConfigurationElement(changeDescriptor.AlteredType, oldConfigurationElement); XmlDataProviderStoreManipulator.AlterStore(updateDataTypeDescriptor, oldConfigurationElement, newConfigurationElement); xmlDataProviderConfiguration.Section.Interfaces.Remove(key); xmlDataProviderConfiguration.Section.Interfaces.Add(newConfigurationElement); xmlDataProviderConfiguration.Save(); return newConfigurationElement; }
public void UpdateType(UpdateDataTypeDescriptor updateDataTypeDescriptor) { Verify.ArgumentNotNullOrEmpty(updateDataTypeDescriptor.ProviderName, "providerName"); Verify.ArgumentNotNull(updateDataTypeDescriptor.OldDataTypeDescriptor, "oldDataTypeDescriptor"); Verify.ArgumentNotNull(updateDataTypeDescriptor.NewDataTypeDescriptor, "newDataTypeDescriptor"); Type interfaceType = null; if (updateDataTypeDescriptor.OldDataTypeDescriptor.IsCodeGenerated) { interfaceType = InterfaceCodeManager.GetType(updateDataTypeDescriptor.NewDataTypeDescriptor, true); } else { interfaceType = DataTypeTypesManager.GetDataType(updateDataTypeDescriptor.NewDataTypeDescriptor); } updateDataTypeDescriptor.NewDataTypeDescriptor.TypeManagerTypeName = TypeManager.SerializeType(interfaceType); DynamicTypeManager.AlterStore(updateDataTypeDescriptor, false); CodeGenerationManager.GenerateCompositeGeneratedAssembly(true); }
public void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, bool forceCompile) { XmlDataProviderDocumentCache.ClearCache(); XmlProviderInterfaceConfigurationElement element = InterfaceConfigurationManipulator.Change(updateDataTypeDescriptor); if (forceCompile) { DataTypeDescriptor dataTypeDescriptor = updateDataTypeDescriptor.NewDataTypeDescriptor; Type dataProviderHelperType; Type dataIdClassType; bool typesExists = EnsureNeededTypes(dataTypeDescriptor, out dataProviderHelperType, out dataIdClassType, true); Verify.That(typesExists, "Could not find or code generated the type '{0}' or one of the needed helper types", dataTypeDescriptor.GetFullInterfaceName()); var xmlDataTypeStoreDataScopes = new List<XmlDataTypeStoreDataScope>(); foreach (DataScopeConfigurationElement dataScopeConfigurationElement in element.ConfigurationStores) { var xmlDataTypeStoreDataScope = new XmlDataTypeStoreDataScope { DataScopeName = dataScopeConfigurationElement.DataScope, CultureName = dataScopeConfigurationElement.CultureName, ElementName = dataScopeConfigurationElement.ElementName, Filename = Path.Combine(_fileStoreDirectory, dataScopeConfigurationElement.Filename) }; xmlDataTypeStoreDataScopes.Add(xmlDataTypeStoreDataScope); } var xmlDataTypeStoreCreator = new XmlDataTypeStoreCreator(_fileStoreDirectory); XmlDataTypeStore xmlDateTypeStore = xmlDataTypeStoreCreator.CreateStoreResult(dataTypeDescriptor, dataProviderHelperType, dataIdClassType, xmlDataTypeStoreDataScopes); Type interfaceType = DataTypeTypesManager.GetDataType(dataTypeDescriptor); UpdateDataTypeStore(dataTypeDescriptor, interfaceType, xmlDateTypeStore); } }
private void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, DataTypeChangeDescriptor changeDescriptor, DataScopeIdentifier dataScope, CultureInfo culture) { try { string originalTableName = GetConfiguredTableName(changeDescriptor.OriginalType, dataScope, culture.Name); string alteredTableName = originalTableName; // This could be done more nicely! But only give the table a new name if the type has changed its name and not because we changed the naming scheme if (updateDataTypeDescriptor.OldDataTypeDescriptor.Name != updateDataTypeDescriptor.NewDataTypeDescriptor.Name || updateDataTypeDescriptor.OldDataTypeDescriptor.Namespace != updateDataTypeDescriptor.NewDataTypeDescriptor.Namespace) { alteredTableName = DynamicTypesCommon.GenerateTableName(changeDescriptor.AlteredType, dataScope, culture); } var tables = GetTablesList(); if (!tables.Contains(originalTableName)) { throw new InvalidOperationException( string.Format( "Unable to alter data type store. The database does not contain expected table {0}", originalTableName)); } bool primaryKeyChanged = changeDescriptor.AddedKeyFields.Any() || changeDescriptor.DeletedKeyFields.Any() || changeDescriptor.KeyFieldsOrderChanged || changeDescriptor.OriginalType.PrimaryKeyIsClusteredIndex != changeDescriptor.AlteredType.PrimaryKeyIsClusteredIndex; DropConstraints(originalTableName, primaryKeyChanged); if (originalTableName != alteredTableName) { if (tables.Contains(alteredTableName)) throw new InvalidOperationException( string.Format("Can not rename table to {0}. A table with that name already exists", alteredTableName)); RenameTable(originalTableName, alteredTableName); } var newIndexes = changeDescriptor.AlteredType.Indexes.Select(i => i.ToString()).ToList(); foreach (var oldIndex in changeDescriptor.OriginalType.Indexes) { if (!newIndexes.Contains(oldIndex.ToString())) { DropIndex(alteredTableName, oldIndex); } } DropFields(alteredTableName, changeDescriptor.DeletedFields, changeDescriptor.OriginalType.Fields); ImplementFieldChanges(alteredTableName, changeDescriptor.ExistingFields); Dictionary<string, object> defaultValues = null; if (updateDataTypeDescriptor.PublicationAdded) { defaultValues = new Dictionary<string, object> { {"PublicationStatus", GenericPublishProcessController.Draft} }; } AppendFields(alteredTableName, changeDescriptor, changeDescriptor.AddedFields, defaultValues); // Clustered index has to be created first. var createIndexActions = new List<Tuple<bool, Action>>(); if (primaryKeyChanged) { bool isClusteredIndex = changeDescriptor.AlteredType.PrimaryKeyIsClusteredIndex; createIndexActions.Add(new Tuple<bool, Action>(isClusteredIndex, () => ExecuteNonQuery(SetPrimaryKey(alteredTableName, changeDescriptor.AlteredType.PhysicalKeyPropertyNames, isClusteredIndex)) )); } var oldIndexes = changeDescriptor.OriginalType.Indexes.Select(i => i.ToString()).ToList(); foreach (var newIndex in changeDescriptor.AlteredType.Indexes) { if (!oldIndexes.Contains(newIndex.ToString())) { var index = newIndex; createIndexActions.Add(new Tuple<bool, Action>(newIndex.Clustered, () => CreateIndex(alteredTableName, index))); } } createIndexActions.Sort((a, b) => b.Item1.CompareTo(a.Item1)); foreach (var createIndex in createIndexActions) { createIndex.Item2(); } SqlTableInformationStore.ClearCache(_connectionString, originalTableName); SqlTableInformationStore.ClearCache(_connectionString, alteredTableName); } catch (Exception ex) { throw MakeVerboseException(ex); } }
private void AlterScopeData(UpdateDataTypeDescriptor updateDataTypeDescriptor, DataTypeChangeDescriptor changeDescriptor, DataScopeIdentifier dataScope) { var culturesToDelete = new List<CultureInfo>(); var culturesToChange = new List<CultureInfo>(); var oldCultures = GetCultures(changeDescriptor.OriginalType).Evaluate(); var newCultures = GetCultures(changeDescriptor.AlteredType).Evaluate(); foreach (var culture in oldCultures) { if (newCultures.Contains(culture)) { culturesToChange.Add(culture); } else { culturesToDelete.Add(culture); } } var culturesToAdd = newCultures.Where(culture => !oldCultures.Contains(culture)).ToList(); culturesToAdd.ForEach(culture => CreateStore(changeDescriptor.AlteredType, dataScope, culture)); culturesToChange.ForEach(culture => AlterStore(updateDataTypeDescriptor, changeDescriptor, dataScope, culture)); if (updateDataTypeDescriptor.LocalesToCopyTo != null) { StringBuilder fieldList = GetCommonFields(changeDescriptor); string fromTableName = GetConfiguredTableName(changeDescriptor.OriginalType, dataScope, ""); foreach (CultureInfo locale in updateDataTypeDescriptor.LocalesToCopyTo) { string toTableName = DynamicTypesCommon.GenerateTableName(changeDescriptor.AlteredType, dataScope, locale); string copyCommandText = string.Format(@" INSERT INTO [{0}] ({2}) SELECT {2} FROM [{1}];", toTableName, fromTableName, fieldList); ExecuteNonQuery(copyCommandText); string updateCommandText = string.Format("UPDATE [{0}] SET [{1}] = '{2}'", toTableName, "SourceCultureName", locale.Name); ExecuteNonQuery(updateCommandText); } string removeCommandText = string.Format(@"DELETE FROM [{0}];", fromTableName); ExecuteNonQuery(removeCommandText); } if (updateDataTypeDescriptor.LocaleToCopyFrom != null) { StringBuilder fieldList = GetCommonFields(changeDescriptor); string fromTableName = GetConfiguredTableName(changeDescriptor.OriginalType, dataScope, updateDataTypeDescriptor.LocaleToCopyFrom.Name); string toTableName = DynamicTypesCommon.GenerateTableName(changeDescriptor.AlteredType, dataScope, CultureInfo.InvariantCulture); string copyCommandText = string.Format(@" INSERT INTO [{0}] ({2}) SELECT {2} FROM [{1}];", toTableName, fromTableName, fieldList); ExecuteNonQuery(copyCommandText); } culturesToDelete.ForEach(culture => DropStore(changeDescriptor.OriginalType, dataScope, culture)); }
internal void AlterStoresForType(UpdateDataTypeDescriptor updateDataTypeDescriptor) { DataTypeChangeDescriptor changeDescriptor = updateDataTypeDescriptor.CreateDataTypeChangeDescriptor(); lock (_lock) { foreach (DataScopeIdentifier dataScope in changeDescriptor.AddedDataScopes) { CreateScopeData(changeDescriptor.AlteredType, dataScope); } foreach (DataScopeIdentifier dataScope in changeDescriptor.ExistingDataScopes) { AlterScopeData(updateDataTypeDescriptor, changeDescriptor, dataScope); } if (updateDataTypeDescriptor.PublicationAdded) { HandleEnablingOfPublication(changeDescriptor); } if (updateDataTypeDescriptor.PublicationRemoved) { HandleDisablingOfPublication(changeDescriptor); } foreach (DataScopeIdentifier dataScope in changeDescriptor.DeletedDataScopes) { DropScopeData(changeDescriptor.AlteredType, dataScope); } } }
public static void AlterStore(UpdateDataTypeDescriptor updateDescriptor, XmlProviderInterfaceConfigurationElement oldConfigurationElement, XmlProviderInterfaceConfigurationElement newConfigurationElement) { DataTypeChangeDescriptor dataTypeChangeDescriptor = updateDescriptor.CreateDataTypeChangeDescriptor(); foreach (KeyValuePair<string, Type> kvp in oldConfigurationElement.PropertyInitializers) { newConfigurationElement.AddPropertyInitializer(kvp.Key, kvp.Value); } Dictionary<string, object> newFieldValues = new Dictionary<string, object>(); foreach (DataScopeIdentifier scopeIdentifier in dataTypeChangeDescriptor.AddedDataScopes) { foreach (DataScopeConfigurationElement dataScopeConfigurationElement in newConfigurationElement.DataScopes[scopeIdentifier.Name].Values) { CreateStore(updateDescriptor.ProviderName, dataScopeConfigurationElement); } } foreach (DataScopeIdentifier scopeIdentifier in dataTypeChangeDescriptor.ExistingDataScopes) { foreach (KeyValuePair<string, DataScopeConfigurationElement> fileForLanguage in oldConfigurationElement.DataScopes[scopeIdentifier.Name]) { string cultureName = fileForLanguage.Key; if (!newConfigurationElement.DataScopes[scopeIdentifier.Name].ContainsKey(cultureName)) { continue; } var oldDataScopeConfigurationElement = fileForLanguage.Value; var newDataScopeConfigurationElement = newConfigurationElement.DataScopes[scopeIdentifier.Name][cultureName]; newFieldValues = new Dictionary<string, object>(); newFieldValues.Add("PublicationStatus", GenericPublishProcessController.Published); CopyData(updateDescriptor.ProviderName, dataTypeChangeDescriptor, oldDataScopeConfigurationElement, newDataScopeConfigurationElement, newFieldValues); } } if (updateDescriptor.PublicationAdded) { foreach (var fileByLanguage in oldConfigurationElement.DataScopes[DataScopeIdentifier.PublicName]) { var oldDataScopeConfigurationElement = fileByLanguage.Value; var newDataScopeConfigurationElement = newConfigurationElement.DataScopes[DataScopeIdentifier.AdministratedName][fileByLanguage.Key]; newFieldValues = new Dictionary<string, object>(); newFieldValues.Add("PublicationStatus", GenericPublishProcessController.Published); CopyData(updateDescriptor.ProviderName, dataTypeChangeDescriptor, oldDataScopeConfigurationElement, newDataScopeConfigurationElement, newFieldValues, false); } } if (updateDescriptor.PublicationRemoved) { foreach (var fileByLanguage in oldConfigurationElement.DataScopes[DataScopeIdentifier.AdministratedName]) { var oldDataScopeConfigurationElement = fileByLanguage.Value; var newDataScopeConfigurationElement = newConfigurationElement.DataScopes[DataScopeIdentifier.PublicName][fileByLanguage.Key]; CopyData(updateDescriptor.ProviderName, dataTypeChangeDescriptor, oldDataScopeConfigurationElement, newDataScopeConfigurationElement, newFieldValues, false); } } bool oldTypeLocalized = updateDescriptor.OldDataTypeDescriptor.Localizeable; bool newTypeLocalized = updateDescriptor.NewDataTypeDescriptor.Localizeable; if (!oldTypeLocalized && newTypeLocalized) { foreach (var newStore in newConfigurationElement.DataScopes.Values.SelectMany(kvp => kvp.Values)) { CreateStore(updateDescriptor.ProviderName, newStore); } foreach (string dataScopeIdentifier in oldConfigurationElement.DataScopes.Keys) { var oldFilesByCulture = oldConfigurationElement.DataScopes[dataScopeIdentifier]; string invariantCultureKey = ""; if (oldFilesByCulture.ContainsKey(invariantCultureKey)) { var oldDataScopeConfigurationElement = oldFilesByCulture[invariantCultureKey]; if (updateDescriptor.LocalesToCopyTo != null) { foreach (CultureInfo locale in updateDescriptor.LocalesToCopyTo) { var newDataScopeConfigurationElement = newConfigurationElement.DataScopes[dataScopeIdentifier][locale.Name]; var nfv = new Dictionary<string, object>(newFieldValues); nfv.Add("SourceCultureName", locale.Name); CopyData(updateDescriptor.ProviderName, dataTypeChangeDescriptor, oldDataScopeConfigurationElement, newDataScopeConfigurationElement, nfv, false); } } DropStore(updateDescriptor.ProviderName, oldDataScopeConfigurationElement); } } } if (oldTypeLocalized && !newTypeLocalized) { foreach (var newStore in newConfigurationElement.DataScopes.Values.SelectMany(kvp => kvp.Values)) { CreateStore(updateDescriptor.ProviderName, newStore); } if (updateDescriptor.LocaleToCopyFrom != null) { foreach (string dataScopeIdentifier in oldConfigurationElement.DataScopes.Keys) { var oldDataScopeConfigurationElement = oldConfigurationElement.DataScopes[dataScopeIdentifier][updateDescriptor.LocaleToCopyFrom.Name]; var newDataScopeConfigurationElement = newConfigurationElement.DataScopes[dataScopeIdentifier][""]; CopyData(updateDescriptor.ProviderName, dataTypeChangeDescriptor, oldDataScopeConfigurationElement, newDataScopeConfigurationElement, newFieldValues, false); } } foreach (var oldStore in oldConfigurationElement.DataScopes.SelectMany(d => d.Value).Where(f => f.Key != "").Select(f => f.Value)) { DropStore(updateDescriptor.ProviderName, oldStore); } } foreach (DataScopeIdentifier scopeIdentifier in dataTypeChangeDescriptor.DeletedDataScopes) { foreach (DataScopeConfigurationElement dataScopeConfigurationElement in oldConfigurationElement.DataScopes[scopeIdentifier.Name].Values) { DropStore(updateDescriptor.ProviderName, dataScopeConfigurationElement); } } }
///// <exclude /> //public static void UpdateType(DataTypeDescriptor oldDataTypeDescriptor, DataTypeDescriptor newDataTypeDescriptor, bool originalTypeHasData) //{ // UpdateType(DataProviderRegistry.DefaultDynamicTypeDataProviderName, oldDataTypeDescriptor, newDataTypeDescriptor, originalTypeHasData); //} ///// <exclude /> //public static void UpdateType(DataTypeDescriptor oldDataTypeDescriptor, DataTypeDescriptor newDataTypeDescriptor) //{ // UpdateType(DataProviderRegistry.DefaultDynamicTypeDataProviderName, oldDataTypeDescriptor, newDataTypeDescriptor, true); //} /// <exclude /> public static void UpdateType(UpdateDataTypeDescriptor updateDataTypeDescriptor) { using (GlobalInitializerFacade.CoreLockScope) { _generatedTypesFacade.UpdateType(updateDataTypeDescriptor); if (_updateTypeDelegate != null) { UpdateTypeDelegate updateDelegate = _updateTypeDelegate; updateDelegate(new UpdateTypeEventArgs()); } } }
// Helper internal static bool EnsureUpdateStore(Type interfaceType, string providerName, bool makeAFlush) { using (TimerProfilerFacade.CreateTimerProfiler(interfaceType.ToString())) { var newDataTypeDescriptor = BuildNewDataTypeDescriptor(interfaceType); var oldDataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(newDataTypeDescriptor.DataTypeId); if (interfaceType.IsGenerated()) { var customFields = oldDataTypeDescriptor.Fields.Where(f => !f.Inherited && !oldDataTypeDescriptor.KeyPropertyNames .Contains(f.Name)); foreach (var field in customFields) { newDataTypeDescriptor.Fields.Remove(newDataTypeDescriptor.Fields[field.Name]); newDataTypeDescriptor.Fields.Add(field); } } if (oldDataTypeDescriptor == null) { DataMetaDataFacade.PersistMetaData(newDataTypeDescriptor); return false; } var dataTypeChangeDescriptor = new DataTypeChangeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor); if (!dataTypeChangeDescriptor.AlteredTypeHasChanges) return false; Log.LogVerbose("DynamicTypeManager", "Updating the store for interface type '{0}' on the '{1}' data provider", interfaceType, providerName); var updateDataTypeDescriptor = new UpdateDataTypeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor, providerName); AlterStore(updateDataTypeDescriptor, makeAFlush); return true; } }
/// <exclude /> public static void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, bool forceRecompile) { _dynamicTypeManager.AlterStore(updateDataTypeDescriptor, forceRecompile); }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { DataTypeDescriptor dataTypeDescriptor = GetDataTypeDescriptor(); DataTypeDescriptor newDataTypeDescriptor = dataTypeDescriptor.Clone(); newDataTypeDescriptor.RemoveSuperInterface(typeof(ILocalizedControlled)); UpdateDataTypeDescriptor updateDataTypeDescriptor = new UpdateDataTypeDescriptor(dataTypeDescriptor, newDataTypeDescriptor, false); if (this.BindingExist("CultureName")) { string cultureName = this.GetBinding<string>("CultureName"); CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(cultureName); updateDataTypeDescriptor.LocaleToCopyFrom = cultureInfo; } GeneratedTypesFacade.UpdateType(updateDataTypeDescriptor); this.CloseCurrentView(); this.CollapseAndRefresh(); }
/// <exclude /> public static void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, bool forceRecompile) { _dynamicTypeManager.AlterStore(updateDataTypeDescriptor, forceRecompile); OnStoreUpdated?.Invoke(updateDataTypeDescriptor); }
// Overload /// <exclude /> public static void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor) { AlterStore(updateDataTypeDescriptor, false); }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { DataTypeDescriptor dataTypeDescriptor = GetDataTypeDescriptor(); // Making changes to type DataTypeDescriptor newDataTypeDescriptor = dataTypeDescriptor.Clone(); newDataTypeDescriptor.AddSuperInterface(typeof(ILocalizedControlled)); List<CultureInfo> localesToCopyTo = new List<CultureInfo>(); if (ThereAreReferencesInLocalizedData()) { localesToCopyTo.AddRange(DataLocalizationFacade.ActiveLocalizationCultures); } else { string cultureName = this.GetBinding<string>("CultureName"); localesToCopyTo.Add(CultureInfo.CreateSpecificCulture(cultureName)); } var updateDataTypeDescriptor = new UpdateDataTypeDescriptor(dataTypeDescriptor, newDataTypeDescriptor, false) { LocalesToCopyTo = localesToCopyTo }; GeneratedTypesFacade.UpdateType(updateDataTypeDescriptor); this.CloseCurrentView(); this.CollapseAndRefresh(); }
// Helper internal static bool EnsureUpdateStore(Type interfaceType, string providerName, bool makeAFlush) { using (TimerProfilerFacade.CreateTimerProfiler(interfaceType.ToString())) { var newDataTypeDescriptor = BuildNewDataTypeDescriptor(interfaceType); var oldDataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(newDataTypeDescriptor.DataTypeId); if (oldDataTypeDescriptor == null) { DataMetaDataFacade.PersistMetaData(newDataTypeDescriptor); return false; } var dataTypeChangeDescriptor = new DataTypeChangeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor); if (!dataTypeChangeDescriptor.AlteredTypeHasChanges) return false; Log.LogVerbose("DynamicTypeManager", "Updating the store for interface type '{0}' on the '{1}' data provider", interfaceType, providerName); var updateDataTypeDescriptor = new UpdateDataTypeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor, providerName); AlterStore(updateDataTypeDescriptor, makeAFlush); return true; } }
/// <summary> /// This method will remove a foreign key (if any exists) that is no longer possible with the /// new meta data system (IPageMetaDataDefinition) /// </summary> /// <param name="dataTypeDescriptor"></param> /// <param name="dataStoreExists"></param> private void UpdateWithNewPageFolderForeignKeySystem(DataTypeDescriptor dataTypeDescriptor, bool dataStoreExists) { if (dataTypeDescriptor.IsPageFolderDataType == false) { return; } DataFieldDescriptor dataFieldDescriptor = dataTypeDescriptor.Fields["IAggregationDescriptionIdForeignKey"]; if (dataFieldDescriptor == null) { return; } Log.LogVerbose("GeneratedTypesFacade", string.Format("Removing the property {0} on the type {1}.{2}", dataFieldDescriptor.Name, dataTypeDescriptor.Namespace, dataTypeDescriptor.Name)); if(!dataStoreExists) { dataTypeDescriptor.Fields.Remove(dataFieldDescriptor); DynamicTypeManager.UpdateDataTypeDescriptor(dataTypeDescriptor, false); return; } DataTypeDescriptor oldDataTypeDescriptor = dataTypeDescriptor.Clone(); dataTypeDescriptor.Fields.Remove(dataFieldDescriptor); var dataTypeChangeDescriptor = new DataTypeChangeDescriptor(oldDataTypeDescriptor, dataTypeDescriptor); UpdateDataTypeDescriptor updateDataTypeDescriptor = new UpdateDataTypeDescriptor(oldDataTypeDescriptor, dataTypeDescriptor); DynamicTypeManager.AlterStore(updateDataTypeDescriptor, false); }