示例#1
0
        /// <summary>
        /// Parses the boolean value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="value">if set to <c>true</c> [value].</param>
        /// <returns>
        /// True, if the parse was successful, otherwise False.
        /// </returns>
        /// <example>
        ///   <code>
        /// mSessionReusable = true;
        /// ConfigurationAccessHelper.ParseBooleanValue(pi.PropertyItems, "SessionReusable", ref mSessionReusable);
        ///   </code>
        ///   </example>
        public static bool ParseBooleanValue(CategoryPropertyItems root, String entryId, ref bool value)
        {
            bool result = false;

            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                result = bool.TryParse(pi.EntryValue, out value);
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            CategoryPropertyItems items = new CategoryPropertyItems();

            if (this.Count > 0)
            {
                for (int i = 0; i < this.Count; i++)
                {
                    items.Add(((ICloneable)this.BaseGet(i)).Clone() as CategoryPropertyItem);
                }
            }
            return(items);
        }
示例#3
0
        /// <summary>
        /// Parses the string value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// True, if the parse was successful, otherwise False.
        /// </returns>
        /// <example>
        ///   <code>
        /// ConfigurationAccessHelper.ParseStringValue(UpdateConfiguration.Settings.CategoryPropertyItems, DOWNLOAD_FOLDER, ref mDownloadFolder);
        ///   </code>
        ///   </example>
        public static bool ParseStringValue(CategoryPropertyItems root, String entryId, ref string value)
        {
            bool result = false;

            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                value  = pi.EntryValue;
                result = true;
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Get configuration categoryproperty item by path like X-Path.
        /// </summary>
        /// <param name="propertyItems">Root categoryproperty where the search begins</param>
        /// <param name="configPath">The expression, example: Animals\Dogs\Charles</param>
        /// <returns>
        /// The value or NULL if item does not exist
        /// </returns>
        /// <example>
        ///   <code>
        /// CategoryPropertyItem configItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(StorageConfiguration.Settings.CategoryPropertyItems, "NHibernateProvider/NHibernateStorages/Default");
        /// if (configItem != null)
        /// {
        /// DEFAULT_SESSION_FACTORY = CreateEntityManagerFactory(configItem);
        /// }
        ///   </code>
        ///   </example>
        /// <exception cref="System.ArgumentNullException">
        /// propertyItems
        /// or
        /// configPath
        /// </exception>
        public static CategoryPropertyItem GetCategoryPropertyByPath(CategoryPropertyItems propertyItems, string configPath)
        {
            if (propertyItems == null)
            {
                throw new ArgumentNullException("propertyItems");
            }
            if (String.IsNullOrEmpty(configPath))
            {
                throw new ArgumentNullException("configPath");
            }

            List <string>        keys   = new List <string>(configPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries));
            CategoryPropertyItem result = FindCategoryPropertyByKey(propertyItems, keys);

            keys.Clear();
            return(result);
        }
示例#5
0
        /// <summary>
        /// Gets the enumerator.
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerator <CategoryPropertyItem> GetEnumerator()
        {
            IEnumerator <CategoryPropertyItem> result = null;

            CategoryPropertyItems pis = PropertyItems;

            if (pis == null)
            {
                result = new List <CategoryPropertyItem>().GetEnumerator();
            }
            else
            {
                result = pis.GetEnumerator();
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// Parses the enum value.
        /// </summary>
        /// <typeparam name="TEnum">The type of the enum.</typeparam>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool ParseEnumValue <TEnum>(CategoryPropertyItems root, string entryId, ref TEnum value) where TEnum : struct
        {
            bool result = false;

            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                try
                {
                    value  = (TEnum)Enum.Parse(typeof(TEnum), pi.EntryValue, true);
                    result = true;
                }
                catch (Exception) { }
            }

            return(result);
        }
示例#7
0
        private static CategoryPropertyItem FindCategoryPropertyByKey(CategoryPropertyItems propertyItems, List <string> keys)
        {
            CategoryPropertyItem result = null;
            CategoryPropertyItem item   = propertyItems[keys[0]];

            if (item != null)
            {
                if (item.Id.Equals(keys[0]))
                {
                    if (keys.Count == 1)
                    {
                        result = item;
                    }
                    else
                    {
                        keys.RemoveAt(0);
                        result = FindCategoryPropertyByKey(item.PropertyItems, keys);
                    }
                }
            }
            return(result);
        }
示例#8
0
        /// <summary>
        /// Parses the float value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="minValue">The min value.</param>
        /// <param name="maxValue">The max value.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// True, if the parse was successful, otherwise False.
        /// </returns>
        /// <exception cref="InvalidConfigurationValueException">
        /// </exception>
        public static bool ParseFloatValue(CategoryPropertyItems root, String entryId, float minValue, float maxValue, ref float value)
        {
            bool result             = false;
            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                result = float.TryParse(pi.EntryValue, out value);
                if (result)
                {
                    if (value < minValue)
                    {
                        throw new InvalidConfigurationValueException(String.Format("Minimum value ({0}) is out of range ({1}) for item: {2}", minValue, result, entryId));
                    }
                    if (value > maxValue)
                    {
                        throw new InvalidConfigurationValueException(String.Format("Maximum value ({0}) is out of range ({1}) for item: {2}", maxValue, result, entryId));
                    }
                }
            }
            return(result);
        }
示例#9
0
 /// <summary>
 /// Categories the property items validator.
 /// </summary>
 /// <param name="items">The items.</param>
 /// <exception cref="System.Configuration.ConfigurationErrorsException">
 /// Id
 /// or
 /// </exception>
 public static void CategoryPropertyItemsValidator(CategoryPropertyItems items)
 {
     if (items != null && items.Count > 0)
     {
         List <string> ids = new List <string>();
         foreach (CategoryPropertyItem catItem in items)
         {
             catItem.Id.ToString();
             if (catItem.Id.Length == 0)
             {
                 throw new ConfigurationErrorsException("Id");
             }
             if (ids.Contains(catItem.Id))
             {
                 throw new ConfigurationErrorsException(String.Format("Duplicated Id: {0}", catItem.Id));
             }
             //catItem.EntryName.ToString();
             catItem.EntryValue.ToString();
             CategoryPropertyItemsValidator(catItem.PropertyItems);
             ids.Add(catItem.Id);
         }
         ids.Clear();
     }
 }