private void AddComboBox(Control panel, int top, int left, int width, IResourceActionProperty property)
        {
            ComboBox edMapped = new ComboBox();
            edMapped.Top = top;
            edMapped.Left = left;
            edMapped.Width = width;
            edMapped.Items.Clear();
            if (property.DataType == typeof(bool))
            {
                edMapped.DropDownStyle = ComboBoxStyle.DropDownList;
                edMapped.Items.Add(Properties.AdminUIResources.TRUE);
                edMapped.Items.Add(Properties.AdminUIResources.FALSE);
                if ((bool)property.Value)
                    edMapped.SelectedIndex = 0;
                else
                    edMapped.SelectedIndex = 1;
            }
            else
            {
                edMapped.DropDownStyle = ComboBoxStyle.DropDown;
                edMapped.Items.Add(string.Empty);

                if (m_resourceManager != null)
                {
                    List<string> systemPropertyNames = new List<string>();
                    foreach (ISystemProperty systemProperty in m_resourceManager.SystemProperties)
                    {
                        if (property.DataType == systemProperty.DataType)
                            systemPropertyNames.Add(systemProperty.PropertyName);
                    }
                    systemPropertyNames.Sort();

                    foreach (string systemPropertyName in systemPropertyNames)
                    {
                        edMapped.Items.Add(systemPropertyName);
                    }
                }
                if (property.MappedSystemProperty == null)
                {
                    if (property.Value == null)
                    {
                        edMapped.Text = String.Empty;
                    }
                    else
                    {
                        edMapped.Text = property.Value.ToString();
                    }
                }
                else
                {
                    edMapped.Text = property.MappedSystemProperty.PropertyName;
                }

                if (property.CustomProperty)
                {
                    AddDeleteButton(panel, property.Name, top, left, edMapped.Height, width, property);
                }
            }

            edMapped.Tag = property;
            m_errorProvider.SetIconAlignment(edMapped, ErrorIconAlignment.MiddleRight);
            edMapped.TextChanged += edMapped_TextChanged;
            panel.Controls.Add(edMapped);
        }
 private void AddTextBox(Control panel, int top, int left, int width, IResourceActionProperty property)
 {
     TextBox edTextBox = new TextBox();
     edTextBox.Top = top;
     edTextBox.Left = left;
     edTextBox.Width = width;
     edTextBox.Tag = property;
     edTextBox.Text = property.Value.ToString();
     m_errorProvider.SetIconAlignment(edTextBox, ErrorIconAlignment.MiddleRight);
     panel.Controls.Add(edTextBox);
 }
 private void AddDateTimePicker(Control panel, int top, int left, int width, IResourceActionProperty property)
 {
     DateTimePicker edDateTimePicker = new DateTimePicker();
     edDateTimePicker.Top = top;
     edDateTimePicker.Left = left;
     edDateTimePicker.Width = width;
     edDateTimePicker.Tag = property;
     edDateTimePicker.Text = property.Value.ToString();
     // TODO: may want to catch dates in the past
     m_errorProvider.SetIconAlignment(edDateTimePicker, ErrorIconAlignment.MiddleRight);
     edDateTimePicker.ValueChanged += new EventHandler(edDateTimePicker_ValueChanged);
     panel.Controls.Add(edDateTimePicker);
 }
        private void AddCheckedListBox(Control panel, int top, int left, int width, IResourceActionProperty property)
        {            
            CheckedListBox checkedListBox = new CheckedListBox();
            checkedListBox.Top = top;
            checkedListBox.Left = left;
            checkedListBox.Width = width;
            checkedListBox.Tag = property;

            string[] checkedItems = property.Value as string[];
            if (null != checkedItems)
            {
                foreach (string checkedItem in checkedItems)
                {
                    string[] keyPair = checkedItem.Split(',');
                    if (2 != keyPair.Length)
                        continue;

                    checkedListBox.Items.Add(keyPair[0], Convert.ToBoolean(keyPair[1], CultureInfo.InvariantCulture));
                }
            }

            checkedListBox.ItemCheck += checkedListBox_ItemCheckedChanged;
            panel.Controls.Add(checkedListBox);
        }
        private void AddCustomUIButton(Control panel, int top, int left, int width, IResourceActionProperty property)
        {
            Button customUITrigger = new Button();
            customUITrigger.Enabled = false;
            customUITrigger.Top = top;
            customUITrigger.Left = left;
            customUITrigger.Width = width;
            customUITrigger.Tag = property;
            customUITrigger.Text = Properties.AdminUIResources.ACTION_CUSTOM_DATATYPE_BUTTON;

            customUITrigger.Click += customUITrigger_Click;
            if (m_action.CustomDataTypeUI != null)
                customUITrigger.Enabled = true;
            else
                m_errorProvider.SetError(customUITrigger, Properties.AdminUIResources.ACTION_CUSTOM_DATATYPE_DOESNT_EXIST_HINT);

            panel.Controls.Add(customUITrigger);
        }
        private void RemovePropertyFromUI(IResourceActionProperty resourceActionProperty)
        {
            List<Control> controls = new List<Control>();
            
            foreach (Control control in m_propertiesControl.Controls)
            {
                if (control.Tag != resourceActionProperty)
                {
                    controls.Add(control);
                }
            }

            m_propertiesControl.Controls.Clear();
            foreach(Control control in controls)
            {
                control.Top = GetTopOfNextControlInCollection(m_propertiesControl.Controls);
                m_propertiesControl.Controls.Add(control);
            }

        }
        private void PlacePropertyControlOnSurface(ref int top, IResourceActionProperty resourceActionProperty)
        {
            if (resourceActionProperty.ReadOnly)
            {
                return;
            }

            Panel resourceActionPropertyPanel = new Panel();
            resourceActionPropertyPanel.Top = top;
            resourceActionPropertyPanel.Left = 0;
            resourceActionPropertyPanel.Width = m_propertiesControl.Width - SystemInformation.VerticalScrollBarWidth;
            resourceActionPropertyPanel.Tag = resourceActionProperty;

            //locations of subcontrols, relative to the resourceActionPropertyPanel
            int vMargin = 3;
            int hMargin = 10;
            int propertyValueTop = vMargin;
            int propertyValueWidth = 140;
            int propertyValueLeft = resourceActionPropertyPanel.Width - (propertyValueWidth + SystemInformation.VerticalScrollBarWidth + hMargin);
            int propertyNameTop = vMargin + 2;
            int propertyNameLeft = 0;
            int propertyNameWidth = propertyValueLeft - (propertyNameLeft + hMargin);
            
            //add ResourceActionProperty name label
            AddLabel(resourceActionPropertyPanel, propertyNameTop, propertyNameLeft, propertyNameWidth, resourceActionProperty.DefaultDisplayName);

            //add ResourceActionProperty value control
            if (resourceActionProperty.DisplayType == PropertyDisplayType.CustomUI)
            {
                AddCustomUIButton(resourceActionPropertyPanel, propertyValueTop, propertyValueLeft, propertyValueWidth, resourceActionProperty);
            } else if ((resourceActionProperty.DataType == typeof(String) ||
                (resourceActionProperty.DataType == typeof(int)))
                && (!resourceActionProperty.CustomProperty))
            {
                AddTextBox(resourceActionPropertyPanel, propertyValueTop, propertyValueLeft, propertyValueWidth, resourceActionProperty);
            }
            else if (resourceActionProperty.DataType == typeof(DateTime))
            {
                AddDateTimePicker(resourceActionPropertyPanel, propertyValueTop, propertyValueLeft, propertyValueWidth, resourceActionProperty);
            }
            else if (resourceActionProperty.DataType == typeof(string[]))
            {
                AddCheckedListBox(resourceActionPropertyPanel, propertyValueTop, propertyValueLeft, propertyValueWidth, resourceActionProperty);
            }
            else
            {
                AddComboBox(resourceActionPropertyPanel, propertyValueTop, propertyValueLeft, propertyValueWidth, resourceActionProperty);
            }

            //resize panel
            int maxHeight = 0;
            foreach (Control control in resourceActionPropertyPanel.Controls)
            {
                if (control.Height > maxHeight)
                {
                    maxHeight = control.Height;
                }
            }
            resourceActionPropertyPanel.Height = maxHeight + vMargin;
            top += resourceActionPropertyPanel.Height;

            m_propertiesControl.Controls.Add(resourceActionPropertyPanel);
        }
 public bool Remove(IResourceActionProperty item)
 {
     List.Remove(item);
     return true;
 }
		private void AddNewPropertyToUI(IResourceActionProperty resourceActionProperty)
		{
            int top = GetTopOfNextControlInCollection(m_propertiesControl.Controls);
			PlacePropertyControlOnSurface(ref top, resourceActionProperty);
		}
 public bool Contains(IResourceActionProperty item)
 {
     return List.Contains(item);
 }
 public void CopyTo(IResourceActionProperty[] array, int arrayIndex)
 {
     List.CopyTo(array, arrayIndex);
 }
 public void Add(IResourceActionProperty item)
 {
     List.Add(item);
 }
