public void TestCreatePreRoutingSetWithInternalExternalSmptRoutingTable() { 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)); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP); 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); channel.Routing = BuildInternalExternalSmtpRouting(); channel.Actions = BuildActionMatrix(policy, false); NxPreRoutingSet nxprs = new NxPreRoutingSet(channel, policy, Guid.NewGuid(), Guid.NewGuid()); XmlNode xml = nxprs.Create(); XmlNodeList nodes = xml.SelectNodes("ObjectLookup"); XmlNode objLookup = nodes[0]; Assert.AreEqual("LDAPAnalyzer", objLookup.Attributes["objectId"].Value); Assert.AreEqual("IsLdapEnabled", objLookup.Attributes["member"].Value); }
public void TestWriteChannels() { Guid languageGuid = new Guid("{054846D4-6540-4C78-BA7D-141C91EE6A4C}"); PolicyLanguage language = new PolicyLanguage(languageGuid, "en"); language[new Guid("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}")] = "Test catalogue"; language[new Guid("{A056EB78-E531-4B13-AA2E-0241BFDE3889}")] = "Test channel"; language[new Guid("{C0845AEC-C8C8-4531-BACB-E932B08DF4F0}")] = "Test channel 2"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); Guid catalogueId = new Guid("{B496E117-29DA-4770-87E9-62573B28BB4F}"); XmlPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(catalogueId, languageGuid) as XmlPolicyCatalogueWriter; Assert.IsNotNull(catalogueWriter, "Expected a valid [IPolicyStoreWriter] writer"); catalogueWriter.WriteName("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}"); string channelGuid = "{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"; PolicyChannel channel = new PolicyChannel(new Guid(channelGuid), new TranslateableLanguageItem("{A056EB78-E531-4B13-AA2E-0241BFDE3889}"), ChannelType.SMTP); catalogueWriter.WriteChannel(channel); channelGuid = "{2F1F664B-74B7-4c4d-B8C2-AB13FAF66F19}"; channel = new PolicyChannel(new Guid(channelGuid), new TranslateableLanguageItem("{C0845AEC-C8C8-4531-BACB-E932B08DF4F0}"), ChannelType.HTTP); catalogueWriter.WriteChannel(channel); catalogueWriter.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteChannels.xml", catalogueStore.GetStoreXML(catalogueId)); }
public void TestWriteChannelAttributes() { Guid languageId = new Guid("{CBEB31FA-7FE8-4E27-A01A-1D19AFCA604C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); language[new Guid("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}")] = "Test channel"; language[new Guid("{EBF8443B-4912-44F2-89BE-A0A055332D1B}")] = "This is my first custom property"; language[new Guid("{8053E60C-EED7-464D-84EA-ECB51C291237}")] = "This is my second custom property"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; Guid catalogueGuid = new Guid("{93634DD0-904C-435E-B282-4E650E55E90D}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); PolicyChannel channel = new PolicyChannel(new Guid("{8E915159-5F01-41B3-9FFF-20731544ADFA}"), new TranslateableLanguageItem("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}"), ChannelType.SMTP); channel["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); channel["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IPolicyCatalogueWriter policyCatalogueWriter = catalogueStore.GetWriter(catalogueGuid, languageId); policyCatalogueWriter.WriteName("Test catalogue"); policyCatalogueWriter.WriteChannel(channel); policyCatalogueWriter.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteChannelAttributes.xml", catalogueStore.GetXMLRepresentation(catalogueGuid)); }
private void ReadRoutings(XmlNode parentNode, PolicyChannel policyChannel) { if (parentNode == null) return; IPolicyObjectCollection<IRoutingTable> routingTables = m_reader.CataloguesCache.RoutingTables; XmlNode routingTableNode = parentNode.SelectSingleNode("RoutingTable"); if (routingTableNode == null) return; bool routingsReadOnly = PolicyUtilities.IsReadOnly(routingTableNode); IAddressGroup entireAddressGroup = m_reader.CataloguesCache.AddressGroup; string guid = routingTableNode.Attributes.GetNamedItem("id").InnerText; Guid identifier = new Guid(guid); bool routingTableReadOnly = PolicyUtilities.IsReadOnly(routingTableNode); RoutingTable routingTable = new RoutingTable(routingTables[identifier] as RoutingTable, routingTableReadOnly); XmlNodeList senderGroupNode = routingTableNode.SelectNodes("./SenderGroup/*"); if (senderGroupNode != null) routingTable.Senders = ReadAddressGroup(senderGroupNode, entireAddressGroup, routingTableReadOnly); XmlNodeList recipientGroupNode = routingTableNode.SelectNodes("./RecipientGroup/*"); if (recipientGroupNode != null) routingTable.Recipients = ReadAddressGroup(recipientGroupNode, entireAddressGroup, routingTableReadOnly); // Now build the matrix relationships... i.e. The Cells... XmlNodeList matrixCellNodes = routingTableNode.SelectNodes("./RoutingMatrixCells/*"); if (matrixCellNodes != null) AddMatrixCells(matrixCellNodes, routingTable); policyChannel.Routing = routingTable; }
private void ReadChannelActions(PolicyChannel policyChannel, string channelId) { string xpath = string.Format(CultureInfo.InvariantCulture, @"{0}/Channel[@id='{1}']/ActionMatrix", m_xpath.Substring(0, m_xpath.LastIndexOf("/")), channelId); XmlActionsReader xmlActionsReader = new XmlActionsReader(m_reader, policyChannel, m_policy, xpath); xmlActionsReader.Read(); }
public PolicyChannel(PolicyChannel rhs) : base(rhs, rhs.ReadOnly, false) { if (null == rhs) throw new Workshare.Policy.Exceptions.ArgumentNullException("rhs", "Input policy channel is null"); CopyChannel(rhs, rhs.ReadOnly, false); }
private void ReadChannelRouting(XmlNode routingNode, PolicyChannel policyChannel, Guid routingId) { IPolicyObjectCollection<IRoutingTable> availableRoutingTables = m_reader.CataloguesCache.RoutingTables; RoutingTable routingTable = availableRoutingTables[routingId] as RoutingTable; if (null == routingTable) return; bool readOnly = PolicyUtilities.IsReadOnly(routingNode) || routingTable.ReadOnly; policyChannel.Routing = new RoutingTable(routingTable, readOnly, false); }
private void ReadChannelRouting(XmlNode channelNode, PolicyChannel policyChannel) { XmlNode routingNode = channelNode.SelectSingleNode("RoutingTable"); if (null == routingNode) return; string routingGuid = routingNode.Attributes.GetNamedItem("id").InnerText; Guid identifier = new Guid(routingGuid); ReadChannelRouting(routingNode, policyChannel, identifier); }
private void CopyChannel(PolicyChannel rhs, bool readOnly, bool createNewId) { m_policySetObserver = rhs.m_policySetObserver; if (null != rhs.Routing) { m_routing = RoutingTableFactory.Instance.Copy(rhs.Routing, readOnly, createNewId); SetRoutingTableObserver(); } if (null != rhs.Actions) { m_actions = (rhs.Actions as ActionMatrix).DeepCopy(readOnly, createNewId) as IActionMatrix; SetActionMatrixObserver(); } }
public override void Read() { PolicyObjectCollection<IPolicyChannel> channels = m_parent as PolicyObjectCollection<IPolicyChannel>; if (channels == null) throw new Workshare.Policy.Exceptions.ArgumentNullException("m_parent", "Expected the object to be of type PolicyObjectCollection<PolicyChannel>"); IPolicyObjectCollection<IChannel> availableChannels = m_reader.CataloguesCache.Channels; XmlElement root = m_reader.PolicyDocument.DocumentElement; XmlNode channelNode = root.SelectSingleNode(m_xpath); if (channelNode == null) return; string channelGuid = channelNode.Attributes.GetNamedItem("id").InnerText; Guid identifier = new Guid(channelGuid); bool readOnly = PolicyUtilities.IsReadOnly(channelNode); PolicyChannel policyChannel = new PolicyChannel(availableChannels[identifier] as PolicyChannel, readOnly, false); ReadChannelRouting(channelNode, policyChannel); ReadChannelActions(policyChannel, channelGuid); channels.Add(policyChannel); }
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)); }
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)); }
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)); }
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)); }
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); }
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); }
public void TestWriteActionMatrixAttributes() { Guid languageId = new Guid("{CBEB31FA-7FE8-4E27-A01A-1D19AFCA604C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); language[new Guid("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}")] = "Test condition"; language[new Guid("{5570ABC5-188E-4893-92E4-6930802F9C05}")] = "Test policy"; language[new Guid("{EBF8443B-4912-44F2-89BE-A0A055332D1B}")] = "This is my first custom property"; language[new Guid("{8053E60C-EED7-464D-84EA-ECB51C291237}")] = "This is my second custom property"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; Guid catalogueGuid = new Guid("{751AEC6C-C164-4E6A-8581-A9ECCED87013}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item"), DataType.Long, 10); ObjectModel.IAction action = new ObjectModel.Action(new Guid("{26BCFA7E-3605-4EE7-ACC6-0AFB4D5EBB71}"), "CustomAction.dll", "Test.Clean", RunAt.Client, false, 1); //TODO JE action.DataElements.Add(new DataElement(new Guid("{EB56B397-954D-45C2-ADBA-263372A8B59F}"), new TranslateableLanguageItem("Test data item stored in data element"), new NonTranslateableLanguageItem(""), DataType.Long, dataItem)); ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{987B7C8B-5ADD-4696-8456-DDE11D95CE0B}"), new TranslateableLanguageItem("Test action group"), 1); actionGroup.Actions.Add(action); ActionMatrix actionMatrix = new ObjectModel.ActionMatrix(); ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("Profanity"), ConditionLogic.OR, false); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{79C512E8-3912-4709-B7D7-E91EFA3BD9FD}"), "Test sources"); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{FDC166E4-EBE5-4285-8F09-6A145D88C707}"), "Test destinations"); ActionMatrixCell actionMatrixCell = new ObjectModel.ActionMatrixCell(senders, recipients); actionMatrixCell.AddActionCondition(conditionGroup, actionGroup, false); actionMatrix["{A81631A6-6AA3-45F7-AADD-4853447E5BD6}", "{D23F36C4-953F-4ED9-B1EB-8921BD50562B}"] = actionMatrixCell; actionMatrix["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); actionMatrix["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IPolicyObjectCollection<IActionMatrix> actions = new PolicyObjectCollection<IActionMatrix>(); actions.Add(actionMatrix); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); channel.Actions = actionMatrix; IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>(); channels.Add(channel); XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{5570ABC5-188E-4893-92E4-6930802F9C05}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("Test policy"), PolicyStatus.Active); IPolicyStoreWriter writer = store.Writer; writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteConditionGroup(policySet, policy, conditionGroup); writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteActionMatrixAttributes.xml", store.StoreXML); }
public void TestChannelConstructors() { IPolicyChannel channel = ReadChannelAttributesHelper(); Assert.AreEqual("This is my first custom property", channel["custom1"].Value); Assert.AreEqual("This is my second custom property", channel["custom2"].Value); PolicyChannel channelCopy = new PolicyChannel(channel as IChannel); Assert.AreEqual("This is my first custom property", channelCopy["custom1"].Value); Assert.AreEqual("This is my second custom property", channelCopy["custom2"].Value); PolicyChannel channelCopy2 = new PolicyChannel(channel as PolicyChannel); Assert.AreEqual("This is my first custom property", channelCopy2["custom1"].Value); Assert.AreEqual("This is my second custom property", channelCopy2["custom2"].Value); PolicyChannel channelCopy3 = new PolicyChannel(channel as PolicyChannel, false, false); Assert.AreEqual("This is my first custom property", channelCopy3["custom1"].Value); Assert.AreEqual("This is my second custom property", channelCopy3["custom2"].Value); PolicyChannel channelCopy4 = new PolicyChannel(channel.Identifier, channel.Name, channel.Type); Assert.AreEqual("", channelCopy4["custom1"].Value); Assert.AreEqual("", channelCopy4["custom2"].Value); PolicyChannel channelCopy5 = new PolicyChannel(channel.Identifier, channel.Name, channel.Type, false); Assert.AreEqual("", channelCopy5["custom1"].Value); Assert.AreEqual("", channelCopy5["custom2"].Value); }
public void TestReadActions() { 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)); XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader; string policySetId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}"; string policyId = "{C7D62E10-D889-4EF5-AF3D-823C82C230CA}"; string channelId = "{EB97BB54-CB76-46EE-B024-3F747ED4424F}"; string xpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Channels/Channel[@id='{2}']/ActionMatrix", policySetId, policyId, channelId); Assert.AreEqual(1, xmlPolicyReader.PolicySets.Count); IPolicySet policySet = xmlPolicyReader.PolicySets[0]; Assert.IsNotNull(policySet); IPolicy policy = policySet.Policies[new Guid(policyId)]; Assert.IsNotNull(policy); PolicyChannel policyChannel = new PolicyChannel(new Guid(channelId), new TranslateableLanguageItem("TestChannel"), ChannelType.SMTP); XmlActionsReader reader = new XmlActionsReader(xmlPolicyReader, policyChannel, policy, xpath); reader.Read(); Assert.IsNotNull(policyChannel.Actions, "Expected a valid actions object"); IActionMatrix actionMatrix = policyChannel.Actions; Assert.IsNotNull(actionMatrix, "Expected a valid action matrix"); Assert.AreEqual("", actionMatrix.Name.Value); Assert.AreEqual(3, actionMatrix.CellCount, "Expected four action matrix cells"); 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.IsNotNull(actionGroup.ActionGroups); Assert.AreEqual(1, actionGroup.ActionGroups.Count, "Expected one action group"); IActionGroup childActionGroup = actionGroup.ActionGroups[0]; Assert.IsNotNull(childActionGroup); Assert.AreEqual(new Guid("{BBEF6879-6D10-455d-A5D9-86D9B8B725A6}"), childActionGroup.Identifier); Assert.IsNotNull(childActionGroup.ActionGroups); Assert.AreEqual(0, childActionGroup.ActionGroups.Count); Assert.IsNotNull(childActionGroup.Actions); Assert.AreEqual(1, childActionGroup.Actions.Count, "Expected the child action group to have one action"); IAction childActionGroupChildAction = childActionGroup.Actions[0]; Assert.IsNotNull(childActionGroupChildAction); Assert.AreEqual(new Guid("{72551FD1-D46D-4AF6-8DA3-76B5BCE01FD8}"), childActionGroupChildAction.Identifier); Assert.IsNotNull(actionGroup.Actions); Assert.AreEqual(1, actionGroup.Actions.Count, "Expected one action"); IAction childAction = actionGroup.Actions[0]; Assert.IsNotNull(childAction); Assert.AreEqual(new Guid("{26BCFA7E-3605-4EE7-ACC6-0AFB4D5EBB71}"), childAction.Identifier); }
public void TestAddChannel() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); IPolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); Assert.AreEqual(1, policyCatalogue.Channels.Count); }
private void AddActionPostAddToChannel(out PolicyChannel channel, out PolicyCatalogue policyCatalogue) { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); Assert.AreEqual(0, policyCatalogue.ActionGroups.Count); Assert.AreEqual(0, policyCatalogue.Actions.Count); Assert.AreEqual(0, policyCatalogue.LocationsCollection.Count); Assert.AreEqual(0, policyCatalogue.Locations.Count); channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "Test sources"); senders.Add(new RoutingItem(new Guid("{D41A47E2-CC13-46FF-BE83-829625792576}"), "James Brown", "*****@*****.**")); senders.Add(new RoutingItem(new Guid("{B031DFE9-54E7-482B-8955-18CFB8F06A40}"), "Nat King Cole", "*****@*****.**")); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "Test destinations"); recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**")); ActionMatrix actionMatrix = new ActionMatrix(); ActionMatrixCell actionMatrixCell = new ActionMatrixCell(senders, recipients); ConditionGroup conditionGroup = new ConditionGroup(new Guid("{9D065722-1106-4FC1-8D48-58733661B929}"), new TranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false); ActionGroup actionGroup = new ActionGroup(new Guid("{E2A16C4D-E112-4249-92B9-612732117809}"), new TranslateableLanguageItem("Test action group"), 1); Action action = new Action(new Guid("{A5FAA63E-4F25-456F-92F9-9BB465C18F1F}"), "Test.dll", "Do.It", RunAt.Client, false, 1); //TODO JE ActionConditionGroup actionConditionGroup = new ActionConditionGroup(conditionGroup, actionGroup, false); actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); actionGroup.Actions.Add(action); actionMatrix[senders, recipients] = actionMatrixCell; channel.Actions = actionMatrix; }
public PolicyChannel(PolicyChannel rhs, bool readOnly, bool createNewId) : base(rhs, readOnly, createNewId) { CopyChannel(rhs, readOnly, createNewId); }
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 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); }
public void TestAddActionPreAddToChannel() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); Assert.AreEqual(0, policyCatalogue.ActionGroups.Count); Assert.AreEqual(0, policyCatalogue.Actions.Count); Assert.AreEqual(0, policyCatalogue.LocationsCollection.Count); Assert.AreEqual(0, policyCatalogue.Locations.Count); PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "Test sources"); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "Test destinations"); ActionMatrix actionMatrix = new ActionMatrix(); channel.Actions = actionMatrix; ActionMatrixCell actionMatrixCell = new ActionMatrixCell(senders, recipients); actionMatrix[senders, recipients] = actionMatrixCell; ConditionGroup conditionGroup = new ConditionGroup(new Guid("{9D065722-1106-4FC1-8D48-58733661B929}"), new TranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false); ActionGroup actionGroup = new ActionGroup(new Guid("{E2A16C4D-E112-4249-92B9-612732117809}"), new TranslateableLanguageItem("Test action group"), 1); Action action = new Action(new Guid("{A5FAA63E-4F25-456F-92F9-9BB465C18F1F}"), "Test.dll", "Do.It", RunAt.Client, false, 1); //TODO JE ActionConditionGroup actionConditionGroup = new ActionConditionGroup(conditionGroup, actionGroup, false); actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); actionGroup.Actions.Add(action); Assert.AreEqual(1, policyCatalogue.Channels.Count, "Expected one channel"); Assert.AreEqual(1, policyCatalogue.ActionGroups.Count, "Expected one action group"); Assert.AreEqual(1, policyCatalogue.Actions.Count, "Expected one action"); Assert.AreEqual(2, policyCatalogue.LocationsCollection.Count, "Expected two location groups"); Assert.AreEqual(0, policyCatalogue.Locations.Count, "Expected no locations"); }
public void TestWriteRoutingMatrixCellAttributes() { Guid languageId = new Guid("{CBEB31FA-7FE8-4E27-A01A-1D19AFCA604C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); language[new Guid("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}")] = "Custom routing"; language[new Guid("{8809EBFF-D902-4C91-BE56-1ABD13C054A1}")] = "Test policy"; language[new Guid("{EBF8443B-4912-44F2-89BE-A0A055332D1B}")] = "This is my first custom property"; language[new Guid("{8053E60C-EED7-464D-84EA-ECB51C291237}")] = "This is my second custom property"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; Guid catalogueGuid = new Guid("{751AEC6C-C164-4E6A-8581-A9ECCED87013}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); IRoutingItemCollection senders1 = new RoutingItemCollection(new Guid("{79C512E8-3912-4709-B7D7-E91EFA3BD9FD}"), "Test sources"); IRoutingItemCollection recipients1 = new RoutingItemCollection(new Guid("{FDC166E4-EBE5-4285-8F09-6A145D88C707}"), "Test destinations"); IRoutingMatrixCell cell1 = new RoutingMatrixCell(new TranslateableLanguageItem("C1"), new TranslateableLanguageItem("Description of the blue cell"), new TranslateableLanguageItem("blue"), 1, senders1, recipients1); cell1["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); cell1["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IRoutingMatrixCell cell2 = new RoutingMatrixCell(new TranslateableLanguageItem("C2"), new TranslateableLanguageItem("Description of the red cell"), new TranslateableLanguageItem("red"), 2, senders1, recipients1); IRoutingMatrixCell cell3 = new RoutingMatrixCell(new TranslateableLanguageItem("C3"), new TranslateableLanguageItem("Description of the green cell"), new TranslateableLanguageItem("green"), 3, senders1, recipients1); RoutingTable routingTable = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}"), ChannelType.SMTP); routingTable["{A81631A6-6AA3-45F7-AADD-4853447E5BD6}", "{D23F36C4-953F-4ED9-B1EB-8921BD50562B}"] = cell1; routingTable["{FA13BE82-9EB1-407E-9DD5-8005F3E840E4}", "{4E1B9EAB-E892-4E47-BBE6-9D70B2438333}"] = cell2; routingTable["{3AD507B6-5E1E-44BB-9ABF-C27A31603C1B}", "{D23F36C4-953F-4ED9-B1EB-8921BD50562B}"] = cell3; XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{8809EBFF-D902-4C91-BE56-1ABD13C054A1}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("Test rule"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); channel.Routing = routingTable; channels.Add(channel); 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, channels); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteRoutingMatrixCellAttributes.xml", store.StoreXML); }
public void TestAddRoutingPostAddToChannel() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); Assert.AreEqual(0, policyCatalogue.RoutingTables.Count); Assert.AreEqual(0, policyCatalogue.LocationsCollection.Count); Assert.AreEqual(0, policyCatalogue.Locations.Count); PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "Test sources"); senders.Add(new RoutingItem(new Guid("{D41A47E2-CC13-46FF-BE83-829625792576}"), "James Brown", "*****@*****.**")); senders.Add(new RoutingItem(new Guid("{B031DFE9-54E7-482B-8955-18CFB8F06A40}"), "Nat King Cole", "*****@*****.**")); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "Test destinations"); recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**")); RoutingTable routingTable = new RoutingTable(new Guid("{CDF0252C-3D5D-4AFB-98C2-89CF00FE2175}"), new TranslateableLanguageItem("Test routing table"), ChannelType.SMTP); routingTable.Sources.Add(senders); routingTable.Destinations.Add(recipients); channel.Routing = routingTable; IRoutingItemCollection recipients2 = new RoutingItemCollection(new Guid("{4E17A792-0CBC-4362-8A82-A1A7FF3C71B0}"), "More test destinations"); recipients2.Add(new RoutingItem(new Guid("{98CE8CF9-6CF1-4F32-BE4F-C2D381E6C972}"), "why you", "*****@*****.**")); routingTable.Destinations.Add(recipients2); Assert.AreEqual(1, policyCatalogue.Channels.Count, "Expected one channel"); Assert.AreEqual(1, policyCatalogue.RoutingTables.Count, "Expected one routing table"); Assert.AreEqual(3, policyCatalogue.LocationsCollection.Count, "Expected two location groups"); Assert.AreEqual(4, policyCatalogue.Locations.Count, "Expected three locations"); }
public override IPolicyObject DeepCopy(bool readOnly, bool createNewId) { PolicyChannel readOnlyCopy = new PolicyChannel(this, readOnly, createNewId); return readOnlyCopy; }
public void TestCreatePolicySetChannelsMasterCataloguePrepopulateRouting() { string testCatalogue = m_testPath + "TestCreatePolicySetChannelsMasterCatalogue.xml"; string languageFilename = m_testPath + "TestCreatePolicySetChannelsMasterCatalogueLanguage.xml"; string policySetFilename = m_testPath + "TestCreatePolicySetChannelsMasterCataloguePolicySet.xml"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); Guid languageId = new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"); PolicyLanguageCache.Instance.ActiveLanguageId = languageId; IPolicyLanguage language = new PolicyLanguage(languageId, "en"); language.DefaultLanguage = true; languageStore.AddLanguage(language); PolicyLanguageCache policyLanguageCache = PolicyLanguageCache.Instance; policyLanguageCache.SetLanguageItemText(languageId, new Guid("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), "New catalogue"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), "New policy set"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), "New policy"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), "Test channel"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{03005F4E-04FC-4287-B2A6-25F877D9C31B}"), "Test sources"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}"), "Test destinations"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), "Test routing table"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), "Test condition group"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), "Test action group"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), "Test data element"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{6197CDBE-9F42-4A61-9369-238355BAB404}"), "Test data element display"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), "Test data item"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "Test action"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(new Guid("{29EC30A5-1271-4306-89C8-5811172D901A}"), new TranslateableLanguageItem("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), policyStore, policyCatalogue, false); IPolicy newPolicy = new P5Policy(policySet, new Guid("{D257D4DC-4A12-438F-A32A-CF1CE4474441}"), new TranslateableLanguageItem("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), PolicyStatus.Active); policySet.Policies.Add(newPolicy); // Create policy set channel PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), ChannelType.SMTP); // Create routing table RoutingTable routingTable = new RoutingTable(new Guid("{CDF0252C-3D5D-4AFB-98C2-89CF00FE2175}"), new TranslateableLanguageItem("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), ChannelType.SMTP); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "{03005F4E-04FC-4287-B2A6-25F877D9C31B}"); senders.Add(new RoutingItem(new Guid("{D41A47E2-CC13-46FF-BE83-829625792576}"), "James Brown", "*****@*****.**")); senders.Add(new RoutingItem(new Guid("{B031DFE9-54E7-482B-8955-18CFB8F06A40}"), "Nat King Cole", "*****@*****.**")); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}"); recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**")); routingTable.Sources.Add(senders); routingTable.Destinations.Add(recipients); // Assign routing table to channel channel.Routing = routingTable; // Create action matrix ActionMatrix actionMatrix = new ObjectModel.ActionMatrix(false); // Create an action matrix cell ActionMatrixCell actionMatrixCell = new ObjectModel.ActionMatrixCell(senders, recipients); // Populate the action matrix cell ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), ConditionLogic.AND, false); ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{32D97853-2680-4B02-A391-22CAEE87B017}"), new TranslateableLanguageItem("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), 1); IActionConditionGroup actionConditionGroup = new ObjectModel.ActionConditionGroup(conditionGroup, actionGroup, false); ObjectModel.Action action = new ObjectModel.Action(new Guid("{5153B00E-7D30-4D37-90F9-75E55AA1B32B}"), new TranslateableLanguageItem("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "TestAction.dll", "Test.Action", RunAt.Client, false, 1); //TODO JE DataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), DataType.String, "Not again, when will it ever end!"); DataElement dataElement = new DataElement(new Guid("{39500989-0B41-4C4E-85DF-CCB4FBD5BEB8}"), new TranslateableLanguageItem("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), new TranslateableLanguageItem("{6197CDBE-9F42-4A61-9369-238355BAB404}"), DataType.String, dataItem); action.DataElements.Add(dataElement); actionConditionGroup.ActionGroup.Actions.Add(action); // Assign the action condition group to the matrix cell actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); // Assign the action matrix cell to the action matrix actionMatrix[senders, recipients] = actionMatrixCell; // Assign action matrix to channel channel.Actions = actionMatrix; // Assign channel to policy newPolicy.Channels.Add(channel); // Save everything IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, language.Identifier); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); policySet.Save(); TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation); IRoutingMatrixCell routingMatrixCell = routingTable[senders, recipients]; string expectedCatalogueXml = System.IO.File.ReadAllText(testCatalogue); expectedCatalogueXml = expectedCatalogueXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper()); expectedCatalogueXml = expectedCatalogueXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper()); testCatalogue += ".tmp"; System.IO.File.WriteAllText(testCatalogue, expectedCatalogueXml); TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policySet.MasterCatalogue.Identifier)); string expectedLanguageXml = System.IO.File.ReadAllText(languageFilename); expectedLanguageXml = expectedLanguageXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper()); expectedLanguageXml = expectedLanguageXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper()); languageFilename += ".tmp"; System.IO.File.WriteAllText(languageFilename, expectedLanguageXml); TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value)); }
private void BuildPolicy(IPolicy policy) { IConditionGroup conditionGroup = new ConditionGroup(Guid.NewGuid(), new TranslateableLanguageItem(""), ConditionLogic.AND, false); policy.Conditions.Add(conditionGroup); ICondition condition = new Condition(Guid.NewGuid(), "TestClass", new TranslateableLanguageItem(""), OperatorType.Equals); conditionGroup.Conditions.Add(condition); condition.Parent = conditionGroup; DataMethod dataMethod = new DataMethod("ThisIsATest"); DataElement parameterDataElement = new DataElement(Guid.NewGuid(), new TranslateableLanguageItem(""), new NonTranslateableLanguageItem(""), DataType.String, "Lets go dynamo"); dataMethod.Parameters.Add(new Parameter("somethingTerrible", parameterDataElement)); IDataSource dataSource = new DataSource("ThisIsADodgyAssembly.dll", "ItWantsToTakeOverYourComputer", dataMethod); condition.DataLeft = new DataElement(Guid.NewGuid(), new TranslateableLanguageItem(""), new NonTranslateableLanguageItem(""), DataType.Object, dataSource); IDataItem dataRightDataItem = DataItem.CreateDataItem(new TranslateableLanguageItem(""), DataType.String, "This is a test"); condition.DataRight = new DataElement(Guid.NewGuid(), new TranslateableLanguageItem(""), new NonTranslateableLanguageItem(""), DataType.String, dataRightDataItem); //Now build a channel PolicyChannel channel = new PolicyChannel(Guid.NewGuid(), new TranslateableLanguageItem(""), ChannelType.SMTP); policy.Channels.Add(channel); RoutingTable routingTable = new RoutingTable(Guid.NewGuid(), new TranslateableLanguageItem(""), ChannelType.SMTP); channel.Routing = routingTable; IRoutingItemCollection senders = new RoutingItemCollection(Guid.NewGuid(), ""); senders.Add(new RoutingItem(Guid.NewGuid(), "James Brown", "*****@*****.**")); senders.Add(new RoutingItem(Guid.NewGuid(), "Nat King Cole", "*****@*****.**")); IRoutingItemCollection recipients = new RoutingItemCollection(Guid.NewGuid(), ""); recipients.Add(new RoutingItem(Guid.NewGuid(), "Jet Li", "*****@*****.**")); routingTable.Sources.Add(senders); routingTable.Destinations.Add(recipients); ActionMatrix actionMatrix = new ActionMatrix(false); channel.Actions = actionMatrix; ActionMatrixCell actionMatrixCell = new ActionMatrixCell(senders, recipients); actionMatrix[senders, recipients] = actionMatrixCell; ConditionGroup conditionGroup2 = new ConditionGroup(Guid.NewGuid(), new TranslateableLanguageItem(""), ConditionLogic.AND, false); ActionGroup actionGroup = new ActionGroup(Guid.NewGuid(), new TranslateableLanguageItem(""), 1); IActionConditionGroup actionConditionGroup = new ActionConditionGroup(conditionGroup2, actionGroup, false); actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); Action action = new Action(Guid.NewGuid(), new TranslateableLanguageItem(""), "TestAction.dll", "Test.Action", RunAt.Client, false, 1); //TODO JE DataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem(""), DataType.String, "Not again, when will it ever end!"); DataElement dataElement = new DataElement(Guid.NewGuid(), new TranslateableLanguageItem(""), new TranslateableLanguageItem(""), DataType.String, dataItem); action.DataElements.Add(dataElement); actionConditionGroup.ActionGroup.Actions.Add(action); //Setup the Action Exception ConditionGroup conditionGroup3 = new ConditionGroup(Guid.NewGuid(), new TranslateableLanguageItem(""), ConditionLogic.AND, false); ActionGroup actionGroup3 = new ActionGroup(Guid.NewGuid(), new TranslateableLanguageItem(""), 1); IActionConditionGroup actionConditionGroup3 = new ActionConditionGroup(conditionGroup3, actionGroup3, false); Action action3 = new Action(Guid.NewGuid(), new TranslateableLanguageItem(""), "TestAction.dll", "Test.Action", RunAt.Client, false, 1); actionConditionGroup3.ActionGroup.Actions.Add(action3); actionMatrix.ActionExceptionHandler.ActionConditionGroups.Add(actionConditionGroup3); //Setup the Offline Actions ConditionGroup conditionGroup4 = new ConditionGroup(Guid.NewGuid(), new TranslateableLanguageItem(""), ConditionLogic.AND, false); ActionGroup actionGroup4 = new ActionGroup(Guid.NewGuid(), new TranslateableLanguageItem(""), 1); IActionConditionGroup actionConditionGroup4 = new ActionConditionGroup(conditionGroup4, actionGroup4, false); Action action4 = new Action(Guid.NewGuid(), new TranslateableLanguageItem(""), "TestAction.dll", "Test.Action", RunAt.Client, false, 1); actionConditionGroup4.ActionGroup.Actions.Add(action4); actionMatrix.Offline.ActionConditionGroups.Add(actionConditionGroup4); }