Ejemplo n.º 1
0
        private object ReadDataElementData(DataType dataType)
        {
            IPolicyObjectCollection<IDataSource> dataSourceCollection = new PolicyObjectCollection<IDataSource>();
            IPolicyObjectCollection<IDataItem> dataItemCollection = new PolicyObjectCollection<IDataItem>();

            bool isArray = (dataType >= DataType.StringArray);
            
            foreach (XmlNode dataNode in m_dataElementNode.ChildNodes)
            {
                ReadDataSource(dataNode, dataSourceCollection);
                if (!isArray && dataSourceCollection.Count != 0)
                    return dataSourceCollection[0];

                ReadDataItem(dataNode, dataType, dataItemCollection);
                if (!isArray && dataItemCollection.Count != 0)
                    return dataItemCollection[0];
            }

            if (dataSourceCollection.Count != 0)
                return dataSourceCollection;

            if (dataItemCollection.Count != 0)
                return dataItemCollection;

            throw new Workshare.Policy.Exceptions.PolicyException("Expected at least one DataSource or DataItem");
        }
        public void TestOrderedChannels()
        {
            TreeViewControllerPolicyOrientedTester controller = new TreeViewControllerPolicyOrientedTester();

            //nominal case
            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            IPolicyChannel channel1 = ChannelFactory.CreateChannel("channel1", ChannelType.HTTP);
            IPolicyChannel channel2 = ChannelFactory.CreateChannel("channel4", ChannelType.SMTP);
            IPolicyChannel channel3 = ChannelFactory.CreateChannel("channel5", ChannelType.ActiveContent);
            channels.Add(channel1);
            channels.Add(channel2);
            channels.Add(channel3);

            List<IPolicyChannel> orderedChannels = controller.OrderedChannels(channels);

            Assert.AreEqual(3, orderedChannels.Count, "unexpected number of channels");
            Assert.AreSame(channel2, orderedChannels[0], "wrong channel");
            Assert.AreSame(channel1, orderedChannels[1], "wrong channel");
            Assert.AreSame(channel3, orderedChannels[2], "wrong channel");            

            //multiple of same type
            IPolicyChannel channel4 = ChannelFactory.CreateChannel("channel4", ChannelType.SMTP);
            channels.Add(channel4);

            orderedChannels = controller.OrderedChannels(channels);

            Assert.AreEqual(4, orderedChannels.Count, "unexpected number of channels");
            Assert.AreSame(channel2, orderedChannels[0], "wrong channel");
            Assert.AreSame(channel4, orderedChannels[1], "wrong channel");
            Assert.AreSame(channel1, orderedChannels[2], "wrong channel");
            Assert.AreSame(channel3, orderedChannels[3], "wrong channel");
        }
Ejemplo n.º 3
0
        public void TestReadConditionsSecondLevel()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policyId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string ruleId = "{56C991B8-953D-46AD-B9E9-0CFB08F52C23}";
            string conditionGroupId = "{D64056E5-A19D-4B29-8F4A-A70337B42A19}";
            string childConditionGroupId = "{661EDD6F-D750-493A-9932-E56C8C22E2CF}";
            string conditionsXpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Conditions/ConditionGroup[@id='{2}']/ConditionGroup[@id='{3}']",
                policyId, ruleId, conditionGroupId, childConditionGroupId);

            PolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();

            XmlConditionGroupReader conditionReader = new XmlConditionGroupReader(xmlPolicyReader, conditions, conditionsXpath);
            conditionReader.Read();

            Assert.AreEqual(1, conditions.Count);

            ICondition condition = conditions[0] as ICondition;
            Assert.IsNotNull(condition);
            Assert.AreEqual(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), condition.Identifier);
            Assert.AreEqual("IDataComparer", condition.Class);
            Assert.AreEqual(OperatorType.GreaterThan, condition.Operator);
        }
