Esempio n. 1
0
 static DataLocalizationFacadeImpl()
 {
     DataEventSystemFacade.SubscribeToDataAfterUpdate <ISystemActiveLocale>(OnSystemActiveLocaleChanged, true);
     DataEventSystemFacade.SubscribeToDataAfterAdd <ISystemActiveLocale>(OnSystemActiveLocaleChanged, true);
     DataEventSystemFacade.SubscribeToDataDeleted <ISystemActiveLocale>(OnSystemActiveLocaleChanged, true);
     DataEventSystemFacade.SubscribeToStoreChanged <ISystemActiveLocale>(OnSystemActiveLocaleStoreChanged, true);
 }
Esempio n. 2
0
        static DataFacadeImpl()
        {
            DataEventSystemFacade.SubscribeToDataAfterUpdate <IData>(OnDataChanged, true);
            DataEventSystemFacade.SubscribeToDataDeleted <IData>(OnDataChanged, true);

            DataEventSystemFacade.SubscribeToDataBeforeAdd <IData>(SetChangeHistoryInformation, true);
            DataEventSystemFacade.SubscribeToDataBeforeUpdate <IData>(SetChangeHistoryInformation, true);
        }
Esempio n. 3
0
        private static void SubscribeToEvents()
        {
            DataEventSystemFacade.SubscribeToDataDeleted <IPagePlaceholderContent>(OnPagePlaceholderChanged, true);
            DataEventSystemFacade.SubscribeToDataAfterUpdate <IPagePlaceholderContent>(OnPagePlaceholderChanged, true);
            DataEventSystemFacade.SubscribeToDataAfterAdd <IPagePlaceholderContent>(OnPagePlaceholderChanged, true);
            DataEventSystemFacade.SubscribeToStoreChanged <IPagePlaceholderContent>(OnPagePlaceholderStoreChanged, true);

            DataEventSystemFacade.SubscribeToDataAfterUpdate <IPage>(OnPageChanged, true);
            DataEventSystemFacade.SubscribeToDataAfterAdd <IPage>(OnPageChanged, true);
            DataEventSystemFacade.SubscribeToDataDeleted <IPage>(OnPageChanged, true);
            DataEventSystemFacade.SubscribeToStoreChanged <IPage>(OnPageStoreChanged, true);

            DataEventSystemFacade.SubscribeToDataAfterAdd <IPageStructure>(OnPageStructureChanged, true);
            DataEventSystemFacade.SubscribeToDataAfterUpdate <IPageStructure>(OnPageStructureChanged, true);
            DataEventSystemFacade.SubscribeToDataDeleted <IPageStructure>(OnPageStructureChanged, true);
            DataEventSystemFacade.SubscribeToStoreChanged <IPageStructure>(OnPageStructureStoreChanged, true);
        }
        public T BuildNew <T>(bool suppressEventing)
            where T : class, IData
        {
            ValidateBuildNewType(typeof(T));

            Type generatedType = DataTypeTypesManager.GetDataTypeEmptyClass(typeof(T));

            IData data = (IData)Activator.CreateInstance(generatedType, new object[] { });

            SetNewInstanceFieldDefaultValues(data);

            if (suppressEventing == false)
            {
                DataEventSystemFacade.FireDataAfterBuildNewEvent <T>(data);
            }

            return((T)data);
        }
        public IData BuildNew(Type interfaceType, bool suppressEventling)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }

            ValidateBuildNewType(interfaceType);

            Type generatedType = DataTypeTypesManager.GetDataTypeEmptyClass(interfaceType);

            IData data = (IData)Activator.CreateInstance(generatedType, new object[] { });

            SetNewInstanceFieldDefaultValues(data);

            if (!suppressEventling)
            {
                DataEventSystemFacade.FireDataAfterBuildNewEvent(generatedType, data);
            }

            return(data);
        }
        private void Delete <T>(IEnumerable <T> dataset, bool suppressEventing, CascadeDeleteType cascadeDeleteType, bool referencesFromAllScopes, HashSet <DataSourceId> dataPendingDeletion)
            where T : class, IData
        {
            Verify.ArgumentNotNull(dataset, nameof(dataset));

            dataset = dataset.Evaluate();

            foreach (var data in dataset)
            {
                var dataSourceId = data.DataSourceId;
                if (!dataPendingDeletion.Contains(dataSourceId))
                {
                    dataPendingDeletion.Add(dataSourceId);
                }
            }

            if (cascadeDeleteType != CascadeDeleteType.Disable)
            {
                foreach (IData data in dataset)
                {
                    Verify.ArgumentCondition(data != null, nameof(dataset), "dataset may not contain nulls");

                    Type interfaceType = data.DataSourceId.InterfaceType;

                    // Not deleting references if the data is versioned and not all of the
                    // versions of the element are to be deleted
                    if (data is IVersioned && interfaceType.GetKeyProperties().Count == 1)
                    {
                        var key      = data.GetUniqueKey();
                        var versions = DataFacade.TryGetDataVersionsByUniqueKey(interfaceType, key).ToList();

                        if (versions.Count > 1 &&
                            (dataset.Count() < versions.Count ||
                             !versions.All(v => dataPendingDeletion.Contains(v.DataSourceId))))
                        {
                            continue;
                        }
                    }

                    using (new DataScope(data.DataSourceId.DataScopeIdentifier))
                    {
                        var allReferences = DataReferenceFacade.GetRefereesInt(data, referencesFromAllScopes, (a, b) => true);

                        if (allReferences.Count == 0)
                        {
                            continue;
                        }

                        Verify.IsTrue(cascadeDeleteType != CascadeDeleteType.Disallow, "One of the given datas is referenced by one or more datas");

                        var optionalReferences    = allReferences.Where(kvp => kvp.Item2.IsOptionalReference);
                        var notOptionalReferences = allReferences.Where(kvp => !kvp.Item2.IsOptionalReference &&
                                                                        !dataPendingDeletion.Contains(kvp.Item1.DataSourceId)).Evaluate();

                        foreach (var reference in optionalReferences)
                        {
                            var referee = reference.Item1;
                            reference.Item2.SourcePropertyInfo.SetValue(referee, null, null);
                            DataFacade.Update(referee, false, true, false);
                        }

                        foreach (var refereeInfo in notOptionalReferences)
                        {
                            if (!refereeInfo.Item2.AllowCascadeDeletes)
                            {
                                throw new InvalidOperationException("One of the given data items is referenced by one or more data items that do not allow cascade delete.");
                            }
                        }

                        var toDelete = notOptionalReferences.Select(_ => _.Item1);
                        Delete <IData>(toDelete, suppressEventing, cascadeDeleteType, referencesFromAllScopes);
                    }
                }
            }


            Dictionary <string, Dictionary <Type, List <IData> > > sortedDatas = dataset.ToDataProviderAndInterfaceTypeSortedDictionary();

            foreach (KeyValuePair <string, Dictionary <Type, List <IData> > > providerPair in sortedDatas)
            {
                foreach (KeyValuePair <Type, List <IData> > interfaceTypePair in providerPair.Value)
                {
                    DataProviderPluginFacade.Delete(providerPair.Key, interfaceTypePair.Value.Select(d => d.DataSourceId));

                    if (DataCachingFacade.IsTypeCacheable(interfaceTypePair.Key))
                    {
                        DataCachingFacade.RemoveFromCache(interfaceTypePair.Value);
                    }
                }
            }


            if (!suppressEventing)
            {
                foreach (IData element in dataset)
                {
                    DataEventSystemFacade.FireDataDeletedEvent(element.DataSourceId.InterfaceType, element);
                }
            }
        }
        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);
        }
        public void Update(IEnumerable <IData> dataset, bool suppressEventing, bool performForeignKeyIntegrityCheck, bool performValidation)
        {
            Verify.ArgumentNotNull(dataset, "dataset");

            var sortedDataset = dataset.ToDataProviderAndInterfaceTypeSortedDictionary();

            if (!suppressEventing)
            {
                foreach (IData data in dataset)
                {
                    DataEventSystemFacade.FireDataBeforeUpdateEvent(data.DataSourceId.InterfaceType, data);
                }
            }


            foreach (IData data in dataset)
            {
                if (performValidation)
                {
                    CheckValidationResult(ValidationFacade.Validate(data), data.DataSourceId.InterfaceType);
                }

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


            foreach (KeyValuePair <string, Dictionary <Type, List <IData> > > providerPair in sortedDataset)
            {
                foreach (KeyValuePair <Type, List <IData> > interfaceTypePair in providerPair.Value)
                {
                    List <IData> dataToUpdate = interfaceTypePair.Value;

                    if (DataCachingFacade.IsTypeCacheable(interfaceTypePair.Key))
                    {
                        List <IData> newDataToUpdate = new List <IData>();

                        foreach (IData d in interfaceTypePair.Value)
                        {
                            newDataToUpdate.Add(DataWrappingFacade.UnWrap(d));
                        }

                        dataToUpdate = newDataToUpdate;
                    }

                    DataProviderPluginFacade.Update(providerPair.Key, dataToUpdate);

                    if (DataCachingFacade.IsTypeCacheable(interfaceTypePair.Key))
                    {
                        DataCachingFacade.ClearCache(interfaceTypePair.Key);
                    }
                }
            }


            if (!suppressEventing)
            {
                foreach (IData data in dataset)
                {
                    DataEventSystemFacade.FireDataAfterUpdateEvent(data.DataSourceId.InterfaceType, data);
                }
            }
        }
Esempio n. 9
0
        private void Delete <T>(IEnumerable <T> dataset, bool suppressEventing, CascadeDeleteType cascadeDeleteType, bool referencesFromAllScopes, HashSet <DataSourceId> dataPendingDeletion)
            where T : class, IData
        {
            Verify.ArgumentNotNull(dataset, nameof(dataset));

            dataset = dataset.Evaluate();

            foreach (var data in dataset)
            {
                var dataSourceId = data.DataSourceId;
                if (!dataPendingDeletion.Contains(dataSourceId))
                {
                    dataPendingDeletion.Add(dataSourceId);
                }
            }

            if (cascadeDeleteType != CascadeDeleteType.Disable)
            {
                foreach (IData element in dataset)
                {
                    Verify.ArgumentCondition(element != null, nameof(dataset), "dataset may not contain nulls");

                    if (!element.IsDataReferred())
                    {
                        continue;
                    }

                    Type interfaceType = element.DataSourceId.InterfaceType;

                    // Not deleting references if the data is versioned and not all of the
                    // versions of the element are to be deleted
                    if (element is IVersioned)
                    {
                        var key      = element.GetUniqueKey();
                        var versions = DataFacade.TryGetDataVersionsByUniqueKey(interfaceType, key).ToList();

                        if (versions.Count > 1 &&
                            (dataset.Count() < versions.Count ||
                             !versions.All(v => dataPendingDeletion.Contains(v.DataSourceId))))
                        {
                            continue;
                        }
                    }

                    Verify.IsTrue(cascadeDeleteType != CascadeDeleteType.Disallow, "One of the given datas is referenced by one or more datas");

                    element.RemoveOptionalReferences();

                    IEnumerable <IData> referees;
                    using (new DataScope(element.DataSourceId.DataScopeIdentifier))
                    {
                        // For some weird reason, this line does not work.... /MRJ
                        // IEnumerable<IData> referees = dataset.GetRefereesRecursively();
                        referees = element.GetReferees(referencesFromAllScopes)
                                   .Where(reference => !dataPendingDeletion.Contains(reference.DataSourceId))
                                   .Evaluate();
                    }

                    foreach (IData referee in referees)
                    {
                        if (!referee.CascadeDeleteAllowed(interfaceType))
                        {
                            throw new InvalidOperationException("One of the given datas is referenced by one or more datas that does not allow cascade delete");
                        }
                    }

                    Delete <IData>(referees, suppressEventing, cascadeDeleteType, referencesFromAllScopes);
                }
            }


            Dictionary <string, Dictionary <Type, List <IData> > > sortedDatas = dataset.ToDataProviderAndInterfaceTypeSortedDictionary();

            foreach (KeyValuePair <string, Dictionary <Type, List <IData> > > providerPair in sortedDatas)
            {
                foreach (KeyValuePair <Type, List <IData> > interfaceTypePair in providerPair.Value)
                {
                    DataProviderPluginFacade.Delete(providerPair.Key, interfaceTypePair.Value.Select(d => d.DataSourceId));

                    if (DataCachingFacade.IsTypeCacheable(interfaceTypePair.Key))
                    {
                        DataCachingFacade.ClearCache(interfaceTypePair.Key, interfaceTypePair.Value.First().DataSourceId.DataScopeIdentifier);
                    }
                }
            }


            if (!suppressEventing)
            {
                foreach (IData element in dataset)
                {
                    DataEventSystemFacade.FireDataDeletedEvent(element.DataSourceId.InterfaceType, element);
                }
            }
        }