예제 #1
0
        public override void Read()
        {
            IActionGroup actionGroup = m_parent as IActionGroup;
            IPolicyObjectCollection<IAction> actions = null;
            if (actionGroup != null)
                actions = actionGroup.Actions;
            else
                actions = m_parent as IPolicyObjectCollection<IAction>;

            if (actions == null)
                throw new Workshare.Policy.Exceptions.ArgumentNullException("actions", "Invalid parent node"); 
            
            XmlElement root = m_reader.PolicyDocument.DocumentElement;
            XmlNode actionNode = root.SelectSingleNode(m_xpath);
            IPolicyObjectCollection<IAction> availableActions = m_reader.CataloguesCache.Actions;

            string guid = actionNode.Attributes.GetNamedItem("id").InnerText;
            Guid identifier = new Guid(guid);
            if (actionNode.Name == "Action")
            {
                bool readOnly = PolicyUtilities.IsReadOnly(actionNode);
                IAction action = new Workshare.Policy.ObjectModel.Action(availableActions[identifier] as Workshare.Policy.ObjectModel.Action, readOnly, false);
                ReadDataElements(action);
                actions.Add(action);
            }
        }
예제 #2
0
        public void TestGetResourcesForAction()
        {
            //setup
            IResourceManager resourceManager = ResourceManagerFactory.CreateResourceManager();

            //nominal case
            IAction action = new Workshare.Policy.ObjectModel.Action(Guid.NewGuid(), "Workshare.Policy.Actions.CleanUserAction.dll", "Workshare.Policy.Actions.CleanUserAction", RunAt.Client, false, 1);
            action[LanguageItemKeys.TYPE] = new NonTranslateableLanguageItem("Clean");
            IResourceAction resourceAction = AddActionState.GetResourcesForAction(resourceManager, action);
            Assert.IsNotNull(resourceAction, "Resource action should be set in the nominal case");
            Assert.AreEqual(resourceAction.Name, action[LanguageItemKeys.TYPE].Value, "The type of the action should match the resource action name");
            Assert.AreEqual(resourceAction.ActionClass, action.Class, "The class of the action should match that of the resource action");

            //matching class, unmatching type
            action[LanguageItemKeys.TYPE] = new NonTranslateableLanguageItem("Some other clean action type which doesn't exist");
            resourceAction = AddActionState.GetResourcesForAction(resourceManager, action);
            Assert.IsNull(resourceAction, "Resource action should be null for unmatching type");

            //matching type, unmatching class
            action = new Workshare.Policy.ObjectModel.Action(Guid.NewGuid(), "Workshare.Policy.Actions.CleanUserAction.dll", "This class does not exist", RunAt.Client, false, 1);
            action[LanguageItemKeys.TYPE] = new NonTranslateableLanguageItem("Clean");
            resourceAction = AddActionState.GetResourcesForAction(resourceManager, action);
            Assert.IsNull(resourceAction, "Resource action should be null for unmatching class");

            //unmatching type and class
            action[LanguageItemKeys.TYPE] = new NonTranslateableLanguageItem("Some other clean action type which doesn't exist");
            resourceAction = AddActionState.GetResourcesForAction(resourceManager, action);
            Assert.IsNull(resourceAction, "Resource action should be null for unmatching type and class");

        }            
예제 #3
0
        private ActionGroup BuildActionGroup()
        {
            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);

            ObjectModel.IAction subAction = new ObjectModel.Action(new Guid("{72551FD1-D46D-4AF6-8DA3-76B5BCE01FD8}"), "CustomAction2.dll", "Test.Publish", RunAt.Server, true, 1); //TODO JE
            subAction.DataElements.Add(new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Do testing stuff"), new TranslateableLanguageItem("Do testing stuff"), DataType.Object, dataSource));

            IActionGroup subActionGroup = new ObjectModel.ActionGroup(new Guid("{BBEF6879-6D10-455D-A5D9-86D9B8B725A6}"), new TranslateableLanguageItem("Test sub action group"), 1);
            subActionGroup.Actions.Add(subAction);

            ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{987B7C8B-5ADD-4696-8456-DDE11D95CE0B}"), new TranslateableLanguageItem("Test action group"), 1);
            actionGroup.ActionGroups.Add(subActionGroup);

            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 TranslateableLanguageItem("Test data item stored in data element"), DataType.Long, dataItem));
            actionGroup.Actions.Add(action);

            return actionGroup;
        }
