public FilterOptions(string col, ComparisonType type, string val) : this() { Col = col; Val = val; Type = type; }
private string comparisonTypeToString(ComparisonType type) { string result = ""; switch (type) { case ComparisonType.E: { result = "="; break; } case ComparisonType.NE: { result = "!="; break; } case ComparisonType.GT: { result = ">"; break; } case ComparisonType.GTE: { result = ">="; break; } case ComparisonType.LS: { result = "<"; break; } case ComparisonType.LSE: { result = "<="; break; } } return result; }
public WhereItem(string field, object value, ComparisonType comparisonType=ComparisonType.Equal,bool parameterize=true) { Field = field; ComparisonType = comparisonType; Value = value; Parameterize = parameterize; }
/// <summary> /// Compares to the given value returning true if comparable. /// </summary> /// <param name="value">The value.</param> /// <param name="compareValue">The compare value.</param> /// <param name="compareType">Type of the compare.</param> /// <returns></returns> public static bool CompareTo( this string value, string compareValue, ComparisonType compareType ) { // Evaluate compare types that are not type specific switch ( compareType ) { case ComparisonType.Contains: return value.Contains( compareValue ); case ComparisonType.DoesNotContain: return !value.Contains( compareValue ); case ComparisonType.StartsWith: return value.StartsWith( compareValue, StringComparison.OrdinalIgnoreCase ); case ComparisonType.EndsWith: return value.EndsWith( compareValue, StringComparison.OrdinalIgnoreCase ); case ComparisonType.IsBlank: return string.IsNullOrWhiteSpace( value ); case ComparisonType.IsNotBlank: return !string.IsNullOrWhiteSpace( value ); case ComparisonType.RegularExpression: return Regex.IsMatch( value, compareValue ); } // numeric compares decimal? decimalValue = value.AsDecimalOrNull(); decimal? decimalCompareValue = compareValue.AsDecimalOrNull(); if ( decimalValue.HasValue && decimalCompareValue.HasValue ) { switch ( compareType ) { case ComparisonType.EqualTo: return decimalValue == decimalCompareValue; case ComparisonType.GreaterThan: return decimalValue.Value > decimalCompareValue.Value; case ComparisonType.GreaterThanOrEqualTo: return decimalValue.Value >= decimalCompareValue.Value; case ComparisonType.LessThan: return decimalValue.Value < decimalCompareValue.Value; case ComparisonType.LessThanOrEqualTo: return decimalValue.Value <= decimalCompareValue.Value; case ComparisonType.NotEqualTo: return decimalValue.Value != decimalCompareValue.Value; } } // date time compares DateTime? datetimeValue = value.AsDateTime(); DateTime? datetimeCompareValue = compareValue.AsDateTime(); if ( datetimeValue.HasValue && datetimeCompareValue.HasValue ) { switch ( compareType ) { case ComparisonType.EqualTo: return datetimeValue == datetimeCompareValue; case ComparisonType.GreaterThan: return datetimeValue.Value > datetimeCompareValue.Value; case ComparisonType.GreaterThanOrEqualTo: return datetimeValue.Value >= datetimeCompareValue.Value; case ComparisonType.LessThan: return datetimeValue.Value < datetimeCompareValue.Value; case ComparisonType.LessThanOrEqualTo: return datetimeValue.Value <= datetimeCompareValue.Value; case ComparisonType.NotEqualTo: return datetimeValue.Value != datetimeCompareValue.Value; } } // string compares switch ( compareType ) { case ComparisonType.EqualTo: return value.Equals( compareValue, StringComparison.OrdinalIgnoreCase ); case ComparisonType.GreaterThan: return value.CompareTo( compareValue ) > 0; case ComparisonType.GreaterThanOrEqualTo: return value.CompareTo( compareValue ) >= 0; case ComparisonType.LessThan: return value.CompareTo( compareValue ) < 0; case ComparisonType.LessThanOrEqualTo: return value.CompareTo( compareValue ) <= 0; case ComparisonType.NotEqualTo: return !value.Equals( compareValue, StringComparison.OrdinalIgnoreCase ); } return false; }
public ConditionMaterial(string target, ComparisonType targetComp, string calc, int needCount,ComparisonType countComp) { Target = target; TargetComparison = targetComp; Calc = calc; NeedCount = needCount; CountComparison = countComp; }
public RangeIfClientAttribute(int minimum, int maximum, string otherProperty, ComparisonType comparisonType, object otherComparisonValue) { Minimum = minimum; Maximum = maximum; OtherProperty = otherProperty; ComparisonType = comparisonType; OtherComparisonValue = otherComparisonValue; }
public Comparison(ComparisonType t, object controlTarget, string controlXPath, object controlValue, object testTarget, string testXPath, object testValue) { type = t; control = new Detail(controlTarget, controlXPath, controlValue); test = new Detail(testTarget, testXPath, testValue); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="value"></param> public ComparisonFilter(ComparisonType type, object value) { IComparable r1 = value as IComparable; if (value != null && r1 == null) { throw new ArgumentException("value is not IComparable", "value"); } m_comparionType = type; m_value = r1; }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionAttribute" /> class with and expected exception type and a message that describes the exception.</summary> /// <param name="exceptionType">An expected type of exception to be thrown by a method.</param> /// <param name="expectedMessage">Message expected to be returned in exception</param> /// <param name="comparisonType">The manner in which the message is evaluated</param> /// <param name="noExceptionMessage">The message to be displayed when no exception occurs in test</param> public ExceptionExpectedAttribute(Type exceptionType, string expectedMessage, ComparisonType comparisonType, string noExceptionMessage) : base(noExceptionMessage) { if (exceptionType == null) throw new ArgumentNullException(nameof(exceptionType)); if (string.IsNullOrEmpty(expectedMessage)) throw new ArgumentNullException(nameof(expectedMessage)); ExceptionType = exceptionType; ExceptionMessage = expectedMessage; ExceptionComparisonType = comparisonType; }
/// <summary> /// Get account recordings /// </summary> /// <param name="dateCreated">Lists all recordings created on or after a certain date. </param> /// <param name="dateCreatedComparasion">Date created comparasion</param> /// <param name="page">Used to return a particular page withing the list.</param> /// <param name="pageSize">Used to specify the amount of list items to return per page.</param> /// <returns></returns> public async Task<RecordingResult> GetAccountRecordings(DateTime? dateCreated, ComparisonType? dateCreatedComparasion, int? page, int? pageSize) { var request = new RestRequest(); request.Resource = RequestUri.AccountRecordingsUri; var dateCreatedParameterName = GetParameterNameWithEquality(dateCreatedComparasion, "DateCreated"); if (dateCreated.HasValue) request.AddParameter(dateCreatedParameterName, dateCreated.Value.ToString("yyyy-MM-dd")); if (page.HasValue) request.AddParameter("Page", page); if (pageSize.HasValue) request.AddParameter("PageSize", pageSize); return await Execute<RecordingResult>(request); }
public static bool Like(this string source, string compareTo, ComparisonType comparisonType) { switch (comparisonType) { case ComparisonType.Contains: return source.Contains(compareTo); case ComparisonType.EndsWith: return source.EndsWith(compareTo); case ComparisonType.StartsWith: return source.StartsWith(compareTo); default: throw new InvalidOperationException(); } }
public void Comparison(ComparisonType comp) { switch (comp) { case ComparisonType.Between: _writer.Write(" BETWEEN "); break; case ComparisonType.Contains: case ComparisonType.EndsWith: case ComparisonType.Like: case ComparisonType.StartsWith: _writer.Write(" LIKE "); break; case ComparisonType.Equal: _writer.Write(" = "); break; case ComparisonType.GreaterThan: _writer.Write(" > "); break; case ComparisonType.GreaterThanEqual: _writer.Write(" >= "); break; case ComparisonType.In: _writer.Write(" IN "); break; case ComparisonType.IsNotNull: _writer.Write(" IS NOT "); _writer.Null(); _writer.Write(" "); break; case ComparisonType.IsNull: _writer.Write(" IS "); _writer.Null(); _writer.Write(" "); break; case ComparisonType.LessThan: _writer.Write(" < "); break; case ComparisonType.LessThanEqual: _writer.Write(" <= "); break; case ComparisonType.NotEqual: _writer.Write(" <> "); break; case ComparisonType.NotLike: throw new NotSupportedException(); } _lastComparison = comp; }
public NotenizerDependency( NotenizerWord governor, NotenizerWord dependent, NotenizerRelation relation, int position, ComparisonType comparisonType, TokenType tokenType) { _governor = governor; _dependent = dependent; _relation = relation; _position = position; _comparisonType = comparisonType; _tokenType = tokenType; }
public ArrayList GetData(object key, ComparisonType comparisonType) { RedBlack.COMPARE compare = RedBlack.COMPARE.EQ; ArrayList result = new ArrayList(); if (_rbTree != null) { switch (comparisonType) { case ComparisonType.EQUALS: compare = RedBlack.COMPARE.EQ; break; case ComparisonType.NOT_EQUALS: compare = RedBlack.COMPARE.NE; break; case ComparisonType.LESS_THAN: compare = RedBlack.COMPARE.LT; break; case ComparisonType.GREATER_THAN: compare = RedBlack.COMPARE.GT; break; case ComparisonType.LESS_THAN_EQUALS: compare = RedBlack.COMPARE.LTEQ; break; case ComparisonType.GREATER_THAN_EQUALS: compare = RedBlack.COMPARE.GTEQ; break; case ComparisonType.LIKE: compare = RedBlack.COMPARE.REGEX; break; case ComparisonType.NOT_LIKE: compare = RedBlack.COMPARE.IREGEX; break; } result = _rbTree.GetData(key as IComparable, compare) as ArrayList; } return result; }
/// <summary> /// Return list of all conference resources associated with a given account /// </summary> /// <param name="friendlyName">List conferences with the given FriendlyName.</param> /// <param name="status">List conferences with the given status.</param> /// <param name="dateCreated">List conferences created on, after, or before a given date.</param> /// <param name="dateCreatedComparasion">Date range can be specified using inequalities.</param> /// <param name="dateUpdated">List conferences updated on, after, or before a given date.</param> /// <param name="dateUpdatedComparasion">Date range can be specified using inequalities.</param> /// <param name="page">Used to return a particular page withing the list.</param> /// <param name="pageSize">Used to specify the amount of list items to return per page.</param> /// <returns></returns> public ConferenceResult GetConferences(string friendlyName, ConferenceStatus? status, DateTime? dateCreated, ComparisonType? dateCreatedComparasion, DateTime? dateUpdated, ComparisonType? dateUpdatedComparasion, int? page, int?pageSize) { var request = new RestRequest(); request.Resource = RequestUri.ConferencesUri; var dateCreatedParameterName = GetParameterNameWithEquality(dateCreatedComparasion, "DateCreated"); var dateUpdatedParemeterName = GetParameterNameWithEquality(dateUpdatedComparasion, "DateUpdated"); if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); if (status.HasValue) request.AddParameter("Status", status.ToString().ToLower()); if (dateCreated.HasValue) request.AddParameter(dateCreatedParameterName, dateCreated.Value.ToString("yyyy-MM-dd")); if (dateUpdated.HasValue) request.AddParameter(dateUpdatedParemeterName, dateUpdated.Value.ToString("yyyy-MM-dd")); if (page.HasValue) request.AddParameter("Page", page); if (pageSize.HasValue) request.AddParameter("PageSize", pageSize); return Execute<ConferenceResult>(request); }
// Create a new key comparer. public static IKeyComparer CreateKeyComparer(ComparisonType comparisonType) { switch(comparisonType) { case ComparisonType.CurrentCulture: { return new KeyComparer (new Comparer(CultureInfo.CurrentCulture), defaultHashCodeProvider); } case ComparisonType.CurrentCultureIgnoreCase: { return new KeyComparer (new CaseInsensitiveComparer (CultureInfo.CurrentCulture), new CaseInsensitiveHashCodeProvider (CultureInfo.CurrentCulture)); } case ComparisonType.InvariantCulture: { return new KeyComparer (Comparer.DefaultInvariant, defaultHashCodeProvider); } case ComparisonType.InvariantCultureIgnoreCase: { return new KeyComparer (CaseInsensitiveComparer.DefaultInvariant, CaseInsensitiveHashCodeProvider.DefaultInvariant); } default: { return new KeyComparer (new OrdinalComparer(), defaultHashCodeProvider); } } }
public static bool Compare(ComparisonType comptype, object e1, object e2) { if(e1 is string && e2 is char) e2 = e2.ToString(); else if(e2 is string && e1 is char) e1 = e1.ToString(); switch(comptype) { case ComparisonType.Equal: return IsEqual(e1, e2); case ComparisonType.NonEqual: return !IsEqual(e1, e2); case ComparisonType.Less: return (Compare(e1, e2) < 0M); case ComparisonType.LessOrEqual: return (Compare(e1, e2) <= 0M); case ComparisonType.GreaterOrEqual: return (Compare(e1, e2) >= 0M); case ComparisonType.Greater: return (Compare(e1, e2) > 0M); } throw new NotImplementedException(); }
public TimeComparison(ITimeable leftSide, ITimeable rightSide, ComparisonType type) { this.leftSide = leftSide; this.rightSide = rightSide; this.type = type; }
/// <summary> /// Compares to the given value returning true if comparable. /// </summary> /// <param name="value">The value.</param> /// <param name="compareValue">The compare value.</param> /// <param name="compareType">Type of the compare.</param> /// <returns></returns> public static bool CompareTo(this string value, string compareValue, ComparisonType compareType) { if (compareType == ComparisonType.Contains) { return(value.Contains(compareValue)); } if (compareType == ComparisonType.DoesNotContain) { return(!value.Contains(compareValue)); } if (compareType == ComparisonType.StartsWith) { return(value.StartsWith(compareValue, StringComparison.OrdinalIgnoreCase)); } if (compareType == ComparisonType.EndsWith) { return(value.EndsWith(compareValue, StringComparison.OrdinalIgnoreCase)); } if (compareType == ComparisonType.IsBlank) { return(string.IsNullOrWhiteSpace(value)); } if (compareType == ComparisonType.IsNotBlank) { return(!string.IsNullOrWhiteSpace(value)); } // Following compares could be numeric decimal?decimalValue = value.AsDecimalOrNull(); decimal?decimalCompareValue = compareValue.AsDecimalOrNull(); if (compareType == ComparisonType.EqualTo) { if (decimalValue.HasValue && decimalCompareValue.HasValue) { return(decimalValue.Value == decimalCompareValue.Value); } return(value.Equals(compareValue, StringComparison.OrdinalIgnoreCase)); } if (compareType == ComparisonType.GreaterThan) { if (decimalValue.HasValue && decimalCompareValue.HasValue) { return(decimalValue.Value > decimalCompareValue.Value); } return(value.CompareTo(compareValue) > 0); } if (compareType == ComparisonType.GreaterThanOrEqualTo) { if (decimalValue.HasValue && decimalCompareValue.HasValue) { return(decimalValue.Value >= decimalCompareValue.Value); } return(value.CompareTo(compareValue) >= 0); } if (compareType == ComparisonType.LessThan) { if (decimalValue.HasValue && decimalCompareValue.HasValue) { return(decimalValue.Value < decimalCompareValue.Value); } return(value.CompareTo(compareValue) < 0); } if (compareType == ComparisonType.LessThanOrEqualTo) { if (decimalValue.HasValue && decimalCompareValue.HasValue) { return(decimalValue.Value >= decimalCompareValue.Value); } return(value.CompareTo(compareValue) <= 0); } if (compareType == ComparisonType.NotEqualTo) { if (decimalValue.HasValue && decimalCompareValue.HasValue) { return(decimalValue.Value != decimalCompareValue.Value); } return(!value.Equals(compareValue, StringComparison.OrdinalIgnoreCase)); } return(false); }
private string GetDetails(Comparison.Detail detail, ComparisonType type) { return(comparisonFormatter.GetDetails(detail, type, formatXml)); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyIfAttribute" /> class. /// </summary> /// <param name="dependentProperty">The dependent property in the model that this object is dependent on.</param> /// <param name="comparisonType">The comparison type to use.</param> /// <param name="dependentValue">The value to compare against.</param> public ReadOnlyIfAttribute(string dependentProperty, ComparisonType comparisonType, object dependentValue) : base(ActionForDependencyType.Disabled, dependentProperty, comparisonType, dependentValue) { }
public ComparisonCondition(ColumnSpec left, ComparisonType comparison, string right) { this.left = left; this.comparison = comparison; this.right = ColumnOrValue.createValue(right); }
private string GetShortString(XmlNode node, string xpath, ComparisonType type) { StringBuilder sb = new StringBuilder(); if (type == ComparisonType.HAS_DOCTYPE_DECLARATION) { XmlDocument doc = node as XmlDocument; AppendDocumentType(sb, doc.DocumentType); AppendDocumentElementIndication(sb, doc); } else if (node is XmlDocument) { XmlDocument doc = node as XmlDocument; AppendDocumentXmlDeclaration(sb, doc.FirstChild as XmlDeclaration); AppendDocumentElementIndication(sb, doc); } else if (node is XmlDeclaration) { XmlDeclaration dec = node as XmlDeclaration; AppendDocumentXmlDeclaration(sb, dec); AppendDocumentElementIndication(sb, dec.OwnerDocument); } else if (node is XmlDocumentType) { XmlDocumentType docType = node as XmlDocumentType; AppendDocumentType(sb, docType); AppendDocumentElementIndication(sb, docType.OwnerDocument); } else if (node is XmlAttribute) { AppendAttribute(sb, node as XmlAttribute); } else if (node is XmlElement) { AppendElement(sb, node as XmlElement); } else if (node is XmlComment) { AppendComment(sb, node as XmlComment); } else if (node is XmlCharacterData) { AppendText(sb, node as XmlCharacterData); } else if (node is XmlProcessingInstruction) { AppendProcessingInstruction(sb, node as XmlProcessingInstruction); } else if (node == null) { sb.Append("<NULL>"); } else { sb.Append("<!--NodeType ").Append(node.NodeType) .Append(' ').Append(node.Name) .Append('/').Append(node.Value) .Append("-->"); } if (!string.IsNullOrEmpty(xpath)) { sb.Append(" at ").Append(xpath); } return(sb.ToString()); }
public FilterOptions(string col, ComparisonType ct, string val) { Column = col; Value = val; CompType = ct; }
public IWhereClause Add(string field, object value, ComparisonType comparisonType, JoinType joinType, bool parameterize = true) { IWhereItem crit; crit = new WhereItem(field, value, comparisonType); MergeWhere(crit, joinType); return this; }
/// <summary> /// Realiza a junção dos indices associados aos tipos informados. /// </summary> /// <param name="leftTypeName">Nome do tipo da esquerda.</param> /// <param name="leftFieldName">Nome do campo do tipo da esquerda.</param> /// <param name="rightTypeName">Nome do tipo da direita.</param> /// <param name="rightFieldName">Nome do campo do tipo da direita.</param> /// <param name="comparisonType">Tipo de comparação que será utilizado.</param> /// <returns></returns> public override IEnumerable <object[]> JoinIndex(string leftTypeName, string leftFieldName, string rightTypeName, string rightFieldName, ComparisonType comparisonType) { return(this.Internal.JoinIndex(leftTypeName, leftFieldName, rightTypeName, rightFieldName, comparisonType)); }
public RequiredIfClientAttribute(string otherProperty, ComparisonType comparisonType, object otherComparisonValue) { OtherProperty = otherProperty; ComparisonType = comparisonType; OtherComparisonValue = otherComparisonValue; }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var rockContext = ( RockContext )serviceInstance.Context; var selectionConfig = SelectionConfig.Parse(selection) ?? new SelectionConfig(); ComparisonType comparisonType = selectionConfig.ComparisonType; decimal amount = selectionConfig.Amount ?? 0.00M; DateRange dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(selectionConfig.SlidingDateRangePickerDelimitedValues); var accountGuids = selectionConfig.AccountGuids; List <int> accountIdList; if (accountGuids != null && accountGuids.Any()) { var financialAccountService = new FinancialAccountService(( RockContext )serviceInstance.Context); accountIdList = financialAccountService.GetByGuids(accountGuids).Select(a => a.Id).ToList(); if (selectionConfig.IncludeChildAccounts) { var parentAccountIds = accountIdList.ToList(); foreach (var parentAccountId in parentAccountIds) { var descendantChildAccountIds = financialAccountService.GetAllDescendentIds(parentAccountId); accountIdList.AddRange(descendantChildAccountIds); } } } else { accountIdList = new List <int>(); } bool combineGiving = selectionConfig.CombineGiving; int transactionTypeContributionId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()).Id; bool useAnalyticsModels = selectionConfig.UseAnalyticsModels; IQueryable <TransactionDetailData> financialTransactionDetailBaseQry; if (useAnalyticsModels) { financialTransactionDetailBaseQry = new AnalyticsSourceFinancialTransactionService(rockContext).Queryable() .Where(xx => xx.AuthorizedPersonAliasId.HasValue) .Where(xx => xx.TransactionTypeValueId == transactionTypeContributionId) .Select(ss => new TransactionDetailData { AuthorizedPersonAliasId = ss.AuthorizedPersonAliasId.Value, TransactionDateTime = ss.TransactionDateTime, Amount = ss.Amount, AccountId = ss.AccountId ?? 0 }); } else { financialTransactionDetailBaseQry = new FinancialTransactionDetailService(rockContext).Queryable() .Where(xx => xx.Transaction.AuthorizedPersonAliasId.HasValue) .Where(xx => xx.Transaction.TransactionDateTime.HasValue) .Where(xx => xx.Transaction.TransactionTypeValueId == transactionTypeContributionId) .Select(ss => new TransactionDetailData { AuthorizedPersonAliasId = ss.Transaction.AuthorizedPersonAliasId.Value, TransactionDateTime = ss.Transaction.TransactionDateTime.Value, Amount = ss.Amount, AccountId = ss.AccountId }); } if (dateRange.Start.HasValue) { financialTransactionDetailBaseQry = financialTransactionDetailBaseQry.Where(xx => xx.TransactionDateTime >= dateRange.Start.Value); } if (dateRange.End.HasValue) { financialTransactionDetailBaseQry = financialTransactionDetailBaseQry.Where(xx => xx.TransactionDateTime < dateRange.End.Value); } if (accountIdList.Any()) { if (accountIdList.Count() == 1) { var accountId = accountIdList[0]; financialTransactionDetailBaseQry = financialTransactionDetailBaseQry.Where(x => accountId == x.AccountId); } else { financialTransactionDetailBaseQry = financialTransactionDetailBaseQry.Where(x => accountIdList.Contains(x.AccountId)); } } if (selectionConfig.IgnoreInactiveAccounts) { var inactiveAccountIdQuery = new FinancialAccountService(rockContext).Queryable().Where(a => !a.IsActive).Select(a => a.Id); financialTransactionDetailBaseQry = financialTransactionDetailBaseQry.Where(a => !inactiveAccountIdQuery.Contains(a.AccountId)); } bool excludePersonsWithTransactions = false; // Create explicit joins to person alias and person tables so that rendered SQL has an INNER Joins vs OUTER joins on Person and PersonAlias var personAliasQry = new PersonAliasService(rockContext).Queryable(); var personQryForJoin = new PersonService(rockContext).Queryable(true); var financialTransactionDetailAmountQry = financialTransactionDetailBaseQry .Join( personAliasQry, t => t.AuthorizedPersonAliasId, pa => pa.Id, (t, pa) => new { TransactionDetailData = t, PersonId = pa.PersonId }) .Join( personQryForJoin, j1 => j1.PersonId, p => p.Id, (j1, p) => new { Amount = j1.TransactionDetailData.Amount, Person = p }); IQueryable <GiverAmountInfo> financialTransactionGivingAmountQry; if (combineGiving) { var financialTransactionGroupByQuery = financialTransactionDetailAmountQry.GroupBy(xx => xx.Person.GivingId); financialTransactionGivingAmountQry = financialTransactionGroupByQuery .Select(xx => new GiverAmountInfo { GivingId = xx.Key, TotalAmount = xx.Sum(ss => ss.Amount) }); } else { var financialTransactionGroupByQuery = financialTransactionDetailAmountQry.GroupBy(xx => xx.Person.Id); financialTransactionGivingAmountQry = financialTransactionGroupByQuery .Select(xx => new GiverAmountInfo { PersonId = xx.Key, TotalAmount = xx.Sum(ss => ss.Amount) }); } if (comparisonType == ComparisonType.LessThan) { // NOTE: Since we want people that have less than the specified, but also want to include people to didn't give anything at all (no transactions) // make this query the same as the GreaterThan, but use it to EXCLUDE people that gave MORE than the specified amount. That // way the filter will include people that had no transactions for the specified date/range and account financialTransactionGivingAmountQry = financialTransactionGivingAmountQry.Where(xx => xx.TotalAmount >= amount); excludePersonsWithTransactions = true; } else if (comparisonType == ComparisonType.EqualTo) { if (amount == 0.00M) { // NOTE: If we want to list people that gave $0.00 (they didn't giving anything) // EXCLUDE people that gave any amount excludePersonsWithTransactions = true; } else { financialTransactionGivingAmountQry = financialTransactionGivingAmountQry.Where(xx => xx.TotalAmount == amount); } } else if (comparisonType == ComparisonType.GreaterThanOrEqualTo) { // NOTE: if the amount filter is 'they gave $0.00 or more', and doing a GreaterThanOrEqualTo, then we don't need to calculate and compare against TotalAmount if (amount == 0.00M) { // no need to filter by amount if greater than or equal to $0.00 } else { financialTransactionGivingAmountQry = financialTransactionGivingAmountQry.Where(xx => xx.TotalAmount >= amount); } } IQueryable <Model.Person> qry; if (combineGiving) { if (excludePersonsWithTransactions) { // the filter is for people that gave LESS than the specified amount, so return people that didn't give MORE than the specified amount qry = new PersonService(rockContext).Queryable().Where(p => !financialTransactionGivingAmountQry.Any(xx => xx.GivingId == p.GivingId)); } else { qry = new PersonService(rockContext).Queryable().Where(p => financialTransactionGivingAmountQry.Any(xx => xx.GivingId == p.GivingId)); } } else { if (excludePersonsWithTransactions) { // the filter is for people that gave LESS than the specified amount, so return people that didn't give MORE than the specified amount qry = new PersonService(rockContext).Queryable().Where(p => !financialTransactionGivingAmountQry.Any(xx => xx.PersonId == p.Id)); } else { qry = new PersonService(rockContext).Queryable().Where(p => financialTransactionGivingAmountQry.Any(xx => xx.PersonId == p.Id)); } } Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); }
/// <summary> /// Constructor /// </summary> /// <param name="PropertyName">Property to compare to</param> /// <param name="Type">Comparison type to use</param> /// <param name="ErrorMessage">Error message</param> public CompareToAttribute(string PropertyName, ComparisonType Type, string ErrorMessage = "") : base(string.IsNullOrEmpty(ErrorMessage) ? "{0} is not {1} {2}" : ErrorMessage) { this.PropertyName = PropertyName; this.Type = Type; }
public string GetValue(ExecutionContext context) { return(ComparisonType.Calculate(TargetAction1Holder.Action, TargetAction2Holder.Action, context) ? ToggleValueType.ValueON : ToggleValueType.ValueOFF); }
public KeyedCollection(ComparisonType comparisonType, int capacity) : base(comparisonType, capacity) {}
/// <summary> /// Compares to the given value returning true if comparable. /// </summary> /// <param name="value">The value.</param> /// <param name="compareValue">The compare value.</param> /// <param name="compareType">Type of the compare.</param> /// <returns></returns> public static bool CompareTo(this string value, string compareValue, ComparisonType compareType) { // Evaluate compare types that are not type specific switch (compareType) { case ComparisonType.Contains: return(value.Contains(compareValue)); case ComparisonType.DoesNotContain: return(!value.Contains(compareValue)); case ComparisonType.StartsWith: return(value.StartsWith(compareValue, StringComparison.OrdinalIgnoreCase)); case ComparisonType.EndsWith: return(value.EndsWith(compareValue, StringComparison.OrdinalIgnoreCase)); case ComparisonType.IsBlank: return(string.IsNullOrWhiteSpace(value)); case ComparisonType.IsNotBlank: return(!string.IsNullOrWhiteSpace(value)); case ComparisonType.RegularExpression: try { return(Regex.IsMatch(value, compareValue)); } catch { return(false); } } // numeric compares decimal?decimalValue = value.AsDecimalOrNull(); decimal?decimalCompareValue = compareValue.AsDecimalOrNull(); if (decimalValue.HasValue && decimalCompareValue.HasValue) { switch (compareType) { case ComparisonType.EqualTo: return(decimalValue == decimalCompareValue); case ComparisonType.GreaterThan: return(decimalValue.Value > decimalCompareValue.Value); case ComparisonType.GreaterThanOrEqualTo: return(decimalValue.Value >= decimalCompareValue.Value); case ComparisonType.LessThan: return(decimalValue.Value < decimalCompareValue.Value); case ComparisonType.LessThanOrEqualTo: return(decimalValue.Value <= decimalCompareValue.Value); case ComparisonType.NotEqualTo: return(decimalValue.Value != decimalCompareValue.Value); } } // date time compares DateTime?datetimeValue = value.AsDateTime(); DateTime?datetimeCompareValue = compareValue.AsDateTime(); if (datetimeValue.HasValue && datetimeCompareValue.HasValue) { switch (compareType) { case ComparisonType.EqualTo: return(datetimeValue == datetimeCompareValue); case ComparisonType.GreaterThan: return(datetimeValue.Value > datetimeCompareValue.Value); case ComparisonType.GreaterThanOrEqualTo: return(datetimeValue.Value >= datetimeCompareValue.Value); case ComparisonType.LessThan: return(datetimeValue.Value < datetimeCompareValue.Value); case ComparisonType.LessThanOrEqualTo: return(datetimeValue.Value <= datetimeCompareValue.Value); case ComparisonType.NotEqualTo: return(datetimeValue.Value != datetimeCompareValue.Value); } } // string compares switch (compareType) { case ComparisonType.EqualTo: return(value.Equals(compareValue, StringComparison.OrdinalIgnoreCase)); case ComparisonType.GreaterThan: return(value.CompareTo(compareValue) > 0); case ComparisonType.GreaterThanOrEqualTo: return(value.CompareTo(compareValue) >= 0); case ComparisonType.LessThan: return(value.CompareTo(compareValue) < 0); case ComparisonType.LessThanOrEqualTo: return(value.CompareTo(compareValue) <= 0); case ComparisonType.NotEqualTo: return(!value.Equals(compareValue, StringComparison.OrdinalIgnoreCase)); } return(false); }
public Application SubmitApplication(SecureSession session, Application application, string workflowState, string assignee = null, ComparisonType? assigneeType = null, int? submitPageId = null) { throw new NotImplementedException(); }
public ParameterWhereCriterion(string fieldName, string parameterName, ComparisonType comparisonType) : base(fieldName, "@" + parameterName, comparisonType) { }
internal ComparisonObject(ComparisonType comparisonType, ObjectType objectType, string name) { this.comparisonType = comparisonType; this.objectType = objectType; this.name = name; }
/// <summary> /// Gets a filter expression for an attribute value. /// </summary> /// <param name="configurationValues">The configuration values.</param> /// <param name="filterValues">The filter values.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <returns></returns> public override Expression AttributeFilterExpression(Dictionary <string, ConfigurationValue> configurationValues, List <string> filterValues, ParameterExpression parameterExpression) { Expression comparison = null; if (filterValues.Count > 1) { //// OR up the where clauses for each of the selected values // and make sure to wrap commas around things so we don't collide with partial matches // so it'll do something like this: // // WHERE ',' + Value + ',' like '%,bacon,%' // OR ',' + Value + ',' like '%,lettuce,%' // OR ',' + Value + ',' like '%,tomato,%' // should be either "Contains" or "Not Contains" or "IsBlank" ComparisonType comparisonType = filterValues[0].ConvertToEnum <ComparisonType>(ComparisonType.Contains); if (comparisonType == ComparisonType.EqualTo) { // If EqualTo was specified, treat it as Contains comparisonType = ComparisonType.Contains; } if (comparisonType == ComparisonType.NotEqualTo) { // If NotEqualTo was specified, treat it as DoesNotContain comparisonType = ComparisonType.DoesNotContain; } // No comparison value was specified, so we can filter if the Comparison Type using no value still makes sense if ((ComparisonType.IsBlank | ComparisonType.IsNotBlank).HasFlag(comparisonType)) { // Just checking if IsBlank or IsNotBlank, so let ComparisonExpression do its thing MemberExpression propertyExpression = Expression.Property(parameterExpression, this.AttributeValueFieldName); return(ComparisonHelper.ComparisonExpression(comparisonType, propertyExpression, AttributeConstantExpression(string.Empty))); } List <string> selectedValues = filterValues[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var selectedValue in selectedValues) { var searchValue = "," + selectedValue + ","; var qryToExtract = new AttributeValueService(new Data.RockContext()).Queryable().Where(a => ("," + a.Value + ",").Contains(searchValue)); var valueExpression = FilterExpressionExtractor.Extract <AttributeValue>(qryToExtract, parameterExpression, "a"); if (comparisonType != ComparisonType.Contains) { valueExpression = Expression.Not(valueExpression); } if (comparison == null) { comparison = valueExpression; } else { comparison = Expression.Or(comparison, valueExpression); } } } if (comparison == null) { return(new NoAttributeFilterExpression()); } return(comparison); }
private object GetValue(object value, ComparisonType type) { return(type == ComparisonType.NODE_TYPE ? NodeType((XmlNodeType)value) : value); }
protected KeyedCollectionBase(ComparisonType comparisonType) : this(KeyComparer.CreateKeyComparer(comparisonType), 16) { }
/// <summary> /// Initializes a new instance of the <see cref="ContingentValidationAttribute" /> class. /// </summary> /// <param name="dependentProperty">The dependent property in the model that this object is dependent on.</param> /// <param name="comparisonType">The comparison type to use.</param> /// <param name="dependentValue">The value to compare against.</param> protected ContingentValidationAttribute(string dependentProperty, ComparisonType comparisonType, object dependentValue) { DependentProperty = dependentProperty; ComparisonType = comparisonType; DependentValue = dependentValue; }
private ComparableValueGetter(IComparable left, object right, ComparisonType comparisonType) { _left = left; _right = right; _comparisonType = comparisonType; }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyIfAttribute" /> class. /// </summary> /// <remarks> /// This constructor implies the dependent property is the property decorated with this attribute (self-referencing). /// </remarks> /// <param name="comparisonType">The comparison type to use.</param> /// <param name="dependentValue">The value to compare against.</param> public ReadOnlyIfAttribute(ComparisonType comparisonType, object dependentValue) : base(ActionForDependencyType.Disabled, null, comparisonType, dependentValue) { }
/// <summary> /// Gets a dropdownlist of the supported comparison types /// </summary> /// <param name="supportedComparisonTypes">The supported comparison types.</param> /// <param name="required">if set to <c>true</c> [required].</param> /// <returns></returns> public static RockDropDownList ComparisonControl( ComparisonType supportedComparisonTypes, bool required = true ) { var ddl = new RockDropDownList(); if ( !required ) { ddl.Items.Add( new ListItem( string.Empty, "0" ) ); } foreach ( ComparisonType comparisonType in Enum.GetValues( typeof( ComparisonType ) ) ) { if ( ( supportedComparisonTypes & comparisonType ) == comparisonType ) { ddl.Items.Add( new ListItem( comparisonType.ConvertToString(), comparisonType.ConvertToInt().ToString() ) ); } } return ddl; }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var values = selection.Split('|'); ComparisonType comparisonType = values[0].ConvertToEnum <ComparisonType>(ComparisonType.EqualTo); string postalCode = values[1]; var familyGroupTypeGuid = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid(); var groupLocationQry = new GroupLocationService(( RockContext )serviceInstance.Context).Queryable(); switch (comparisonType) { case ComparisonType.EqualTo: groupLocationQry = groupLocationQry.Where(gl => gl.Location.PostalCode == postalCode); break; case ComparisonType.NotEqualTo: groupLocationQry = groupLocationQry.Where(gl => gl.Location.PostalCode != postalCode); break; case ComparisonType.StartsWith: groupLocationQry = groupLocationQry.Where(gl => gl.Location.PostalCode.StartsWith(postalCode)); break; case ComparisonType.Contains: groupLocationQry = groupLocationQry.Where(gl => gl.Location.PostalCode.Contains(postalCode)); break; case ComparisonType.DoesNotContain: groupLocationQry = groupLocationQry.Where(gl => !gl.Location.PostalCode.Contains(postalCode)); break; case ComparisonType.IsBlank: groupLocationQry = groupLocationQry .Where(gl => gl.Location.PostalCode == null || gl.Location.PostalCode == string.Empty); break; case ComparisonType.IsNotBlank: groupLocationQry = groupLocationQry .Where(gl => gl.Location.PostalCode != null && gl.Location.PostalCode != string.Empty); break; case ComparisonType.EndsWith: groupLocationQry = groupLocationQry.Where(gl => gl.Location.PostalCode.EndsWith(postalCode)); break; default: break; } IQueryable <Rock.Model.Person> qry; //Limit by location type if applicable if (values.Length >= 3 && values[2].AsInteger() != 0) { int locationTypeId = values[2].AsInteger(); groupLocationQry = groupLocationQry.Where(gl => gl.GroupLocationTypeValueId == locationTypeId); } var groupMemberQry = groupLocationQry.Select(gl => gl.Group) .Where(g => g.GroupType.Guid == familyGroupTypeGuid) .SelectMany(g => g.Members); // Families which do not have locations need to be added separately if (comparisonType == ComparisonType.IsBlank || comparisonType == ComparisonType.DoesNotContain || comparisonType == ComparisonType.NotEqualTo) { IQueryable <Model.GroupMember> noLocationGroupMembersQry; if (values.Length >= 3 && values[2].AsInteger() != 0) { int locationTypeId = values[2].AsInteger(); noLocationGroupMembersQry = new GroupService(( RockContext )serviceInstance.Context).Queryable() .Where(g => g.GroupType.Guid == familyGroupTypeGuid && !g.GroupLocations.Any(gl => gl.GroupLocationTypeValueId == locationTypeId)) .SelectMany(g => g.Members); } else { noLocationGroupMembersQry = new GroupService(( RockContext )serviceInstance.Context).Queryable() .Where(g => g.GroupType.Guid == familyGroupTypeGuid && !g.GroupLocations.Any()) .SelectMany(g => g.Members); } qry = new PersonService(( RockContext )serviceInstance.Context).Queryable() .Where(p => groupMemberQry.Any(xx => xx.PersonId == p.Id) || noLocationGroupMembersQry.Any(xx => xx.PersonId == p.Id)); } else { qry = new PersonService(( RockContext )serviceInstance.Context).Queryable() .Where(p => groupMemberQry.Any(xx => xx.PersonId == p.Id)); } Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); }
/// <summary> /// Constructor /// </summary> /// <param name="Value">Value to compare to</param> /// <param name="Type">Comparison type to use</param> /// <param name="ErrorMessage">Error message</param> public CompareAttribute(object Value, ComparisonType Type, string ErrorMessage = "") : base(string.IsNullOrEmpty(ErrorMessage) ? "{0} is not {1} {2}" : ErrorMessage) { this.Value = Value; this.Type = Type; }
/// <summary> /// Gets the expression. /// </summary> /// <param name="context">The context.</param> /// <param name="entityIdProperty">The entity identifier property.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override System.Linq.Expressions.Expression GetExpression(Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection) { string[] selectionValues = selection.Split('|'); if (selectionValues.Length < 4) { return(null); } ComparisonType comparisonType = selectionValues[0].ConvertToEnum <ComparisonType>(ComparisonType.GreaterThanOrEqualTo); decimal amount = selectionValues[1].AsDecimalOrNull() ?? 0.00M; DateRange dateRange; if (selectionValues.Length >= 7) { string slidingDelimitedValues = selectionValues[6].Replace(',', '|'); dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(slidingDelimitedValues); } else { // if converting from a previous version of the selection DateTime?startDate = selectionValues[2].AsDateTime(); DateTime?endDate = selectionValues[3].AsDateTime(); dateRange = new DateRange(startDate, endDate); if (dateRange.End.HasValue) { // the DateRange picker doesn't automatically add a full day to the end date dateRange.End.Value.AddDays(1); } } var accountIdList = new List <int>(); if (selectionValues.Length >= 5) { var accountGuids = selectionValues[4].Split(',').Select(a => a.AsGuid()).ToList(); accountIdList = new FinancialAccountService(context).GetByGuids(accountGuids).Select(a => a.Id).ToList(); } bool combineGiving = false; if (selectionValues.Length >= 6) { combineGiving = selectionValues[5].AsBooleanOrNull() ?? false; } bool useAnalytics = false; if (selectionValues.Length >= 8) { useAnalytics = selectionValues[7].AsBooleanOrNull() ?? false; } int transactionTypeContributionId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()).Id; IQueryable <decimal> personTotalAmountQry; if (useAnalytics) { var financialTransactionQry = new AnalyticsSourceFinancialTransactionService(context).Queryable() .Where(xx => xx.TransactionTypeValueId == transactionTypeContributionId) .Where(xx => xx.AuthorizedPersonAliasId.HasValue); if (dateRange.Start.HasValue) { financialTransactionQry = financialTransactionQry.Where(xx => xx.TransactionDateTime >= dateRange.Start.Value); } if (dateRange.End.HasValue) { financialTransactionQry = financialTransactionQry.Where(xx => xx.TransactionDateTime < dateRange.End.Value); } bool limitToAccounts = accountIdList.Any(); if (limitToAccounts) { financialTransactionQry = financialTransactionQry.Where(xx => xx.AccountId.HasValue && accountIdList.Contains(xx.AccountId.Value)); } if (comparisonType == ComparisonType.LessThan) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Amount < amount); } else if (comparisonType == ComparisonType.EqualTo) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Amount == amount); } else if (comparisonType == ComparisonType.GreaterThanOrEqualTo) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Amount >= amount); } if (combineGiving) { var personAmount = new AnalyticsDimPersonCurrentService(context).Queryable() .Join(financialTransactionQry, p => p.GivingId, f => f.GivingId, (p, f) => new { p.PersonId, f.Amount }); personTotalAmountQry = new PersonService(context).Queryable() .Select(p => personAmount .Where(ww => ww.PersonId == p.Id) .Sum(ww => ww.Amount)); } else { var personAmount = new AnalyticsDimPersonCurrentService(context).Queryable() .Join(financialTransactionQry, p => p.Id, f => f.AuthorizedPersonKey, (p, f) => new { p.PersonId, f.Amount }); personTotalAmountQry = new PersonService(context).Queryable() .Select(p => personAmount .Where(ww => ww.PersonId == p.Id) .Sum(ww => ww.Amount)); } } else { var financialTransactionQry = new FinancialTransactionDetailService(context).Queryable() .Where(xx => xx.Transaction.TransactionTypeValueId == transactionTypeContributionId) .Where(xx => xx.Transaction.AuthorizedPersonAliasId.HasValue); if (dateRange.Start.HasValue) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Transaction.TransactionDateTime >= dateRange.Start.Value); } if (dateRange.End.HasValue) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Transaction.TransactionDateTime < dateRange.End.Value); } bool limitToAccounts = accountIdList.Any(); if (limitToAccounts) { financialTransactionQry = financialTransactionQry.Where(xx => accountIdList.Contains(xx.AccountId)); } if (comparisonType == ComparisonType.LessThan) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Amount < amount); } else if (comparisonType == ComparisonType.EqualTo) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Amount == amount); } else if (comparisonType == ComparisonType.GreaterThanOrEqualTo) { financialTransactionQry = financialTransactionQry.Where(xx => xx.Amount >= amount); } if (combineGiving) { //// if combineGiving.. // if they aren't in a giving group, sum up transactions amounts by the person // if they are in a giving group, sum up transactions amounts by the persons that are in the person's giving group personTotalAmountQry = new PersonService(context).Queryable() .Select(p => financialTransactionQry .Where(ww => (!p.GivingGroupId.HasValue && ww.Transaction.AuthorizedPersonAlias.PersonId == p.Id) || (p.GivingGroupId.HasValue && ww.Transaction.AuthorizedPersonAlias.Person.GivingGroupId == p.GivingGroupId)) .Sum(aa => aa.Amount)); } else { personTotalAmountQry = new PersonService(context).Queryable() .Select(p => financialTransactionQry .Where(ww => ww.Transaction.AuthorizedPersonAlias.PersonId == p.Id) .Sum(aa => aa.Amount)); } } var selectExpression = SelectExpressionExtractor.Extract(personTotalAmountQry, entityIdProperty, "p"); return(selectExpression); }
public IFilterComparison(ComparisonType comparison, T value) { Comparison = comparison; Value = value; }
/// <summary> /// Gets the comparison expression. /// </summary> /// <param name="comparisonType">Type of the comparison.</param> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <param name="value2">If doing ComparisonType.Between, value2 is the upper value between expression</param> /// <returns></returns> public static Expression ComparisonExpression( ComparisonType comparisonType, MemberExpression property, Expression value, Expression value2 = null) { MemberExpression valueExpression; Expression comparisonExpression = null; bool isNullableType = property.Type.IsGenericType && property.Type.GetGenericTypeDefinition() == typeof( Nullable<> ); if ( isNullableType ) { // if Nullable Type compare on the .Value of the property (if it HasValue) valueExpression = Expression.Property( property, "Value" ); } else { valueExpression = property; } if ( comparisonType == ComparisonType.Contains ) { if ( valueExpression.Type == typeof( int ) ) { comparisonExpression = Expression.Call( value, typeof(List<int>).GetMethod( "Contains", new Type[] { typeof(int) } ), valueExpression ); } else { comparisonExpression = Expression.Call( valueExpression, typeof( string ).GetMethod( "Contains", new Type[] { typeof( string ) } ), value ); } } else if ( comparisonType == ComparisonType.DoesNotContain ) { comparisonExpression = Expression.Not( Expression.Call( valueExpression, typeof( string ).GetMethod( "Contains", new Type[] { typeof( string ) } ), value ) ); } else if ( comparisonType == ComparisonType.EndsWith ) { comparisonExpression = Expression.Call( valueExpression, typeof( string ).GetMethod( "EndsWith", new Type[] { typeof( string ) } ), value ); } else if ( comparisonType == ComparisonType.EqualTo ) { comparisonExpression = Expression.Equal( valueExpression, value ); } else if ( comparisonType == ComparisonType.GreaterThan || comparisonType == ComparisonType.GreaterThanOrEqualTo || comparisonType == ComparisonType.LessThan || comparisonType == ComparisonType.LessThanOrEqualTo || comparisonType == ComparisonType.Between ) { Expression leftExpression = valueExpression; Expression rightExpression = value; Expression rightExpression2 = value2; if ( valueExpression.Type == typeof( string ) ) { var method = valueExpression.Type.GetMethod( "CompareTo", new[] { typeof( string ) } ); leftExpression = Expression.Call( valueExpression, method, value ); rightExpression = Expression.Constant( 0 ); } if ( comparisonType == ComparisonType.GreaterThan ) { comparisonExpression = Expression.GreaterThan( leftExpression, rightExpression ); } else if ( comparisonType == ComparisonType.GreaterThanOrEqualTo ) { comparisonExpression = Expression.GreaterThanOrEqual( leftExpression, rightExpression ); } else if ( comparisonType == ComparisonType.LessThan ) { comparisonExpression = Expression.LessThan( leftExpression, rightExpression ); } else if ( comparisonType == ComparisonType.LessThanOrEqualTo ) { comparisonExpression = Expression.LessThanOrEqual( leftExpression, rightExpression ); } else if (comparisonType == ComparisonType.Between) { var lowerComparisonExpression = rightExpression != null ? Expression.GreaterThanOrEqual( leftExpression, rightExpression ) : null; var upperComparisonExpression = rightExpression2 != null ? Expression.LessThanOrEqual( leftExpression, rightExpression2 ) : null; if ( rightExpression != null && rightExpression2 != null ) { comparisonExpression = Expression.AndAlso( lowerComparisonExpression, upperComparisonExpression ); } else if (rightExpression != null ) { comparisonExpression = lowerComparisonExpression; } else if ( rightExpression2 != null ) { comparisonExpression = upperComparisonExpression; } } } else if ( comparisonType == ComparisonType.IsBlank ) { if ( valueExpression.Type == typeof( string ) ) { Expression trimmed = Expression.Call( valueExpression, typeof( string ).GetMethod( "Trim", System.Type.EmptyTypes ) ); comparisonExpression = Expression.Or( Expression.Equal( trimmed, value ), Expression.Equal( valueExpression, Expression.Constant( null, valueExpression.Type ) ) ); } else { if ( isNullableType ) { comparisonExpression = Expression.Equal( Expression.Property( property, "HasValue" ), Expression.Constant( false ) ); } else { // if not a Nullable type, return false since there aren't any null values comparisonExpression = Expression.Constant( false ); } } } else if ( comparisonType == ComparisonType.IsNotBlank ) { if ( valueExpression.Type == typeof( string ) ) { Expression trimmed = Expression.Call( valueExpression, typeof( string ).GetMethod( "Trim", System.Type.EmptyTypes ) ); Expression emptyString = Expression.Constant( string.Empty ); comparisonExpression = Expression.And( Expression.NotEqual( trimmed, emptyString ), Expression.NotEqual( valueExpression, Expression.Constant( null, valueExpression.Type ) ) ); } else { if ( isNullableType ) { comparisonExpression = Expression.Property( property, "HasValue" ); } else { // if not a Nullable type, return true since there aren't any non-null values comparisonExpression = Expression.Constant( true ); } } } else if ( comparisonType == ComparisonType.NotEqualTo ) { comparisonExpression = Expression.NotEqual( valueExpression, value ); } else if ( comparisonType == ComparisonType.StartsWith ) { comparisonExpression = Expression.Call( valueExpression, typeof( string ).GetMethod( "StartsWith", new Type[] { typeof( string ) } ), value ); } // unless we are simply checking for Null/NotNull, make sure to check on HasValue for Nullable types if ( !( ComparisonType.IsBlank | ComparisonType.IsNotBlank ).HasFlag( comparisonType ) ) { if ( comparisonExpression != null && isNullableType ) { // if Nullable Type we are comparing on the .Value of the property, so also make sure it HasValue MemberExpression hasValue = Expression.Property( property, "HasValue" ); return Expression.AndAlso( hasValue, comparisonExpression ); } } return comparisonExpression; }
public void BasicTranWithListLengthCondition(string value, ComparisonType type, long length, bool expectTran) { using (var muxer = Create()) { RedisKey key = Me(), key2 = Me() + "2"; var db = muxer.GetDatabase(); db.KeyDelete(key, CommandFlags.FireAndForget); db.KeyDelete(key2, CommandFlags.FireAndForget); var expectSuccess = false; Condition condition = null; var valueLength = value?.Length ?? 0; switch (type) { case ComparisonType.Equal: expectSuccess = valueLength == length; condition = Condition.ListLengthEqual(key2, length); break; case ComparisonType.GreaterThan: expectSuccess = valueLength > length; condition = Condition.ListLengthGreaterThan(key2, length); break; case ComparisonType.LessThan: expectSuccess = valueLength < length; condition = Condition.ListLengthLessThan(key2, length); break; } for (var i = 0; i < valueLength; i++) { db.ListRightPush(key2, i, flags: CommandFlags.FireAndForget); } Assert.IsFalse(db.KeyExists(key)); Assert.AreEqual(valueLength, db.ListLength(key2)); var tran = db.CreateTransaction(); var cond = tran.AddCondition(condition); var push = tran.StringSetAsync(key, "any value"); var exec = tran.ExecuteAsync(); var get = db.StringLength(key); Assert.AreEqual(expectTran, db.Wait(exec), "expected tran result"); if (expectSuccess) { Assert.IsTrue(db.Wait(exec), "eq: exec"); Assert.IsTrue(cond.WasSatisfied, "eq: was satisfied"); Assert.AreEqual(true, db.Wait(push), "eq: push"); Assert.AreEqual("any value".Length, get, "eq: get"); } else { Assert.IsFalse(db.Wait(exec), "neq: exec"); Assert.False(cond.WasSatisfied, "neq: was satisfied"); Assert.AreEqual(TaskStatus.Canceled, push.Status, "neq: push"); Assert.AreEqual(0, get, "neq: get"); } } }
public KeyedCollection(ComparisonType comparisonType) : base(comparisonType) {}
public Requirement() { value = "0"; comparison = ComparisonType.Equals; }
public WhereCriterion(string field, object value, ComparisonType comparisonType) { Field = field; ComparisonType = comparisonType; Value = value; }
public Requirement(Requirement copySource) { value = copySource.value; comparison = copySource.comparison; }
public virtual IWhereClause Add(string field, object value, ComparisonType comparisonType, bool parameterize=true) { return Add(field, value, comparisonType, JoinType.And, parameterize); }
public BenchmarkChartListViewModel(List <ChartViewModel> modelList, ComparisonListModel comparisonList, List <ChartViewModel> chartGroups, ComparisonType comparisonType, BenchmarkCriteria advancedCriteria, SimpleCriteria simpleCriteria, SchoolFinancialDataModel benchmarkSchoolData, EstablishmentType estabType, EstablishmentType searchedEstabType, string schoolArea, string selectedArea, string latestTermAcademies, string latestTermMaintained, ComparisonArea areaType, string laCode, string urn, int basketSize, TrustComparisonViewModel trustComparisonList = null) { base.SchoolComparisonList = comparisonList; base.ModelList = modelList; this.ChartGroups = chartGroups; this.AdvancedCriteria = advancedCriteria; this.SimpleCriteria = simpleCriteria; this.ComparisonType = comparisonType; this.BenchmarkSchoolData = benchmarkSchoolData; this.EstablishmentType = estabType; this.SearchedEstablishmentType = searchedEstabType; this.SchoolArea = schoolArea; this.SelectedArea = selectedArea; this.TrustComparisonList = trustComparisonList; this.LatestTermAcademies = latestTermAcademies; this.LatestTermMaintained = latestTermMaintained; this.AreaType = areaType; this.LaCode = laCode; this.URN = urn; this.BasketSize = basketSize; }
/// <summary> /// Set the property values parsed from a settings string. /// </summary> /// <param name="version">The version number of the parameter set.</param> /// <param name="parameters">An ordered collection of strings representing the parameter values.</param> protected override void OnSetParameters( int version, IReadOnlyList<string> parameters ) { // Parameter 1: Person Data View PersonDataViewGuid = DataComponentSettingsHelper.GetParameterOrEmpty( parameters, 0 ).AsGuidOrNull(); // Parameter 2: Person Count Comparison PersonCountComparison = DataComponentSettingsHelper.GetParameterAsEnum( parameters, 1, ComparisonType.GreaterThan ); // Parameter 3: Person Count PersonCount = DataComponentSettingsHelper.GetParameterOrEmpty( parameters, 2 ).AsInteger(); }
/// <summary> /// Gets the comparison expression. /// </summary> /// <param name="comparisonType">Type of the comparison.</param> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <param name="value2">If doing ComparisonType.Between, value2 is the upper value between expression</param> /// <returns></returns> public static Expression ComparisonExpression(ComparisonType comparisonType, MemberExpression property, Expression value, Expression value2 = null) { MemberExpression valueExpression; Expression comparisonExpression = null; bool isNullableType = property.Type.IsGenericType && property.Type.GetGenericTypeDefinition() == typeof(Nullable <>); if (isNullableType) { // if Nullable Type compare on the .Value of the property (if it HasValue) valueExpression = Expression.Property(property, "Value"); } else { valueExpression = property; } if (comparisonType == ComparisonType.Contains) { if (valueExpression.Type == typeof(int)) { comparisonExpression = Expression.Call(value, typeof(List <int>).GetMethod("Contains", new Type[] { typeof(int) }), valueExpression); } else { comparisonExpression = Expression.Call(valueExpression, typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), value); } } else if (comparisonType == ComparisonType.DoesNotContain) { comparisonExpression = Expression.Not(Expression.Call(valueExpression, typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), value)); } else if (comparisonType == ComparisonType.EndsWith) { comparisonExpression = Expression.Call(valueExpression, typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) }), value); } else if (comparisonType == ComparisonType.EqualTo) { comparisonExpression = Expression.Equal(valueExpression, value); } else if (comparisonType == ComparisonType.GreaterThan || comparisonType == ComparisonType.GreaterThanOrEqualTo || comparisonType == ComparisonType.LessThan || comparisonType == ComparisonType.LessThanOrEqualTo || comparisonType == ComparisonType.Between) { Expression leftExpression = valueExpression; Expression rightExpression = value; Expression rightExpression2 = value2; if (valueExpression.Type == typeof(string)) { var method = valueExpression.Type.GetMethod("CompareTo", new[] { typeof(string) }); leftExpression = Expression.Call(valueExpression, method, value); rightExpression = Expression.Constant(0); } if (comparisonType == ComparisonType.GreaterThan) { comparisonExpression = Expression.GreaterThan(leftExpression, rightExpression); } else if (comparisonType == ComparisonType.GreaterThanOrEqualTo) { comparisonExpression = Expression.GreaterThanOrEqual(leftExpression, rightExpression); } else if (comparisonType == ComparisonType.LessThan) { comparisonExpression = Expression.LessThan(leftExpression, rightExpression); } else if (comparisonType == ComparisonType.LessThanOrEqualTo) { comparisonExpression = Expression.LessThanOrEqual(leftExpression, rightExpression); } else if (comparisonType == ComparisonType.Between) { var lowerComparisonExpression = rightExpression != null?Expression.GreaterThanOrEqual(leftExpression, rightExpression) : null; var upperComparisonExpression = rightExpression2 != null?Expression.LessThanOrEqual(leftExpression, rightExpression2) : null; if (rightExpression != null && rightExpression2 != null) { comparisonExpression = Expression.AndAlso(lowerComparisonExpression, upperComparisonExpression); } else if (rightExpression != null) { comparisonExpression = lowerComparisonExpression; } else if (rightExpression2 != null) { comparisonExpression = upperComparisonExpression; } else { return(new NoAttributeFilterExpression()); } } } else if (comparisonType == ComparisonType.IsBlank) { if (valueExpression.Type == typeof(string)) { Expression trimmed = Expression.Call(valueExpression, typeof(string).GetMethod("Trim", System.Type.EmptyTypes)); comparisonExpression = Expression.Or(Expression.Equal(trimmed, value), Expression.Equal(valueExpression, Expression.Constant(null, valueExpression.Type))); } else { if (isNullableType) { comparisonExpression = Expression.Equal(Expression.Property(property, "HasValue"), Expression.Constant(false)); } else { // if not a Nullable type, return false since there aren't any null values comparisonExpression = Expression.Constant(false); } } } else if (comparisonType == ComparisonType.IsNotBlank) { if (valueExpression.Type == typeof(string)) { Expression trimmed = Expression.Call(valueExpression, typeof(string).GetMethod("Trim", System.Type.EmptyTypes)); Expression emptyString = Expression.Constant(string.Empty); comparisonExpression = Expression.And(Expression.NotEqual(trimmed, emptyString), Expression.NotEqual(valueExpression, Expression.Constant(null, valueExpression.Type))); } else { if (isNullableType) { comparisonExpression = Expression.Property(property, "HasValue"); } else { // if not a Nullable type, return true since there aren't any non-null values comparisonExpression = Expression.Constant(true); } } } else if (comparisonType == ComparisonType.NotEqualTo) { comparisonExpression = Expression.NotEqual(valueExpression, value); } else if (comparisonType == ComparisonType.StartsWith) { comparisonExpression = Expression.Call(valueExpression, typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) }), value); } // unless we are simply checking for Null/NotNull, make sure to check on HasValue for Nullable types if (!(ComparisonType.IsBlank | ComparisonType.IsNotBlank).HasFlag(comparisonType)) { if (comparisonExpression != null && isNullableType) { // if Nullable Type we are comparing on the .Value of the property, so also make sure it HasValue MemberExpression hasValue = Expression.Property(property, "HasValue"); return(Expression.AndAlso(hasValue, comparisonExpression)); } } return(comparisonExpression); }
protected KeyedCollectionBase(ComparisonType comparisonType, int capacity) : this(KeyComparer.CreateKeyComparer(comparisonType), capacity) { }
public string GetDetails(Comparison.Detail details, ComparisonType type, bool formatXml) { return("DETAIL-" + details.Value); }
public IComparer <TrackingReplay.TrackPoint> GetComparison(ComparisonType comparisonType) { this._comparisonType = comparisonType; return(new MyComparison <T>() as IComparer <TrackingReplay.TrackPoint>); }