Beispiel #1
0
 protected virtual void OnPolicyItemsChanged(PolicyItemsChangedEventArgs e)
 {
     if (this.PolicyItemsChanged == null)
     {
         return;
     }
     this.PolicyItemsChanged((object)this, e);
 }
Beispiel #2
0
        private void OnPolicyItemsChanged(object sender, PolicyItemsChangedEventArgs e)
        {
            Dictionary <ModelItem, List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> > dictionary1 = this._removes;
            Dictionary <ModelItem, List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> > dictionary2 = this._adds;

            this._removes = this._adds = (Dictionary <ModelItem, List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> >)null;
            if (dictionary1 == null)
            {
                dictionary1 = new Dictionary <ModelItem, List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> >();
            }
            else
            {
                dictionary1.Clear();
            }
            if (dictionary2 == null)
            {
                dictionary2 = new Dictionary <ModelItem, List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> >();
            }
            else
            {
                dictionary2.Clear();
            }
            foreach (ModelItem key in e.ItemsRemoved)
            {
                List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> list;
                if (!this._featureProviders.TryGetValue(key, out list))
                {
                    list = new List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData>();
                }
                bool flag = false;
                foreach (PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData providerData in list)
                {
                    if (PolicyDrivenFeatureConnector <TFeatureProviderType> .PolicyNode.Remove(ref providerData.AssociatedPolicies, e.Policy))
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    dictionary1[key] = list;
                }
            }
            foreach (ModelItem key in e.ItemsAdded)
            {
                List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> dataList;
                if (!this._featureProviders.TryGetValue(key, out dataList))
                {
                    dataList = new List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData>();
                }
                bool flag = false;
                foreach (TFeatureProviderType featureProviderType in (IEnumerable <TFeatureProviderType>) this.CreateFeatureProviders(key, e.Policy, dataList))
                {
                    PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData providerData = new PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData();

                    providerData.Provider           = featureProviderType;
                    providerData.AssociatedPolicies = new PolicyDrivenFeatureConnector <TFeatureProviderType> .PolicyNode(e.Policy, providerData.AssociatedPolicies);

                    providerData.IsValid = this.IsValidProvider((FeatureProvider)featureProviderType);
                    dataList.Add(providerData);
                    flag = true;
                }
                if (flag)
                {
                    dictionary2[key] = dataList;
                }
            }
            List <TFeatureProviderType> list1 = (List <TFeatureProviderType>)null;

            foreach (KeyValuePair <ModelItem, List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> > keyValuePair in dictionary1)
            {
                ModelItem key = keyValuePair.Key;
                if (list1 != null)
                {
                    list1.Clear();
                }
                for (int index = 0; index < keyValuePair.Value.Count; ++index)
                {
                    PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData providerData = keyValuePair.Value[index];
                    if (providerData.AssociatedPolicies == null)
                    {
                        if (providerData.IsValid)
                        {
                            if (list1 == null)
                            {
                                list1 = new List <TFeatureProviderType>();
                            }
                            list1.Add(providerData.Provider);
                        }
                        keyValuePair.Value.RemoveAt(index);
                        --index;
                    }
                }
                if (keyValuePair.Value.Count == 0)
                {
                    this._featureProviders.Remove(key);
                }
                if (list1 != null && list1.Count > 0)
                {
                    this.FeatureProvidersRemoved(key, (IEnumerable <TFeatureProviderType>)list1);
                }
            }
            foreach (KeyValuePair <ModelItem, List <PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData> > keyValuePair in dictionary2)
            {
                ModelItem key = keyValuePair.Key;
                if (list1 != null)
                {
                    list1.Clear();
                }
                for (int index = 0; index < keyValuePair.Value.Count; ++index)
                {
                    PolicyDrivenFeatureConnector <TFeatureProviderType> .ProviderData providerData = keyValuePair.Value[index];
                    if (providerData.AssociatedPolicies != null && !providerData.AssociatedPolicies.HasMultiple && (providerData.AssociatedPolicies.Contains(e.Policy) && providerData.IsValid))
                    {
                        if (list1 == null)
                        {
                            list1 = new List <TFeatureProviderType>();
                        }
                        list1.Add(providerData.Provider);
                    }
                }
                this._featureProviders[key] = keyValuePair.Value;
                if (list1 != null && list1.Count > 0)
                {
                    this.FeatureProvidersAdded(key, (IEnumerable <TFeatureProviderType>)list1);
                }
            }
            dictionary1.Clear();
            dictionary2.Clear();
            this._removes = dictionary1;
            this._adds    = dictionary2;
        }