public DataElement Read()
        {
            if(m_dataElementNode == null)
                throw new Workshare.Policy.Exceptions.ArgumentNullException("m_dataElementNode", "Data element node is null");

            XmlAttributeCollection attributes = m_dataElementNode.Attributes;
            if(attributes == null)
                throw new Workshare.Policy.Exceptions.ArgumentNullException("attributes", "Data element node does not have any attributes");

            List<string> exclusions = new List<string>();
            exclusions.Add("id");
            exclusions.Add("name");
            exclusions.Add("type");
            exclusions.Add("readonly");
            exclusions.Add("displayname");

            string guid = attributes.GetNamedItem(exclusions[0]).InnerText;
            string name = attributes.GetNamedItem(exclusions[1]).InnerText;
            string type = attributes.GetNamedItem(exclusions[2]).InnerText;
            string displayname = attributes.GetNamedItem(exclusions[4]).InnerText;

            XmlNode readOnlyNode = attributes.GetNamedItem(exclusions[3]);
            bool readOnly = readOnlyNode != null && readOnlyNode.InnerText != null && readOnlyNode.InnerText.ToLower(CultureInfo.InvariantCulture) == "true";

            DataType dataType = Workshare.Policy.ObjectModel.TypeConverters.GetDataType(type);
            object data = ReadDataElementData(dataType);
            DataElement dataElement = new DataElement(new Guid(guid), LanguageItemFactory.Create(name), LanguageItemFactory.Create(displayname), dataType, data, readOnly);
            new XmlCustomAttributesReader(dataElement, attributes, exclusions).Read();

            return dataElement;
        }
        public void TestGetDisplayName()
        {

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

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

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

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

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

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

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

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

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

            //no data
            fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = fileTypeParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
示例#4
0
 private void SetDefaults(string className, OperatorType operatorType, DataElement m_dataLeft, bool createNewId)
 {
     m_className = className;
     m_operatorType = operatorType;
     if (null != m_dataLeft)
     {
         m_dataLeft = new DataElement(m_dataLeft, m_dataLeft.ReadOnly, createNewId);
     }
 }
		public void TestGetDisplayName()
		{
			//nominal case - display name already set
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "4096"));
			ConditionDisplayParameterTotalAttachmentSize attachmentsSizeParam = new ConditionDisplayParameterTotalAttachmentSize(dataElement, Callback, Policy.PolicyType.ClientEmail);
			Assert.AreEqual("4096", attachmentsSizeParam.GetDisplayName(), "unexpected displayname - display name should be same as dataElement");

			//data items in data item
			dataElement.DisplayName.Value = "";
			Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
			Assert.AreEqual("4096", attachmentsSizeParam.GetDisplayName(), "unexpected displayname");
			Assert.AreEqual("4096", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

			//no data
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, ""));
			Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
			attachmentsSizeParam = new ConditionDisplayParameterTotalAttachmentSize(dataElement, Callback, Policy.PolicyType.ClientEmail);
			Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_TOTALATTACHMENTSIZE_DEFAULT, attachmentsSizeParam.GetDisplayName(), "unexpected displayname");
			Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_TOTALATTACHMENTSIZE_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value");

			//invalid format for data
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, new PolicyObjectCollection<IDataItem>());
			attachmentsSizeParam = new ConditionDisplayParameterTotalAttachmentSize(null, Callback, Policy.PolicyType.ClientEmail)
								{
									Object = dataElement
								};
			try
			{
				attachmentsSizeParam.GetDisplayName();
				Assert.IsTrue(false, "didn't throw on invalid data format");
			}
			catch (PolicyDesignerException)
			{
				Assert.IsTrue(true);
			}
			catch
			{
				Assert.IsTrue(false, "Unexpected exception");
			}

			//no data
			attachmentsSizeParam = new ConditionDisplayParameterTotalAttachmentSize(null, Callback, Policy.PolicyType.ClientEmail);
			try
			{
				attachmentsSizeParam.GetDisplayName();
				Assert.IsTrue(false, "didn't throw on empty data");
			}
			catch (PolicyDesignerException)
			{
				Assert.IsTrue(true);
			}
			catch
			{
				Assert.IsTrue(false, "Unexpected exception");
			}
		}
