예제 #1
0
        public static List<IPolicyResponseAction> GetPolicyResponseActions(PolicyResponseObject upi)
        {
            List<IPolicyResponseAction> policyResponseActionCollection = new List<IPolicyResponseAction>();
            Dictionary<String, PolicyResponseActionMerger> allPRAs = new Dictionary<string, PolicyResponseActionMerger>();

            Collection<IContentItem> fileCollection = upi.ContentCollection;
            foreach (ContentItem filePolicyInfo in fileCollection)
            {
                if (filePolicyInfo.PolicySetCollection == null)
                    continue;

                foreach (PolicySetResponse policySetResponse in filePolicyInfo.PolicySetCollection)
                {
                    if (policySetResponse.PolicyReportCollection == null)
                        continue;

                    foreach (IPolicyResponse policyResponse in policySetResponse.PolicyReportCollection)
                    {
                        if (!policyResponse.Triggered)
                            continue;

                        if (policyResponse.ActionCollection == null)
                            continue;

                        foreach (PolicyResponseAction policyResponseAction in policyResponse.ActionCollection)
                        {
                            if (policyResponseAction == null || policyResponseAction.Action == null 
                                || policyResponseAction.IsExceptionAction )
                                continue;

                            if (allPRAs.ContainsKey(policyResponseAction.Type))
                                allPRAs[policyResponseAction.Type].AddActionPropertySet(policyResponseAction.InternalProperties);
                            else
                            {
                                PolicyResponseActionMerger merger = new PolicyResponseActionMerger(policyResponseAction);
                                if (merger != null)
                                    allPRAs.Add(policyResponseAction.Type, merger);
                            }
                        }
                    }
                }
            }

            foreach (KeyValuePair<String, PolicyResponseActionMerger> kvp in allPRAs)
            {
                PolicyResponseActionMerger merger = kvp.Value;
                policyResponseActionCollection.Add(merger.MergePra());
            }

            policyResponseActionCollection.Sort(new ActionInfoSorterGenerics());

            return policyResponseActionCollection;
        }
        public void CorrectlyMergedUIProperties()
        {
            string[] props = { "EXECUTE", "transparent", "autoexpand" };
            #region setup

            BasicAction basic = new BasicAction();
            PolicyResponseAction pra = new PolicyResponseAction();
            pra.Action = basic;

            PolicyResponseActionMerger merger = new PolicyResponseActionMerger(pra);

            bool propValue = true;
            for (int i = 0; i < 3; i++)
            {
                //set the property sets up such that the properties have different values
                ActionPropertySet newSet = new ActionPropertySet();
                foreach (string s in props)
                {
                    newSet[s] = new ActionProperty(s, typeof(bool), PropertyDisplayType.Checkbox, propValue, propValue, propValue, false);
                }
                merger.AddActionPropertySet(newSet);
                propValue = !propValue;
            }

            #endregion

            PolicyResponseAction resultPra = merger.MergePra() as PolicyResponseAction;

            // if at least one user override is false then the override is false
            // if at least one visible is true the it should be what ?
            foreach (string s in props)
            {
                Assert.IsFalse((bool)resultPra.InternalProperties[s].Override, "Override should be disallowed for {0}", s);
                Assert.IsTrue((bool)resultPra.InternalProperties[s].Visible, "props should be visible for {0}", s);
            }
            Assert.IsTrue((bool)(resultPra.InternalProperties["EXECUTE"].Value), "EXECUTE property should be true if at least one set specifies true");
            Assert.IsFalse((bool)(resultPra.InternalProperties["transparent"].Value), "transparent property should be false if at least one set specifies false");
            Assert.IsTrue((bool)resultPra.InternalProperties["autoexpand"].Value, "autoexpand property value should be true");
        }
        public void TestMergePra()
        {
            BasicAction basic = new BasicAction();
            ActionPropertySet set = new ActionPropertySet();
            set.Add("Test", new ActionProperty("Test","test"));
            basic.PropertySet = set;
            PolicyResponseAction pra = new PolicyResponseAction();
            pra.Action = basic;
            pra.InternalProperties = set;
            
            PolicyResponseActionMerger merger = new PolicyResponseActionMerger(pra);
            set["Test"].Value = "test2";
            merger.AddActionPropertySet(set);

            PolicyResponseAction praNew = (PolicyResponseAction) merger.MergePra();
            Assert.AreEqual(praNew.InternalProperties["ThisWasMerged"].Value.ToString(), "sisterhood", "Property value should be - sisterhood");
            Assert.AreEqual(2, basic.CountMerged, "Expected 2 property sets to be sent to the action");
            Assert.AreNotEqual(praNew, pra, "Expected a new {0} back", praNew.GetType().ToString());
        }
        public void EnsureSystemPropertiesArePreserved()
        {
            #region setup
            string[] systemProperties = { "CurrentUser", "Date", "RecipientList", "RunAt", "FileType" };

            BasicAction basic = new BasicAction();
            ActionPropertySet set = new ActionPropertySet();
            set["Add"] = new ActionProperty("TEST", "test");
            basic.PropertySet = set;
            PolicyResponseAction pra = new PolicyResponseAction();
            pra.Action = basic;
            pra.InternalProperties = set;

            set["Add"].Value = "test2";
            foreach (string s in systemProperties)
            {
                set.SystemProperties[s] = new ActionProperty(s, s);
            }

            PolicyResponseActionMerger merger = new PolicyResponseActionMerger(pra);

            merger.AddActionPropertySet(set);
            #endregion

            //execute
            pra = merger.MergePra() as PolicyResponseAction;

            //verify
            foreach (string s in systemProperties)
            {
                SortedList<string, IActionProperty> aps = pra.InternalProperties.SystemProperties;
                Assert.IsTrue(aps.ContainsKey(s) && aps[s].Value.ToString() == s, "System property {0} has been modified after merge", s);
            }
        }