public PickerCollectionItemVM(FilterValue value)
        {
            Id = value.Id;

            Value     = value.Value;
            ValueName = value.ValueName;
        }
Beispiel #2
0
        internal override string CreateWhere(IDictionary <string, string> objectPropertyToColumnNameMapper, int parameterIndex)
        {
            if (objectPropertyToColumnNameMapper == null)
            {
                throw new ArgumentNullException(nameof(objectPropertyToColumnNameMapper));
            }
            if (FilterType == SetFilterType.Between && FilterValue.Count() != 2)
            {
                throw new ArgumentOutOfRangeException(nameof(objectPropertyToColumnNameMapper), "The 'Between' search type may only be used with exactly 2 values.");
            }

            var columnName       = objectPropertyToColumnNameMapper[PropertyName];
            var parametersString = FilterType == SetFilterType.Between ? $"@p{parameterIndex++} AND @p{parameterIndex++}" : string.Join(", ", FilterValue.Select(value => $"@p{parameterIndex++}"));

            switch (FilterType)
            {
            case SetFilterType.In:
                return($"[{columnName}] IN ({parametersString})");

            case SetFilterType.Between:
                return($"[{columnName}] BETWEEN {parametersString}");

            case SetFilterType.NotIn:
                return($"[{columnName}] NOT IN ({parametersString})");

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #3
0
        private questStatus create(MasterPricingEntities dbContext, List <Quest.Functional.MasterPricing.FilterValue> filterValueList, out List <Quest.Functional.MasterPricing.FilterValue> filterValueIdList)
        {
            // Initialize
            filterValueIdList = null;


            // Perform create
            try
            {
                List <Quest.Services.Dbio.MasterPricing.FilterValues> _filterValueList = new List <Quest.Services.Dbio.MasterPricing.FilterValues>();
                foreach (Quest.Functional.MasterPricing.FilterValue filterValue in filterValueList)
                {
                    Quest.Services.Dbio.MasterPricing.FilterValues _filterValue = new Quest.Services.Dbio.MasterPricing.FilterValues();
                    BufferMgr.TransferBuffer(filterValue, _filterValue);
                    _filterValueList.Add(_filterValue);
                }
                dbContext.FilterValues.AddRange(_filterValueList);
                dbContext.SaveChanges();

                filterValueIdList = new List <FilterValue>();
                foreach (Quest.Services.Dbio.MasterPricing.FilterValues _filterValue in _filterValueList)
                {
                    Quest.Functional.MasterPricing.FilterValue filterValue = new FilterValue();
                    filterValue.Id = _filterValue.Id;
                    filterValueIdList.Add(filterValue);
                }
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
        List<FilterValue> _Items;			// list of FilterValue

		public FilterValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p)
		{
			FilterValue f;
            _Items = new List<FilterValue>();
			// Loop thru all the child nodes
			foreach(XmlNode xNodeLoop in xNode.ChildNodes)
			{
				if (xNodeLoop.NodeType != XmlNodeType.Element)
					continue;
				switch (xNodeLoop.Name)
				{
					case "FilterValue":
						f = new FilterValue(r, this, xNodeLoop);
						break;
					default:	
						f=null;		// don't know what this is
						// don't know this element - log it
						OwnerReport.rl.LogError(4, "Unknown FilterValues element '" + xNodeLoop.Name + "' ignored.");
						break;
				}
				if (f != null)
					_Items.Add(f);
			}
			if (_Items.Count == 0)
				OwnerReport.rl.LogError(8, "For FilterValues at least one FilterValue is required.");
			else
                _Items.TrimExcess();
		}
Beispiel #5
0
    protected void gvOrders_HeaderFilterFillItems(object sender, ASPxGridViewHeaderFilterEventArgs e)
    {
        if (e.Column.FieldName == "CustomDescription")
        {
            List <string>      exsistingNewValues = new List <string>();
            List <FilterValue> newValues          = new List <FilterValue>();
            foreach (FilterValue value in e.Values)
            {
                string   description = value.Value;
                string[] items       = description.Split(';');
                foreach (string item in items)
                {
                    if (!exsistingNewValues.Contains(item))
                    {
                        exsistingNewValues.Add(item);

                        FilterValue newValue = new FilterValue();
                        newValue.DisplayText = item.Substring(1, item.Length - 2);
                        newValue.Query       = String.Format("Contains([{0}], '{1}')", e.Column.FieldName, item);
                        newValues.Add(newValue);
                    }
                }
            }
            e.Values.Clear();
            e.Values.AddRange(newValues);
        }
    }
Beispiel #6
0
        public ActionResult Create(FilterValueViewModel model)
        {
            if (ModelState.IsValid)
            {
                //_context.dbFilterValue.Add(new FilterValue
                //{
                //    Name = model.Name
                //});

                FilterValue categoryValue = new FilterValue()
                {
                    Name = model.Name
                };
                _context.dbFilterValue.Add(categoryValue);
                _context.SaveChanges();

                _context.dbFilterNameGroups.Add(new FilterNameGroups
                {
                    FilterNameId  = model.NameFilterId,
                    FilterValueId = categoryValue.Id,
                    CategoryId    = model.CategoryId
                });
                _context.SaveChanges();

                return(RedirectToAction("Index", "FilterValue"));
            }
            else
            {
                return(View(model));
            }
        }
        FilterValue ReadValueFromEnd(int position)
        {
            var result = new FilterValue();

            while (position >= _bufferLength)
            {
                position -= _bufferLength;
            }

            while (position < 0)
            {
                position += _bufferLength;
            }

            int positionFromBufferStartPointer = _bufferTopPointer - position;

            if (positionFromBufferStartPointer < 0)
            {
                positionFromBufferStartPointer += _bufferLength;
            }

            result = _buffer[positionFromBufferStartPointer];


            return(result);
        }
        public void FindByFilter()
        {
            AreaModel match = new AreaModel {
                Area = "ROM", Value = 200
            };
            AreaModel noMatch = new AreaModel {
                Area = "ROM", Value = 100
            };
            AreaModel extra = new AreaModel {
                Area = "Mining", Value = 100
            };

            Repository.Add(match);
            Repository.Add(noMatch);
            Repository.Add(extra);

            Assert.That(Records.Count, Is.EqualTo(3));

            IList <AreaModel> models = Repository.FindByFilter();

            Assert.That(models, Is.Not.Empty);
            Assert.That(models.Count, Is.EqualTo(2));
            Assert.That(models[0].Area, Is.EqualTo("ROM"));
            Assert.That(models[1].Area, Is.EqualTo("ROM"));

            models = Repository.FindByFilter(FilterValue.Parse("Value=100"));

            Assert.That(models, Is.Not.Empty);
            Assert.That(models.Count, Is.EqualTo(1));
            Assert.That(models[0].Area, Is.EqualTo("ROM"));
            Assert.That(models[0].Value, Is.EqualTo(100));
        }
        private FilterValue[] ExtractFilterValues(IEnumerable <IColumn> columns, Type dataModelType)
        {
            PropertyInfo[] props = dataModelType
                                   .GetProperties();

            var result = new FilterValue[props.Count()];

            int index = 0;

            foreach (PropertyInfo prop in props)
            {
                object[] attrs = prop.GetCustomAttributes(true);

                foreach (var attr in attrs)
                {
                    var dataColumnAttr = attr as CsvHeaderAttribute;

                    if (dataColumnAttr != null)
                    {
                        var filterValue = new FilterValue
                        {
                            Index        = columns.First(c => c.Value == dataColumnAttr.ColumnName).Index,
                            PropertyInfo = prop,
                            Type         = prop.PropertyType,
                            Label        = dataColumnAttr.ColumnName
                        };

                        result[index++] = filterValue;
                    }
                }
            }
            return(result.OrderBy(x => x.Index).ToArray());
        }
Beispiel #10
0
        public void FilterCollection()
        {
            if (FilterValue == null || FilterValue.Equals(default(TInner)))
            {
                FilteredCollection.Clear();
                return;
            }

            foreach (var item in UnfilteredCollection)
            {
                if (PassFilterDelegate(item, FilterValue))
                {
                    if (!FilteredCollection.Contains(item))
                    {
                        FilteredCollection.Add(item);
                    }
                }
                else
                {
                    if (FilteredCollection.Contains(item))
                    {
                        FilteredCollection.Remove(item);
                    }
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Gets the versions of the model
        /// </summary>
        /// <param name="id">The unique identifier.</param>
        /// <returns></returns>
        public ModelVersions GetVersions(int id)
        {
            IAmplaViewProperties <TModel> amplaViewProperties = GetViewProperties(null);

            amplaViewProperties.Enforce.CanView();

            FilterValue     idFilter      = new FilterValue("Id", Convert.ToString(id));
            FilterValue     deletedFilter = new FilterValue("Deleted", "");
            GetDataRequest  dataRequest   = GetDataRequest(false, idFilter, deletedFilter);
            GetDataResponse dataResponse  = webServiceClient.GetData(dataRequest);
            TModel          model;
            AmplaRecord     amplaRecord = FindAmplaRecord(dataResponse, ModelProperties, amplaViewProperties, out model);

            if (amplaRecord != null)
            {
                var request = GetAuditDataRequest(amplaRecord);
                GetAuditDataResponse    response     = webServiceClient.GetAuditData(request);
                List <AmplaAuditRecord> auditRecords = new List <AmplaAuditRecord>();
                IAmplaBinding           binding      = new AmplaGetAuditDataRecordBinding <TModel>(response, amplaRecord, auditRecords, modelProperties);
                if (binding.Validate() && binding.Bind())
                {
                    AmplaAuditRecord auditRecord    = auditRecords.Count > 0 ? auditRecords[0] : null;
                    ModelVersions    modelVersions  = new ModelVersions(amplaRecord);
                    IAmplaBinding    historyBinding = new AmplaGetDataVersionsBinding <TModel>(amplaRecord, auditRecord, model, modelVersions, modelProperties, amplaViewProperties);
                    if (historyBinding.Validate() && historyBinding.Bind())
                    {
                        return(modelVersions);
                    }
                }
            }
            return(null);
        }
Beispiel #12
0
 private bool FilterMatches(ScanResults fileProperties)
 {
     if (FilterType == YaraFilterType.AlwaysRun)
     {
         return(true);
     }
     else if (FilterType == YaraFilterType.IsPeFile)
     {
         return(fileProperties.IsPe);
     }
     else if (FilterType == YaraFilterType.FileExtension)
     {
         return(string.Equals(FilterValue.Replace(".", ""), fileProperties.Extension.Replace(".", ""), StringComparison.InvariantCultureIgnoreCase));
     }
     else if (FilterType == YaraFilterType.MimeType)
     {
         return(string.Equals(FilterValue, fileProperties.MimeType, StringComparison.InvariantCultureIgnoreCase));
     }
     else if (FilterType == YaraFilterType.ElseNoMatch)
     {
         return(false);
     }
     else
     {
         throw new NotImplementedException($"You must have added a new {nameof(YaraFilterType)} enum without adding the appropriate logic in {nameof(YaraFilter)}.{nameof(FilterMatches)}.");
     }
 }
        private static BinaryExpression GetExpression <T>
            (ParameterExpression param, FilterValue filter1, FilterValue filter2)
        {
            Expression bin1 = GetExpression <T>(param, filter1);
            Expression bin2 = GetExpression <T>(param, filter2);

            return(Expression.AndAlso(bin1, bin2));
        }
        /// <summary>
        /// Initialize new <see cref="Setting{T}"/> instance.
        /// </summary>
        /// <param name="group">Group for which this setting belongs to.</param>
        /// <param name="key">Unique key used to identify this setting.</param>
        /// <param name="defaultValue">Default value of setting which can be restored.</param>
        /// <param name="filter">Optional delegate which can be used to filter values
        /// on assignment if specified. It is important to note that default values
        /// are also filtered on assignment.</param>
        internal Setting(DynamicSettingGroup group, string key, T defaultValue, FilterValue <T> filter)
        {
            this._group = group;

            this.Key          = key;
            this.DefaultValue = defaultValue;

            this._filter = filter;
        }
Beispiel #15
0
 private object Check <TType, TFilter, TValue>(FilterValue <TType, TFilter, TValue> obj, string parameter)
     where TType : struct, IComparable, IConvertible
     where TFilter : struct, IComparable, IConvertible
     where TValue : struct, IComparable, IConvertible
 {
     return(obj.ToString() == parameter
         ? obj.Value
         : Binding.DoNothing);
 }
        internal override void Save()
        {
            var node = (XmlElement)CreateNode("d:top10");

            node.SetAttribute("filterVal", FilterValue.ToString("R15", CultureInfo.InvariantCulture));
            node.SetAttribute("percent", Percent ? "1": "0");
            node.SetAttribute("top", Top ? "1" : "0");
            node.SetAttribute("val", Value.ToString("R15", CultureInfo.InvariantCulture));
        }
Beispiel #17
0
 public override TSource Visit(SingleValuePropertyAccessNode nodeIn)
 {
     current.FieldName = nodeIn.Property.Name;
     //We are finished, add current to collection.
     filterValueList.Add(current);
     //Reset current
     current = new FilterValue();
     return(null);
 }
Beispiel #18
0
    protected void grid_HeaderFilterFillItems(object sender, ASPxGridViewHeaderFilterEventArgs e)
    {
        if (e.Column.FieldName != "CategoryNameNull")
        {
            return;
        }

        e.Values.Insert(0, FilterValue.CreateShowBlanksValue(e.Column, "Blanks"));
        e.Values.Insert(1, FilterValue.CreateShowNonBlanksValue(e.Column, "Non Blanks"));
    }
Beispiel #19
0
        public CollectionItemVM(FilterDataType dataType, FilterValue value, bool selected)
        {
            DataType = dataType;
            Id       = value.Id;

            ValueName = !value.ValueName.IsNullOrEmtpy() ? value.ValueName : value.Value;
            Value     = value.Value;

            Selected = selected;
        }
Beispiel #20
0
        public UdpFilterViewModel(FilterValue filterValue, FilterFormatType type, string crProcess, DynamicTypeManager theDynamicTypeManager, string name, string crFieldName, FilterList filterList)
        {
            if (theDynamicTypeManager == null)
            {
                throw new ArgumentNullException("theDynamicTypeManager");
            }

            Name = name;
            Type = type != null ? GetTypeForView(type.MemberType.Name != "Nullable`1" ? type.MemberType : type.MemberType.GenericTypeArguments[0]) : "Text";

            if (crProcess != null)
            {
                //Type itemType = theDynamicTypeManager.GetInfoType<IInfoClass>(crProcess);
                //PropertyInfo guidProperty = itemType.GetPropertyByName("Guid");
               // PropertyInfo crFieldProperty = itemType.GetPropertyByName(crFieldName);

                if (crProcess == Constants.StateProcessName)
                {
                    Values = theDynamicTypeManager.GetList<IInfoList>(crProcess, string.Empty, 0, int.MaxValue, null, filterList)
                            .Cast<IStateInfo>()
                            .Select(x => new IdValuePair
                            {
                                Id = x.Id.ToString(CultureInfo.InvariantCulture),//guidProperty.With(v => v.GetValue(x)).Return(v => v.ToString(), string.Empty),
                                //Value = crFieldProperty.GetValue(x)
                                Value = x.GetValueByPropertyName(crFieldName)

                            })
                            .ToList();
                }
                else
                {
                    Values = theDynamicTypeManager.GetList<IInfoList>(crProcess, string.Empty, 0, int.MaxValue)
                        .Cast<IInfoClass>()
                        .Select(x => new IdValuePair
                        {
                            Id = x.Id.ToString(CultureInfo.InvariantCulture),
                            Value = x.GetValueByPropertyName(crFieldName)
                        })
                        .ToList();
                }
            }
            else
            {
                if (Type == "Approval")
                {
                    Values = Enum.GetValues(typeof(ApprovalStates)).Cast<ApprovalStates>().Select(x => new IdValuePair { Id = x.ToString(), Value = x.GetDescription() }).ToList();
                }
                else
                {
                    Values = null;
                }
            }

            DefaultValue = filterValue != null && filterValue.DefaultValue != null ? Convert.ToString(filterValue.DefaultValue, CultureInfo.InvariantCulture) : string.Empty;
        }
        private static int ApplyFilter(bool isFilterEnabled, FilterType filterType, string columnName, List <string> values, FilterValue[] filters, int filterCount)
        {
            if (isFilterEnabled)
            {
                filters[filterCount++] = new FilterValue {
                    FilterType = filterType, ColumnName = columnName, Values = values
                };
            }

            return(filterCount);
        }
        /// <summary>
        /// Tries the get filter specified
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="filterValues">The filter values.</param>
        /// <returns></returns>
        public static bool TryGetFilter <TModel>(out FilterValue[] filterValues)
        {
            AmplaDefaultFiltersAttribute attribute;

            if (typeof(TModel).TryGetAttribute(out attribute))
            {
                filterValues = attribute.Filters;
                return(filterValues.Length > 0);
            }
            filterValues = new FilterValue[0];
            return(false);
        }
Beispiel #23
0
        public override Expression <Func <FilledForm, bool> > GetFilterExpression(FilterValue filter)
        {
            if (filter is RangeFilterValue)
            {
                var rangeFilterValue = filter as RangeFilterValue;

                int?fromValue = null;
                int?toValue   = null;

                if (!string.IsNullOrEmpty(rangeFilterValue.FromValue))
                {
                    fromValue = Convert.ToInt32(rangeFilterValue.FromValue);
                }

                if (!string.IsNullOrEmpty(rangeFilterValue.ToValue))
                {
                    toValue = Convert.ToInt32(rangeFilterValue.ToValue);
                }

                Expression <Func <FilledForm, bool> > result = null;

                if (fromValue.HasValue && !toValue.HasValue)
                {
                    result = f => f.FormValues.Any(v => v.MetricId == this.Id && v.NumericValue >= fromValue.Value);
                }
                else if (!fromValue.HasValue && toValue.HasValue)
                {
                    result = f => f.FormValues.Any(v => v.MetricId == this.Id && v.NumericValue <= toValue.Value);
                }
                else if (fromValue.HasValue && toValue.HasValue)
                {
                    result = f => f.FormValues.Any(v => v.MetricId == this.Id && v.NumericValue >= fromValue.Value && v.NumericValue <= toValue.Value);
                }

                return(result);
            }

            if (filter is MultipleFilterValue)
            {
                var multipleFilterValue = filter as MultipleFilterValue;
                var values = new List <double?>();
                foreach (var item in multipleFilterValue.Values)
                {
                    values.Add(Convert.ToDouble(item));
                }

                Expression <Func <FilledForm, bool> > result = f => f.FormValues.Any(v => v.MetricId == this.Id && values.Contains(v.NumericValue));

                return(result);
            }

            throw new InvalidOperationException("FilterValue could not be cast! invalid value.");
        }
Beispiel #24
0
        public override Expression <Func <FilledForm, bool> > GetFilterExpression(FilterValue filterValue)
        {
            var singleValue = filterValue as SingleFilterValue;
            var value       = singleValue.Value;

            var punctuation = value.Where(Char.IsPunctuation).Distinct().ToArray();
            var words       = value.Split().Select(x => x.Trim(punctuation));

            Expression <Func <FilledForm, bool> > result = (FilledForm f) => f.FormValues.Any(v => v.MetricId == this.Id && words.Any(w => v.TextValue.Contains(w)));

            return(result);
        }
Beispiel #25
0
        private void SetFilter(FilterTypes type, object filter, bool value)
        {
            switch (type)
            {
            case FilterTypes.Level:
                FilterLevel = new FilterValue <FilterTypes, LevelValues, bool>(type, (LevelValues)filter, value);
                break;

            case FilterTypes.Highlight:
                FilterHighlighted = new FilterValue <FilterTypes, int, bool>(type, Convert.ToInt32(filter), value);
                break;
            }
        }
Beispiel #26
0
        public ArrayList GetFilterArrays(Type fieldType)
        {
            string[] spValues = FilterValue.Split((",").ToCharArray());

            ArrayList al = new ArrayList();

            foreach (string spValue in spValues)
            {
                al.Add(Convert.ChangeType(spValue, fieldType));
            }

            return(al);
        }
Beispiel #27
0
        public static FilterValueResult ToAggregate(this FilterValue filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            return(new FilterValueResult
            {
                Id = filter.Id,
                Content = filter.Content
            });
        }
        public static List<int> FilterCollection(List<int> list, FilterValue filter)
        {
            List<int> result = new List<int>();

            foreach (var item in list)
            {
                if (filter(item))
                {
                    result.Add(item);
                }
            }

            return result;
        }
Beispiel #29
0
        /// <summary>
        /// Finds the record.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AmplaRecord FindRecord(int id)
        {
            IAmplaViewProperties <TModel> amplaViewProperties = GetViewProperties(null);

            amplaViewProperties.Enforce.CanView();

            FilterValue     idFilter      = new FilterValue("Id", Convert.ToString(id));
            FilterValue     deletedFilter = new FilterValue("Deleted", "");
            var             request       = GetDataRequest(true, idFilter, deletedFilter);
            GetDataResponse response      = webServiceClient.GetData(request);
            TModel          model;

            return(FindAmplaRecord(response, ModelProperties, amplaViewProperties, out model));
        }
Beispiel #30
0
        public questStatus Update(DbMgrTransaction trans, FilterValue filterValue)
        {
            // Initialize
            questStatus status = null;


            // Update filterValue
            status = _dbFilterValuesMgr.Update(trans, filterValue);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Beispiel #31
0
        public override Expression <Func <FilledForm, bool> > GetFilterExpression(FilterValue filter)
        {
            var multipleFilterValue = filter as MultipleFilterValue;
            var values = new List <bool?>();

            foreach (var item in multipleFilterValue.Values)
            {
                var value = Convert.ToInt32(item);
                values.Add(Convert.ToBoolean(value));
            }

            Expression <Func <FilledForm, bool> > result = f => f.FormValues.Any(v => v.MetricId == this.Id && values.Contains(v.BoolValue));

            return(result);
        }
Beispiel #32
0
        protected virtual IEnumerable <TItem> FilterItems(IEnumerable <TItem> items)
        {
            if (FilterValue == null || (FilterValue as string) == "")
            {
                return(items);
            }

            var key = FilterValue.ToString();

            return(items.Where(x =>
            {
                var itemKey = ((dynamic)x)[FilterField] ?? ReflectionUtils.GetPropertyValue(x, FilterField);
                return itemKey != null && ((object)itemKey).ToString() == key;
            }));
        }
        public StringBuilder TheValues(FilterValue filterValue, int nr)
        {
            StringBuilder query = new StringBuilder();

            if (filterValue.Filter.Group.ParentGroup == 0)
            {
                query.AppendFormat(" G{0}.{1} = '{2}'", nr, filterValue.FilterValueName, filterValue.Value);
            }
            else
            {
                query.AppendFormat(" G{0}.{1} = '{2}'", nr, filterValue.Filter.FilterName, filterValue.FilterValueName);
            }

            return(query);
        }
        public void FilterOptionsCommandShouldUpdatProcessFieldAfterPopupIsClosed()
        {
            var filter = Mock.Create<IFilterDescriptor>(Behavior.Loose);
            var stepEdit = DisplayListRequiredStepEdit.NewStep(1);
            stepEdit.SelectedFields = new DisplayListStepFields();

            var processFieldViewModel = new ProcessFieldViewModel(new FieldEdit(), new ProcessSectionViewModel(Mock.Create<ISectionEdit>()));

            var vm = new ProcessFieldDisplayListRequiredStepViewModel(stepEdit, new StepInfo(1), processFieldViewModel);

            Mock.Arrange(() => vm.GetProcessedFilter()).IgnoreInstance().Returns(Mock.Create<IFilterDescriptor>());

            var processEdit = Mock.Create<ProcessEdit>(Behavior.Loose);
            var fieldsViewModel = new ProcessFieldsViewModel { Model = processEdit };
            vm.Model = fieldsViewModel;

            var popupFactory = Mock.Create<PopupFactory>(Behavior.Loose);
            var popupBuilder = Mock.Create<PopupBuilder>(Behavior.CallOriginal);
            Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder);
            Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) => ok());
            vm.ThePopupFactory = popupFactory;

            var filterOptions = Mock.Create<FilterOptionsViewModel>(Behavior.Loose);
            vm.FilterOptionsVM = new Lazy<FilterOptionsViewModel>(() => filterOptions);

            var procField = new ProcessField("test", "test");
            filterOptions.IsProcessField = true;
            filterOptions.SelectedProcessField = procField;

            var filterValue = new FilterValue { Type = FilterValueType.ProcessField };
            Mock.Arrange(() => filter.Value).Returns(filterValue);

            vm.FilterOptionsCommand.Execute(filter);
            Assert.AreEqual("FLD: test", filterValue.ProvidedValue.ToString());

            Mock.Arrange(() => filter.Value).Returns((FilterValue)null);
            vm.FilterOptionsCommand.Execute(filter);
            Mock.AssertSet(() => filter.Value = Arg.IsAny<FilterValue>());
        }
        private FilterParameterMetadata CreateReverseCrossReferenceParameter(
            FilterValue filterValue,
            ReverseCrossReferenceFieldMetadata field,
            bool includeValues)
        {
            var parameter = CreateGenericParameter(filterValue, field);

            if (includeValues)
            {
                parameter.Values.AddRange(FilteringUtils.GetReverseCrossReferenceFieldValues(field));
                parameter.ValuesSpecified = true;
            }

            return parameter;
        }
        private FilterParameterMetadata CreateParameterMetadata(IProcessMetadata process, FilterValue filterValue, bool includeParameterValues)
        {
            if (process.SupportsStates && IsCurrentStateFilter(filterValue))
            {
                return CreateCurrentStateParameter(filterValue, process, includeParameterValues);
            }

            var field = FilteringUtils.FindProcessField(process, filterValue.SystemName);

            return field != null ? CreateParameter(filterValue, field, includeParameterValues) : CreateParameter(filterValue);
        }
 private static FilterParameterMetadata CreateParameter(FilterValue filterValue)
 {
     return new FilterParameterMetadata
                {
                    Name = filterValue.SystemName,
                    DisplayName = filterValue.DisplayName,
                    DefaultValue = filterValue.DefaultValue,
                    DataType = FilterDataType.String
                };
 }
        private bool IsCurrentStateFilter(FilterValue filterValue)
        {
            var fieldName = filterValue.SystemName;

            return FilteringUtils.IsCurrentState(fieldName);
        }
        private FilterParameterMetadata CreateParameter(FilterValue filterValue, IFieldMetadata field, bool includeValues)
        {
            switch (field.ColumnType)
            {
                case ColumnTypes.Approval:
                    return CreateApprovalParameter(filterValue, field, includeValues);

                case ColumnTypes.DateTime:
                    return CreateDateTimeParameter(filterValue, (DateTimeFieldMetadata)field);

                case ColumnTypes.Reference:
                case ColumnTypes.MultiReference:
                    return CreateCrossReferenceParameter(filterValue, (CrossReferenceFieldMetadata)field, includeValues);

                case ColumnTypes.ReverseReference:
                case ColumnTypes.ReverseMultiReference:
                    return CreateReverseCrossReferenceParameter(filterValue, (ReverseCrossReferenceFieldMetadata)field, includeValues);

                default:
                    return CreateGenericParameter(filterValue, field);
            }
        }
        private FilterParameterMetadata CreateCurrentStateParameter(FilterValue filterValue, IProcessMetadata process, bool includeValues)
        {
            var parameter = new FilterParameterMetadata
                                {
                                    Name = filterValue.SystemName,
                                    DisplayName = filterValue.DisplayName,
                                    DefaultValue = filterValue.DefaultValue,
                                    DataType = FilterDataType.State
                                };

            if (includeValues)
            {
                parameter.Values.AddRange(
                    filterValue.SystemName == Constants.CurrentStateGuidColumnName
                        ? FilteringUtils.GetCurrentStateGuidValues(process)
                        : FilteringUtils.GetCurrentStateIdValues(process));
                parameter.ValuesSpecified = true;
            }

            return parameter;
        }
 private static FilterParameterMetadata CreateGenericParameter(FilterValue filterValue, IFieldMetadata field)
 {
     return new FilterParameterMetadata
                {
                    Name = filterValue.SystemName,
                    DisplayName = filterValue.DisplayName,
                    DefaultValue = filterValue.DefaultValue,
                    DataType = GetDataType(field.ColumnType)
                };
 }
        private FilterParameterMetadata CreateApprovalParameter(FilterValue filterValue, IFieldMetadata field, bool includeValues)
        {
            var parameter = CreateGenericParameter(filterValue, field);

            if (includeValues)
            {
                parameter.Values.AddRange(FilteringUtils.GetApprovalFieldValues());
                parameter.ValuesSpecified = true;
            }

            return parameter;
        }
        private FilterParameterMetadata CreateDateTimeParameter(FilterValue filterValue, DateTimeFieldMetadata field)
        {
            var parameter = CreateGenericParameter(filterValue, field);
            parameter.DateTimeFormat = field.DateTimeFormat;

            return parameter;
        }
 private static void Static(WeakEventListener<ProcessMetricsGadgetViewModel, FilterValue, PropertyChangedEventArgs> listener, FilterValue source)
 {
     source.PropertyChanged -= listener.OnEvent;
 }