Ejemplo n.º 1
0
        public List <T> AddNew <T>(IEnumerable <T> dataset, DataProviderContext dataProviderContext)
            where T : class, IData
        {
            SqlDataTypeStore sqlDataTypeStore = TryGetsqlDataTypeStore(typeof(T));

            if (sqlDataTypeStore == null)
            {
                throw new InvalidOperationException(string.Format("The interface '{0}' has not been configures", typeof(T).FullName));
            }

            var resultDataset = new List <T>();

            using (var dataContext = CreateDataContext())
            {
                foreach (IData data in dataset)
                {
                    Verify.ArgumentCondition(data != null, "dataset", "Data set may not contain nulls");

                    IData newData = sqlDataTypeStore.AddNew(data, dataProviderContext, dataContext);

                    (newData as IEntity).Commit();

                    CheckConstraints(newData);

                    resultDataset.Add((T)newData);
                }

                SubmitChanges(dataContext);
            }

            return(resultDataset);
        }
Ejemplo n.º 2
0
        private InitializeStoreResult EmbedDataContextInfo(InterfaceGeneratedClassesInfo initInfo, Type dataContextType)
        {
            var result = new InitializeStoreResult();

            if (initInfo.InterfaceType == null)
            {
                return(result);
            }

            result.InterfaceType = initInfo.InterfaceType;

            var sqlDataTypeStoreTables = new Dictionary <SqlDataTypeStoreTableKey, SqlDataTypeStoreTable>();

            foreach (SqlDataTypeStoreDataScope storeDataScope in initInfo.DataScopes)
            {
                var key = new SqlDataTypeStoreTableKey(storeDataScope.DataScopeName, storeDataScope.CultureName);

                result.TableNames.Add(key, storeDataScope.TableName);

                Verify.IsNotNull(initInfo.Fields, "Fields collection is null");

                StoreTypeInfo fieldInfo;
                if (!initInfo.Fields.TryGetValue(key, out fieldInfo))
                {
                    continue;
                }

                Verify.IsNotNull(fieldInfo, "Field info is missing");


                FieldInfo dataContextFieldInfo = dataContextType != null
                    ? dataContextType.GetField(fieldInfo.FieldName)
                    : fieldInfo.DataContextField;

                Type sqlDataProvdierHelperType = fieldInfo.SqlHelperClass;

                var sqlDataProviderHelper = (ISqlDataProviderHelper)Activator.CreateInstance(sqlDataProvdierHelperType);

                var sqlDataTypeStoreTable = new SqlDataTypeStoreTable(
                    initInfo.DataTypeDescriptor.DataTypeId,
                    dataContextFieldInfo,
                    sqlDataProviderHelper,
                    fieldInfo.FieldName,
                    fieldInfo.FieldType);
                _createdSqlDataTypeStoreTables.Add(sqlDataTypeStoreTable);

                sqlDataTypeStoreTables.Add(key, sqlDataTypeStoreTable);
            }


            var sqlDataTypeStore = new SqlDataTypeStore(result.InterfaceType,
                                                        sqlDataTypeStoreTables,
                                                        initInfo.DataTypeDescriptor.IsCodeGenerated,
                                                        _sqlDataTypeStoresContainer);

            result.SqlDataTypeStore = sqlDataTypeStore;

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method adds the support of the given data interface type to the xml data provider.
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="sqlDataTypeStore"></param>
        internal void AddSupportedDataTypeStore(Type interfaceType, SqlDataTypeStore sqlDataTypeStore)
        {
            _sqlDataTypeStores.Add(interfaceType, sqlDataTypeStore);

            _supportedInterfaces.Add(interfaceType);
            AddKnownInterface(interfaceType);

            if (sqlDataTypeStore.IsGeneretedDataType)
            {
                _generatedInterfaces.Add(interfaceType);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method adds the support of the given data interface type to the xml data provider.
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="sqlDataTypeStore"></param>
        internal void AddSupportedDataTypeStore(Type interfaceType, SqlDataTypeStore sqlDataTypeStore)
        {
            Verify.That(!_sqlDataTypeStores.ContainsKey(interfaceType), "Type {0} is registered in the SqlDataProvider configuration multiple types", interfaceType);
            _sqlDataTypeStores.Add(interfaceType, sqlDataTypeStore);

            _supportedInterfaces.Add(interfaceType);
            AddKnownInterface(interfaceType);

            if (sqlDataTypeStore.IsGeneretedDataType)
            {
                _generatedInterfaces.Add(interfaceType);
            }
        }
Ejemplo n.º 5
0
        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());
            }
        }
