public void Delete(IEnumerable <DataSourceId> dataSourceIds) { Verify.ArgumentNotNull(dataSourceIds, "dataSourceIds"); using (TimerProfilerFacade.CreateTimerProfiler()) { Type interfaceType = null; foreach (DataSourceId dataSourceId in dataSourceIds) { if (dataSourceId == null) { throw new ArgumentException("datas enumeration may not contain nulls"); } if (interfaceType == null) { interfaceType = dataSourceId.InterfaceType; } else if (interfaceType != dataSourceId.InterfaceType) { throw new ArgumentException(string.Format("Only one data interface per enumerable type supported")); } } string errorMessage; if (!DataTypeValidationRegistry.IsValidForProvider(interfaceType, _dataProviderContext.ProviderName, out errorMessage)) { throw new InvalidOperationException(errorMessage); } _sqlDataTypeStoresContainer.Delete(dataSourceIds, _dataProviderContext); } }
private void ValidateBuildNewType(Type interfaceType) { string errorMessage; if (!DataTypeValidationRegistry.Validate(interfaceType, null, out errorMessage)) { Log.LogCritical(LogTitle, errorMessage); throw new InvalidOperationException(errorMessage); } }
private void AddDataTypeStore(DataTypeDescriptor dataTypeDescriptor, Type interfaceType, XmlDataTypeStore xmlDateTypeStore) { bool interfaceValidated = DataTypeValidationRegistry.Validate(interfaceType, dataTypeDescriptor); if (xmlDateTypeStore != null && interfaceValidated) { _xmlDataTypeStoresContainer.AddSupportedDataTypeStore(interfaceType, xmlDateTypeStore); DataProviderRegistry.AddNewDataType(interfaceType, _dataProviderContext.ProviderName); } else { _xmlDataTypeStoresContainer.AddKnownInterface(interfaceType); } }
public IQueryable <T> GetData <T>() where T : class, IData { using (TimerProfilerFacade.CreateTimerProfiler(typeof(T).ToString())) { string errorMessage; if (!DataTypeValidationRegistry.IsValidForProvider(typeof(T), _dataProviderContext.ProviderName, out errorMessage)) { throw new InvalidOperationException(errorMessage); } SqlDataTypeStore result = _sqlDataTypeStoresContainer.GetDataTypeStore(typeof(T)); return((IQueryable <T>)result.GetQueryable()); } }
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 T GetData <T>(IDataId dataId) where T : class, IData { Verify.ArgumentNotNull(dataId, "dataId"); using (TimerProfilerFacade.CreateTimerProfiler(string.Format("dataId ({0})", typeof(T)))) { string errorMessage; if (!DataTypeValidationRegistry.IsValidForProvider(typeof(T), _dataProviderContext.ProviderName, out errorMessage)) { throw new InvalidOperationException(errorMessage); } SqlDataTypeStore result = _sqlDataTypeStoresContainer.GetDataTypeStore(typeof(T)); IData data = result.GetDataByDataId(dataId, _dataProviderContext); return((T)data); } }
private bool ValidateTables(InitializeStoreResult initializeStoreResult, bool isInitialization) { var errors = new StringBuilder(); bool isValid = true; var interfaceType = initializeStoreResult.InterfaceType; foreach (string tableName in initializeStoreResult.TableNames.Values) { bool isTableValid = ValidateTable(interfaceType, tableName, errors); if (!isTableValid) { isValid = false; } } if (!isValid) { DataTypeValidationRegistry.AddValidationError(initializeStoreResult.InterfaceType, _dataProviderContext.ProviderName, errors.ToString()); if (isInitialization && GlobalSettingsFacade.EnableDataTypesAutoUpdate && interfaceType.IsAutoUpdateble() && !interfaceType.IsGenerated()) { Log.LogInformation(LogTitle, "Data schema for the data interface '{0}' on the SqlDataProvider '{1}' is not matching and will be updated.", initializeStoreResult.InterfaceType, _dataProviderContext.ProviderName); Log.LogInformation(LogTitle, errors.ToString()); } else { Log.LogCritical(LogTitle, "The data interface '{0}' will not work for the SqlDataProvider '{1}'", initializeStoreResult.InterfaceType, _dataProviderContext.ProviderName); Log.LogCritical(LogTitle, errors.ToString()); } } return(isValid); }
public List <T> AddNew <T>(IEnumerable <T> dataset) where T : class, IData { Verify.ArgumentNotNull(dataset, "dataset"); using (TimerProfilerFacade.CreateTimerProfiler()) { string errorMessage; if (!DataTypeValidationRegistry.IsValidForProvider(typeof(T), _dataProviderContext.ProviderName, out errorMessage)) { throw new InvalidOperationException(errorMessage); } using (var scope = new RequireTransactionScope()) { var result = _sqlDataTypeStoresContainer.AddNew <T>(dataset, _dataProviderContext); scope.Complete(); return(result); } } }
private InterfaceGeneratedClassesInfo InitializeStoreTypes(InterfaceConfigurationElement element, Dictionary <DataTypeDescriptor, IEnumerable <SqlDataTypeStoreDataScope> > allSqlDataTypeStoreDataScopes, Type dataContextClass, Dictionary <Guid, Type> dataTypes, bool forceCompile, ref bool dataContextRecompilationNeeded, ref HelperClassesGenerationInfo helperClassesGenerationInfo) { var result = new InterfaceGeneratedClassesInfo(); var dataScopes = new List <SqlDataTypeStoreDataScope>(); foreach (StorageInformation storageInformation in element.Stores) { var sqlDataTypeStoreDataScope = new SqlDataTypeStoreDataScope { DataScopeName = storageInformation.DataScope, CultureName = storageInformation.CultureName, TableName = storageInformation.TableName }; dataScopes.Add(sqlDataTypeStoreDataScope); } result.DataScopes = dataScopes; 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)); } result.DataTypeDescriptor = dataTypeDescriptor; Type interfaceType = null; try { if (dataTypes == null || !dataTypes.TryGetValue(dataTypeId, out interfaceType) || interfaceType == null) { interfaceType = DataTypeTypesManager.GetDataType(dataTypeDescriptor); } if (interfaceType == null) { Log.LogWarning(LogTitle, "The data interface type '{0}' does not exists and is not code generated. It will not be unusable", dataTypeDescriptor.TypeManagerTypeName); return(result); } result.InterfaceType = interfaceType; string validationMessage; bool isValid = DataTypeValidationRegistry.Validate(interfaceType, dataTypeDescriptor, out validationMessage); if (!isValid) { Log.LogCritical(LogTitle, validationMessage); throw new InvalidOperationException(validationMessage); } Dictionary <SqlDataTypeStoreTableKey, StoreTypeInfo> fields; helperClassesGenerationInfo = EnsureNeededTypes(dataTypeDescriptor, dataScopes, allSqlDataTypeStoreDataScopes, dataContextClass, out fields, ref dataContextRecompilationNeeded, forceCompile); result.Fields = fields; return(result); } catch (Exception ex) { if (interfaceType != null) { DataProviderRegistry.RegisterDataTypeInitializationError(interfaceType, ex); DataProviderRegistry.AddKnownDataType(interfaceType, _dataProviderContext.ProviderName); Log.LogError(LogTitle, "Failed initialization for the datatype {0}", dataTypeDescriptor.TypeManagerTypeName); } Log.LogError(LogTitle, ex); result.Fields = new Dictionary <SqlDataTypeStoreTableKey, StoreTypeInfo>(); return(result); } }