public ConditionDisplayParameterString(string name, IDataElement dataElement, RuleObject.OnExecuteHandler executeEventHandler, Workshare.Policy.PolicyType type)
     : base(name, null, type)
 {
     AddExecuteEventHandler(executeEventHandler);
     if (dataElement != null)
     {
         Object = dataElement;
         Text = GetDisplayName();
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataElement"></param>
        /// <returns></returns>
        public ConditionDisplayParameterFileName(IDataElement dataElement, RuleObject.OnExecuteHandler executeEventHandler, Workshare.Policy.PolicyType type)
            : base(Properties.Resources.IDS_EXPRESSION_PARAM_FILENAME_DEFAULT, null, type)
        {
            AddExecuteEventHandler(executeEventHandler);

            if (dataElement != null)
            {
                Object = dataElement;
                Text = GetDisplayName();
            }
        }
        public ConditionDisplayParameterOperator(ICondition condition, RuleObject.OnExecuteHandler executeEventHandler, Workshare.Policy.PolicyType type)
            : base(Properties.Resources.IDS_EXPRESSION_PARAM_OPERATOR_DEFAULT, null, type)
        {
            AddExecuteEventHandler(executeEventHandler);

            if (condition != null)
            {
                Object = condition;
                Text = GetDisplayName();
            }
        }
        public ConditionDisplayParameterContent(IDataElement contentElement, RuleObject.OnExecuteHandler executeEventHandler, Workshare.Policy.PolicyType type)
            : base(Properties.Resources.IDS_EXPRESSION_CONTENTPARAM_DEFAULT, contentElement, type)
        {
            AddExecuteEventHandler(executeEventHandler);

            if (contentElement != null)
            {
                this.Object = contentElement;
                this.Text = GetDisplayName();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataElement"></param>
        /// <param name="executeEventHandler"></param>
        public ConditionDisplayParameterCustomPropertyValue(CustomPropertyType customPropertyType, IDataElement dataElement, RuleObject.OnExecuteHandler executeEventHandler, Workshare.Policy.PolicyType type)
            : base(Properties.Resources.IDS_EXPRESSION_PARAM_CUSTOMPROPERTYVALUE_DEFAULT, null, type)
        {
            AddExecuteEventHandler(executeEventHandler);
            m_type = customPropertyType;

            if (dataElement != null)
            {
                Object = dataElement;
                Text = GetDisplayName();
            }
        }
        public ConditionDisplayParameterAddressType(IDataElement dataElement, RuleObject.OnExecuteHandler executeEventHandler, List<AddressTypes> enumAddressTypes, Workshare.Policy.PolicyType type)
            : base(Properties.Resources.IDS_EXPRESSION_ADDRESSTYPE_DEFAULT, null, type)
        {
            AddExecuteEventHandler(executeEventHandler);

            m_enumAddressTypes = enumAddressTypes;

            if (dataElement != null)
            {
                Object = dataElement;
                Text = GetDisplayName();
            }
        }
		public ConditionDisplayParameterHiddenDataInPDF(IDataElement dataElement, RuleObject.OnExecuteHandler executeEventHandler, List<ConditionUnitFactory.FileHiddenDataType> enumTypes, Workshare.Policy.PolicyType type)
			: base(Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_DEFAULT, null, type)
		{
			AddExecuteEventHandler(executeEventHandler);

			m_enumTypes = enumTypes;

			if (dataElement != null)
			{
				Object = dataElement;
				Text = GetDisplayName();
			}
		}
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 private void EditFileNameParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterRegex)sender).Edit();
 }
		private void EditTotalAttachmentSizeParameter(RuleObject sender)
		{
			((ConditionDisplayParameterTotalAttachmentSize) sender).Edit();
			UpdateConditionSummary(m_condition);
		}
        /// <summary>
        /// 
        /// </summary>
        private void EditFileTypeParameter(RuleObject sender)
        {
            List<Workshare.Policy.FileType> originalFileTypes = GetFileTypes();

            //work out what file types have passwords
            Array enumTypes = Enum.GetValues(typeof(Workshare.Policy.FileType));
            List<Workshare.Policy.FileType> availableFileTypes = new List<Workshare.Policy.FileType>();
            foreach (Workshare.Policy.FileType type in enumTypes)
            {
				if (FileTypeToPasswordMapper.Instance.FileTypeHasPassword(type))
				{
                    availableFileTypes.Add(type);
                }
            }

            //do editing
            ((ConditionDisplayParameterFileType)sender).Edit(availableFileTypes);
            UpdateConditionSummary(m_condition);
        }
		/// <summary>
		/// 
		/// </summary>
		private void EditFileTypeParameter(RuleObject sender)
		{
			List<Policy.FileType> originalFileTypes = GetFileTypes();

			//work out what file types have hidden data
			Array enumTypes = Enum.GetValues(typeof(Policy.FileType));
			List<Policy.FileType> availableFileTypes = new List<Policy.FileType>();
			foreach (Policy.FileType type in enumTypes)
			{
				if (FileTypeToHiddenDataMapper.FileTypeHasHiddenData(type))
				{
					if (type != Policy.FileType.PDFDocument) // We have a PDF Hidden Data condition
						availableFileTypes.Add(type);
				}
			}

			//do editing
			((ConditionDisplayParameterFileType) sender).Edit(availableFileTypes);
			List<Policy.FileType> newFileTypes = GetFileTypes();

			//has file type selection changed?
			bool fileTypesChanged = false;
			if (originalFileTypes.Count == newFileTypes.Count)
			{
				foreach (Policy.FileType fileType in newFileTypes)
				{
					if (!originalFileTypes.Contains(fileType))
					{
						fileTypesChanged = true;
						break;
					}
				}
			}
			else
			{
				fileTypesChanged = true;
			}

			//update selected contexts
			if (fileTypesChanged)
			{
				IDataElement dataElement = m_hiddenDataTypeData.Object as IDataElement;
				IPolicyObjectCollection<IDataItem> originalHiddenData = dataElement.Data as IPolicyObjectCollection<IDataItem>;
				IPolicyObjectCollection<IDataItem> newHiddenData = new PolicyObjectCollection<IDataItem>();
				List<ConditionUnitFactory.FileHiddenDataType> validHiddenData = FileTypeToHiddenDataMapper.GetHiddenDataForFileType(newFileTypes);

				foreach (IDataItem dataItem in originalHiddenData)
				{
					ConditionUnitFactory.FileHiddenDataType hiddenDataType = (ConditionUnitFactory.FileHiddenDataType) Enum.Parse(typeof(ConditionUnitFactory.FileHiddenDataType), dataItem.Value.ToString());
					if (validHiddenData.Contains(hiddenDataType))
					{
						newHiddenData.Add(dataItem);
					}
				}

				//ensure we have at least one value set
				if (newHiddenData.Count == 0)
				{
					ConditionUnitFactory.FileHiddenDataType defaultHiddenData = FileTypeToHiddenDataMapper.GetDefaultHiddenDataForFileType(newFileTypes[0]);
					newHiddenData.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), defaultHiddenData)));
				}

				//update the selected hidden data types
				originalHiddenData.Clear();
				foreach (IDataItem dataItem in newHiddenData)
				{
					originalHiddenData.Add(dataItem);
				}

				//set display name
				if (newHiddenData.Count == validHiddenData.Count)
				{
					dataElement.DisplayName.Value = Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_ANY;
				}
				else
				{
					dataElement.DisplayName.Value = m_hiddenDataTypeData.GetDisplayNameFromDataItems();
				}
				m_hiddenDataTypeData.Text = dataElement.DisplayName.Value;
			}
		}
		private void EditOperator(RuleObject sender)
		{
			((ConditionDisplayParameterOperator) sender).Edit();
			UpdateConditionSummary(m_condition);
		}
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 private void EditContextParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterContext)sender).Edit(GetCurrentFileTypes());
 }
 private void EditFileSizeParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterFileSize)sender).Edit();
     UpdateConditionSummary(m_condition);
 }
        /// <summary>
        /// Initialises the visual representation of the condition.
        /// </summary>
        /// <param name="text">Representation of the text to be displayed</param>
        /// <param name="objects">parameter hyperlink objects</param>
        protected void Initialise(string text, RuleObject[] objects)
        {
            System.Reflection.Assembly assem = this.GetType().Assembly;

            int prevIdx = 0;
            int idx = text.IndexOf("%");
            int firstIdx = 0;
            while (0 <= idx)
            {
                string hyperlinkIdx = text.Substring(idx + 1, 1);

                RuleObject obj = null;
                try
                {
                    int actualIdx = Convert.ToInt32(hyperlinkIdx, CultureInfo.InvariantCulture);
                    if (0 == firstIdx)
                        firstIdx = -actualIdx;
                    obj = objects[actualIdx + firstIdx];
                }
                catch (ArgumentOutOfRangeException ex)
                {
					Logger.LogError(ex);
                    throw new RulesBoxLineException("There is a mismatch between the number of hyperlinks defined in parameter [text], and the number of objects.");
                }

                if (idx > 0)
                    m_TextObjects.Add(text.Substring(prevIdx, idx - prevIdx));

                m_TextObjects.Add(new HyperlinkElement(obj));
                m_HyperlinkObjects.Add(obj);

                prevIdx = idx + 2;
                idx = text.IndexOf("%", prevIdx);
            }

            if (prevIdx < text.Length)
                m_TextObjects.Add(text.Substring(prevIdx, text.Length - prevIdx));

        }
 private void EditCustomPropertyNameParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterCustomPropertyName)sender).Edit();
     UpdateConditionSummary(m_condition);
 }
 protected void GetHyperlinkDisplay(RuleObject ruleObject)
 {
     object ruleobject = ruleObject.Object;
 }
 /// <summary>
 /// Invokes a dialog to edit the document restriction parameter
 /// </summary>
 /// <param name="sender">RuleObject containing file type parameter data</param>
 private void EditDocumentRestrictionParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterDocumentRestriction)sender).Edit();
     UpdateConditionSummary(m_condition);
 }
 /// <summary>
 /// Invokes a dialog to edit the file type parameter
 /// </summary>
 /// <param name="sender">RuleObject containing file type parameter data</param>
 private void EditFileTypeParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterFileType)sender).Edit(DocumentRestrictionUtils.Instance.SupportedFileTypes());
     UpdateConditionSummary(m_condition);
 }
        private void EditCustomPropertyValueParameter(RuleObject sender)
        {
            ConditionDisplayParameterCustomPropertyValue parameter = sender as ConditionDisplayParameterCustomPropertyValue;

            //get current custom property type
            DataSource dataSource = m_condition.DataLeft.Data as DataSource;
            IDataElement typeDataElement = ((IParameter)dataSource.Method.Parameters[1]).Value as IDataElement;
            CustomPropertyType currentType = (CustomPropertyType)Enum.Parse(typeof(CustomPropertyType), ((IDataItem)typeDataElement.Data).Value.ToString());

            parameter.Type = currentType;
            parameter.Edit();

            //update custom property type
            if (parameter.Type != currentType)
            {
                typeDataElement.Data = DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(CustomPropertyType), parameter.Type));
            }

            UpdateConditionSummary(m_condition);
        }
		protected virtual void EditHiddenDataParameter(RuleObject sender)
		{
			((ConditionDisplayParameterHiddenData) sender).Edit(GetFileTypes());
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        private void EditFileTypeParameter(RuleObject sender)
        {
            List<Workshare.Policy.FileType> originalFileTypes = GetCurrentFileTypes();

            //work out what file types have contexts
            Array enumTypes = Enum.GetValues(typeof(Workshare.Policy.FileType));
            List<Workshare.Policy.FileType> availableFileTypes = new List<Workshare.Policy.FileType>();
            foreach (Workshare.Policy.FileType type in enumTypes)
            {
				if (FileTypeToContextMapper.Instance.FileTypeHasContext(type))
				{
					availableFileTypes.Add(type);
				}
            }

            //do editing
            ((ConditionDisplayParameterFileType)sender).Edit(availableFileTypes);
            List<Workshare.Policy.FileType> newFileTypes = GetCurrentFileTypes();

            bool fileTypesChanged = false;
            if (originalFileTypes.Count == newFileTypes.Count)
            {                
                foreach (Workshare.Policy.FileType fileType in newFileTypes)
                {
                    if (!originalFileTypes.Contains(fileType))
                    {
                        fileTypesChanged = true;
                        break;
                    }
                }
            }
            else
            {
                fileTypesChanged = true;
            }

            if (fileTypesChanged)
            {
                //update contexts to contain only those allowed by the new file type selection

                //create list of currently selected contexts that are valid for the new file types
                IDataElement dataElement = m_contextData.Object as IDataElement;
                IPolicyObjectCollection<IDataItem> originalContexts = dataElement.Data as IPolicyObjectCollection<IDataItem>;
                IPolicyObjectCollection<IDataItem> newContexts = new PolicyObjectCollection<IDataItem>();
                List<ConditionUnitFactory.FileContextType> validContexts = FileTypeToContextMapper.Instance.GetContextsForFileType(newFileTypes, m_type);
                foreach (IDataItem dataItem in originalContexts)
                {
                    ConditionUnitFactory.FileContextType contextType = (ConditionUnitFactory.FileContextType)Enum.Parse(typeof(ConditionUnitFactory.FileContextType), dataItem.Value.ToString());
                    if (validContexts.Contains(contextType))
                    {
                        newContexts.Add(dataItem);
                    }
                }

                //ensure we have at least one value set
                if (newContexts.Count == 0)
                {
                    ConditionUnitFactory.FileContextType defaultContext = FileTypeToContextMapper.Instance.GetDefaultContextForFileType(newFileTypes[0]);
                    newContexts.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), defaultContext)));
                }

                //update the selected contexts
                originalContexts.Clear();
                foreach (IDataItem dataItem in newContexts)
                {
                    originalContexts.Add(dataItem);
                }

                //set display name
                if (newContexts.Count == validContexts.Count)
                {
                    dataElement.DisplayName.Value = Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_ANY;
                }
                else
                {
                    dataElement.DisplayName.Value = m_contextData.GetDisplayNameFromDataItems();
                }
                m_contextData.Text = dataElement.DisplayName.Value;
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 private void EditAddressContentParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterAddressContent)sender).Edit();
     
     UpdateConditionSummary();
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 private void EditContentParameter(RuleObject sender)
 {
     ((ConditionDisplayParameterContent)sender).Edit();
 }
 private void EditValue(RuleObject sender)
 {
     ((ConditionDisplayParameterPropertyValue)sender).Edit();
 }