/// <summary>
        /// Filters the given collection of default properties providing only the properties that depends
        /// on the given current property.
        /// The keys of the dictionary are the names of the dependent properties,
        /// while the values of this dictionary are the lists of allowed values for each property
        /// </summary>
        /// <param name="defaultProperties">list of all available default properties, i.e. the result of
        ///     IPropertiesRepository.GetDefaultProperties() method</param>
        /// <param name="property">current property whose dependencies are to be discovered</param>
        /// <returns>an empty dictionary if any error occurred</returns>
        public static IDictionary <string, List <string> > FilterDependentProperties(
            ICollection <DefaultProperty> defaultProperties, SnippetProperty property)
        {
            Dictionary <string, List <string> > res = new Dictionary <string, List <string> >();

            if ((property == null) || (defaultProperties == null))
            {
                return(res);
            }

            foreach (DefaultProperty defProp in defaultProperties)
            {
                if ((defProp == null) || (defProp.DependsOn.IsNullOrEmpty()))
                {
                    continue;
                }

                //check if this default property depends on the current property:
                if (defProp.DependsOn.Contains(property))
                {
                    //add a new entry in the resulting dictionary:
                    res.Add(defProp.Name, defProp.PossibleValues);
                }
            }

            return(res);
        }
Exemple #2
0
        /// <summary>
        /// This is the init/copy method for this class.
        /// It should be used by the children classes in the constructor in order to correctly fill the properties of the object.
        /// </summary>
        /// <param name="objToCopy"></param>
        protected bool Init(SnippetProperty objToCopy)
        {
            if (objToCopy == null)
            {
                return(false);
            }

            Init(0 /*objToCopy.ID*/, objToCopy.SnippetID, objToCopy.Name, objToCopy.Value, objToCopy.IsVisible);

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Deserialize an XML fragment into a list of properties for this snippet
        /// </summary>
        /// <param name="xml"></param>
        protected void ParseProperties(XElement xml)
        {
            if (xml == null)
            {
                return;
            }

            List <XElement> elems = xml.GetNodes("Property", false);

            Properties = new List <SnippetProperty>();
            foreach (XElement el in elems)
            {
                SnippetProperty prop = new SnippetProperty(el.ToString(), SerialFormat.XML);
                prop.SnippetID = this.ID;
                Properties.Add(prop);
            }
        }
Exemple #4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////

        #region PUBLIC API
        /////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     override object.Equals
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            SnippetProperty other = obj as SnippetProperty;

            if (!Name.Equals(other.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }
            if (!Value.Equals(other.Value, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Filters the given collection of default properties providing only the properties that depends 
        /// on the given current property.
        /// The keys of the dictionary are the names of the dependent properties, 
        /// while the values of this dictionary are the lists of allowed values for each property
        /// </summary>
        /// <param name="defaultProperties">list of all available default properties, i.e. the result of 
        ///     IPropertiesRepository.GetDefaultProperties() method</param>
        /// <param name="property">current property whose dependencies are to be discovered</param>
        /// <returns>an empty dictionary if any error occurred</returns>
        public static IDictionary<string, List<string>> FilterDependentProperties(
            ICollection<DefaultProperty> defaultProperties, SnippetProperty property)
        {
            Dictionary<string, List<string>> res = new Dictionary<string, List<string>>();
            if ((property == null) || (defaultProperties == null))
                return res;

            foreach (DefaultProperty defProp in defaultProperties)
            {
                if ((defProp == null) || (defProp.DependsOn.IsNullOrEmpty()))
                    continue;

                //check if this default property depends on the current property:
                if (defProp.DependsOn.Contains(property))
                {
                    //add a new entry in the resulting dictionary:
                    res.Add(defProp.Name, defProp.PossibleValues);
                }
            }

            return res;
        }
        public bool DeleteSnippetProperty(SnippetProperty prop)
        {
            if ((prop == null) || !prop.DataAreValid())
            {
                SetLastError(log, ErrorCodes.WRONG_INPUT, string.Format("Input error: property={0}", prop.PrintNull()));
                return false;
            }

            //send the request and parse the response:
            string contentToSend = string.Format("snippetID={0}&name={1}&value={2}",
                                        prop.SnippetID, HttpUtility.UrlEncode(prop.Name), HttpUtility.UrlEncode(prop.Value));
            S2CResObj<object> resp = SendReqObj(DELETE_PROPERTY_BYNAME_URL, contentToSend, true);

            //build the result:
            return ParseBoolResponse(resp);
        }
        /// <summary>
        /// This is the init/copy method for this class.
        /// It should be used by the children classes in the constructor in order to correctly fill the properties of the object.
        /// </summary>
        /// <param name="objToCopy"></param>
        protected bool Init(SnippetProperty objToCopy)
        {
            if (objToCopy == null)
                return false;

            Init(0 /*objToCopy.ID*/, objToCopy.SnippetID, objToCopy.Name, objToCopy.Value, objToCopy.IsVisible);

            return true;
        }
Exemple #8
0
        /// <summary>
        /// Deserialize an XML fragment into a list of properties for this snippet
        /// </summary>
        /// <param name="xml"></param>
        protected void ParseProperties(XElement xml)
        {
            if (xml == null)
                return;

            List<XElement> elems = xml.GetNodes("Property", false);
            foreach (XElement el in elems)
            {
                SnippetProperty prop = new SnippetProperty(el.ToString(), SerialFormat.XML);
                prop.SnippetID = this.ID;
                AddProperty(prop);
            }
        }
Exemple #9
0
        /// <summary>
        /// Adds the given property to the list of properties, if not yet present.
        /// This procedure modifies only the local in-memory content of the snippet.
        /// </summary>
        /// <param name="addingProp"></param>
        public void AddOrReplaceProperty(SnippetProperty addingProp)
        {
            if (addingProp == null)
                return;

            string propName = addingProp.Name;
            string propValue = addingProp.Value;

            //skip the property if not valid:
            if (!SnippetProperty.DataAreValid(propName, propValue))
                return;

            //replace the value of the property with the existing value, if it can be found:
            foreach (SnippetProperty prop in Properties)
            {
                if (prop == null)
                    continue;
                if (prop.Name.Equals(propName, StringComparison.InvariantCultureIgnoreCase))
                {
                    prop.Value = propValue;
                    return;
                }
            }

            //if the property is not yet present in the list, add it:
            if (m_properties == null)
                m_properties = new List<SnippetProperty>();
            m_properties.Add(new SnippetProperty(propName, propValue, ID, addingProp.IsVisible));
        }
Exemple #10
0
        /// <summary>
        /// Adds the given property to the list of properties, if not yet present.
        /// This procedure modifies only the local in-memory content of the snippet.
        /// </summary>
        /// <param name="addingProp"></param>
        public void AddProperty(SnippetProperty addingProp)
        {
            if (addingProp == null)
                return;

            string propName = addingProp.Name;
            string propValue = addingProp.Value;

            //skip the property if not valid:
            if (!SnippetProperty.DataAreValid(propName, propValue))
                return;
            //foreach (SnippetProperty prop in Properties)
            //{
            //    if (prop == null)
            //        continue;
            //    if (prop.Name.Equals(propName, StringComparison.InvariantCultureIgnoreCase))
            //    {
            //        prop.Value = propValue;
            //        return;
            //    }
            //}

            //if the property is not yet present in the list, add it:
            if (m_properties == null)
                m_properties = new List<SnippetProperty>();

            m_properties.Add(new SnippetProperty(propName, propValue, ID, addingProp.IsVisible));
        }
        private List<SnippetProperty> BuildPropertiesList(Control.ControlCollection comboxesList, bool includeEmptyValues, bool getSelectedValue = false)
        {
            List<SnippetProperty> pList = new List<SnippetProperty>();

            // retrieve the properties:
            foreach (Control elem in comboxesList)
            {
                ComboBox comb = elem as ComboBox;
                if (comb == null)
                    continue;
                if ((comb.SelectedItem == null) && (string.IsNullOrEmpty(comb.Text)))
                    continue;

                // Search only for combobox having properties name:
                if (comb.Name.StartsWith("Name_"))
                {
                    string idx = GetCustomIndex(comb);
                    if (!string.IsNullOrEmpty(idx))
                    {
                        string propVal = string.Empty;

                        // Search for related value:
                        foreach (Control elemVal in propertiesPanel.Controls)
                        {
                            ComboBox combVal = elemVal as ComboBox;
                            if ((combVal != null) && combVal.Name.Equals("Value_" + idx))
                            {
                                string selValue = combVal.SelectedItem as string;
                                string combText = combVal.Text;

                                if ((selValue == null) && (combText == null))
                                    continue;   // this property is invalid...

                                if (getSelectedValue)
                                    propVal = string.IsNullOrEmpty(selValue) ? combText : selValue.ToString();
                                else
                                    propVal = combText;
                                break;
                            }
                        }

                        if (!string.IsNullOrEmpty(propVal) || includeEmptyValues)
                        {
                            SnippetProperty newProp = new SnippetProperty(comb.SelectedItem == null ? comb.Text.Trim() : comb.SelectedItem.ToString(), propVal);
                            pList.Add(newProp);
                        }
                    }
                }
            }

            return pList;
        }
        private Control CreateComboBox(object[] items, SnippetProperty p, bool isValue, string numRdn, bool onlyRead)
        {
            Control cbN = null;
            if (onlyRead)
            {
                cbN = new TextBox();
                ((TextBox)cbN).Enabled = false;
            }
            else
            {
                cbN = new ComboBox();
                ((ComboBox)cbN).MaxLength = PROP_NAME_MAX_LENGTH;
                ((ComboBox)cbN).Margin = new Padding(1);
                ((ComboBox)cbN).SelectionChangeCommitted += new EventHandler(ComboBox_SelectedValueChanged);
                ((ComboBox)cbN).LostFocus += new EventHandler(ComboBox_LostFocus);
                ((ComboBox)cbN).KeyUp += new KeyEventHandler(ComboBox_KeyUp);
            }

            if (isValue)
            {
                if (p != null)
                {
                    if (!onlyRead)
                        ((ComboBox)cbN).SelectedValue = p.Value;
                    cbN.Text = p.Value;
                }
                cbN.Name = "Value_" + numRdn;
            }
            else
            {
                if (p != null)
                {
                    if (!onlyRead)
                        ((ComboBox)cbN).SelectedValue = p;
                    cbN.Text = p.Name;
                }
                cbN.Name = "Name_" + numRdn;
            }
            
            if (!onlyRead && (items != null))
                ((ComboBox)cbN).Items.AddRange(items);
            
            cbN.Width = 115;
            cbN.Font = Utilities.s_regularFont;
            cbN.BackColor = Color.White;
           
            if (propertiesPanel.InvokeRequired)
                this.Invoke(new Action(() => propertiesPanel.Controls.Add(cbN)));
            else
                propertiesPanel.Controls.Add(cbN);

            return cbN;
        }