Пример #1
0
        private List <string> GetWritableDataProviders(Type type)
        {
            var dataProviders = DataProviderRegistry.GetWriteableDataProviderNamesByInterfaceType(type);

            if (dataProviders.Count > 1 && dataProviders.Contains(DataProviderRegistry.DefaultDynamicTypeDataProviderName))
            {
                dataProviders = new List <string> {
                    DataProviderRegistry.DefaultDynamicTypeDataProviderName
                };
            }

            return(dataProviders);
        }
        /// <summary>
        /// </summary>
        /// <param name="oldDataTypeDescriptor"></param>
        /// <param name="newDataTypeDescriptor"></param>
        /// <param name="originalTypeHasData"></param>
        public UpdateDataTypeDescriptor(DataTypeDescriptor oldDataTypeDescriptor, DataTypeDescriptor newDataTypeDescriptor, bool originalTypeHasData = true)
        {
            OldDataTypeDescriptor = oldDataTypeDescriptor;
            NewDataTypeDescriptor = newDataTypeDescriptor;

            var interfaceType = oldDataTypeDescriptor.GetInterfaceType();

            ProviderName = interfaceType != null
                ? DataProviderRegistry.GetWriteableDataProviderNamesByInterfaceType(interfaceType)
                           .SingleOrException("Failed to get data provider by type '{0}'",
                                              "Multiple data providers for type '{0}'", interfaceType.FullName)
                : DataProviderRegistry.DefaultDynamicTypeDataProviderName;
        }
Пример #3
0
        private static List <T> AddNew_AddingMethod <T>(string providerName, IEnumerable <T> dataset, bool suppressEventing, bool performForeignKeyIntegrityCheck, bool performValidation)
            where T : class, IData
        {
            Verify.ArgumentNotNullOrEmpty(providerName, "providerName");
            Verify.ArgumentNotNull(dataset, "dataset");
            Verify.ArgumentCondition(!dataset.Contains(null), "dataset", "The enumeration may not contain null values");


            List <string> writeableProviders = DataProviderRegistry.GetWriteableDataProviderNamesByInterfaceType(typeof(T));

            if (!writeableProviders.Contains(providerName))
            {
                Log.LogVerbose(LogTitle, $"Type data interface '{typeof(T)}' is marked auto updateable and is not supported by the provider '{providerName}', adding it");

                DynamicTypeManager.EnsureCreateStore(typeof(T), providerName);
            }

            writeableProviders = DataProviderRegistry.GetWriteableDataProviderNamesByInterfaceType(typeof(T));
            if (!writeableProviders.Contains(providerName))
            {
                throw new InvalidOperationException($"The writeable data providers '{providerName}' does not support the interface '{typeof(T)}'.");
            }


            foreach (T data in dataset)
            {
                if (performValidation)
                {
                    CheckValidationResult(ValidationFacade.Validate <T>(data), typeof(T));
                }

                if (performForeignKeyIntegrityCheck)
                {
                    data.ValidateForeignKeyIntegrity();
                }
            }


            if (!suppressEventing)
            {
                foreach (T data in dataset)
                {
                    DataEventSystemFacade.FireDataBeforeAddEvent <T>(data);
                }
            }

            List <T> addedDataset = DataProviderPluginFacade.AddNew <T>(providerName, dataset);

            DataCachingFacade.ClearCache(typeof(T), DataScopeManager.MapByType(typeof(T)), LocalizationScopeManager.MapByType(typeof(T)));

            if (!suppressEventing)
            {
                foreach (T data in addedDataset)
                {
                    DataEventSystemFacade.FireDataAfterAddEvent <T>(data);
                }
            }


            return(addedDataset);
        }