示例#6
0
        private void AddSimpleParameter(XmlNode parameterNode, string name)
        {
            XmlNode firstChildNode = parameterNode.FirstChild;
            if ((firstChildNode == null) || (firstChildNode.Name != "#text"))
                return;

            string value = parameterNode.InnerText;
            IDataElement dataElement = new DataElement(Guid.NewGuid(), null, null, DataType.String, value);
            m_parameters.Add(new Parameter(name, dataElement));
        }
        public void TestGetDisplayName()
        {
            //nominal case - display name already set
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "anotherFileName.xls"));
            ConditionDisplayParameterFileName fileNameParam = new ConditionDisplayParameterFileName(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("anotherFileName.xls", fileNameParam.GetDisplayName(), "unexpected displayname - display name should be the same as dataElement");

            //data items in data item
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("anotherFileName.xls", fileNameParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("anotherFileName.xls", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //no data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, ""));
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            fileNameParam = new ConditionDisplayParameterFileName(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_FILENAME_DEFAULT, fileNameParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_FILENAME_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, new PolicyObjectCollection<IDataItem>());
            fileNameParam = new ConditionDisplayParameterFileName(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            fileNameParam.Object = dataElement;
            try
            {
                string displayName = fileNameParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            fileNameParam = new ConditionDisplayParameterFileName(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = fileNameParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterFileType fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, fileTypeParam.Object), "unexpected Object");
            Assert.IsTrue(Properties.Resources.IDS_EXPRESSION_PARAM_FILETYPE_DEFAULT == fileTypeParam.Text, "unexpected Text");
                        
            //nominal case with no display name
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

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

            m_callbackCalled = false;
            fileTypeParam.Execute();

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

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

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

            m_callbackCalled = false;
            fileTypeParam.Execute();

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

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
                fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
示例#9
0
        /// <summary>
        /// This method creates an invisible, nonoveridable, non-custom DataElement, of type bool.
        /// </summary>
        /// <param name="name">The name of the data element</param>
        /// <param name="value">The boolean value</param>
        /// <returns>IDataElement corresponding to the input parameters</returns>
        public static IDataElement CreateBoolElement(string name, bool value)
        {
            NonTranslateableLanguageItem dataElementName = new NonTranslateableLanguageItem(name);

            DataElement elem = new DataElement(dataElementName, dataElementName, DataType.Boolean, false);

            elem["iscustomproperty"].Value = false.ToString(CultureInfo.InvariantCulture);
            elem["allowoverride"].Value = false.ToString(CultureInfo.InvariantCulture);
            elem["visible"].Value = false.ToString(CultureInfo.InvariantCulture);

            elem.Data = DataItem.CreateDataItem(new NonTranslateableLanguageItem(String.Empty), DataType.Boolean, value);

            return elem;
        }
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterContext contextParam = new ConditionDisplayParameterContext(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, contextParam.Object), "unexpected Object");
            Assert.IsTrue(Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_DEFAULT == contextParam.Text, "unexpected Text");

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

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

            m_callbackCalled = false;
            contextParam.Execute();

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

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

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

            m_callbackCalled = false;
            contextParam.Execute();

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

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Footnote)));
                contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
        public void TestConstructor2()
        {
            //empty dataElement
            ConditionDisplayParameterContent contentParam = new ConditionDisplayParameterContent(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, contentParam.Object), "unexpected Object");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_CONTENTPARAM_DEFAULT, contentParam.Text, "unexpected Text");

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

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

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

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

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, "My content");
                contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
