Beispiel #1
0
        /// <summary>
        /// This method returns the Comparison Text for the ComparisonType given.
        /// </summary>
        public string GetComparisonText(ComparisonTypeEnum comparisonType)
        {
            // initial value
            string comparisonText = "";

            // determine the return value based upon a comparisonType
            switch (comparisonType)
            {
            case ComparisonTypeEnum.LessThan:

                // set the return value
                comparisonText = "is less than";

                // required
                break;

            case ComparisonTypeEnum.LessThanOrEqual:

                // set the return value
                comparisonText = "is less than or equal to";

                // required
                break;

            case ComparisonTypeEnum.Equal:

                // set the return value
                comparisonText = "is equal to";

                // required
                break;

            case ComparisonTypeEnum.GreaterThanOrEqual:

                // set the return value
                comparisonText = "is greater than or equal";

                // required
                break;

            case ComparisonTypeEnum.GreaterThan:

                // set the return value
                comparisonText = "is greater than";

                // required
                break;

            case ComparisonTypeEnum.NotEqual:

                // set the return value
                comparisonText = "is not equal to";

                // required
                break;
            }

            // return value
            return(comparisonText);
        }
        /// <summary>
        /// Compares the in.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="compareType">Type of the compare.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool CompareIn(string left, string right, ComparisonTypeEnum compareType)
        {
            var list = right.Split(new char[] { '|' }, StringSplitOptions.None);

            if (compareType == ComparisonTypeEnum.Datetime)
            {
                return(CompareDateTime(left, list));
            }

            return(list.Contains(left));
        }
Beispiel #3
0
        /// <summary>
        /// Create a new instance of an IfStatement object and set the properties.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="comparisonType"></param>
        /// <param name="target"></param>
        public IfStatement(string source, ComparisonTypeEnum comparisonType, string target, int level)
        {
            // Set the properties
            this.Source         = source;
            this.ComparisonType = comparisonType;
            this.Target         = target;
            this.Level          = level;

            // Perform initializations for this object
            Init();
        }
