示例#1
0
        void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(DataScope));
            }

            if (_servicesDisabled)
            {
                EnableServices();
            }

            if (_dataScopePushed)
            {
                DataScopeManager.PopDataScope();
            }

            if (_cultureInfoPushed)
            {
                LocalizationScopeManager.PopLocalizationScope();
            }

            if (_dataServicePushed)
            {
                DataServiceScopeManager.PopDataServiceScope();
            }

            _disposed = true;
        }
示例#2
0
 /// <exclude />
 public DataScope(CultureInfo cultureInfo)
 {
     if (cultureInfo != null)
     {
         LocalizationScopeManager.PushLocalizationScope(cultureInfo);
         _cultureInfoPushed = true;
     }
 }
示例#3
0
        private static string GetCacheKey <T>(Guid id, Guid versionId)
        {
            var cultureInfo = LocalizationScopeManager.MapByType(typeof(T));

            Verify.IsNotNull(cultureInfo, "Localization culture is not set");

            var dataScope = DataScopeManager.MapByType(typeof(T));

            Verify.IsNotNull(dataScope, "Publication scope is not set");

            return(id + dataScope.Name + cultureInfo + (versionId != Guid.Empty ? versionId.ToString() : ""));
        }
示例#4
0
        /// <exclude />
        public void Dispose()
        {
            if (_dataScopePushed)
            {
                DataScopeManager.PopDataScope();
            }

            if (_cultureInfoPushed)
            {
                LocalizationScopeManager.PopLocalizationScope();
            }
        }
示例#5
0
 /// <summary>
 /// This is for internal use only!
 /// </summary>
 public DataSourceId(IDataId dataId, string providerName, Type interfaceType)
 {
     if (string.IsNullOrEmpty(providerName))
     {
         throw new ArgumentNullException(nameof(providerName));
     }
     this.DataId         = dataId ?? throw new ArgumentNullException(nameof(dataId));
     ProviderName        = providerName;
     InterfaceType       = interfaceType ?? throw new ArgumentNullException(nameof(interfaceType));
     DataScopeIdentifier = DataScopeManager.MapByType(interfaceType);
     LocaleScope         = LocalizationScopeManager.MapByType(interfaceType);
     this.ExistsInStore  = true;
 }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataScope"></param>
        /// <param name="cultureInfo">null for default culture</param>
        public DataScope(DataScopeIdentifier dataScope, CultureInfo cultureInfo)
        {
            DataScopeManager.PushDataScope(dataScope);
            _dataScopePushed = true;


            if (cultureInfo != null)
            {
                LocalizationScopeManager.PushLocalizationScope(cultureInfo);
                _cultureInfoPushed = true;
            }
            else if (LocalizationScopeManager.IsEmpty)
            {
                LocalizationScopeManager.PushLocalizationScope(DataLocalizationFacade.DefaultLocalizationCulture);
                _cultureInfoPushed = true;
            }
        }
        /// <summary>
        /// This is for internal use only!
        /// </summary>
        public DataSourceId(IDataId dataId, string providerName, Type interfaceType)
        {
            if (null == dataId)
            {
                throw new ArgumentNullException("dataId");
            }
            if (string.IsNullOrEmpty(providerName))
            {
                throw new ArgumentNullException("providerName");
            }
            if (null == interfaceType)
            {
                throw new ArgumentNullException("interfaceType");
            }


            this.DataId          = dataId;
            ProviderName         = providerName;
            InterfaceType        = interfaceType;
            _dataScopeIdentifier = DataScopeManager.MapByType(interfaceType);
            _localeScope         = LocalizationScopeManager.MapByType(interfaceType);
            this.ExistsInStore   = true;
        }
        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);
        }