示例#12
0
        public DataElement(DataElement rhs, object data)
            : base(rhs)
        {
            if (null == rhs)
            {
                Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage(
                    "INPUT_DATAELEMENT_NULL",
                    "Workshare.Policy.Properties.Resources",
                    Assembly.GetExecutingAssembly());
				Logger.LogError(errorMessage.LogString);
                throw new Workshare.Policy.Exceptions.ArgumentNullException("rhs", errorMessage.DisplayString);
            }

            DataType dataType = rhs.Type;
            SetDefaults(dataType, DataItem.CreateDataItem(rhs.Name, dataType, data), rhs.DisplayName, false);
        }
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterCustomPropertyValue customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, customPropertyValueParam.Object), "unexpected Object");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CUSTOMPROPERTYVALUE_DEFAULT, customPropertyValueParam.Text, "unexpected Text");
            Assert.AreEqual(Enum.GetName(typeof(CustomPropertyType), CustomPropertyType.Text), customPropertyValueParam.Type.ToString(), "unexpected custom property type");

            //nominal case with no display name
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "My Doc Type"));
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, customPropertyValueParam.Object), "unexpected Object");
            Assert.AreEqual("My Doc Type", customPropertyValueParam.Text, "unexpected Text");
            Assert.AreEqual(Enum.GetName(typeof(CustomPropertyType), CustomPropertyType.Text), customPropertyValueParam.Type.ToString(), "unexpected custom property type");

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

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, customPropertyValueParam.Object), "unexpected Object");
            Assert.AreEqual("My Doc Type", customPropertyValueParam.Text, "unexpected Text - display name should be the same as dataElement");
            Assert.AreEqual(Enum.GetName(typeof(CustomPropertyType), CustomPropertyType.Text), customPropertyValueParam.Type.ToString(), "unexpected custom property type");

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

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, new PolicyObjectCollection<IDataItem>());
                customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
		public void TestConstructor()
		{
			//empty dataElement
			ConditionDisplayParameterTotalAttachmentSize attachmentsSizeParam = new ConditionDisplayParameterTotalAttachmentSize(null, Callback, Policy.PolicyType.ClientEmail);
			Assert.IsTrue(ReferenceEquals(null, attachmentsSizeParam.Object), "unexpected Object");
			Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_TOTALATTACHMENTSIZE_DEFAULT, attachmentsSizeParam.Text, "unexpected Text");

			//nominal case with no display name
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "1024"));
			attachmentsSizeParam = new ConditionDisplayParameterTotalAttachmentSize(dataElement, Callback, Policy.PolicyType.ClientEmail);
			Assert.IsTrue(ReferenceEquals(dataElement, attachmentsSizeParam.Object), "unexpected Object");
			Assert.AreEqual("1024", attachmentsSizeParam.Text, "unexpected Text");

			_callbackCalled = false;
			attachmentsSizeParam.Execute();
			Assert.IsTrue(_callbackCalled, "Execute not called");

			//nominal case with display name
			dataElement.DisplayName.Value = "This is a display name";
			attachmentsSizeParam = new ConditionDisplayParameterTotalAttachmentSize(dataElement, Callback, Policy.PolicyType.ClientEmail);
			Assert.IsTrue(ReferenceEquals(dataElement, attachmentsSizeParam.Object), "unexpected Object");
			Assert.AreEqual("1024", attachmentsSizeParam.Text, "unexpected Text - display name should be same as dataElement");

			_callbackCalled = false;
			attachmentsSizeParam.Execute();
			Assert.IsTrue(_callbackCalled, "Execute not called");

			//invalid format case
			try
			{
				dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, new PolicyObjectCollection<IDataItem>());
				new ConditionDisplayParameterTotalAttachmentSize(dataElement, Callback, Policy.PolicyType.ClientEmail);
				Assert.IsTrue(false, "Didnt throw on invalid dataelement");
			}
			catch (PolicyDesignerException)
			{
				Assert.IsTrue(true);
			}
			catch
			{
				Assert.IsTrue(false, "unexpected exception thrown");
			}
		}
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterRegex regexParam = new ConditionDisplayParameterRegex(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, regexParam.Object), "unexpected Object");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_REGEX_DEFAULT, regexParam.Text, "unexpected Text");

            //nominal case with no display name
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "my regex"));
            regexParam = new ConditionDisplayParameterRegex(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, regexParam.Object), "unexpected Object");
            Assert.AreEqual("my regex", regexParam.Text, "unexpected Text");

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

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            regexParam = new ConditionDisplayParameterRegex(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, regexParam.Object), "unexpected Object");
            Assert.AreEqual("my regex", regexParam.Text, "unexpected Text - displayname must be the same as dataElement");

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

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, new PolicyObjectCollection<IDataItem>());
                regexParam = new ConditionDisplayParameterRegex(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
        public void TestGetDisplayName()
        {

            //nominal case
            ICondition condition = new Condition(Guid.NewGuid(), "MyClass", OperatorType.GreaterThan);
            ConditionDisplayParameterOperator operatorParam = new ConditionDisplayParameterOperator(condition, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("greater than", operatorParam.GetDisplayName(), "unexpected displayname");

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

            //no data
            operatorParam = new ConditionDisplayParameterOperator(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = operatorParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
示例#17
0
        public DataElement(DataElement rhs, bool readOnly, bool createNewId)
            : base(rhs, readOnly, createNewId)
        {
            if (rhs == null)
            {
                Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage(
                    "INPUT_DATAELEMENT_NULL",
                    "Workshare.Policy.Properties.Resources",
                    Assembly.GetExecutingAssembly());
				Logger.LogError(errorMessage.LogString);
				throw new Workshare.Policy.Exceptions.ArgumentNullException("rhs", errorMessage.DisplayString);
            }

            object data = CopyDataItem(rhs, createNewId);
            if (data == null)
            {
                data = CopyDataSource(rhs, createNewId);
            }

            SetDefaults(rhs.Type, data, rhs.DisplayName, createNewId);
        }
示例#18
0
        public void TestCreatePolicySetConditionsMasterCatalogue()
        {
            string testCatalogue = m_testPath + "TestCreatePolicySetConditionsMasterCatalogue.xml";
            string languageFilename = m_testPath + "TestCreatePolicySetConditionsMasterCatalogueLanguage.xml";
            string policySetFilename = m_testPath + "TestCreatePolicySetConditionsMasterCataloguePolicySet.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.Reset();

            Guid languageId = new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}");
            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");

            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 a condition group for the policy.
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{8EB7FF08-1DC8-4F11-9D55-AF47F83F843A}"), "Test condition group");
            IConditionGroup conditionGroup = new ConditionGroup(new Guid("{B87DF614-2400-4C1F-BEA8-3C2EB3964EAE}"), new TranslateableLanguageItem("{8EB7FF08-1DC8-4F11-9D55-AF47F83F843A}"), ConditionLogic.AND, false);
            newPolicy.Conditions.Add(conditionGroup);

            // Create a condition for the condition group.
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{EC8E1E63-7097-4330-8130-5776D4FDF1ED}"), "Test condition");
            ICondition condition = new Condition(new Guid("{98C73BC3-3E20-403C-8023-C91E2818355F}"), "TestClass", new TranslateableLanguageItem("{EC8E1E63-7097-4330-8130-5776D4FDF1ED}"), OperatorType.Equals);
            conditionGroup.Conditions.Add(condition);

            // Create the data left for the condition data.
            DataMethod dataMethod = new DataMethod("ThisIsATest");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{BA56AB4C-43D0-465A-BE67-D8A569A1894C}"), "Test data item to the left");

            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{AB454A4B-1A0F-4864-9F46-3AAC8A34ACA5}"), "Test parameter data element");
            DataElement parameterDataElement = new DataElement(new Guid("{015035B7-1793-464D-AF69-030E9DC7151E}"), new TranslateableLanguageItem("{AB454A4B-1A0F-4864-9F46-3AAC8A34ACA5}"), new NonTranslateableLanguageItem(""), DataType.String, "Lets go dynamo");
            dataMethod.Parameters.Add(new Parameter("somethingTerrible", parameterDataElement));
            IDataSource dataSource = new DataSource("ThisIsADodgyAssembly.dll", "ItWantsToTakeOverYourComputer", dataMethod);

            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{79784B11-5FCC-47A8-A35E-C8399BE71C05}"), "Test data left");
            condition.DataLeft = new DataElement(new Guid("{454672AC-BCED-4DAB-813F-6CF14E6289C5}"), new TranslateableLanguageItem("{79784B11-5FCC-47A8-A35E-C8399BE71C05}"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);

            // Create the data right for the condition data.
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{BD40DDEE-B045-4D3B-8092-D596329230FE}"), "Test data item to the right");
            IDataItem dataRightDataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("{BD40DDEE-B045-4D3B-8092-D596329230FE}"), DataType.String, "This is a test");

            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{8549333F-0A4D-4939-8A36-36FB0FF1C89A}"), "Test data right");
            condition.DataRight = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("{8549333F-0A4D-4939-8A36-36FB0FF1C89A}"), new NonTranslateableLanguageItem(""), DataType.String, dataRightDataItem);

            // Save everything
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, language.Identifier);
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            policySet.Save();

            TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation);
            TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policySet.MasterCatalogue.Identifier));
            TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value));
        }