Beispiel #13
0
        //TODO: check that all these conversions work correctly. Write tests for each datatype
        public static string GetStringValue(IResourceActionProperty resourceActionProperty)
        {
            string dataType = PolicyResourceTypes.GetStringFromType(resourceActionProperty.DataType);
            switch (dataType)
            {
                case "boolean": return (0 == string.Compare(Boolean.TrueString, resourceActionProperty.Value.ToString(), true, CultureInfo.InvariantCulture)) ? Boolean.TrueString : Boolean.FalseString;
                case "datetime": return ((DateTime)(resourceActionProperty.Value)).ToString(CultureInfo.InvariantCulture);
                case "long": return resourceActionProperty.Value.ToString();
                case "double": return resourceActionProperty.Value.ToString();
                case "string": return resourceActionProperty.Value as string;
                case "stringarray": return ConvertCheckedItemStringArrayToString(resourceActionProperty.Value);
                
                default:
					Logger.LogError(String.Format(CultureInfo.InvariantCulture, "XmlResourceHelper.GetStringValue: invalid data type: {0}", resourceActionProperty.DataType.ToString()));
                    throw new ApplicationException(Properties.Resources.COULD_NOT_WRITE_RESOURCES);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Populate the resource action property from the data in the input DataElement node
        /// </summary>
        /// <remarks>
        /// A DataElement node has the following attributes:
        /// 
        /// name                - unique ID for the property
        /// defaultdisplayname  - the default display name for the property
        /// type                - the .NET type of the property
        /// displaytype         - enum indicating the control used to represent the value in the client UI
        /// override            - boolean indicating whether the user can override the value
        /// visible             - boolean indicating whether the control representing the property in the client UI is visible
        /// 
        /// If the DataElement is a normal property i.e. it maps directly to a property in the Action, 
        /// then the value is contained within a child DataItem node.
        /// 
        /// If the DataElement is a mapped system property then the system property being mapped
        /// is contained within a child DataSource node.
        /// </remarks>
        /// <param name="dataElementNode">The DataElement node as read from the propert resource XML</param>
        /// <param name="resourceActionProperty">The ResourceActionProperty being populated</param>
        public static void AddDataElementToResource(XPathNavigator dataElementNode, IResourceActionProperty resourceActionProperty)
        {
            // Add attributes
            try
            {
                (resourceActionProperty as ResourceActionProperty).Name = dataElementNode.GetAttribute(@"name", RESOURCE_NAMESPACE_URI);
                resourceActionProperty.DefaultDisplayName = dataElementNode.GetAttribute(@"displayname", RESOURCE_NAMESPACE_URI);
               
                if (HasAttribute("override", dataElementNode))
                    resourceActionProperty.Override = Convert.ToBoolean(dataElementNode.GetAttribute(@"override", RESOURCE_NAMESPACE_URI), CultureInfo.InvariantCulture);
                else resourceActionProperty.Override = true;
                if (HasAttribute("visible", dataElementNode))
                    resourceActionProperty.Visible = Convert.ToBoolean(dataElementNode.GetAttribute(@"visible", RESOURCE_NAMESPACE_URI), CultureInfo.InvariantCulture);
                else resourceActionProperty.Visible = true;

                if (HasAttribute("type", dataElementNode))
                    (resourceActionProperty as ResourceActionProperty).DataType = PolicyResourceTypes.GetTypeFromString(dataElementNode.GetAttribute(@"type", RESOURCE_NAMESPACE_URI));
                if (HasAttribute("displaytype", dataElementNode))
                    (resourceActionProperty as ResourceActionProperty).DisplayType = (PropertyDisplayType)(Enum.Parse(typeof(PropertyDisplayType), dataElementNode.GetAttribute(@"displaytype", RESOURCE_NAMESPACE_URI), true));
                if (HasAttribute("readonly", dataElementNode))
                {
                    (resourceActionProperty as ResourceActionProperty).ReadOnly = Convert.ToBoolean(dataElementNode.GetAttribute(@"readonly", RESOURCE_NAMESPACE_URI), CultureInfo.InvariantCulture);
                }
                else
                {
                    (resourceActionProperty as ResourceActionProperty).ReadOnly = false;
                }
                if (HasAttribute("customproperty", dataElementNode))
                {
                    (resourceActionProperty as ResourceActionProperty).CustomProperty = Convert.ToBoolean(dataElementNode.GetAttribute(@"customproperty", RESOURCE_NAMESPACE_URI), CultureInfo.InvariantCulture);
                }
                else
                {
                    (resourceActionProperty as ResourceActionProperty).CustomProperty = false;
                }
            }
            catch (Exception e)
            {
				Logger.LogError(e);
                throw new ApplicationException(Properties.Resources.COULD_NOT_READ_RESOURCES);
            }

            // If the node is a data source then it needs to be added as a mapped system property
            XPathNavigator dataSourceNode = dataElementNode.SelectSingleNode(@"DataSource");
            if (dataSourceNode != null)
            {
                // Retrieve the data sources properties
                XPathNavigator dataMethodNode = dataSourceNode.SelectSingleNode(@"DataMethod");
                if (dataMethodNode == null)
                {
                    Logger.LogError("XmlResourceHelper.AddDataElementToResource: No DataMethod node within DataSource Node");
                    throw new ApplicationException(Properties.Resources.COULD_NOT_READ_RESOURCES);
                }

                string description = "";
                if (HasAttribute("description", dataSourceNode))
                {
                    description = dataSourceNode.GetAttribute("description", RESOURCE_NAMESPACE_URI);
                }

                resourceActionProperty.MappedSystemProperty = new SystemProperty(
                                                                        dataSourceNode.GetAttribute("assembly", RESOURCE_NAMESPACE_URI),
                                                                        PolicyResourceTypes.GetTypeFromString(dataSourceNode.GetAttribute("type", RESOURCE_NAMESPACE_URI)),
                                                                        dataSourceNode.GetAttribute("class", RESOURCE_NAMESPACE_URI),
                                                                        dataMethodNode.Value,
                                                                        "");
            }
            else
            {
                // Add data item value
                XPathNavigator dataItemNode = dataElementNode.SelectSingleNode(@"DataItem");
                if (dataItemNode != null)
                {
                    resourceActionProperty.Value = GetObjectValue(dataElementNode, resourceActionProperty.DataType);
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// Add a property as a mapped system property
        /// </summary>
        /// <remarks>
        /// The property gets added to the resources xml as a data source and
        /// not a data item, with the mapped system property name entered as
        /// the data method name e.g.
        /// <DataElement>
        ///     <DataSource assembly="property.assembly" class="mappedproperty.actionclass">
        ///     <DataMethod>propertyname</DataMethod>
        ///     </DataSource>
        /// </DataElement>
        /// </remarks>
        /// <param name="dataElementNode">The data element node that the data source is being added to</param>
        /// <param name="property">The resource property that has been mapped to a system property</param>
        public static void AddMappedSystemProperty(XmlNode dataElementNode, IResourceActionProperty property)
        {
            XmlDocument xmlDocument = dataElementNode.OwnerDocument;
            XmlNode dataSourceNode = xmlDocument.CreateElement("DataSource");
            AddAttribute(dataSourceNode, "assembly", property.MappedSystemProperty.Assembly);
            AddAttribute(dataSourceNode, "class", property.MappedSystemProperty.Class);
            AddAttribute(dataSourceNode, "type", PolicyResourceTypes.GetStringFromType(property.MappedSystemProperty.DataType));

            XmlNode dataMethodNode = xmlDocument.CreateElement("DataMethod");
            dataMethodNode.InnerText = property.MappedSystemProperty.PropertyName;
            dataSourceNode.AppendChild(dataMethodNode);
            dataElementNode.AppendChild(dataSourceNode);
        }
Beispiel #16
0
        /// <summary>
        /// Add an DataElement XML node to the DataElements node that corresponds
        /// to the ResourceActionProperty passed in.
        /// </summary>
        /// <param name="dataElementsNode">The parent node being added to</param>
        /// <param name="property">The property being added</param>
        public static void AddProperty(XmlNode dataElementsNode, IResourceActionProperty property)
        {
            XmlDocument xmlDocument = dataElementsNode.OwnerDocument;
            XmlNode dataElementNode = xmlDocument.CreateElement("DataElement");
            AddDataElementNodeAttributes(dataElementNode, 
                                        property.Name, 
                                        property.DefaultDisplayName, 
                                        property.DataType, 
                                        property.DisplayType, 
                                        property.Visible, 
                                        property.Override,
                                        property.ReadOnly,
                                        property.CustomProperty);


            // If the property has been mapped to a system property then it needs to
            // be written out as a data source otherwise it's a data item
            if (property.MappedSystemProperty != null)
            {
                AddMappedSystemProperty(dataElementNode, property);
            }
            else
            {
                XmlNode dataItemNode = xmlDocument.CreateElement("DataItem");
                dataItemNode.InnerText = GetStringValue(property);
                dataElementNode.AppendChild(dataItemNode);
            }
            dataElementsNode.AppendChild(dataElementNode);
        }