Example #1
0
        /// <summary>
        /// Checks the condition.
        /// </summary>
        /// <param name="expectedValue">Expected value for the condition</param>
        /// <param name="actualValue">Actual value for the condition</param>
        /// <returns>
        /// <c>true</c> if the value satisfy the condition; otherwise, <c>false</c>.
        /// </returns>
        bool CheckCondition(object expectedValue, object actualValue)
        {
            TimeSpan?nullable = null;

            if (actualValue is DateTime)
            {
                DateTime time  = (DateTime)actualValue;
                DateTime time2 = (DateTime)actualValue;
                DateTime time3 = (DateTime)actualValue;
                DateTime time4 = (DateTime)actualValue;
                nullable = new TimeSpan(0, time.Hour, time2.Minute, time3.Second, time4.Millisecond);
            }
            else if (actualValue is TimeSpan)
            {
                nullable = new TimeSpan?((TimeSpan)actualValue);
            }
            if ((actualValue == null) || actualValue.Equals(string.Empty))
            {
                return(this.IgnoreBlank);
            }
            if (actualValue is string)
            {
                try
                {
                    nullable = new TimeSpan?(ConditionValueConverter.ToTimeSpan(actualValue));
                }
                catch (InvalidCastException)
                {
                    return(false);
                }
            }
            if (nullable.HasValue)
            {
                if (!nullable.HasValue && (expectedValue != null))
                {
                    return(false);
                }
                try
                {
                    if (nullable.HasValue)
                    {
                        TimeSpan span;
                        if (expectedValue is TimeSpan)
                        {
                            span = (TimeSpan)expectedValue;
                        }
                        else
                        {
                            DateTime?nullable2 = ConditionValueConverter.TryDateTime(expectedValue);
                            if (!nullable2.HasValue)
                            {
                                return(false);
                            }
                            span = new TimeSpan(0, nullable2.Value.Hour, nullable2.Value.Minute, nullable2.Value.Second, nullable2.Value.Millisecond);
                        }
                        switch (this.CompareType)
                        {
                        case DateCompareType.EqualsTo:
                            return(this.IsEquals(span, nullable.Value));

                        case DateCompareType.NotEqualsTo:
                            return(!this.IsEquals(span, nullable.Value));

                        case DateCompareType.Before:
                            return(this.IsBefore(span, nullable.Value));

                        case DateCompareType.BeforeEqualsTo:
                            return(this.IsBefore(span, nullable.Value) || this.IsEquals(span, nullable.Value));

                        case DateCompareType.After:
                            return(this.IsAfter(span, nullable.Value));

                        case DateCompareType.AfterEqualsTo:
                            return(this.IsAfter(span, nullable.Value) || this.IsEquals(span, nullable.Value));
                        }
                    }
                }
                catch
                {
                }
            }
            return(false);
        }