示例#19
0
        public void TestAddDataElement()
        {
            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.DataElements.Count);

            // Create data elements
            DataMethod dataMethod = new DataMethod("ThisIsATest");
            DataItem parameterDataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item to the left"), DataType.String, "Lets go dynamo");

            DataElement parameterDataElement = new DataElement(new Guid("{015035B7-1793-464D-AF69-030E9DC7151E}"), new TranslateableLanguageItem("Test parameter data element"), new TranslateableLanguageItem(""), DataType.String, parameterDataItem);
            dataMethod.Parameters.Add(new Parameter("somethingTerrible", parameterDataElement));
            IDataSource dataSource = new DataSource("ThisIsADodgyAssembly.dll", "ItWantsToTakeOverYourComputer", dataMethod);

            DataElement leftDataElement = new DataElement(new Guid("{454672AC-BCED-4DAB-813F-6CF14E6289C5}"), new TranslateableLanguageItem("Test data left"), new TranslateableLanguageItem(""), DataType.Object, dataSource);
            policySetObserver.AddObject(leftDataElement);

            IDataItem dataRightDataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item to the right"), DataType.String, "This is a test");
            DataElement rightDataElement = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Test data right"), new TranslateableLanguageItem(""), DataType.String, dataRightDataItem);

            policySetObserver.AddObject(rightDataElement);

            Assert.AreEqual(2, policyCatalogue.DataElements.Count);
        }