예제 #4
0
        /// <summary>
        /// Invokes a dialog to allow the user to construct a new action
        /// </summary>
        protected void AddNewAction()
        {
            if (!VerifyOKToAdd())
                return;

            //TODO: don't construct the form here, as this ties into a particular UI and makes it difficult to test
            try
            {
                m_addEditActionsForm = new AddEditActionsForm(ResourcesCache.GetResources());
            }
            catch(TypeInitializationException)
            {
                MessageBox.Show(Properties.Resources.REMOTECACHENOTRUNNING, Properties.Resources.REMOTECACHENOTRUNNING_CAP, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            m_addEditActionsForm.OpenForEdit = false;
            m_addEditActionsForm.Channel = m_channel;
            m_addEditActionsForm.Policy = m_policy;
            m_addEditActionsForm.AllowTransparent = RoutingHelper.SupportTransparentProcessing(m_channel.Routing);
            m_addEditActionsForm.IsExceptionCell = (m_Cell is ActionExceptionCell);

            // Set the actions that are already present for the cell
            m_addEditActionsForm.CurrentActions = m_Cell.ActionConditionGroups[0].ActionGroup.Actions;
            
            // Check if any items can be added
            if (!m_addEditActionsForm.CanExistingActionCoexist())
            {
                return;
            }

            if (!m_addEditActionsForm.AreAnyActionsAvailable())
            {
                return;
            }

            if (m_addEditActionsForm.PolicySupportsActions())
            {
                if (m_addEditActionsForm.ShowDialog() == DialogResult.OK)
                {
                    if (ShouldAddActionIfDuplicateForType(m_addEditActionsForm.BaseAction))
                    {
						Workshare.Policy.ObjectModel.Action anAction = new Workshare.Policy.ObjectModel.Action(Guid.NewGuid(), m_addEditActionsForm.AssemblyName, m_addEditActionsForm.ClassName, m_addEditActionsForm.RunAt, m_addEditActionsForm.Override, m_addEditActionsForm.BasePrecedence + m_addEditActionsForm.Precedence);
                        anAction.Name.Value = m_addEditActionsForm.MyName;
						
						anAction[LanguageItemKeys.TYPE] = new NonTranslateableLanguageItem(m_addEditActionsForm.BaseAction);
                        
                        IDataElement transparentDataElem = CreateBoolElement(LanguageItemKeys.TRANSPARENT, m_addEditActionsForm.Transparent);
                        anAction.DataElements.Add(transparentDataElem);

                        IDataElement executeDataElem = CreateBoolElement(LanguageItemKeys.ALWAYSEXECUTE, false);
                        SetExecutionDataElemProps(executeDataElem);
                        anAction.DataElements.Add(executeDataElem);

                        IDictionaryEnumerator propEnumerator = m_addEditActionsForm.ListItems.GetEnumerator();
                        while (propEnumerator.MoveNext())
                        {
                            string name = propEnumerator.Key as string;
                            ActionDataElement ade = (ActionDataElement)propEnumerator.Value;

                            if (0 == string.Compare(ade.Name, LanguageItemKeys.AUTOEXPAND, StringComparison.InvariantCultureIgnoreCase))
                                continue;

                            if (0 == string.Compare(ade.Name, LanguageItemKeys.ALWAYSEXECUTE, StringComparison.InvariantCultureIgnoreCase))
                                continue;

                            object dataElementData = null;
                            DataType dataType;
                            if (ade.IsSystemProperty)
                            {
                                //create a new DataElement that contains the system property as a data source
                                dataType = DataType.Object;
                                ISystemProperty systemProperty = ade.MappedSystemProperty as ISystemProperty;
                                IDataMethod dataMethod = new DataMethod(systemProperty.PropertyName);
                                dataElementData = new DataSource(systemProperty.Assembly, systemProperty.Class, dataMethod);
                            }
                            else
                            {
                                //if not a system property, must be a non-object data type
                                dataType = ConditionUnitFactory.GetDataType(ade.Value.GetType());
                                dataElementData = DataItem.CreateDataItem(new NonTranslateableLanguageItem(ade.Name), dataType, ade.Value);
                                if (dataType == DataType.StringArray)
                                {
                                    dataElementData = ConversionUtils.StringArrayToPolicyObjectModelStringArray((string[])ade.Value);
                                }
                            }
                            DataElement de = new DataElement(new NonTranslateableLanguageItem(ade.Name), new TranslateableLanguageItem(name), dataType, dataElementData);
                            de["iscustomproperty"].Value = ade.IsCustomProperty.ToString();
                            de["allowoverride"].Value = ade.Override.ToString();
                            de["visible"].Value = ade.Visible.ToString();

                            anAction.DataElements.Add(de);
                        }

                        // For the file types, as well as adding them as a collection in their
                        // own right, add them as a new data element consisting of a delimited string

                        propEnumerator = m_addEditActionsForm.FileItems.GetEnumerator();
                        while (propEnumerator.MoveNext())
                        {
                            ActionFiletype filetype = (ActionFiletype)propEnumerator.Value;
                            anAction.Filetypes.Add(filetype);
                        }

                        //// Set the supported types as custom attributes on the Actions
                        //propEnumerator = m_addEditActionsForm.SupportedChannels.GetEnumerator();
                        //while (propEnumerator.MoveNext())
                        //{
                        //    ChannelType channelType = ((Channel)propEnumerator.Value).Type;
                        //    anAction[channelType.ToString().ToLower(CultureInfo.InvariantCulture)] = new NonTranslateableLanguageItem("true");
                        //}

                        // Set the supported types as custom attributes on the Actions
                        propEnumerator = m_addEditActionsForm.SupportedPolicies.GetEnumerator();
                        while (propEnumerator.MoveNext())
                        {
                            PolicyType policyType = (PolicyType)propEnumerator.Value;
                            anAction[policyType.ToString().ToLower(CultureInfo.InvariantCulture)] = new NonTranslateableLanguageItem("true");
                        }

                        if (!AddAction(anAction))
                        {
							ArgumentException ex = new ArgumentException("Could not add this action as an action already exists with the same id");
                            Logger.LogError(ex.Message);
                            throw ex;
                        }

                        StateMachine.ChildForm.IsModified = true;
                    }
                }
            }
            else
            {
                string str = string.Format(CultureInfo.CurrentCulture, Properties.Resources.ACTION_NOTSUPPORT, m_channel.Name.Value);
                MessageBox.Show(str, Properties.Resources.ACTION_NOTSUPPORT_CAP, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        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 TestWriteActionAttributes()
        {
            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("{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";
            language[new Guid("{6B37988A-2D68-4249-BB26-CBDE39091E7A}")] = "This is test action";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.AddLanguage(language);

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();

            Guid catalogueGuid = new Guid("{8CF1172E-476C-46A5-AECF-A7A8BC5ACE30}");
            PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore);

            ObjectModel.Action action = new ObjectModel.Action(new Guid("{8E915159-5F01-41B3-9FFF-20731544ADFA}"), new TranslateableLanguageItem("{6B37988A-2D68-4249-BB26-CBDE39091E7A}"), "TestMe.dll", "Test.DoNothing", RunAt.Client, false, 1); //TODO JE
            DataElement dataElem = new DataElement(new Guid("{C2342D29-2B5A-490F-9B3F-5834EBA8047B}"), new TranslateableLanguageItem("Jill"), new TranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem("whatever"), DataType.String, "nag nag nag"));
            action.DataElements.Add(dataElem);

            action["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}");
            action["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}");

            IPolicyCatalogueWriter policyCatalogueWriter = catalogueStore.GetWriter(catalogueGuid, languageId);
            policyCatalogueWriter.WriteName("Test catalogue");
            policyCatalogueWriter.WriteAction(action);
            policyCatalogueWriter.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteActionAttributes.xml", catalogueStore.GetXMLRepresentation(catalogueGuid));
        }
        public void TestWriteCatalogueTwice()
        {
            Guid languageId = new Guid("{054846D4-6540-4C78-BA7D-141C91EE6A4C}");
            PolicyLanguage language = new PolicyLanguage(languageId, "en");
            language[new Guid("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}")] = "Test catalogue";
            language[new Guid("{A77E610D-9E96-47EE-ADB5-8ECF609BE16D}")] = "Test action";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.AddLanguage(language);

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();

            Guid catalogueId = new Guid("{B496E117-29DA-4770-87E9-62573B28BB4F}");
            IPolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueId, languageId, new TranslateableLanguageItem("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}"), catalogueStore);

            Guid actionId = new Guid("{26BCFA7E-3605-4EE7-ACC6-0AFB4D5EBB71}");
            ObjectModel.Action action = new ObjectModel.Action(actionId, new TranslateableLanguageItem("{A77E610D-9E96-47EE-ADB5-8ECF609BE16D}"), "CustomAction.dll", "Workshare.Clean", RunAt.Client, false, 1); //TODO JE
            DataElement dataElem = new DataElement(new Guid("{C2342D29-2B5A-490F-9B3F-5834EBA8047B}"), new TranslateableLanguageItem("Jill"), new NonTranslateableLanguageItem(""), DataType.String, "nag nag nag");
            action.DataElements.Add(dataElem);
            policyCatalogue.Actions.Add(action);

            IPolicyCatalogueWriter policyCatalogueWriter = catalogueStore.GetWriter(catalogueId, languageId);
            policyCatalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            policyCatalogueWriter.WriteCatalogue(policyCatalogue);
            policyCatalogueWriter.Close();

            policyCatalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            policyCatalogueWriter.WriteCatalogue(policyCatalogue);
            policyCatalogueWriter.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteCatalogue.xml", catalogueStore.GetStoreXML(catalogueId));
        }
        public void TestWriteActions()
        {
            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("{63A4F19E-332A-4006-BD0A-688BD184CB9F}")] = "Financial Users";
            language[new Guid("{852F1BEC-CCB6-4203-8701-89CAE87EA97B}")] = "Legal Users";
            language[new Guid("{A77E610D-9E96-47EE-ADB5-8ECF609BE16D}")] = "This is a test action 1";
            language[new Guid("{880EDEEA-F138-414C-B513-A157C7B19917}")] = "This is a test action 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 actionGuid = "{26BCFA7E-3605-4EE7-ACC6-0AFB4D5EBB71}";
            string elemGuid = "{49A44562-D6FA-4021-BEA0-3F5E9DCF8DE8}";
            ObjectModel.Action action = new ObjectModel.Action(new Guid(actionGuid), new TranslateableLanguageItem("{A77E610D-9E96-47EE-ADB5-8ECF609BE16D}"), "CustomAction.dll", "Workshare.Clean", RunAt.Client, false, 1); //TODO JE
            DataElement dataElem = new DataElement(new Guid(elemGuid), new TranslateableLanguageItem("Jack"), new NonTranslateableLanguageItem(""), DataType.String, "waffles and sausages");
            action.DataElements.Add(dataElem);
            catalogueWriter.WriteAction(action);

            actionGuid = "{72551FD1-D46D-4AF6-8DA3-76B5BCE01FD8}";
            elemGuid = "{C2342D29-2B5A-490F-9B3F-5834EBA8047B}";
            action = new ObjectModel.Action(new Guid(actionGuid), new TranslateableLanguageItem("{880EDEEA-F138-414C-B513-A157C7B19917}"), "CustomAction2.dll", "Workshare.Publish", RunAt.Server, true, 1); //TODO JE
            dataElem = new DataElement(new Guid(elemGuid), new TranslateableLanguageItem("Jill"), new NonTranslateableLanguageItem(""), DataType.String, "nag nag nag");
            action.DataElements.Add(dataElem);
            catalogueWriter.WriteAction(action);

            catalogueWriter.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteActions.xml", catalogueStore.GetStoreXML(catalogueId));
        }
예제 #9
0
        public void TestIsInMyMasterCatalogue()
        {

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.Reset();
            IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en");
            languageStore.AddLanguage(language);
            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(Guid.NewGuid(), new TranslateableLanguageItem("TestPolicySet"), policyStore, policyCatalogue, false); 
            IPolicy policy = PolicyFactory.CreatePolicy("TestPolicy", policySet, PolicyStatus.Active, "None");

            //Item not in any catalogues doesn't appear in master catalogue
            Workshare.Policy.ObjectModel.IAction action = new Workshare.Policy.ObjectModel.Action(new Guid("{2814A571-5979-4065-A588-5E31A391ECF9}"), "AnAssembly", "AClassName", RunAt.Both, false, 1); //TODO JE

            Assert.AreEqual(false, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Unexpectedly found IPolicyObject in catalogue");

            IRoutingTable smtpRouting = policy.Channels[0].Routing;
            Assert.IsNotNull(smtpRouting, "Expected the routing table type to be SMTP");

            //Same item does appear after adding to my master catalogue... 
            RoutingHelper.AddCellToActionMatrix(policy.Channels[0].Actions, smtpRouting.Sources[0], smtpRouting.Sources[0]);
            IActionMatrixCell cell = policy.Channels[0].Actions[smtpRouting.Sources[0], smtpRouting.Sources[0]];
            cell.ActionConditionGroups[0].ActionGroup.Actions.Add(action);

            Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Didn't find IPolicyObject in catalogue");

            //...and try again using the other override
            Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(policySet, action), "Didn't find IPolicyObject in catalogue");

            //Different item in another catalogue doesn't appear in my master catalogue...
            PolicyCatalogue otherPolicyCatalogue = new PolicyCatalogue(new Guid("{6F294319-CE31-4919-9BC7-4AC6EDD8656D}"), language.Identifier, new TranslateableLanguageItem("otherCatalogue"), catalogueStore);
            catalogueStore.AddPolicyCatalogue(otherPolicyCatalogue);

            IPolicySet otherPolicySet = new PolicySet(Guid.NewGuid(), new TranslateableLanguageItem("TestPolicySet"), policyStore, otherPolicyCatalogue, false);
            IPolicy otherPolicy = PolicyFactory.CreatePolicy("OtherTestPolicy", otherPolicySet, PolicyStatus.Active, "None");

            action = new Workshare.Policy.ObjectModel.Action(new Guid("{27F68034-A414-4043-BD6A-BD3A912CF7ED}"), "AnAssembly", "AClassName", RunAt.Both, false, 1); //TODO JE

            IRoutingTable otherSmtpRouting = otherPolicy.Channels[0].Routing;
            Assert.IsNotNull(smtpRouting, "Expected the other routing table type to be SMTP");

            RoutingHelper.AddCellToActionMatrix(otherPolicy.Channels[0].Actions, otherSmtpRouting.Sources[0], otherSmtpRouting.Sources[0]);
            cell = otherPolicy.Channels[0].Actions[otherSmtpRouting.Sources[0], otherSmtpRouting.Sources[0]];
            cell.ActionConditionGroups[0].ActionGroup.Actions.Add(action);

            Assert.AreEqual(false, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Unexpectedly found IPolicyObject in catalogue");

            //...but does appear in the other policy's master catalogue
            Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(otherPolicy, action), "Didn't find IPolicyObject in catalogue");

            //Item in another catalogue, with same GUID as an item in my catalogue, doesn't appear in my master catalogue...
            action = new Workshare.Policy.ObjectModel.Action(new Guid("{2814A571-5979-4065-A588-5E31A391ECF9}"), "AnAssembly", "AClassName", RunAt.Both, false, 1); //TODO JE
            cell = otherPolicy.Channels[0].Actions[otherSmtpRouting.Sources[0], otherSmtpRouting.Sources[0]];
            cell.ActionConditionGroups[0].ActionGroup.Actions.Add(action);

            Assert.AreEqual(false, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Unexpectedly found IPolicyObject in catalogue");

            //...but does appear in the other policy's master catalogue
            Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(otherPolicy, action), "Didn't find IPolicyObject in catalogue");

            //Test a new type of IPolicyObject isn't handled
            try
            {
                MockIPolicyObject mockObject = new MockIPolicyObject();
                bool value = PolicyFactory.IsInMyMasterCatalogue(policy, mockObject);
                Assert.IsTrue(false, "Unexpectedly handled an unknown IPolicyObject type");
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);                
            }
            catch (Exceptions.PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }

        }