public static bool ComposeFilterString(string filter, QueueViewerIncludesAndExcludes excluding, QueueViewerIncludesAndExcludes including, out string combinedFilter, out LocalizedString error) { error = LocalizedString.Empty; combinedFilter = string.Empty; if (including == null && excluding == null) { combinedFilter = filter; return(true); } bool includeDeliveryType = false; bool includeNextHop = false; int[] array = new int[QueueViewerIncludesAndExcludes.MaxFilterCount]; int[] array2 = (including != null) ? including.filter : new int[QueueViewerIncludesAndExcludes.MaxFilterCount]; int[] array3 = (excluding != null) ? excluding.filter : new int[QueueViewerIncludesAndExcludes.MaxFilterCount]; if (filter == null) { filter = string.Empty; } for (int i = 0; i < array.Length; i++) { if (array3[i] != 0 || array2[i] != 0) { if (array3[i] == 1 && array2[i] == 1) { error = DataStrings.IncludeExcludeConflict(QueueViewerIncludesAndExcludes.GetName(i)); return(false); } if (array3[i] == 1) { array[i] = array3[i] * -1; } else { if (array2[i] != 1) { throw new InvalidOperationException(string.Format("Invalid filter value found. Exclude: {0}, Include: {1}", array3[i], array2[i])); } array[i] = array2[i]; if (QueueViewerIncludesAndExcludes.IsDeliveryType(i)) { includeDeliveryType = true; } else if (QueueViewerIncludesAndExcludes.IsNextHopCategory(i)) { includeNextHop = true; } } } } combinedFilter = QueueViewerIncludesAndExcludes.CreateFilterString(filter, array, includeDeliveryType, includeNextHop); return(true); }
private static string CreateFilterString(string filter, int[] combinedIncludeExclude, bool includeDeliveryType, bool includeNextHop) { StringBuilder stringBuilder = new StringBuilder(filter); string arg = (filter.Length > 0) ? " -AND " : string.Empty; for (int i = 0; i < QueueViewerIncludesAndExcludes.deliveryTypeNames.Length; i++) { if (combinedIncludeExclude[i] < 0 || (includeDeliveryType && combinedIncludeExclude[i] == 0)) { stringBuilder.AppendFormat("{0} {1} -ne '{2}'", arg, QueueViewerIncludesAndExcludes.DeliveryTypeProperty, QueueViewerIncludesAndExcludes.GetName(i)); arg = " -AND "; } } for (int j = QueueViewerIncludesAndExcludes.NextHopCategoryBaseIndex; j < QueueViewerIncludesAndExcludes.nextHopCategoryNames.Length + QueueViewerIncludesAndExcludes.NextHopCategoryBaseIndex; j++) { if (combinedIncludeExclude[j] < 0 || (includeNextHop && combinedIncludeExclude[j] == 0)) { stringBuilder.AppendFormat("{0} {1} -ne '{2}'", arg, QueueViewerIncludesAndExcludes.NextHopCategoryProperty, QueueViewerIncludesAndExcludes.GetName(j)); arg = " -AND "; } } if (combinedIncludeExclude[QueueViewerIncludesAndExcludes.EmptyIndex] < 0) { stringBuilder.AppendFormat("{0} {1} -gt 0", arg, QueueViewerIncludesAndExcludes.MessageCountProperty); arg = " -AND "; } else if (combinedIncludeExclude[QueueViewerIncludesAndExcludes.EmptyIndex] > 0) { stringBuilder.AppendFormat("{0} {1} -eq 0", arg, QueueViewerIncludesAndExcludes.MessageCountProperty); arg = " -AND "; } if (combinedIncludeExclude[QueueViewerIncludesAndExcludes.HighRiskIndex] < 0) { stringBuilder.AppendFormat("{0} {1} -ne '{2}'", arg, QueueViewerIncludesAndExcludes.RiskLevelProperty, "High"); } else if (combinedIncludeExclude[QueueViewerIncludesAndExcludes.HighRiskIndex] > 0) { stringBuilder.AppendFormat("{0} {1} -eq '{2}'", arg, QueueViewerIncludesAndExcludes.RiskLevelProperty, "High"); } return(stringBuilder.ToString()); }
public override string ToString() { if (this.filterString == null) { StringBuilder stringBuilder = new StringBuilder(); string arg = string.Empty; for (int i = 0; i < QueueViewerIncludesAndExcludes.deliveryTypeNames.Length; i++) { if (this.filter[i] == 1) { stringBuilder.AppendFormat("{0} {1} -eq {2}", arg, QueueViewerIncludesAndExcludes.DeliveryTypeProperty, QueueViewerIncludesAndExcludes.GetName(i)); arg = " -AND "; } } for (int j = QueueViewerIncludesAndExcludes.NextHopCategoryBaseIndex; j < QueueViewerIncludesAndExcludes.nextHopCategoryNames.Length + QueueViewerIncludesAndExcludes.NextHopCategoryBaseIndex; j++) { if (this.filter[j] == 1) { stringBuilder.AppendFormat("{0} {1} -eq {2}", arg, QueueViewerIncludesAndExcludes.NextHopCategoryProperty, QueueViewerIncludesAndExcludes.GetName(j)); arg = " -AND "; } } if (this.filter[QueueViewerIncludesAndExcludes.EmptyIndex] == 1) { stringBuilder.AppendFormat("{0} empty", arg); } if (this.filter[QueueViewerIncludesAndExcludes.HighRiskIndex] == 1) { stringBuilder.AppendFormat("{0} {1}", arg, "High"); } this.filterString = stringBuilder.ToString(); } return(this.filterString); }