예제 #1
0
        // --------------------------------------------------------

        // основной конструктор
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="TextRules"/> class.
        /// </summary>
        /// <param name="rootRulesLoader">
        /// The root rules loader.
        /// </param>
        /// <param name="FieldNameResolver">
        /// The field name resolver.
        /// </param>
        public TextRules(XElement rootRulesLoader = null, SearchFieldNameResolver FieldNameResolver = null)
        {
            this.FieldNameResolver = FieldNameResolver;

            if (rootRulesLoader != null)
            {
                LoadRules(rootRulesLoader);
            }
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StringParamReplacer"/> class.
 /// </summary>
 /// <param name="StringMatcher">
 /// The string matcher.
 /// </param>
 /// <param name="Replacer">
 /// The replacer.
 /// </param>
 /// <param name="FlaggedOnly">
 /// The flagged only.
 /// </param>
 /// <param name="FieldNameResolver">
 /// The field name resolver.
 /// </param>
 public StringParamReplacer(
     StringMatchingBase StringMatcher,
     string Replacer,
     bool FlaggedOnly = false,
     SearchFieldNameResolver FieldNameResolver = null)
     : base(StringMatcher, FlaggedOnly, FieldNameResolver)
 {
     this.Replacer = Replacer;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StringParamTrimmer"/> class.
 /// </summary>
 /// <param name="StringMatcher">
 /// The string matcher.
 /// </param>
 /// <param name="Direction">
 /// The direction.
 /// </param>
 /// <param name="FlaggedOnly">
 /// The flagged only.
 /// </param>
 /// <param name="FieldNameResolver">
 /// The field name resolver.
 /// </param>
 public StringParamTrimmer(
     StringMatchingBase StringMatcher,
     WardUnidimensional Direction,
     bool FlaggedOnly = false,
     SearchFieldNameResolver FieldNameResolver = null)
     : base(StringMatcher, FlaggedOnly, FieldNameResolver)
 {
     this.Direction = Direction;
 }
예제 #4
0
        // --------------------------------------------------------

        // конвертировать строку

        // --------------------------------------------------------
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="StringConverterBase"/> class.
        /// </summary>
        /// <param name="StringMatcher">
        /// The string matcher.
        /// </param>
        /// <param name="FlaggedOnly">
        /// The flagged only.
        /// </param>
        /// <param name="FieldNameResolver">
        /// The field name resolver.
        /// </param>
        protected StringConverterBase(
            StringMatchingBase StringMatcher,
            bool FlaggedOnly = false,
            SearchFieldNameResolver FieldNameResolver = null)
        {
            this.StringMatcher = StringMatcher;
            this.FlaggedOnly   = FlaggedOnly;
            AllowedFields      = new PolicySearchFields(FieldNameResolver);
        }
예제 #5
0
        /// <summary>
        /// The load keys.
        /// </summary>
        /// <param name="configFile">
        /// The config file.
        /// </param>
        /// <param name="subTypes">
        /// The sub types.
        /// </param>
        /// <param name="FieldNameResolver">
        /// The field name resolver.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        public static List <LoadedKey> LoadKeys(
            Stream configFile,
            out Dictionary <string, string> subTypes,
            SearchFieldNameResolver FieldNameResolver = null)
        {
            var keys = new List <LoadedKey>();

            subTypes = new Dictionary <string, string>();
            using (var reader = XmlReader.Create(configFile))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        try
                        {
                            switch (reader.Name)
                            {
                            case "Key":
                            case "key":
                                var xKey = XElement.Load(reader.ReadSubtree());
                                var key  = new LoadedKey
                                {
                                    name    = xKey.Attribute("name").Value,
                                    type    = int.Parse(xKey.Attribute("type").Value),
                                    formula = GetFieldsTypes(xKey.Attribute("value").Value, FieldNameResolver)
                                };
                                if (xKey.Attribute("subtype") != null)
                                {
                                    key.subtype = int.Parse(xKey.Attribute("subtype").Value);
                                }

                                keys.Add(key);
                                break;

                            case "subtype":
                            case "subType":
                                var xsubtype = XElement.Load(reader.ReadSubtree());
                                subTypes.Add(xsubtype.Attribute("name").Value, xsubtype.Attribute("value").Value);
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Ошибка при чтении ключей из конфигурационного файла: ", ex);
                        }
                    }
                }
            }

            return(keys);
        }
예제 #6
0
        /// <summary>
        /// The get fields types.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="FieldNameResolver">
        /// The field name resolver.
        /// </param>
        /// <returns>
        /// The <see cref="FieldTypes[]"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private static FieldTypes[] GetFieldsTypes(string value, SearchFieldNameResolver FieldNameResolver = null)
        {
            var fields     = value.Split(new[] { '+' });
            var fieldTypes = new FieldTypes[fields.Length];

            try
            {
                for (var i = 0; i < fields.Length; i++)
                {
                    fieldTypes[i] = FieldNameResolver(fields[i].Trim());
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Ошибка при чтении ключей из конфигурационного файла:", ex);
            }

            return(fieldTypes);
        }
예제 #7
0
        // --------------------------------------------------------
        // public statics

        // public static FieldTypes IndexToField(int index)
        // {
        // unchecked
        // {
        // return (FieldTypes)index;
        // }
        // }

        // --------------------------------------------------------

        // public static int FieldToIndex(FieldTypes field)
        // {
        // unchecked
        // {
        // return (int)field;
        // }
        // }

        // --------------------------------------------------------

        // public static FieldTypes TryResolveFieldName(string fieldName, PolicySearchFieldNameResolver resolver = null)
        // {
        // FieldTypes field;
        // if (resolver != null)
        // {
        // field = resolver(fieldName);
        // if (field != FieldTypes.Undefined)
        // return field;
        // }
        // try
        // {
        // return (FieldTypes)Enum.Parse(typeof(FieldTypes), fieldName, ignoreCase: true);
        // }
        // catch { }
        // return FieldTypes.Undefined;
        // }

        // --------------------------------------------------------
        // properties

        // --------------------------------------------------------

        // public IEnumerable<FieldTypes> Fields // !! может вернуть null
        // {
        // get
        // {
        // CheckWhetherResolved();
        // return fields;
        // }
        // }

        // --------------------------------------------------------
        // publics
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="PolicySearchFields"/> class.
        /// </summary>
        /// <param name="FieldNameResolver">
        /// The field name resolver.
        /// </param>
        public PolicySearchFields(SearchFieldNameResolver FieldNameResolver = null)
        {
            this.FieldNameResolver = FieldNameResolver;
        }