public static void DropStore(string providerName, XmlProviderInterfaceConfigurationElement configurationElement) { foreach (DataScopeConfigurationElement scopeElement in configurationElement.ConfigurationStores) { DropStore(providerName, scopeElement); } }
public static void CreateStore(string providerName, XmlProviderInterfaceConfigurationElement configurationElement) { foreach (DataScopeConfigurationElement scopeElement in configurationElement.ConfigurationStores) { CreateStore(providerName, scopeElement); } }
/// <summary> /// Create an invariant store /// </summary> /// <param name="providerName"></param> /// <param name="dataTypeDescriptor"></param> public static void AddNew(string providerName, DataTypeDescriptor dataTypeDescriptor) { var xmlDataProviderConfiguration = new XmlDataProviderConfiguration(providerName); string interfaceType = dataTypeDescriptor.TypeManagerTypeName; if (interfaceType != null) { object key = xmlDataProviderConfiguration.Section.Interfaces.GetKey(dataTypeDescriptor); if (key != null) { Log.LogWarning(LogTitle, "Configuration file '{0}' already contains an interface type '{1} 'with id '{2}'. " + "Possibly there are multiple AppDomain-s running.", xmlDataProviderConfiguration.ConfigurationFilePath, dataTypeDescriptor, dataTypeDescriptor.DataTypeId); return; } } XmlProviderInterfaceConfigurationElement configurationElement = BuildXmlProviderInterfaceConfigurationElement(dataTypeDescriptor); XmlDataProviderStoreManipulator.CreateStore(providerName, configurationElement); xmlDataProviderConfiguration.Section.Interfaces.Add(configurationElement); xmlDataProviderConfiguration.Save(); }
public static void Remove(string providerName, DataTypeDescriptor dataTypeDescriptor) { XmlDataProviderConfiguration xmlDataProviderConfiguration = new XmlDataProviderConfiguration(providerName); object key = xmlDataProviderConfiguration.Section.Interfaces.GetKey(dataTypeDescriptor); if (key != null) { XmlProviderInterfaceConfigurationElement element = xmlDataProviderConfiguration.Section.Interfaces.Get(key); xmlDataProviderConfiguration.Section.Interfaces.Remove(key); xmlDataProviderConfiguration.Save(); XmlDataProviderStoreManipulator.DropStore(providerName, element); } }
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> { { "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> { { "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) { { "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); } } }
/// <summary> /// Builds a <see cref="GeneratedTypesInfo"/> object that describes information about helper types generation /// </summary> private GeneratedTypesInfo BuildGeneratedTypesInfo(DataTypeDescriptor dataTypeDescriptor, Type interfaceType, XmlProviderInterfaceConfigurationElement element = null) { string dataProviderHelperClassFullName, dataIdClassFullName; GetGeneratedClassNames(dataTypeDescriptor, out dataProviderHelperClassFullName, out dataIdClassFullName); Type dataProviderHelperClass = TypeManager.TryGetType(dataProviderHelperClassFullName); Type dataIdClass = TypeManager.TryGetType(dataIdClassFullName); bool compilationNeeded = CodeGenerationManager.IsRecompileNeeded(interfaceType, new[] { dataProviderHelperClass, dataIdClass }); return new GeneratedTypesInfo { Element = element, DataTypeDescriptor = dataTypeDescriptor, InterfaceType = interfaceType, DataIdClass = dataIdClass, DataIdClassName = dataIdClassFullName, DataProviderHelperClass = dataProviderHelperClass, DataProviderHelperClassName = dataProviderHelperClassFullName, CompilationNeeded = compilationNeeded }; }
private static DataTypeDescriptor GetDataTypeDescriptorNotNull(XmlProviderInterfaceConfigurationElement element) { Guid dataTypeId = element.DataTypeId; var dataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(dataTypeId, true); if (dataTypeDescriptor == null) { throw NewConfigurationException(element, "Failed to get a DataTypeDescriptor by id '{0}'".FormatWith(dataTypeId)); } return dataTypeDescriptor; }
private static XmlProviderInterfaceConfigurationElement BuildXmlProviderInterfaceConfigurationElement( DataTypeDescriptor dataTypeDescriptor, CultureInfo addedCultureInfo, CultureInfo removedCultureInfo, XmlProviderInterfaceConfigurationElement existingElement) { var configurationElement = new XmlProviderInterfaceConfigurationElement { DataTypeId = dataTypeDescriptor.DataTypeId, IsGeneratedType = dataTypeDescriptor.IsCodeGenerated }; bool isLocalized = dataTypeDescriptor.Localizeable; foreach (DataScopeIdentifier dataScopeIdentifier in dataTypeDescriptor.DataScopes) { if (!isLocalized) { configurationElement.ConfigurationStores.Add(new DataScopeConfigurationElement { DataScope = dataScopeIdentifier.Name, CultureName = CultureInfo.InvariantCulture.Name, Filename = NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, CultureInfo.InvariantCulture.Name), ElementName = NamesCreator.MakeElementName(dataTypeDescriptor) }); } if (isLocalized) { List <string> localizationNames = DataLocalizationFacade.ActiveLocalizationNames.ToList(); foreach (string cultureName in localizationNames) { if (removedCultureInfo != null && removedCultureInfo.Name == cultureName) { continue; } string existingFileName = null; string existingElementName = null; if (existingElement != null) { foreach (DataScopeConfigurationElement store in existingElement.ConfigurationStores) { if (store.DataScope == dataScopeIdentifier.Name && store.CultureName == cultureName) { existingFileName = store.Filename; existingElementName = store.ElementName; break; } } } configurationElement.ConfigurationStores.Add(new DataScopeConfigurationElement { DataScope = dataScopeIdentifier.Name, CultureName = cultureName, Filename = existingFileName ?? NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, cultureName), ElementName = existingElementName ?? NamesCreator.MakeElementName(dataTypeDescriptor) }); } if (addedCultureInfo != null && !localizationNames.Contains(addedCultureInfo.Name)) { configurationElement.ConfigurationStores.Add(new DataScopeConfigurationElement { DataScope = dataScopeIdentifier.Name, CultureName = addedCultureInfo.Name, Filename = NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, addedCultureInfo.Name), ElementName = NamesCreator.MakeElementName(dataTypeDescriptor) }); } } } configurationElement.ConfigurationDataIdProperties = new SimpleNameTypeConfigurationElementCollection(); foreach (DataFieldDescriptor field in dataTypeDescriptor.KeyFields) { configurationElement.ConfigurationDataIdProperties.Add(field.Name, field.InstanceType); } configurationElement.ConfigurationPropertyNameMappings = new PropertyNameMappingConfigurationElementCollection(); configurationElement.ConfigurationPropertyInitializers = new SimpleNameTypeConfigurationElementCollection(); return(configurationElement); }
private static XmlProviderInterfaceConfigurationElement BuildXmlProviderInterfaceConfigurationElement( DataTypeDescriptor dataTypeDescriptor, XmlProviderInterfaceConfigurationElement existingElement = null) { return(BuildXmlProviderInterfaceConfigurationElement(dataTypeDescriptor, null, null, existingElement)); }
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); } } }
private static XmlProviderInterfaceConfigurationElement BuildXmlProviderInterfaceConfigurationElement( DataTypeDescriptor dataTypeDescriptor, CultureInfo addedCultureInfo, CultureInfo removedCultureInfo, XmlProviderInterfaceConfigurationElement existingElement) { var configurationElement = new XmlProviderInterfaceConfigurationElement { DataTypeId = dataTypeDescriptor.DataTypeId, IsGeneratedType = dataTypeDescriptor.IsCodeGenerated }; bool isLocalized = dataTypeDescriptor.Localizeable; foreach (DataScopeIdentifier dataScopeIdentifier in dataTypeDescriptor.DataScopes) { if (!isLocalized) { configurationElement.ConfigurationStores.Add(new DataScopeConfigurationElement { DataScope = dataScopeIdentifier.Name, CultureName = CultureInfo.InvariantCulture.Name, Filename = NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, CultureInfo.InvariantCulture.Name), ElementName = NamesCreator.MakeElementName(dataTypeDescriptor) }); } if (isLocalized) { List<string> localizationNames = DataLocalizationFacade.ActiveLocalizationNames.ToList(); foreach (string cultureName in localizationNames) { if (removedCultureInfo != null && removedCultureInfo.Name == cultureName) continue; string existingFileName = null; string existingElementName = null; if (existingElement != null) { foreach (DataScopeConfigurationElement store in existingElement.ConfigurationStores) { if (store.DataScope == dataScopeIdentifier.Name && store.CultureName == cultureName) { existingFileName = store.Filename; existingElementName = store.ElementName; break; } } } configurationElement.ConfigurationStores.Add(new DataScopeConfigurationElement { DataScope = dataScopeIdentifier.Name, CultureName = cultureName, Filename = existingFileName ?? NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, cultureName), ElementName = existingElementName ?? NamesCreator.MakeElementName(dataTypeDescriptor) }); } if (addedCultureInfo != null && !localizationNames.Contains(addedCultureInfo.Name)) { configurationElement.ConfigurationStores.Add(new DataScopeConfigurationElement { DataScope = dataScopeIdentifier.Name, CultureName = addedCultureInfo.Name, Filename = NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, addedCultureInfo.Name), ElementName = NamesCreator.MakeElementName(dataTypeDescriptor) }); } } } configurationElement.ConfigurationDataIdProperties = new SimpleNameTypeConfigurationElementCollection(); foreach (DataFieldDescriptor field in dataTypeDescriptor.KeyFields) { configurationElement.ConfigurationDataIdProperties.Add(field.Name, field.InstanceType); } configurationElement.ConfigurationPropertyNameMappings = new PropertyNameMappingConfigurationElementCollection(); configurationElement.ConfigurationPropertyInitializers = new SimpleNameTypeConfigurationElementCollection(); return configurationElement; }
private static XmlProviderInterfaceConfigurationElement BuildXmlProviderInterfaceConfigurationElement( DataTypeDescriptor dataTypeDescriptor, XmlProviderInterfaceConfigurationElement existingElement = null) { return BuildXmlProviderInterfaceConfigurationElement(dataTypeDescriptor, null, null, existingElement); }