Ejemplo n.º 1
0
        public void TestExportChannels()
        {           
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.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));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            ps.Export(policyStore);

            string nxstore = policyStore.XMLRepresentation;
            CompiledPolicySetExtractor pse = new CompiledPolicySetExtractor(nxstore);
            List<string> channelNames = pse.GetChannelNames();
            foreach (string channel in channelNames)
            {
                Assert.AreNotEqual("", pse.GetRules(channel));
                Assert.AreNotEqual("", pse.GetObjects(channel));
            }
        }
Ejemplo n.º 2
0
        private void CompileNxBrePolicySet(IPolicySetVersionCache version, IPolicySet policySet, string target)
        {
            if ((null == version) || (null == policySet) || (string.IsNullOrEmpty(target)))
                return;

            NxPolicyStore nxBreStore = new NxPolicyStore();
            nxBreStore.ResourceManager = ResourcesCache.GetResources();
            policySet.Export(nxBreStore);

            CompiledPolicySetExtractor cpse = new CompiledPolicySetExtractor(nxBreStore.XMLRepresentation);
            List<string> channels = cpse.GetChannelNames();

            foreach (string channel in channels)
            {
                string objects = cpse.GetObjects(channel);
                string rules = cpse.GetRules(channel);

                ICompiledPolicySetCache cps = version.GetCompiledPolicySet(channel, target);
                if (cps == null)
                {
                    cps = version.NewCompiledPolicySet(channel, target, rules, objects);
                }
                else
                {
                    cps.Content = rules;
                    cps.ObjectReferences = objects;
                }
                    
                SaveLanguages(cpse.GetLanguages(), cps);
            }
        }
Ejemplo n.º 3
0
        public void TestExportChannel()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogueWithSingleChannel.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicyWithSingleChannel.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            Guid languageId = languageStore.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));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            ps.Export(policyStore);

            string nxstore = policyStore.XMLRepresentation;
            string emailrules = System.IO.Path.GetTempFileName();
            string emailobjects = System.IO.Path.GetTempFileName();

            CompiledPolicySetExtractor pse = new CompiledPolicySetExtractor(nxstore);
            System.IO.File.WriteAllText(emailrules, pse.GetRules("SMTP"));
            System.IO.File.WriteAllText(emailobjects, pse.GetObjects("SMTP"));

            pse.GetLanguages();
      
            XmlDocument rulesXml = new XmlDocument();
            rulesXml.Load(emailrules);

            string xpath = string.Format("/xBusinessRules/Set");
            XmlNodeList nodes = rulesXml.SelectNodes(xpath);

            Assert.AreEqual("Policies", nodes[0].Attributes["id"].Value);
            Assert.AreEqual("w-C1C0D5EA-5B82-4607-AE41-D52739AA6AB1", nodes[1].Attributes["id"].Value);
            Assert.AreEqual("w-c7d62e10-d889-4ef5-af3d-823c82c230ca", nodes[2].Attributes["id"].Value);
            Assert.AreEqual("w-af6e5d89-0c6f-4b10-9a6c-658d13cd3ea8", nodes[4].Attributes["id"].Value);

            System.IO.File.Delete(emailrules);
            System.IO.File.Delete(emailobjects);
        }
Ejemplo n.º 4
0
        private string GenerateNxBreInputXml(string policyCatalogueFilename, string policyLanguageFilename, string policyFilename)
        {
            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.Reset();
            languageStore.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));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            ps.Export(policyStore);
            return policyStore.XMLRepresentation;
        }
Ejemplo n.º 5
0
        private XmlDocument GetRulesForPolicyAndChannel(string policyFile, string channel)
        {
            Workshare.Policy.ObjectModel.PolicyCataloguesCache.Instance().Reset();
            Workshare.Policy.ObjectModel.PolicyLanguageCache.Instance.Reset();

            PolicySetItem policySetItem = PolicySuites.Instance.LoadPolicySet("localhost", policyFile);

            IPolicyObjectCollection<IPolicySet> policySet = policySetItem.Data.PolicyStore.Reader.PolicySets;
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            ps.Export(policyStore);

            string nxstore = policyStore.XMLRepresentation;
            CompiledPolicySetExtractor cpse = new CompiledPolicySetExtractor(nxstore);

            string emailRules = cpse.GetRules(channel);
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(emailRules);

            return xmldoc;
        }
Ejemplo n.º 6
0
        private XmlDocument ExportRules(string catalogue, string language, string policyset, string channel)
        {
            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.Reset();
            languageStore.AddLanguage(System.IO.File.ReadAllText(language));
            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(catalogue));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyset));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            ps.Export(policyStore);

            string nxstore = policyStore.XMLRepresentation;
            CompiledPolicySetExtractor cpse = new CompiledPolicySetExtractor(nxstore);

            string emailRules = cpse.GetRules(channel);
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(emailRules);
            return xmldoc;
        }