Beispiel #4
0
        /// <summary>
        /// This method returns the Comparison Type
        /// </summary>
        private static ComparisonTypeEnum GetComparisonType(string op)
        {
            // initial value
            ComparisonTypeEnum comparisonType = ComparisonTypeEnum.NotSet;

            // determine the operator
            switch (op)
            {
            case ">":

                // set the return value
                comparisonType = ComparisonTypeEnum.GreaterThan;

                // required
                break;

            case ">=":

                // set the return value
                comparisonType = ComparisonTypeEnum.GreaterThanOrEqual;

                // required
                break;

            case "==":

                // set the return value
                comparisonType = ComparisonTypeEnum.Equal;

                // required
                break;

            case "<=":

                // set the return value
                comparisonType = ComparisonTypeEnum.LessThanOrEqual;

                // required
                break;

            case "<":

                // set the return value
                comparisonType = ComparisonTypeEnum.LessThan;

                // required
                break;
            }

            // return value
            return(comparisonType);
        }
        /// <summary>
        /// Compares the starts with.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="compareType">Type of the compare.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool CompareStartsWith(string left, string right, ComparisonTypeEnum compareType)
        {
            var list = right.Split(new char[] { '|' }, StringSplitOptions.None);

            if (compareType == ComparisonTypeEnum.Datetime)
            {
                return(CompareDateTime(left, right));
            }

            throw new NotImplementedException("Compare option not implimented.");
#pragma warning disable CS0162 // Unreachable code detected
            return(left == right);

#pragma warning restore CS0162 // Unreachable code detected
        }
        /// <summary>
        /// Compares the equal.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="compareType">Type of the compare.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool CompareEqual(string left, string right, ComparisonTypeEnum compareType, int leftZone, int rightZone)
        {
            var list = right.Split(new char[] { '|' }, StringSplitOptions.None);

            if (compareType == ComparisonTypeEnum.Datetime)
            {
                return(CompareDateTime(left, right, leftZone, rightZone));
            }
            else if (compareType == ComparisonTypeEnum.Date)
            {
                return(CompareDate(left, right));
            }
            else if (compareType == ComparisonTypeEnum.Integer)
            {
                return(CompareInteger(left, right));
            }


            return(left == right);
        }
        /// <summary>
        /// Determines whether the specified left is equal.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="compareType">Type of the compare.</param>
        /// <param name="operator">The operator.</param>
        /// <returns><c>true</c> if the specified left is equal; otherwise, <c>false</c>.</returns>
        public static bool IsEqual(string left, string right, ComparisonTypeEnum compareType, OperatorEnums @operator, string ignoreChars, int leftZone, int rightZone)
        {
            right       = string.IsNullOrEmpty(right) ? string.Empty : right;
            left        = string.IsNullOrEmpty(left) ? string.Empty : left;
            ignoreChars = string.IsNullOrEmpty(ignoreChars) ? string.Empty : ignoreChars;

            ignoreChars.ToList().ForEach(@char => right = right.Replace(@char, ' '));
            ignoreChars.ToList().ForEach(@char => left  = left.Replace(@char, ' '));

            if (@operator == OperatorEnums.In)
            {
                return(CompareIn(left, right, compareType));
            }

            if (@operator == OperatorEnums.Table)
            {
                return(CompareTable(left, right, compareType, leftZone, rightZone));
            }

            if (@operator == OperatorEnums.Equals)
            {
                return(CompareEqual(left, right, compareType, leftZone, rightZone));
            }

            if (@operator == OperatorEnums.StartsWidth)
            {
                return(right.StartsWith(left));
            }

            if (@operator == OperatorEnums.EndsWidth)
            {
                return(right.EndsWith(left));
            }

            if (@operator == OperatorEnums.Contains)
            {
                return(right.Contains(left));
            }

            return(false);
        }
        /// <summary>
        /// Compares the tabe.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="compareType">Type of the compare.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool CompareTable(string left, string right, ComparisonTypeEnum compareType, int leftZone, int rightZone)
        {
            List <string> date1 = new List <string>();
            List <string> date2 = new List <string>();

            var list1 = left.Split(new char[] { '|' }, StringSplitOptions.None);
            var list2 = right.Split(new char[] { '|' }, StringSplitOptions.None);

            if (compareType == ComparisonTypeEnum.Datetime)
            {
                foreach (var item in list1)
                {
                    DateTime.TryParse(item, out DateTime d1);
                    date1.Add(d1.AddHours(leftZone).ToString());
                }
                foreach (var item in list2)
                {
                    DateTime.TryParse(item, out DateTime d2);
                    date2.Add(d2.AddHours(rightZone).ToString());
                }
                left  = string.Join("|", date1.ToArray());
                right = string.Join("|", date2.ToArray());
                list1 = left.Split(new char[] { '|' }, StringSplitOptions.None);
                list2 = right.Split(new char[] { '|' }, StringSplitOptions.None);
            }

            var o1 = string.Join("|", list1.OrderBy(o => o));
            var o2 = string.Join("|", list2.OrderBy(o => o));

            return(o1 == o2);


            // var count1 = list1.Except(list2).Count();
            //var count1 = list1.Except(list2).Count();

            //return list1.Except(list2).Count() == 0 && list2.Except(list1).Count() == 0;
        }
Beispiel #9
0
 /// <summary>
 /// Конструктор, вызываемый при создании фильтра-предиката
 /// для составных типов данных, содержащих определение свойства <paramref name="propName"/>.
 /// </summary>
 /// <param name="propName">Наименование свойства объекта типа <see cref="{T}"/>, по которому необходимо выполнить фильтрацию.</param>
 /// <param name="comparison">Тип операции сравнения.</param>
 /// <param name="val">Объект, с которым сравнивается значение свойства <paramref name="propName"/>.</param>
 public QFilter(string propName, ComparisonTypeEnum comparison, object val)
 {
     PropName   = propName;
     Comparison = comparison;
     Value      = val;
 }
Beispiel #10
0
 /// <summary>
 /// Конструктор, вызываемый при создании фильтра-предиката
 /// для простых (не составных) типов данных, не имеющих определений свойств.
 /// </summary>
 /// <param name="comparison">Тип операции сравнения.</param>
 /// <param name="val">Объект, с которым сравнивается значение элементов списка.</param>
 public QFilter(ComparisonTypeEnum comparison, object val)
 {
     PropName   = null;
     Comparison = comparison;
     Value      = val;
 }