Ejemplo n.º 4
0
        public void TestReadChannel()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));
            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policySetId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string policyId = "{F067B5B0-431A-4A34-BDD8-307C83DD8F7C}";
            string xpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Channels",
                policySetId, policyId);

            Assert.AreEqual(1, xmlPolicyReader.PolicySets.Count);
            IPolicySet policySet = xmlPolicyReader.PolicySets[0];
            Assert.IsNotNull(policySet);

            IPolicy policy = policySet.Policies[new Guid(policyId)];
            Assert.IsNotNull(policy);

            PolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            XmlChannelsReader reader = new XmlChannelsReader(xmlPolicyReader, channels, policy, xpath);
            reader.Read();

            Assert.AreEqual(2, channels.Count, "Expected two channels");

            int channelIndex = 0;
            ValidateChannel1(channels[channelIndex++]);
            ValidateChannel2(channels[channelIndex++]);
        }
        public void TestGetDisplayName()
        {

            //nominal case - display name already set
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Header)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.TextBox)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.StringArray, dataItems);
            ConditionDisplayParameterContext contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("Header, Text box", contextParam.GetDisplayName(), "unexpected displayname - display name should be same as dataElement");

            //data items in collection
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("Header, Text box", contextParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("Header, Text box", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //no data items in collection
            dataItems = new PolicyObjectCollection<IDataItem>();
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_DEFAULT, contextParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), ConditionUnitFactory.FileContextType.Endnote)));
            contextParam = new ConditionDisplayParameterContext(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            contextParam.Object = dataElement;
            try
            {
                string displayName = contextParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            contextParam = new ConditionDisplayParameterContext(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = contextParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
        public void TestGetDisplayName()
        {

            //nominal case - display name already set
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.StringArray, dataItems);
            ConditionDisplayParameterFileType fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.GetDisplayName(), "unexpected displayname - displayname should be the same dataElement");

            //data items in collection
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //no data items in collection
            dataItems = new PolicyObjectCollection<IDataItem>();
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_FILETYPE_DEFAULT, fileTypeParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_FILETYPE_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument)));
            fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            fileTypeParam.Object = dataElement;
            try
            {
                string displayName = fileTypeParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = fileTypeParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
Ejemplo n.º 7
0
 public static object StringArrayToPolicyObjectModelStringArray(string[] items)
 {
     IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
     foreach (string item in items)
     {
         dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, item));
     }
     return dataItems;
 }
Ejemplo n.º 8
0
        public void TestClone_TranslatableDisplayName()
        {
            IPolicyObjectCollection<IDataItem> collection = new PolicyObjectCollection<IDataItem>(); 
            DataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("content"), new TranslateableLanguageItem("Word or phrase"), DataType.StringArray, collection);

            DataElement dataElementCopy = dataElement.Clone() as DataElement;

            Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier);
            Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value);
            Assert.AreNotEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier);
        }
Ejemplo n.º 9
0
        public IPolicyObjectCollection<IDataElement> Read()
        {
            if (m_dataElementsNode == null)
                throw new Workshare.Policy.Exceptions.ArgumentNullException("m_dataElementsNode", "Data elements node is null");

            IPolicyObjectCollection<IDataElement> dataElements = new PolicyObjectCollection<IDataElement>();

            foreach (XmlNode dataElementNode in m_dataElementsNode)
            {
                dataElements.Add(new XmlDataElementReader(dataElementNode).Read());
            }

            return dataElements;
        }
        public void TestConstructor2()
        {
            //empty dataElement
            ConditionDisplayParameterContent contentParam = new ConditionDisplayParameterContent(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, contentParam.Object), "unexpected Object");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_CONTENTPARAM_DEFAULT, contentParam.Text, "unexpected Text");

            //nominal case with no display name
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "some content"));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "more content"));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            
            dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Boolean, true));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Boolean, false));
            IDataElement matchWordElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("matchWholeWords"), new NonTranslateableLanguageItem(""), DataType.BooleanArray, dataItems);
            contentParam = new ConditionDisplayParameterContent(dataElement, matchWordElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, contentParam.Object), "unexpected Object");

            m_callbackCalled = false;
            contentParam.Execute();
            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, contentParam.Object), "unexpected Object");
            Assert.AreEqual("some content, more content", contentParam.Text, "unexpected Text, display name should be the same as dataElement");

            m_callbackCalled = false;
            contentParam.Execute();
            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, "My content");
                contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterContext contextParam = new ConditionDisplayParameterContext(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, contextParam.Object), "unexpected Object");
            Assert.IsTrue(Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_DEFAULT == contextParam.Text, "unexpected Text");

            //nominal case with no display name
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.CellText)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Footer)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, contextParam.Object), "unexpected Object");
            Assert.AreEqual("Cell text, Footer", contextParam.Text, "unexpected Text");

            m_callbackCalled = false;
            contextParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, contextParam.Object), "unexpected Object");
            Assert.AreEqual("Cell text, Footer", contextParam.Text, "unexpected Text - display name should be same dataElement");

            m_callbackCalled = false;
            contextParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Footnote)));
                contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterFileType fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, fileTypeParam.Object), "unexpected Object");
            Assert.IsTrue(Properties.Resources.IDS_EXPRESSION_PARAM_FILETYPE_DEFAULT == fileTypeParam.Text, "unexpected Text");
                        
            //nominal case with no display name
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, fileTypeParam.Object), "unexpected Object");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.Text, "unexpected Text");

            m_callbackCalled = false;
            fileTypeParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, fileTypeParam.Object), "unexpected Object");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.Text, "unexpected Text - displayname should be the same as dataElement");

            m_callbackCalled = false;
            fileTypeParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
                fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