Ejemplo n.º 7
0
        public void TestWriteActionExceptionHandlerObjects()
        {
            string path = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\src\NxBrePolicyStore.Tests\TestFiles\");
            string catalogue = path + "TestActionExceptionHandler.Catalogue.xml";
            string language = path + "TestActionExceptionHandler.Language.xml";
            string policyset = path + "TestActionExceptionHandler.PolicySet.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            Guid languageId = languageStore.AddLanguage(System.IO.File.ReadAllText(language));
            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();

            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(catalogue));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyset));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            List<Guid> policiesToExport = new List<Guid>();

            policiesToExport.Add(new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"));
            ps.Export(policyStore, policiesToExport);

            string nxstore = policyStore.XMLRepresentation;
            CompiledPolicySetExtractor pse = new CompiledPolicySetExtractor(nxstore);
            string rules = pse.GetRules("SMTP");
            string objects = pse.GetObjects("SMTP");

            XmlDocument objectsxml = new XmlDocument();
            objectsxml.LoadXml(objects);

            XmlNodeList actions = objectsxml.SelectNodes("/PolicyObjects/Actions/*");
            Assert.AreEqual(2, actions.Count, "Hint - Check the actions are registered with the policy designer?");

            XmlNode object1 = actions[0];
            Assert.AreEqual("CustomAction2.dll", object1.Attributes["assembly"].Value);
            Assert.AreEqual("Workshare.Policy.Actions.PDFUserAction", object1.Attributes["class"].Value);
            Assert.AreEqual("1", object1.Attributes["precedence"].Value);

            XmlNode object2 = actions[1];
            Assert.AreEqual("CustomAction.dll", object2.Attributes["assembly"].Value);
            Assert.AreEqual("Workshare.Policy.Actions.CleanUserAction", object2.Attributes["class"].Value);
            Assert.AreEqual("1", object2.Attributes["precedence"].Value);
            Assert.AreEqual("False", object2.Attributes["allowoverride"].Value);
        }
Ejemplo n.º 8
0
        public void TestWriteActionExceptionHandlerRules()
        {
            string path = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\src\NxBrePolicyStore.Tests\TestFiles\");
            string catalogue = path + "TestActionExceptionHandler.Catalogue.xml";
            string language = path + "TestActionExceptionHandler.Language.xml";
            string policyset = path + "TestActionExceptionHandler.PolicySet.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            Guid languageId = languageStore.AddLanguage(System.IO.File.ReadAllText(language));
            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();

            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(catalogue));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyset));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            List<Guid> policiesToExport = new List<Guid>();

            policiesToExport.Add(new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"));
            ps.Export(policyStore, policiesToExport);

            string nxstore = policyStore.XMLRepresentation;
            CompiledPolicySetExtractor pse = new CompiledPolicySetExtractor(nxstore);
            string rules = pse.GetRules("SMTP");
            string objects = pse.GetObjects("SMTP");

            XmlDocument rulesxml = new XmlDocument();
            rulesxml.LoadXml(rules);

            XmlNode exceptionHandler = rulesxml.SelectSingleNode("/xBusinessRules/Set[@id='ExceptionHandler']");
            XmlNodeList evaluateNodes = exceptionHandler.SelectNodes("Evaluate");

            Assert.AreEqual(2, evaluateNodes.Count, "There should have been two evaluate nodes");

            // Check the values of the object ref and override nodes (the 4th and 5th respectively).
            // The 1st and third nodes are the name and supported file types.
            XmlNode objectRef1 = evaluateNodes[0].ChildNodes[3];
            Assert.AreEqual("72551fd1-d46d-4af6-8da3-76b5bce01fd8", objectRef1.Attributes["value"].Value);
            XmlNode override1 = evaluateNodes[0].ChildNodes[4];
            Assert.AreEqual("True", override1.Attributes["value"].Value);
            
            XmlNode objectRef2 = evaluateNodes[1].ChildNodes[3];
            Assert.AreEqual("26bcfa7e-3605-4ee7-acc6-0afb4d5ebb71", objectRef2.Attributes["value"].Value);
            XmlNode override2 = evaluateNodes[1].ChildNodes[4];
            Assert.AreEqual("False", override2.Attributes["value"].Value);
        }