Ejemplo n.º 6
0
        public void Delete(IEnumerable <DataSourceId> dataSourceIds, DataProviderContext dataProivderContext)
        {
            DataContext dataContext = null;

            try
            {
                foreach (DataSourceId dataSourceId in dataSourceIds)
                {
                    if (dataSourceId == null)
                    {
                        throw new ArgumentException("dataSourceIds contains nulls");
                    }

                    using (new DataScope(dataSourceId.DataScopeIdentifier, dataSourceId.LocaleScope))
                    {
                        SqlDataTypeStore sqlDataTypeStore = TryGetsqlDataTypeStore(dataSourceId.InterfaceType);
                        if (sqlDataTypeStore == null)
                        {
                            throw new InvalidOperationException(string.Format("The interface '{0}' has not been configures", dataSourceId.InterfaceType.FullName));
                        }

                        IData data = sqlDataTypeStore.GetDataByDataId(dataSourceId.DataId, dataProivderContext);

                        Verify.That(data != null, "Row has already been deleted");

                        if (dataContext == null)
                        {
                            dataContext = CreateDataContext();
                        }

                        sqlDataTypeStore.RemoveData(data, dataContext);
                    }
                }

                if (dataContext != null)
                {
                    SubmitChanges(dataContext);
                }
            }
            finally
            {
                if (dataContext != null)
                {
                    dataContext.Dispose();
                }
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
        private InitializeStoreResult EmbedDataContextInfo(InterfaceGeneratedClassesInfo initInfo, Type dataContextType)
        {
            var result = new InitializeStoreResult();

            if (initInfo.InterfaceType == null)
            {
                return result;
            }

            result.InterfaceType = initInfo.InterfaceType;

            var sqlDataTypeStoreTables = new Dictionary<SqlDataTypeStoreTableKey, SqlDataTypeStoreTable>();
            foreach (SqlDataTypeStoreDataScope storeDataScope in initInfo.DataScopes)
            {
                var key = new SqlDataTypeStoreTableKey(storeDataScope.DataScopeName, storeDataScope.CultureName);

                result.TableNames.Add(key, storeDataScope.TableName);

                Verify.IsNotNull(initInfo.Fields, "Fields collection is null");

                StoreTypeInfo fieldInfo;
                if (!initInfo.Fields.TryGetValue(key, out fieldInfo))
                {
                    continue;
                }

                Verify.IsNotNull(fieldInfo, "Field info is missing");

                FieldInfo dataContextFieldInfo = dataContextType != null
                    ? dataContextType.GetField(fieldInfo.FieldName)
                    : fieldInfo.DataContextField;

                Type sqlDataProvdierHelperType = fieldInfo.SqlHelperClass;

                var sqlDataProviderHelper = (ISqlDataProviderHelper)Activator.CreateInstance(sqlDataProvdierHelperType);

                var sqlDataTypeStoreTable = new SqlDataTypeStoreTable(
                    initInfo.DataTypeDescriptor.DataTypeId,
                    dataContextFieldInfo,
                    sqlDataProviderHelper,
                    fieldInfo.FieldName,
                    fieldInfo.FieldType);
                _createdSqlDataTypeStoreTables.Add(sqlDataTypeStoreTable);

                sqlDataTypeStoreTables.Add(key, sqlDataTypeStoreTable);
            }

            var sqlDataTypeStore = new SqlDataTypeStore(result.InterfaceType,
                sqlDataTypeStoreTables,
                initInfo.DataTypeDescriptor.IsCodeGenerated,
                _sqlDataTypeStoresContainer);

            result.SqlDataTypeStore = sqlDataTypeStore;

            return result;
        }