Ejemplo n.º 13
0
        private void FilterPolicies(IPolicySet policySet)
        {
            if (null == policySet)
                return;

            IPolicyObjectCollection<IPolicy> policies = new PolicyObjectCollection<IPolicy>();

            foreach (IPolicy policy in policySet.Policies)
            {
                IPolicy reducedPolicy = FilterPolicy(policy);
                if (null == reducedPolicy)
                    continue;

                policies.Add(reducedPolicy);
            }
            
            m_reducedPolicySet.Policies = policies;
        }
Ejemplo n.º 14
0
        public void TestClone_CollectionOfItems()
        {
            PolicyObjectCollection<IDataItem> items = new PolicyObjectCollection<IDataItem>();

            items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 1"));
            items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 2"));
            items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 3"));

            DataElement elem = new DataElement(
                new TranslateableLanguageItem(Guid.NewGuid()),
                new TranslateableLanguageItem(Guid.NewGuid()),
                DataType.String,
                items
                );

            DataElement copy = elem.Clone() as DataElement;
            Assert.IsNotNull(copy.Data);

            PolicyObjectCollection<IDataItem> copyOfItems = copy.Data as PolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(copyOfItems);

            Assert.AreEqual(3, copyOfItems.Count);

            for (int i = 0; i < copyOfItems.Count; i++)
            {
                IDataItem item = items[i];
                IDataItem copyOfItem = copyOfItems[i];

                Assert.IsNotNull(item);
                Assert.IsNotNull(copyOfItem);

                Assert.AreNotEqual(item.Identifier, copyOfItem.Identifier);
                Assert.AreNotEqual(item.Name.Identifier, copyOfItem.Name.Identifier);
                Assert.AreEqual(item.Name.Value, copyOfItem.Name.Value);
                Assert.AreEqual(item.ReadOnly, copyOfItem.ReadOnly);
                Assert.AreEqual(item.Value, copyOfItem.Value);
            }
        }
Ejemplo n.º 15
0
        public void TestReadConditionGroups()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policyId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string ruleId = "{56C991B8-953D-46AD-B9E9-0CFB08F52C23}";
            string conditionGroupId = "{D64056E5-A19D-4B29-8F4A-A70337B42A19}";
            string conditionsXpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Conditions/ConditionGroup[@id='{2}']",
                policyId, ruleId, conditionGroupId);

            PolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();

            XmlConditionGroupReader XmlConditionGroupReader = new XmlConditionGroupReader(xmlPolicyReader, conditions, conditionsXpath);
            XmlConditionGroupReader.Read();

            Assert.AreEqual(2, conditions.Count);

            IConditionGroup conditionGroup = conditions[0] as IConditionGroup;
            Assert.IsNotNull(conditionGroup);
            Assert.AreEqual(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), conditionGroup.Identifier);
            Assert.AreEqual("Profanity", conditionGroup.Name.Value);
            Assert.AreEqual(1, conditionGroup.Conditions.Count);

            ICondition conditionGroupCondition = conditionGroup.Conditions[0] as ICondition;
            Assert.IsNotNull(conditionGroupCondition);
            Assert.AreEqual(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), conditionGroupCondition.Identifier);
            Assert.AreEqual(OperatorType.GreaterThan, conditionGroupCondition.Operator);
            Assert.AreEqual(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), conditionGroupCondition.DataLeft.Identifier);
            IDataSource dataSource = conditionGroupCondition.DataLeft.Data as IDataSource;
            Assert.IsNotNull(dataSource, "Expected a valid data source");
            IDataItem data = conditionGroupCondition.DataRight.Data as IDataItem;
            Assert.IsNotNull(data);
            Assert.AreEqual(10, data.Value);

            ICondition condition = conditions[1] as ICondition;
            Assert.IsNotNull(condition);
            Assert.AreEqual(new Guid("{A6F876B6-AD6D-4842-BC0D-4635D1EEE916}"), condition.Identifier);
            Assert.AreEqual("IDataComparer", condition.Class);
            Assert.AreEqual(OperatorType.GreaterThanOrEqualTo, condition.Operator);
            Assert.AreEqual(new Guid("{7CED5561-FD8C-423C-838F-9440EDFE6758}"), condition.DataLeft.Identifier);
            dataSource = condition.DataLeft.Data as IDataSource;
            Assert.IsNotNull(dataSource, "Expected a valid data source");
            data = condition.DataRight.Data as IDataItem;
            Assert.IsNotNull(data);
            Assert.AreEqual(2, data.Value);
        }