Ejemplo n.º 9
0
        public void TestExportSimpleOrConditionGroup()
        {
            string catalogue = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\NxBrePolicyStore.Tests\TestFiles\Simple or condition group\catalogue.xml");
            string language = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\NxBrePolicyStore.Tests\TestFiles\Simple or condition group\language.xml");
            string policyset = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\NxBrePolicyStore.Tests\TestFiles\Simple or condition group\policyset.xml");

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.Reset();
            languageStore.AddLanguage(System.IO.File.ReadAllText(language));
            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(catalogue));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyset));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            ps.Export(policyStore);

            string nxstore = policyStore.XMLRepresentation;
            CompiledPolicySetExtractor pse = new CompiledPolicySetExtractor(nxstore);
            string emailRules = pse.GetRules("SMTP");
            XmlDocument rulesxml = new XmlDocument();
            rulesxml.LoadXml(emailRules);

            XmlNode conditionNode = rulesxml.SelectSingleNode("/xBusinessRules/Set[@id='w-cefb3600-beb2-471c-b35d-2bcdaed1e50b']");
            Assert.IsNotNull(conditionNode, "There should be a condition node");

            XmlNode logicNode = conditionNode.SelectSingleNode("Logic[position()=last()]");
            XmlNode orNode = logicNode.SelectSingleNode("If/Or");

            Assert.IsNotNull(orNode, "There should be an or node");
            Assert.AreEqual(2, orNode.ChildNodes.Count, "There should only be two child nodes (as there are only 2 condition groups)");
        }
Ejemplo n.º 10
0
        public void TestExportWithDataSourceAsParameter()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogueWithDataSourceAsParameter.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBaseWithDataSourceAsParameter.xml";
            string policyFilename = m_testPath + "SamplePolicyWithDataSourceAsParameter.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.Reset();
            languageStore.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));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            ps.Export(policyStore);

            string nxstore = policyStore.XMLRepresentation;
            CompiledPolicySetExtractor pse = new CompiledPolicySetExtractor(nxstore);
                  
            
            string emailRules = pse.GetRules("SMTP");
            XmlDocument emailxml = new XmlDocument();
            emailxml.LoadXml(emailRules);

            XmlNode setNode = emailxml.SelectSingleNode("/xBusinessRules/Set[@id='w-c7d62e10-d889-4ef5-af3d-823c82c230ca']");
            XmlNodeList objectLookups = setNode.SelectNodes("ObjectLookup");
            Assert.AreEqual(2, objectLookups.Count);
            Assert.AreEqual("this", objectLookups[0].Attributes["objectId"].Value);
            Assert.AreEqual("CurrentFile", objectLookups[0].Attributes["member"].Value);
            Assert.AreEqual("TextLookupCount", objectLookups[1].Attributes["member"].Value);
            XmlNodeList arugments = objectLookups[1].SelectNodes("Argument");
            Assert.AreEqual(2, arugments.Count);
            string id = objectLookups[0].Attributes["id"].Value;
            Assert.AreEqual(id, arugments[0].Attributes["valueId"].Value);
            Assert.AreEqual("Paragraph", arugments[1].Attributes["value"].Value);
        }
Ejemplo n.º 11
0
        public void TestExportMultiplePolicies()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            Guid languageId = languageStore.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));
            IPolicyObjectCollection<IPolicySet> policySet = store.Reader.PolicySets;
            IPolicyObjectCollection<IPolicy> policies = store.Reader.Policies(policySet[0]);
            IPolicy policy = policies[0];
            IPolicySet ps = policySet[0];

            NxPolicyStore policyStore = new NxPolicyStore();
            policyStore.ResourceManager = ResourcesCache.GetResources();
            List<Guid> policiesToExport = new List<Guid>();
            policiesToExport.Add(new Guid("{C7D62E10-D889-4EF5-AF3D-823C82C230CA}"));
            policiesToExport.Add(new Guid("{56C991B8-953D-46AD-B9E9-0CFB08F52C23}"));
            ps.Export(policyStore, policiesToExport);

            string nxstore = policyStore.XMLRepresentation;

            string emailrules = System.IO.Path.GetTempFileName();
            string emailobjects = System.IO.Path.GetTempFileName();
            string language = System.IO.Path.GetTempFileName();

            CompiledPolicySetExtractor pse = new CompiledPolicySetExtractor(nxstore);
            System.IO.File.WriteAllText(emailrules, pse.GetRules("SMTP"));
            System.IO.File.WriteAllText(emailobjects, pse.GetObjects("SMTP"));

            pse.GetLanguages();

   
            XmlDocument rulesXml = new XmlDocument();
            rulesXml.Load(emailrules);

            string xpath = string.Format("/xBusinessRules/Set[@id='Policies']/InvokeSet");
            XmlNodeList nodes = rulesXml.SelectNodes(xpath);

            Assert.AreEqual(1, nodes.Count);
            Assert.AreEqual("w-C1C0D5EA-5B82-4607-AE41-D52739AA6AB1", nodes[0].Attributes["id"].Value);

            xpath = string.Format("/xBusinessRules/Set[@id='w-C1C0D5EA-5B82-4607-AE41-D52739AA6AB1']");
            nodes = rulesXml.SelectNodes(xpath);

            Assert.AreEqual("w-C1C0D5EA-5B82-4607-AE41-D52739AA6AB1", nodes[0].Attributes["id"].Value);

            System.IO.File.Delete(emailrules);
            System.IO.File.Delete(emailobjects);
            System.IO.File.Delete(language);
        }