public XmlDataTypeStoreDataScope GetDataScope(DataScopeIdentifier dataScope, CultureInfo culture, Type type) { string dataScopeName = dataScope.Name; Verify.That(HasDataScopeName(dataScope), "The store named '{0}' is not supported for data type '{1}'", dataScopeName, type); string cultureName = culture.Name; XmlDataTypeStoreDataScope dateTypeStoreDataScope = _xmlDateTypeStoreDataScopes.SingleOrDefault(f => f.DataScopeName == dataScopeName && f.CultureName == cultureName); if (dateTypeStoreDataScope == null) { if (culture.Equals(CultureInfo.InvariantCulture) && DataLocalizationFacade.IsLocalized(type)) { throw new InvalidOperationException("Failed to get data for type '{0}', no localization scope is provided for a localized type." .FormatWith(type.FullName)); } throw new InvalidOperationException("Failed to get '{0}' data for data scope ({1}, {2})" .FormatWith(type.FullName, dataScopeName, culture.Equals(CultureInfo.InvariantCulture) ? "invariant" : cultureName)); } return(dateTypeStoreDataScope); }
/// <summary> /// This class is used to create <see cref="XmlDataTypeStore"/>. /// Either for existing stores or for just newly created/added stores. /// There exist one store for each data type that the provider handles. /// While the <see cref="XmlDataTypeStore"/> is created, the input and /// configuration is validated. /// </summary> /// <param name="dataTypeDescriptor"></param> /// <param name="dataProviderHelperClassType">The runtime type for the generated implementation of <see cref="IXmlDataProviderHelper"/></param> /// <param name="dataIdClassType">The runtime type for the generated data id class.</param> /// <param name="xmlDataTypeStoreDataScopes">If this is null, default values will be created.</param> /// <returns> /// Returns a <see cref="XmlDataTypeStore"/> if it is valid, else null /// </returns> public XmlDataTypeStore CreateStoreResult(DataTypeDescriptor dataTypeDescriptor, Type dataProviderHelperClassType, Type dataIdClassType, IEnumerable<XmlDataTypeStoreDataScope> xmlDataTypeStoreDataScopes) { if (xmlDataTypeStoreDataScopes == null) { var defaultDataScopes = new List<XmlDataTypeStoreDataScope>(); IEnumerable<string> cultureNames; if (dataTypeDescriptor.Localizeable) { cultureNames = DataLocalizationFacade.ActiveLocalizationNames; } else { cultureNames = new[] { CultureInfo.InvariantCulture.Name }; } foreach (DataScopeIdentifier dataScopeIdentifier in dataTypeDescriptor.DataScopes.Distinct()) { foreach (string cultureName in cultureNames) { var defaultXmlDataTypeStoreDataScope = new XmlDataTypeStoreDataScope { DataScopeName = dataScopeIdentifier.Name, CultureName = cultureName, ElementName = NamesCreator.MakeElementName(dataTypeDescriptor), Filename = Path.Combine(_fileStoreDirectory, NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, cultureName)) }; var document = new XDocument(new XElement(defaultXmlDataTypeStoreDataScope.ElementName)); document.SaveToFile(defaultXmlDataTypeStoreDataScope.Filename); defaultDataScopes.Add(defaultXmlDataTypeStoreDataScope); } } xmlDataTypeStoreDataScopes = defaultDataScopes; } return new XmlDataTypeStore(dataTypeDescriptor, dataProviderHelperClassType, dataIdClassType, xmlDataTypeStoreDataScopes, dataTypeDescriptor.IsCodeGenerated); }
/// <summary> /// This class is used to create <see cref="XmlDataTypeStore"/>. /// Either for existing stores or for just newly created/added stores. /// There exist one store for each data type that the provider handles. /// While the <see cref="XmlDataTypeStore"/> is created, the input and /// configuration is validated. /// </summary> /// <param name="dataTypeDescriptor"></param> /// <param name="dataProviderHelperClassType">The runtime type for the generated implementation of <see cref="IXmlDataProviderHelper"/></param> /// <param name="dataIdClassType">The runtime type for the generated data id class.</param> /// <param name="xmlDataTypeStoreDataScopes">If this is null, default values will be created.</param> /// <returns> /// Returns a <see cref="XmlDataTypeStore"/> if it is valid, else null /// </returns> public XmlDataTypeStore CreateStoreResult(DataTypeDescriptor dataTypeDescriptor, Type dataProviderHelperClassType, Type dataIdClassType, IEnumerable <XmlDataTypeStoreDataScope> xmlDataTypeStoreDataScopes) { if (xmlDataTypeStoreDataScopes == null) { var defaultDataScopes = new List <XmlDataTypeStoreDataScope>(); IEnumerable <string> cultureNames; if (dataTypeDescriptor.Localizeable) { cultureNames = DataLocalizationFacade.ActiveLocalizationNames; } else { cultureNames = new[] { CultureInfo.InvariantCulture.Name }; } foreach (DataScopeIdentifier dataScopeIdentifier in dataTypeDescriptor.DataScopes.Distinct()) { foreach (string cultureName in cultureNames) { var defaultXmlDataTypeStoreDataScope = new XmlDataTypeStoreDataScope { DataScopeName = dataScopeIdentifier.Name, CultureName = cultureName, ElementName = NamesCreator.MakeElementName(dataTypeDescriptor), Filename = Path.Combine(_fileStoreDirectory, NamesCreator.MakeFileName(dataTypeDescriptor, dataScopeIdentifier, cultureName)) }; var document = new XDocument(new XElement(defaultXmlDataTypeStoreDataScope.ElementName)); document.SaveToFile(defaultXmlDataTypeStoreDataScope.Filename); defaultDataScopes.Add(defaultXmlDataTypeStoreDataScope); } } xmlDataTypeStoreDataScopes = defaultDataScopes; } return(new XmlDataTypeStore(dataTypeDescriptor, dataProviderHelperClassType, dataIdClassType, xmlDataTypeStoreDataScopes, dataTypeDescriptor.IsCodeGenerated)); }
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); } }
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 InitializeExistingStores() { var xmlDataTypeStoreCreator = new XmlDataTypeStoreCreator(_fileStoreDirectory); _xmlDataTypeStoresContainer = new XmlDataTypeStoresContainer(_dataProviderContext.ProviderName); var dataTypes = LoadDataTypes(_dataTypeConfigurationElements); var storesToLoad = new List<GeneratedTypesInfo>(); foreach (XmlProviderInterfaceConfigurationElement element in _dataTypeConfigurationElements) { var dataTypeDescriptor = GetDataTypeDescriptorNotNull(element); Type interfaceType = null; try { interfaceType = dataTypes[dataTypeDescriptor.DataTypeId]; if (interfaceType == null) { Log.LogError(LogTitle, "The data interface type '{0}' does not exists and is not code generated. It will not be usable", dataTypeDescriptor.TypeManagerTypeName); continue; } storesToLoad.Add(BuildGeneratedTypesInfo(dataTypeDescriptor, interfaceType, element)); } catch (Exception ex) { if (interfaceType != null) { DataProviderRegistry.AddKnownDataType(interfaceType, _dataProviderContext.ProviderName); } Log.LogError(LogTitle, "Failed initialization for the datatype {{{0}}}, {1}", dataTypeDescriptor.DataTypeId, dataTypeDescriptor.TypeManagerTypeName); Log.LogError(LogTitle, ex); } } CompileMissingTypes(storesToLoad); foreach (var storeToLoad in storesToLoad) { try { var xmlDataTypeStoreDataScopes = new List<XmlDataTypeStoreDataScope>(); foreach (DataScopeConfigurationElement dataScopeConfigurationElement in storeToLoad.Element.ConfigurationStores) { var xmlDataTypeStoreDataScope = new XmlDataTypeStoreDataScope { DataScopeName = dataScopeConfigurationElement.DataScope, CultureName = dataScopeConfigurationElement.CultureName, ElementName = dataScopeConfigurationElement.ElementName, Filename = Path.Combine(_fileStoreDirectory, dataScopeConfigurationElement.Filename) }; xmlDataTypeStoreDataScopes.Add(xmlDataTypeStoreDataScope); } XmlDataTypeStore xmlDateTypeStore = xmlDataTypeStoreCreator.CreateStoreResult(storeToLoad.DataTypeDescriptor, storeToLoad.DataProviderHelperClass, storeToLoad.DataIdClass, xmlDataTypeStoreDataScopes); AddDataTypeStore(storeToLoad.DataTypeDescriptor, storeToLoad.InterfaceType, xmlDateTypeStore); } catch (Exception ex) { DataProviderRegistry.AddKnownDataType(storeToLoad.InterfaceType, _dataProviderContext.ProviderName); Log.LogError(LogTitle, "Failed initialization for the datatype {{{0}}}, {1}", storeToLoad.DataTypeDescriptor.DataTypeId, storeToLoad.DataTypeDescriptor.TypeManagerTypeName); Log.LogError(LogTitle, ex); } } }
private static FileRecord GetFileRecord(XmlDataTypeStore dataTypeStore, XmlDataTypeStoreDataScope dataTypeStoreDataScope) { return(XmlDataProviderDocumentCache.GetFileRecord(dataTypeStoreDataScope.Filename, dataTypeStoreDataScope.ElementName, dataTypeStore.Helper.CreateDataId)); }
private void InitializeExistingStores() { var xmlDataTypeStoreCreator = new XmlDataTypeStoreCreator(_fileStoreDirectory); _xmlDataTypeStoresContainer = new XmlDataTypeStoresContainer(_dataProviderContext.ProviderName); var dataTypes = LoadDataTypes(_dataTypeConfigurationElements); var storesToLoad = new List <GeneratedTypesInfo>(); foreach (XmlProviderInterfaceConfigurationElement element in _dataTypeConfigurationElements) { var dataTypeDescriptor = GetDataTypeDescriptorNotNull(element); Type interfaceType = null; try { if (!dataTypes.TryGetValue(dataTypeDescriptor.DataTypeId, out interfaceType) || interfaceType == null) { Log.LogWarning(LogTitle, "The data interface type '{0}' does not exist and is not code generated. It will not be usable", dataTypeDescriptor.TypeManagerTypeName); continue; } storesToLoad.Add(BuildGeneratedTypesInfo(dataTypeDescriptor, interfaceType, element)); } catch (Exception ex) { if (interfaceType != null) { DataProviderRegistry.AddKnownDataType(interfaceType, _dataProviderContext.ProviderName); } Log.LogError(LogTitle, "Failed initialization for the datatype {{{0}}}, {1}", dataTypeDescriptor.DataTypeId, dataTypeDescriptor.TypeManagerTypeName); Log.LogError(LogTitle, ex); } } CompileMissingTypes(storesToLoad); foreach (var storeToLoad in storesToLoad) { try { var xmlDataTypeStoreDataScopes = new List <XmlDataTypeStoreDataScope>(); foreach (DataScopeConfigurationElement dataScopeConfigurationElement in storeToLoad.Element.ConfigurationStores) { var xmlDataTypeStoreDataScope = new XmlDataTypeStoreDataScope { DataScopeName = dataScopeConfigurationElement.DataScope, CultureName = dataScopeConfigurationElement.CultureName, ElementName = dataScopeConfigurationElement.ElementName, Filename = Path.Combine(_fileStoreDirectory, dataScopeConfigurationElement.Filename) }; xmlDataTypeStoreDataScopes.Add(xmlDataTypeStoreDataScope); } XmlDataTypeStore xmlDateTypeStore = xmlDataTypeStoreCreator.CreateStoreResult(storeToLoad.DataTypeDescriptor, storeToLoad.DataProviderHelperClass, storeToLoad.DataIdClass, xmlDataTypeStoreDataScopes); AddDataTypeStore(storeToLoad.DataTypeDescriptor, storeToLoad.InterfaceType, xmlDateTypeStore); } catch (Exception ex) { DataProviderRegistry.AddKnownDataType(storeToLoad.InterfaceType, _dataProviderContext.ProviderName); Log.LogError(LogTitle, "Failed initialization for the datatype {{{0}}}, {1}", storeToLoad.DataTypeDescriptor.DataTypeId, storeToLoad.DataTypeDescriptor.TypeManagerTypeName); Log.LogError(LogTitle, ex); } } }