Ejemplo n.º 16
0
        public void TestReadChannelRoutingMatrix()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));
            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policySetId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string policyId = "{C7D62E10-D889-4EF5-AF3D-823C82C230CA}";
            string xpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Channels",
                policySetId, policyId);

            Assert.AreEqual(1, xmlPolicyReader.PolicySets.Count);
            IPolicySet policySet = xmlPolicyReader.PolicySets[0];
            Assert.IsNotNull(policySet);

            IPolicy policy = policySet.Policies[new Guid(policyId)];
            Assert.IsNotNull(policy);

            PolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            XmlChannelsReader reader = new XmlChannelsReader(xmlPolicyReader, channels, policy, xpath);
            reader.Read();

            Assert.AreEqual(1, channels.Count, "Expected one channel");
            IPolicyChannel channel = channels[0];
            Assert.IsNotNull(channel);
            Assert.IsNotNull(channel.Routing, "Expected a valid instance of the channel routing collection");
            IRoutingTable smtpRouting = channel.Routing;
            Assert.IsNotNull(smtpRouting, "Expected the routing table type to be SMTP");
            Assert.IsTrue(smtpRouting.CellCount > 0, "Expected a routing matrix with cells inserted");
        }
Ejemplo n.º 17
0
        public void TestReadChannelActionMatrix()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));
            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policySetId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string policyId = "{C7D62E10-D889-4EF5-AF3D-823C82C230CA}";
            string xpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Channels",
                policySetId, policyId);

            Assert.AreEqual(1, xmlPolicyReader.PolicySets.Count);
            IPolicySet policySet = xmlPolicyReader.PolicySets[0];
            Assert.IsNotNull(policySet);

            IPolicy policy = policySet.Policies[new Guid(policyId)];
            Assert.IsNotNull(policy);

            PolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            XmlChannelsReader reader = new XmlChannelsReader(xmlPolicyReader, channels, policy, xpath);
            reader.Read();

            Assert.AreEqual(1, channels.Count, "Expected one channel");
            IPolicyChannel channel = channels[0];
            Assert.IsNotNull(channel);
            Assert.IsNotNull(channel.Actions, "Expected a valid instance of the channel actions collection");
            IActionMatrix actionMatrix = channel.Actions;
            Assert.IsNotNull(actionMatrix);
            Assert.AreEqual("", actionMatrix.Name.Value);

            Dictionary<KeyValuePair<Guid, Guid>, IActionMatrixCell>.Enumerator enumerator = actionMatrix.GetEnumerator();
            Assert.IsTrue(enumerator.MoveNext(), "Expectd the enumerator to move to the first item");
            IActionMatrixCell actionMatrixCell = enumerator.Current.Value;
            Assert.IsNotNull(actionMatrixCell, "Expected a valid action matrix cell");
            IPolicyObjectCollection<IActionConditionGroup> actionConditiongroups = actionMatrixCell.ActionConditionGroups;
            Assert.IsNotNull(actionConditiongroups, "Expected a valid action condition group collection");
            Assert.AreEqual(1, actionConditiongroups.Count, "Expected one action condition group collection");
            IActionConditionGroup actionConditionGroup = actionConditiongroups[0];
            Assert.IsNotNull(actionConditionGroup, "Expected a valid action condition group");

            IActionGroup actionGroup = actionConditionGroup.ActionGroup;

            Assert.IsNotNull(actionGroup, "Expected a valid action group");
            Assert.AreEqual(new Guid("{987B7C8B-5ADD-4696-8456-DDE11D95CE0B}"), actionGroup.Identifier);
            Assert.AreEqual("Protect us please", actionGroup.Name.Value);
            Assert.AreEqual(1, actionGroup.ActionGroups.Count);
            IActionGroup subActionGroup = actionGroup.ActionGroups[0];
            Assert.IsNotNull(subActionGroup, "Expected a valid sub-action group");
            Assert.AreEqual(new Guid("{BBEF6879-6D10-455d-A5D9-86D9B8B725A6}"), subActionGroup.Identifier);
            Assert.AreEqual("Email us please", subActionGroup.Name.Value);
            Assert.IsNotNull(subActionGroup.ActionGroups, "Expected the sub-ActionGroup's ActionGroup to be valid");
            Assert.AreEqual(0, subActionGroup.ActionGroups.Count);
            Assert.IsNotNull(subActionGroup.Actions, "Expected the sub-ActionGroup's Actions to be valid");
            Assert.AreEqual(1, subActionGroup.Actions.Count);
            IAction action = subActionGroup.Actions[0];
            Assert.IsNotNull(action, "Expected a valid action");
            Assert.AreEqual(new Guid("{72551FD1-D46D-4af6-8DA3-76B5BCE01FD8}"), action.Identifier);
            Assert.AreEqual("CustomAction2.dll", action.Assembly);
            Assert.IsNotNull(action.DataElements, "Expected the data elements to be valid for the action");
            Assert.AreEqual(1, action.DataElements.Count);
            IDataElement dataElement = action.DataElements[0];
            Assert.IsNotNull(dataElement, "Expected a valid data element");
            Assert.AreEqual(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), dataElement.Identifier);
            Assert.AreEqual("Profanity lookup", dataElement.Name.Value);

            Assert.AreEqual(1, actionGroup.Actions.Count);
            action = actionGroup.Actions[0];
            Assert.IsNotNull(action, "Expected a valid action");
            Assert.AreEqual(new Guid("{26BCFA7E-3605-4ee7-ACC6-0AFB4D5EBB71}"), action.Identifier);
            Assert.AreEqual("CustomAction.dll", action.Assembly);
            Assert.IsNotNull(action.DataElements, "Expected the data elements to be valid for the action");
            Assert.AreEqual(1, action.DataElements.Count);
            dataElement = action.DataElements[0];
            Assert.IsNotNull(dataElement, "Expected a valid data element");
            Assert.AreEqual(new Guid("{7CED5561-FD8C-423C-838F-9440EDFE6758}"), dataElement.Identifier);
            Assert.AreEqual("Discrimination lookup", dataElement.Name.Value);
        }
