示例#1
0
        public override PolicyConfigBase ConvertFromStorage(ExPolicyConfigProvider provider, UnifiedPolicyStorageBase storageObject)
        {
            ArgumentValidator.ThrowIfNull("provider", provider);
            ArgumentValidator.ThrowIfNull("storageObject", storageObject);
            PolicyConfigBase policyConfigBase = provider.NewBlankConfigInstance <TPolicyConfig>();

            if (!provider.ReadOnly)
            {
                policyConfigBase.RawObject = storageObject;
            }
            Guid identity = storageObject.Guid;

            if (!ExPolicyConfigProvider.IsFFOOnline)
            {
                identity = storageObject.MasterIdentity;
            }
            policyConfigBase.Identity       = identity;
            policyConfigBase.Name           = storageObject.Name;
            policyConfigBase.Version        = PolicyVersion.Create(storageObject.PolicyVersion);
            policyConfigBase.Workload       = storageObject.Workload;
            policyConfigBase.WhenChangedUTC = storageObject.WhenChangedUTC;
            policyConfigBase.WhenCreatedUTC = storageObject.WhenChangedUTC;
            this.copyPropertiesToPolicyConfigDelegate((TPolicyStorage)((object)storageObject), (TPolicyConfig)((object)policyConfigBase));
            policyConfigBase.ResetChangeTracking();
            return(policyConfigBase);
        }
示例#2
0
        private static PolicyBindingConfig ToBindingScope(ScopeStorage storageScope)
        {
            PolicyBindingConfig policyBindingConfig = new PolicyBindingConfig();

            policyBindingConfig.Identity = (ExPolicyConfigProvider.IsFFOOnline ? storageScope.Guid : storageScope.MasterIdentity);
            policyBindingConfig.Name     = storageScope.Name;
            policyBindingConfig.Mode     = storageScope.Mode;
            policyBindingConfig.Scope    = BindingMetadata.FromStorage(storageScope.Scope);
            policyBindingConfig.Version  = PolicyVersion.Create(storageScope.PolicyVersion);
            policyBindingConfig.ResetChangeTracking();
            return(policyBindingConfig);
        }
        private static void CopyPropertiesFromStorage <T>(T baseConfiguration, FacadeBase storage) where T : PolicyConfigurationBase
        {
            baseConfiguration.Name           = (string)storage.InnerPropertyBag[ADObjectSchema.Name];
            baseConfiguration.Workload       = (Workload)storage.InnerPropertyBag[UnifiedPolicyStorageBaseSchema.WorkloadProp];
            baseConfiguration.WhenCreatedUTC = (DateTime?)storage.InnerPropertyBag[ADObjectSchema.WhenCreatedUTC];
            baseConfiguration.WhenChangedUTC = (DateTime?)storage.InnerPropertyBag[ADObjectSchema.WhenChangedUTC];
            baseConfiguration.ChangeType     = ((storage.InnerConfigurable.ObjectState == ObjectState.Deleted) ? ChangeType.Delete : ChangeType.Update);
            baseConfiguration.Version        = PolicyVersion.Create((Guid)storage.InnerPropertyBag[UnifiedPolicyStorageBaseSchema.PolicyVersion]);
            IEnumerable <PropertyInfo> reflectedProperties = UnifiedPolicyStorageFactory.GetReflectedProperties <T>();

            UnifiedPolicyStorageFactory.InitializeIncrementalAttributes(baseConfiguration, reflectedProperties);
            IEnumerable <PropertyDefinition> propertyDefinitions = DalHelper.GetPropertyDefinitions(storage, false);

            using (IEnumerator <PropertyDefinition> enumerator = propertyDefinitions.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    PropertyDefinition property = enumerator.Current;
                    object             propertyValue;
                    if (UnifiedPolicyStorageFactory.TryReadPropertyValue(storage, property, out propertyValue))
                    {
                        PropertyInfo propertyInfo = reflectedProperties.FirstOrDefault((PropertyInfo p) => UnifiedPolicyStorageFactory.PropertiesMatch(property, p));
                        if (!(propertyInfo == null) && !UnifiedPolicyStorageFactory.IsIncrementalCollection(propertyInfo))
                        {
                            UnifiedPolicyStorageFactory.CopyPropertyFromStorage(propertyInfo, propertyValue, baseConfiguration);
                        }
                    }
                }
            }
            using (IEnumerator <PropertyInfo> enumerator2 = (from p in reflectedProperties
                                                             where UnifiedPolicyStorageFactory.IsIncrementalCollection(p)
                                                             select p).GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    UnifiedPolicyStorageFactory.< > c__DisplayClassf <T> CS$ < > 8__locals2 = new UnifiedPolicyStorageFactory.< > c__DisplayClassf <T>();
                    CS$ < > 8__locals2.incrementalCollectionProp = enumerator2.Current;
                    PropertyDefinition addedProperty      = propertyDefinitions.FirstOrDefault((PropertyDefinition p) => UnifiedPolicyStorageFactory.PropertiesMatch(p, CS$ < > 8__locals2.incrementalCollectionProp));
                    PropertyDefinition propertyDefinition = propertyDefinitions.FirstOrDefault((PropertyDefinition p) => p.Name == UnifiedPolicyStorageFactory.GetRemovedCollectionPropertyName(addedProperty));
                    if (addedProperty != null && propertyDefinition != null)
                    {
                        UnifiedPolicyStorageFactory.CopyIncrementalCollection(CS$ < > 8__locals2.incrementalCollectionProp, addedProperty, propertyDefinition, storage, baseConfiguration);
                    }
                }
            }
        }
        internal static ChangeNotificationData CreateChangeData(Workload workload, UnifiedPolicyStorageBase policyStorageObject)
        {
            if (policyStorageObject.ObjectState == ObjectState.Unchanged || (policyStorageObject.Workload != Workload.None && (policyStorageObject.Workload & workload) != workload))
            {
                return(null);
            }
            Guid parentId = Guid.Empty;
            ConfigurationObjectType objectType = (policyStorageObject is ScopeStorage) ? ConfigurationObjectType.Scope : PolicyConfigConverterTable.GetConfigurationObjectType(policyStorageObject);

            if (policyStorageObject is RuleStorage)
            {
                parentId = ((RuleStorage)policyStorageObject).ParentPolicyId;
            }
            else if (policyStorageObject is BindingStorage)
            {
                parentId = ((BindingStorage)policyStorageObject).PolicyId;
            }
            return(new ChangeNotificationData(policyStorageObject.Id.ObjectGuid, parentId, objectType, (policyStorageObject.ObjectState == ObjectState.Deleted) ? ChangeType.Delete : ChangeType.Update, workload, PolicyVersion.Create(policyStorageObject.PolicyVersion), UnifiedPolicyErrorCode.Unknown, ""));
        }