Beispiel #11
0
        /// <summary>
        /// This method attempts to parse an IfStatement object out of the sourceCode given.
        /// </summary>
        public static IfStatement ParseIfStatement(string sourceCode, int level = 1)
        {
            // initial value
            IfStatement ifStatement = null;

            // local
            int                openParenCount  = 0;
            int                closeParenCount = 0;
            int                openParenIndex  = 0;
            int                closeParenIndex = 0;
            char               openParen       = OpenParenString[0];
            char               closeParen      = CloseParenString[0];
            int                len             = 0;
            string             innerCode       = "";
            string             source          = "";
            string             op             = "";
            string             target         = "";
            ComparisonTypeEnum comparisonType = ComparisonTypeEnum.NotSet;

            // if the sourceCode exists
            if (!String.IsNullOrEmpty(sourceCode))
            {
                // trim the sourceCode
                sourceCode = sourceCode.Trim();

                // if this is an ifStatement
                if (sourceCode.StartsWith("if"))
                {
                    // set the count of each character to make sure we have a valid ifStatement
                    openParenCount  = GetOccurrencesOfChar(sourceCode, openParen);
                    closeParenCount = GetOccurrencesOfChar(sourceCode, closeParen);

                    // if this is a 'Simple' IfStatement
                    if ((openParenCount == closeParenCount) && (openParenCount == 1))
                    {
                        // get the index of the openParen
                        openParenIndex  = sourceCode.IndexOf(openParen);
                        closeParenIndex = sourceCode.IndexOf(closeParen);
                        len             = closeParenIndex - openParenIndex - 1;

                        // set the inner code
                        innerCode = sourceCode.Substring(openParenIndex + 1, len);

                        // if the innerCode exists
                        if (!String.IsNullOrEmpty(innerCode))
                        {
                            // get the words
                            List <Word> words = CSharpCodeParser.ParseWords(innerCode);

                            // if the words collection existsre are exactly 3 words
                            if (words != null)
                            {
                                // if there is only one word
                                if (words.Count == 1)
                                {
                                    // set the sourceWord
                                    source = words[0].Text;

                                    // if this is a NotComparison
                                    bool isEqual = (!source.StartsWith("!"));

                                    // create the ifStatement
                                    ifStatement = new IfStatement(source, isEqual, level);
                                }
                                // if there are exactly 3 words
                                else if (words.Count == 3)
                                {
                                    // parse out the items that build the ifStatement
                                    source = words[0].Text;
                                    op     = words[1].Text;
                                    target = words[2].Text;

                                    // Get the comparisonType for the operator
                                    comparisonType = IfStatementParser.GetComparisonType(op);

                                    // now create the ifStatement
                                    ifStatement = new IfStatement(source, comparisonType, target, level);
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(ifStatement);
        }
        /// <summary>
        /// This method returns the Comparison Type
        /// </summary>
        public static ComparisonTypeEnum SetComparisonType(string text, ref PixelCriteria pixelCriteria)
        {
            // initial value
            ComparisonTypeEnum comparisonType = ComparisonTypeEnum.Unknown;

            // locals
            int number1 = -1000;
            int number2 = -1000;
            int number3 = -1000;
            int number4 = -1000;

            // if the text exists
            if ((TextHelper.Exists(text)) && (NullHelper.Exists(pixelCriteria)))
            {
                // drawing is different for DrawLine
                if (pixelCriteria.PixelType == PixelTypeEnum.DrawLine)
                {
                    // Parse out the numbers from the text
                    ParseNumbers(text, ref number1, ref number2, ref number3, ref number4);

                    // Set the Start and End Point
                    pixelCriteria.StartPoint = new Point(number1, number2);
                    pixelCriteria.EndPoint   = new Point(number3, number4);
                }
                else
                {
                    // Parse out the numbers from the text
                    ParseNumbers(text, ref number1, ref number2);

                    // if the text contains less than
                    if (text.Contains("<"))
                    {
                        // Set to Less Than
                        comparisonType = ComparisonTypeEnum.LessThan;

                        // Set the MaxValue
                        pixelCriteria.MaxValue = number1;
                    }
                    // if the text contains between
                    else if (text.Contains("between"))
                    {
                        // Set to Between
                        comparisonType = ComparisonTypeEnum.Between;

                        // Set the MinValue
                        pixelCriteria.MinValue = number1;

                        // Set the MaxValue
                        pixelCriteria.MaxValue = number2;
                    }
                    // if the text contains greater than
                    else if (text.Contains(">"))
                    {
                        // Set to Greater Than
                        comparisonType = ComparisonTypeEnum.GreaterThan;

                        // Set the MinValue
                        pixelCriteria.MinValue = number1;
                    }
                    else if (text.Contains("="))
                    {
                        // Set to Equals
                        comparisonType = ComparisonTypeEnum.Equals;

                        // Set the TargetValue
                        pixelCriteria.TargetValue = number1;
                    }
                }

                // set the comparisonType on the object passed in
                pixelCriteria.ComparisonType = comparisonType;
            }

            // return value
            return(comparisonType);
        }