Ejemplo n.º 18
0
        public void TestActionExceptionHandlerWithOffline()
        {
            string testCatalogue = m_testPath + "TestActionExceptionHandlerWithOffline.Catalogue.xml";
            string testLanguage = m_testPath + "TestActionExceptionHandlerWithOffline.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);

            // Build the ActionException cell for the action matrix.
            IActionMatrix actions = new ObjectModel.ActionMatrix();

            ActionExceptionCell actionExceptionCell = actions.ActionExceptionHandler as ObjectModel.ActionExceptionCell;
            Assert.IsNotNull(actionExceptionCell);

            OfflineActionMatrixCell offlineCell = actions.Offline as OfflineActionMatrixCell;

            ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false);
            ICondition subCondition = new Condition(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), "ITestOne", OperatorType.GreaterThan);

            DataMethod dataMethod = new DataMethod("Test method");
            dataMethod.Parameters.Add(new Parameter("FindSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "missing")));
            dataMethod.Parameters.Add(new Parameter("RunSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "just do it!")));
            DataSource dataSource = new DataSource("Testme.dll", "TestMe", dataMethod);
            subCondition.DataLeft = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Do testing stuff"), new TranslateableLanguageItem(""), DataType.Object, dataSource);
            IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item"), DataType.Long, "10");
            subCondition.DataRight = new DataElement(new Guid("{EB56B397-954D-45C2-ADBA-263372A8B59F}"), new TranslateableLanguageItem("Test data item stored in data element"), new TranslateableLanguageItem(""), DataType.Long, dataItem);
            conditionGroup.Conditions.Add(subCondition);

            policy.Conditions.Add(conditionGroup);
            actionExceptionCell.AddActionCondition(conditionGroup, BuildActionGroup(), false);

            channel.Actions = actions;
            channels.Add(channel);
            policy.Channels = channels;

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");
            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, policy.Conditions);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            string expectedPolicySetFile = m_testPath + "TestActionExceptionHandlerWithOffline.PolicySet.xml";
            TestHelpers.CompareXml(expectedPolicySetFile, store.StoreXML);
        }
        public void TestConditionGroupCopyConstructors()
        {
            IConditionGroup conditionGroup = ReadConditionGroupAttributesHelper();
            Assert.AreEqual("This is my first custom property", conditionGroup["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroup["custom2"].Value);

            ConditionGroup conditionGroupCopy = new ConditionGroup(conditionGroup as ConditionGroup);
            Assert.AreEqual("This is my first custom property", conditionGroupCopy["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroupCopy["custom2"].Value);

            ConditionGroup conditionGroupCopy2 = new ConditionGroup(conditionGroup as ConditionGroup, false, false);
            Assert.AreEqual("This is my first custom property", conditionGroupCopy2["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroupCopy2["custom2"].Value);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();
            conditions.Add(new Condition(Guid.Empty, "Test condition", OperatorType.GreaterThan));
            ConditionGroup conditionGroupCopy3 = new ConditionGroup(conditionGroup as ConditionGroup, conditions);
            Assert.AreEqual("This is my first custom property", conditionGroupCopy3["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroupCopy3["custom2"].Value);

            ConditionGroup conditionGroupCopy4 = new ConditionGroup(conditionGroup.Identifier, conditionGroup.Name, conditionGroup.Logic, conditionGroup.ExitOnFirstPass);
            Assert.AreEqual("", conditionGroupCopy4["custom1"].Value);
            Assert.AreEqual("", conditionGroupCopy4["custom2"].Value);
        }
Ejemplo n.º 20
0
        private IPolicyObjectCollection<IPolicyObject> BuildConditions()
        {
            DataMethod dataMethod = new DataMethod("Test method");
            dataMethod.Parameters.Add(new Parameter("FindSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "missing")));
            dataMethod.Parameters.Add(new Parameter("RunSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "just do it!")));
            DataSource dataSource = new DataSource("Testme.dll", "TestMe", dataMethod);

            ICondition subCondition = new Condition(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), "ITestOne", OperatorType.GreaterThan);
            subCondition.DataLeft = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Do testing stuff"), new TranslateableLanguageItem(""), DataType.Object, dataSource);
            IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item"), DataType.Long, "10");
            subCondition.DataRight = new DataElement(new Guid("{EB56B397-954D-45C2-ADBA-263372A8B59F}"), new TranslateableLanguageItem("Test data item stored in data element"), new TranslateableLanguageItem(""), DataType.Long, dataItem);

            IConditionGroup subConditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("Test group two"), ConditionLogic.AND, false);
            subConditionGroup.Conditions.Add(subCondition);
            IConditionGroup conditionGroup = new ConditionGroup(new Guid("{D64056E5-A19D-4B29-8F4A-A70337B42A19}"), new TranslateableLanguageItem("Test group one"), ConditionLogic.OR, true);
            conditionGroup.Conditions.Add(subConditionGroup);

            DataMethod dataMethod2 = new DataMethod("Test method two");
            dataMethod2.Parameters.Add(new Parameter("DoIt", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "You should do this")));
            dataMethod2.Parameters.Add(new Parameter("DontDoIt", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "You should not do this")));
            DataSource dataSource2 = new DataSource("Test2.dll", "JustDoIt", dataMethod2);

            ICondition condition = new Condition(new Guid("{A6F876B6-AD6D-4842-BC0D-4635D1EEE916}"), "ITestTwo", OperatorType.GreaterThanOrEqualTo);
            condition.DataLeft = new DataElement(new Guid("{7CED5561-FD8C-423C-838F-9440EDFE6758}"), new TranslateableLanguageItem("Some data source"), new TranslateableLanguageItem(""), DataType.Object, dataSource2);
            IDataItem dataItem2 = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item 2"), DataType.Long, "2");
            condition.DataRight = new DataElement(new Guid("{C6E38158-AB8C-496B-B97D-FD413680977D}"), new TranslateableLanguageItem("Test result2"), new TranslateableLanguageItem(""), DataType.Long, dataItem2);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();
            conditions.Add(conditionGroup);
            conditions.Add(condition);

            return conditions;
        }
Ejemplo n.º 21
0
        public void TestWriteHttpOfflineNoActions()
        {
            string testCatalogue = m_testPath + "TestHttpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestHttpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP);

            // Build the offline cell for the action matrix.
            IActionMatrix actions = new ObjectModel.ActionMatrix();

            OfflineActionMatrixCell offlineCell = actions.Offline as OfflineActionMatrixCell;
            Assert.IsNotNull(offlineCell);

            ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new NonTranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false);
            policy.Conditions.Add(conditionGroup);
            offlineCell.AddActionCondition(conditionGroup, BuildActionGroupNoActions(), false);

            channel.Actions = actions;
            channels.Add(channel);
            policy.Channels = channels;

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");
            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            string expectedPolicySetFile = m_testPath + "TestHttpOfflineNoActions.PolicySet.xml";
            TestHelpers.CompareXml(expectedPolicySetFile, store.StoreXML);

            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteCatalogue(policySet.MasterCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestHttpOfflineNoActions.Catalogue.xml";
            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
Ejemplo n.º 22
0
        public void TestWriteSmtpOfflineRouting()
        {
            string testCatalogue = m_testPath + "TestSmtpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestSmtpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);
            IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.SMTP);
            IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called
            channel.Routing = routings;
            channels.Add(channel);
            policy.Channels = channels;

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestSmtpOfflineRouting.Catalogue.Modified.xml";
            string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile);
            expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogueFile = expectedCatalogueFile + ".tmp";
            System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue);

            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
Ejemplo n.º 23
0
        public void TestWriteHttpOfflineRouting()
        {
            string testCatalogue = m_testPath + "TestHttpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestHttpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP);
            IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.HTTP);
            IRoutingItemCollection defaultSender = routings.DefaultSource;
            IRoutingItemCollection defaultRecipient = routings.DefaultDestination;
            IRoutingMatrixCell routingCell = routings[defaultSender, defaultRecipient];
            IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called
            channel.Routing = routings;
            channels.Add(channel);
            policy.Channels = channels;

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestHttpOfflineRouting.Catalogue.Modified.xml";
            string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile);
            expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogue = expectedCatalogue.Replace("{73B623E3-7D1A-470B-9C3A-BCE2B4D2B3CD}", defaultSender.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{0FC0FBD3-FC51-4D19-B7CE-04C6A5447E8C}", defaultSender.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E811E002-16F5-41B6-877E-6C7741529965}", defaultRecipient.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{3D594866-8C44-4896-91FD-A549B6481722}", defaultRecipient.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{6ACC2C34-071A-445E-88A2-4C5B94452E5B}", routingCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{1BE90656-9FF3-4747-960D-176E6183C673}", routingCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogueFile = expectedCatalogueFile + ".tmp";
            System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue);

            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
Ejemplo n.º 24
0
        public void TestWriteChildCollectionRuleChannels()
        {
            string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml";
            string testLanguage = m_testPath + "TestRealPolicyLanguage.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);
            channel.Actions = BuildActionMatrix(policy, false); 
            channel.Routing = BuildSmtpRouting();
            channels.Add(channel);

            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, null, policy.Conditions);
            writer.WriteChildCollection(policySet, policy, "Copy of test rule", CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteChildCollectionRuleChannels.xml", store.StoreXML);
        }
Ejemplo n.º 25
0
        public void TestWriteRuleHttpRouting()
        {
            string testLanguage = m_testPath + "TestHttpRoutingLanguage.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{E4C8224A-4CBC-4BFF-B50E-A7E60AAABCFD}"), languageId, catalogueStore);
            policyCatalogue.Name = new TranslateableLanguageItem("{3DDE25D7-E892-430D-A85C-075EBA5535AC}");
            catalogueStore.AddPolicyCatalogue(policyCatalogue);

            XmlStore store = new XmlStore();

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP);

            RoutingTable routing = RoutingTableFactory.Instance.Create(ChannelType.HTTP, new Guid("{8B097CCF-02C8-40C4-9866-AD6EC09C5AB2}"), new NonTranslateableLanguageItem("Test active content routing"), false) as RoutingTable;
            Assert.IsNotNull(routing);
            IRoutingItemCollection defaultRecipient = routing.DefaultDestination;
            Assert.IsNotNull(defaultRecipient);
            IRoutingItemCollection defaultSender = routing.DefaultSource;
            Assert.IsNotNull(defaultSender);
            IRoutingMatrixCell routingCell = routing[defaultSender, defaultRecipient];
            Assert.IsNotNull(routingCell);

            channel.Routing = routing;
            channels.Add(channel);

            policy.Channels = channels;

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");
            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            TestHelpers.CompareXml(m_testPath + "TestHttpRoutingPolicySet.xml", store.StoreXML);

            string expectedCatalogue = System.IO.File.ReadAllText(m_testPath + "TestHttpRoutingCatalogue.xml");
            expectedCatalogue = expectedCatalogue.Replace("{A176A59A-8AFB-4820-B7D4-4074B64C9F14}", defaultSender.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{14C8BE82-D52D-4CE3-9131-FBEA60C88731}", defaultRecipient.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{6ACC2C34-071A-445E-88A2-4C5B94452E5B}", routingCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{ABBFAC23-846B-42D8-BA14-84CB9E5A095A}", routingCell.Description.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{6D82D228-A194-4F00-BEE1-DF01368E572F}", defaultSender.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{7EC9EBD4-67B3-42C3-A750-12CFC9B4DFD0}", defaultRecipient.Name.Identifier.ToString("B").ToUpper());

            string catalogueFile = m_testPath + "TestHttpRoutingCatalogue.xml.tmp";
            System.IO.File.WriteAllText(catalogueFile, expectedCatalogue);

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            TestHelpers.CompareXml(catalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
Ejemplo n.º 26
0
        public void TestWriteMultiplePoliciesMultipleChannels()
        {
            string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml";
            string testLanguage = m_testPath + "TestRealPolicyLanguage.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);

            IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>();
            PolicyChannel channel = new PolicyChannel(new Guid("{EB97BB54-CB76-46EE-B024-3F747ED4424F}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);
            channel.Routing = BuildSmtpRouting();
            channel.Actions = BuildActionMatrix(policy, false);
            channels.Add(channel);

            writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels);

            ObjectModel.PolicySet policySet2 = new ObjectModel.PolicySet(new Guid("{807F2757-373C-4629-AB4E-F0AEB3DE447B}"), new TranslateableLanguageItem("{F7916FE9-8871-4650-A3ED-9597A3F91A74}"), store, policyCatalogue, false);
            writer.WritePolicySet(policySet2);
            writer.WritePolicy(policySet2, policy);
            writer.WriteChildCollection(policySet2, policy, "Conditions", policy.Conditions);

            channel = new PolicyChannel(new Guid("{B28CD900-603B-4FE7-9994-EE2B7BCAD2F8}"), new TranslateableLanguageItem("{BFC3A7A1-E753-48CF-BB41-F2765D08B1B5}"), ChannelType.SMTP);
            channel.Routing = BuildSmtpRouting();
            channels.Add(channel);

            writer.WriteChildCollection(policySet2, policy, policy.Name.Value, channels);

            writer.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteMultiplePoliciesMultipleChannels.xml", store.StoreXML);
        }
Ejemplo n.º 27
0
        public void TestWriteMultiplePolicies()
        {
            string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml";
            string testLanguage = m_testPath + "TestRealPolicyLanguage.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>(BuildConditions() as PolicyObjectCollection<IPolicyObject>);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, conditions);

            ObjectModel.PolicySet policySet2 = new ObjectModel.PolicySet(new Guid("{807F2757-373C-4629-AB4E-F0AEB3DE447B}"), new TranslateableLanguageItem("{F7916FE9-8871-4650-A3ED-9597A3F91A74}"), store, policyCatalogue, false);
            writer.WritePolicySet(policySet2);
            writer.WritePolicy(policySet2, policy);

            conditions.RemoveAt(0);
            writer.WriteChildCollection(policySet2, policy, policy.Name.Value, conditions);

            writer.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteMultiplePolicies.xml", store.StoreXML);
        }
Ejemplo n.º 28
0
        public void TestWriteReadOnlyChannelActions()
        {
            string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml";
            string testLanguage = m_testPath + "TestRealPolicyLanguage.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);

            channel.Actions = BuildActionMatrix(policy, false);

            Dictionary<KeyValuePair<Guid, Guid>, IActionMatrixCell>.Enumerator actionMatrixEnumerator = channel.Actions.GetEnumerator();
            actionMatrixEnumerator.MoveNext();

            IActionMatrixCell actionMatrixCell = actionMatrixEnumerator.Current.Value;
            IActionConditionGroup actionConditionGroup = actionMatrixCell.ActionConditionGroups[0];
            ObjectModel.Action action = actionConditionGroup.ActionGroup.ActionGroups[0].Actions[0] as ObjectModel.Action;
            actionConditionGroup.ActionGroup.ActionGroups[0].Actions.RemoveAt(0);
            actionConditionGroup.ActionGroup.ActionGroups[0].Actions.Insert(0, action.DeepCopy(true));

            channels.Add(channel);

            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels);
            writer.Close();

			TestHelpers.CompareXml(m_testPath + "ExpectedWriteReadOnlyChannelActions.xml", store.StoreXML);
        }
Ejemplo n.º 29
0
        public void TestReadMultiplePoliciesConditionGroups()
        {
            string policyCatalogueFilename = m_testPath + "ExpectedMultiplePoliciesCatalogue.xml";
            string policyLanguageFilename = m_testPath + "ExpectedMultiplePoliciesLanguage.xml";
            string policyFilename = m_testPath + "ExpectedWriteMultiplePolicies.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policyId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string ruleId = "{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}";
            string conditionGroupId = "{D64056E5-A19D-4B29-8F4A-A70337B42A19}";
            string conditionsXpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Conditions/ConditionGroup[@id='{2}']",
                policyId, ruleId, conditionGroupId);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();
            XmlConditionGroupReader conditionReader = new XmlConditionGroupReader(xmlPolicyReader, conditions, conditionsXpath);
            conditionReader.Read();

            Assert.AreEqual(1, conditions.Count);
            IConditionGroup conditionGroup = conditions[0] as IConditionGroup;
            Assert.IsNotNull(conditionGroup);
            Assert.AreEqual(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), conditionGroup.Identifier);
            Assert.AreEqual(1, conditionGroup.Conditions.Count);
            Assert.AreEqual(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), conditionGroup.Conditions[0].Identifier);
        }
Ejemplo n.º 30
0
        public void TestReadMultiplePoliciesConditions()
        {
            string policyCatalogueFilename = m_testPath + "ExpectedMultiplePoliciesCatalogue.xml";
            string policyLanguageFilename = m_testPath + "ExpectedMultiplePoliciesLanguage.xml";
            string policyFilename = m_testPath + "ExpectedWriteMultiplePolicies.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policyId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string ruleId = "{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}";
            string conditionsXpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Conditions",
                policyId, ruleId);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();
            XmlConditionsReader xmlConditionsReader = new XmlConditionsReader(xmlPolicyReader, conditions, conditionsXpath);
            xmlConditionsReader.Read();

            Assert.AreEqual(2, conditions.Count);
            Assert.IsNotNull(conditions[0] as IConditionGroup);
            Assert.IsNotNull(conditions[1] as ICondition);
        }