示例#20
0
        public void TestAddDataElementPreAddToCondition()
        {
            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.Conditions.Count);
            Assert.AreEqual(0, policyCatalogue.DataElements.Count);

            DataElement dataElementLeft = new DataElement(new Guid("{AC48B709-8DED-467D-8778-BB0A1520FDDC}"), new TranslateableLanguageItem("Data left test"), new TranslateableLanguageItem("This is the data to the left"), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem("Test"), DataType.String, "This is some data"));
            DataElement dataElementRight = new DataElement(new Guid("{697DAD36-021C-451A-A67C-08D892CFC23A}"), new TranslateableLanguageItem("Data right test"), new TranslateableLanguageItem("This is the data to the right"), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem("Test"), DataType.String, "This is some data"));
            Condition condition = new Condition(new Guid("{79F9C52C-8F04-473B-8487-8CB241DBED31}"), "Myclass", new TranslateableLanguageItem("Test condition"), OperatorType.Equals);
            condition.DataLeft = dataElementLeft;
            condition.DataRight = dataElementRight;

            policySetObserver.AddObject(condition);

            Assert.AreEqual(1, policyCatalogue.Conditions.Count, "Expected one condition");
            Assert.AreEqual(2, policyCatalogue.DataElements.Count, "Expected two data elements");
        }
        public void TestReadDataElementCopyConstructors()
        {
            IDataElement dataElement = ReadDataElementAttributesHelper();
            Assert.AreEqual("This is my first custom property", dataElement["custom1"].Value);
            Assert.AreEqual("This is my second custom property", dataElement["custom2"].Value);

            DataElement dataElementCopy = new DataElement(dataElement as DataElement);
            Assert.AreEqual("This is my first custom property", dataElementCopy["custom1"].Value);
            Assert.AreEqual("This is my second custom property", dataElementCopy["custom2"].Value);

            DataElement dataElementCopy2 = new DataElement(dataElement as DataElement, "This is some data");
            Assert.AreEqual("This is my first custom property", dataElementCopy2["custom1"].Value);
            Assert.AreEqual("This is my second custom property", dataElementCopy2["custom2"].Value);

            object data = DataItem.CreateDataItem(new TranslateableLanguageItem("item1"), DataType.String, "Some test data, yeah");
            DataElement dataElementCopy3 = new DataElement(new TranslateableLanguageItem("DataElement1"), new TranslateableLanguageItem(""), DataType.String, data);
            Assert.AreEqual("", dataElementCopy3["custom1"].Value);
            Assert.AreEqual("", dataElementCopy3["custom2"].Value);

            DataElement dataElementCopy4 = new DataElement(Guid.Empty, new TranslateableLanguageItem("DataElement1"), new TranslateableLanguageItem(""), DataType.String, data);
            Assert.AreEqual("", dataElementCopy4["custom1"].Value);
            Assert.AreEqual("", dataElementCopy4["custom2"].Value);

            DataElement dataElementCopy5 = new DataElement(Guid.Empty, new TranslateableLanguageItem("DataElement1"), new TranslateableLanguageItem(""), DataType.String, data, false);
            Assert.AreEqual("", dataElementCopy5["custom1"].Value);
            Assert.AreEqual("", dataElementCopy5["custom2"].Value);
        }
        public void TestGetDisplayName()
        {
            //nominal case - display name already set in non-date custom type
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "This is my doc type"));
            ConditionDisplayParameterCustomPropertyValue customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("This is my doc type", customPropertyValueParam.GetDisplayName(), "unexpected Text - display name should be the same as dataElement");

            ////display name already set in date custom type. In this case we shouldn't use the display name, in case the 
            ////locale of the machine has changed
            //dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "2006-05-22 00:00:00Z"));
            //customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Date, dataElement, this.Callback);
            ////this will fail if the locale of the test machine changes, but is correct for UK.
            //Assert.AreEqual("22/05/2006", customPropertyValueParam.GetDisplayName(), "unexpected displayname");
            
            //data items in text custom property type - display value of item
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "This is some text"));
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("This is some text", customPropertyValueParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("This is some text", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            ////data items in date custom type - in this case, should get short date representation of a UTC time
            //dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "2006-05-22 00:00:00Z"));
            //customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Date, dataElement, this.Callback);
            //dataElement.DisplayName.Value = "";
            //Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            ////this will fail if the locale of the test machine changes, but is correct for UK.
            //Assert.AreEqual("22/05/2006", customPropertyValueParam.GetDisplayName(), "unexpected displayname");
            //Assert.AreEqual("22/05/2006", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //data items in number custom property type - display value of item
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "12345678"));
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Number, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("12345678", customPropertyValueParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("12345678", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //data items in YesNo custom type - in this case, should get Yes or No for True or False values
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Boolean.TrueString));
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.YesNo, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("Yes", customPropertyValueParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("Yes", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Boolean.FalseString));
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.YesNo, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("No", customPropertyValueParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("No", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");
            
            //no data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, ""));
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CUSTOMPROPERTYVALUE_DEFAULT, customPropertyValueParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CUSTOMPROPERTYVALUE_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, new PolicyObjectCollection<IDataItem>());
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            customPropertyValueParam.Object = dataElement;
            try
            {
                string displayName = customPropertyValueParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = customPropertyValueParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
示例#23
0
        private object CopyDataSource(DataElement dataElement, bool createNewId)
        {
            if (dataElement.Data is DataItem)
                return null;

            if (dataElement.Data is DataSource)
            {
                DataSource dataSource = dataElement.Data as DataSource;
                return dataSource.DeepCopy(dataSource.ReadOnly, createNewId);
            }
            else if (dataElement.Data is PolicyObjectCollection<IDataSource>)
            {
                if (createNewId)
                    return CollectionConverter.ConvertReadOnly<IDataSource, DataSource>(dataElement.Data as PolicyObjectCollection<IDataSource>, this.ReadOnly, createNewId);

                return dataElement.Data;
            }
            return null;
        }
        public void TestGetDisplayNameFromDataItems()
        {
            //nominal case
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "a doc type"));
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            ConditionDisplayParameterCustomPropertyValue customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("a doc type", customPropertyValueParam.GetDisplayNameFromDataItems(), "unexpected displayname");
            Assert.AreEqual("a doc type", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //no data in data item
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, ""));
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CUSTOMPROPERTYVALUE_DEFAULT, customPropertyValueParam.GetDisplayNameFromDataItems(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CUSTOMPROPERTYVALUE_DEFAULT, dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, new PolicyObjectCollection<IDataItem>());
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            customPropertyValueParam.Object = dataElement;
            try
            {
                string displayName = customPropertyValueParam.GetDisplayNameFromDataItems();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            customPropertyValueParam = new ConditionDisplayParameterCustomPropertyValue(CustomPropertyType.Text, null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = customPropertyValueParam.GetDisplayNameFromDataItems();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
示例#25
0
        private object CopyDataItem(DataElement dataElement, bool createNewId)
        {
            if (dataElement.Data is DataSource)
                return null;

            if (dataElement.Data is DataItem)
            {
                return ((DataItem)dataElement.Data).DeepCopy(dataElement.ReadOnly, createNewId);
            }
            else if (dataElement.Data is PolicyObjectCollection<IDataItem>)
            {
                if (createNewId)
                    return CollectionConverter.ConvertReadOnly<IDataItem, DataItem>(dataElement.Data as PolicyObjectCollection<IDataItem>, this.ReadOnly, createNewId);

                return dataElement.Data;
            }
            else if (dataElement.Data != null)
            {
                return dataElement.Data;
            }
            return null;
        }
示例#26
0
        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));
        }
        public void TestGetDisplayNameFromDataItems()
        {
            //nominal case
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "the race is on"));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "we've got the fire! grrr!"));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            ConditionDisplayParameterContent contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("the race is on, we've got the fire! grrr!", contentParam.GetDisplayNameFromDataItems(), "unexpected displayname");
            Assert.AreEqual("the race is on, we've got the fire! grrr!", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

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

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

            //no data
            contentParam = new ConditionDisplayParameterContent(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = contentParam.GetDisplayNameFromDataItems();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
示例#28
0
		private static ICondition CreateEmbeddedEmailCondition()
		{
			//condition
			ICondition condition = new Condition(Guid.NewGuid(), "IDataComparer", new TranslateableLanguageItem(""), OperatorType.Equals);

			//condition attributes
			CustomAttributes.SetPreDefinedConditionType(condition, PreDefinedConditionType.EmbeddedEmail);
			CustomAttributes.SetIgnore(condition, false);
			CustomAttributes.SetLongDescription(condition, "");
			CustomAttributes.SetRiskRating(condition, RiskRatingType.Medium);
			CustomAttributes.SetConditionSummary(condition, "");

			//dataleft
			IDataMethod method = new DataMethod("IsEmail");

			//file parameter
			IDataMethod fileMethod = new DataMethod("CurrentFile");
			IDataSource dataSource = new DataSource("this", "this", fileMethod);
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("file"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			IParameter parameter = new Parameter("file", dataElement);
			method.Parameters.Add(parameter);

			//  Data source for method
			dataSource = new DataSource("Workshare.Policy.Condition.ContentAnalysis.dll", "Workshare.Policy.Condition.EmailAnalyzer", method);
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("propertyMatchInFileType"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			condition.DataLeft = dataElement;

			//dataright
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("numberOfOccurrences"), new NonTranslateableLanguageItem(""), DataType.Boolean, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Boolean, true));
			condition.DataRight = dataElement;

			return condition;
		}
示例#29
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 TestGetDisplayNameFromDataItems()
		{
			//nominal case
			IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
			dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.Properties)));
			dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.Attachments)));
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
			Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
			ConditionDisplayParameterHiddenDataInPDF hiddenDataParam = new ConditionDisplayParameterHiddenDataInPDF(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
			Assert.AreEqual("Properties, Attachments", hiddenDataParam.GetDisplayNameFromDataItems(), "unexpected displayname");
			Assert.AreEqual("Properties, Attachments", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

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

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

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