public virtual void Add(IFieldPath path) { // nothing to do if we're at the end of the path if (path.Count <= 1) { return; } var field = (IRelationField)path[0]; if (field.Subject.Equals(Subject)) { if (!_paths.ContainsKey(field)) { _paths.Add(field, new UniqueFieldPath(field) { Predecessor = this }); } _paths[field].Add(path[1, null]); } else { throw new ArgumentException(String.Format("Cannot add given FieldPath to UniqueFieldPath as parent subjects at this point differ ({0}, trying to add {1}).", Field.ToString(), path[0].ToString())); } }
/// <summary> /// Add another field path to this path. Will ensure it's still a valid path from root to last. /// </summary> /// <param name="other"></param> public void Add(IFieldPath other) { foreach (var f in other) { Add(f); } }
public WebObjectGraphReaderEnumerator(IEnumerator <TData> enumerator, IFieldPath <TypeModel, PropertyInfoField> fieldPath, ITypeInstanceFactory typeInstanceFactory) { _enumerator = enumerator; _fieldPath = fieldPath; _typeInstanceFactory = typeInstanceFactory; }
/// <summary> /// Works with values that are BetweenValue objects. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) { return(null); } var v = values[0] as BetweenValue; if (v != null) { if (v.From != null && v.To != null) { return(new SqlBetweenParameter(path, v.From, v.To)); } else if (v.To == null) { return(new SqlSimpleParameter(path, ">=", v.From)); } else if (v.From == null) { return(new SqlSimpleParameter(path, "<=", v.To)); } } return(null); }
/// <summary> /// Works with BetweenValues of DateValues. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> /// <param name="path"></param> /// <param name="values"></param> /// <returns></returns> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) return null; var v = values[0] as BetweenValue; if (v != null) { var from = ((BetweenValue)v).From as DateValue; var to = ((BetweenValue)v).To as DateValue; if (from == null && to == null) return null; else if (from != null && to != null) return new Conjunction() .Parameter(new SimpleParameter(path, ">=", from.Lower)) .Parameter(new SimpleParameter(path, "<", to.Upper)); else if (to == null) return new SimpleParameter(path, ">=", from.Lower); else if (from == null) return new SimpleParameter(path, "<", to.Upper); } return null; }
/// <summary> /// Use a column in the select list, sort and group by it too. /// </summary> /// <param name="path"></param> /// <param name="direction"></param> /// <returns></returns> public virtual SqlGenerator ColumnOrderByGroupBy(IFieldPath path, SortDirection direction) { Column(path); OrderBy(path, direction); GroupBy(path); return(this); }
/// <summary> /// Works with any value that can be interpreted by the data provider being used. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null) { return(Other.Build(path, null)); } Junction j = (Type == JunctionType.Conjunction ? (Junction) new Conjunction() : new Disjunction()); foreach (var v in values) { var p = Other.Build(path, v); if (p != null) { j.Add(p); } } if (j.Count == 0) { return(null); } else if (j.Count == 1) { return(j[0]); } return(j); }
/// <summary> /// Works with any value that can be interpreted by the data provider being used. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) return null; return new SimpleParameter(path, Operator, values[0]); }
public Parser Create(IFieldPath path, ParameterBuilder builder) { Parser parser = null; if (ParserLookup != null && ParserLookup.ContainsKey(path.Last)) { parser = ParserLookup[path.Last]; } else { if (path.Last.DataType == typeof(DateTime)) { parser = new ExtendedDateParser(); } else if (IsWholeNumber(path.Last.DataType)) { parser = new ConvertParser <object, long>(); } else if (IsDecimal(path.Last.DataType)) { parser = new ConvertParser <object, double>(); } } return(parser); }
public UIElement <UIElement> Build(IFieldPath path, ParameterBuilder builder) { UIElement <System.Windows.UIElement> c; var f = path.Last; var listArgs = OnListRequired(path); if (builder is JunctionBuilder) { return(Build(path, ((JunctionBuilder)builder).Other)); } else if (builder is BetweenBuilder || builder is DateBetweenBuilder) { var between = new BetweenElement(Build(path, null), Build(path, null)); if (!String.IsNullOrEmpty(path.Last.DisplayFormat)) { // assume standard formatting codes // ^C\d*$ = currency (or "$#.00") // ^P\d*$ = percent (or "0.00\%") if (System.Text.RegularExpressions.Regex.IsMatch(path.Last.DisplayFormat.Trim(), @"^([Cc]\d*)|(\$.*)$")) { between.PrefixText = System.Globalization.NumberFormatInfo.CurrentInfo.CurrencySymbol; } else if (System.Text.RegularExpressions.Regex.IsMatch(path.Last.DisplayFormat.Trim(), @"^([Pp]\d*)|([^%]*%)$")) { between.PostfixText = "%"; } } return(between); } else if (builder is BooleanBuilder || builder is NullBuilder) { return(null); } else if (builder is NotBuilder) { return(Build(path, ((NotBuilder)builder).Other)); } else if (f.DataType == typeof(bool)) { c = new CheckBoxElement(); } else if (listArgs.List != null) { if (listArgs.Type == Configuration.FieldListType.Limited) { c = new ListBoxElement(listArgs.List, 400); } else { c = new ComboBoxElement(listArgs.List, true); } } else { c = new TextBoxElement(); } return(c); }
/// <summary> /// Factory method to create concrete part. /// </summary> /// <param name="path"></param> /// <returns></returns> protected virtual PresetPart <T> CreatePart(IFieldPath path) { var part = new PresetPart <T>(path); part.SelectedBuilder = _builderFactory.GetDefault(part.SelectedPath); part.UIElement = _controlFactory.Build(part.SelectedPath, part.SelectedBuilder); return(part); }
public WebOpenGraphEnumerableStream(WebObjectGraphReaderWriterBase objectReaderWriter, IFieldPath <TypeModel, PropertyInfoField> fieldPath, ITypeInstanceFactory typeInstanceFactory) { _objectReaderWriter = objectReaderWriter; _fieldPath = fieldPath; _typeInstanceFactory = typeInstanceFactory; }
public bool CheckPath(IFieldPath <EntityModel, EntityField> fieldPath) { // technically we could fetch the names for each column in the query result and check the field is actually present // but do we need to in reality? the generated queries shouldn't fault var ord = _queryResult.GetOrdinal(fieldPath.FinalField.ProjectionAlias); return(!_queryResult.IsDBNull(ord)); }
public override IParameter Build(IFieldPath path, params object[] values) { var other = Other.Build(path, values); if (other == null) return null; return new NotParameter(other); }
public BindingList<object> this[IFieldPath key] { get { if (ContainsKey(key)) return _listCache[key].Data; return null; } }
/// <summary> /// Works with any value that can be interpreted by the data provider being used. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) { return(null); } return(new SimpleParameter(path, Operator, values[0])); }
private ListRequestedArgs OnListRequired(IFieldPath path) { var args = new ListRequestedArgs(path); if (ListRequested != null) { ListRequested(this, args); } return(args); }
/// <summary> /// Works with values which are strings. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) return null; var v = values[0]; if (v is string) return new LikeParameter(path, (string)v, Mode); return null; }
public override IParameter Build(IFieldPath path, params object[] values) { var other = Other.Build(path, values); if (other == null || !(other is ISqlParameter)) { return(null); } return(new SqlNotParameter((ISqlParameter)other)); }
public BindingList <object> this[IFieldPath key] { get { if (ContainsKey(key)) { return(_listCache[key].Data); } return(null); } }
public virtual UniqueFieldPath this[IFieldPath key] { get { // unwrap FieldPath recursively to find the last step, assuming FieldPath.Last is IField (i.e. we don't traverse it) if (key.Count == 1) { return(this); } return(_paths[(IRelationField)key[0]][key[1, null]]); } }
public ConvertedViewIntersectionField( string fieldName, bool canRead, bool canWrite, TypeModel declaringTypeModel, PropertyInfoField originPropertyField, IFieldPath <ViewIntersectionModel, ViewIntersectionField> path, TryConvertDelegate <TSourceData, TDestinationData> tryConvertDelegate ) : base( fieldName, canRead, canWrite, typeof(TDestinationData), declaringTypeModel, originPropertyField ) { _path = path; _tryConvertDelegate = tryConvertDelegate; }
public IEnumerable <ViewIntersectionField> GetPathFields(IFieldPath <ViewIntersectionField> fieldPath) { if (fieldPath.FinalField == null) { return(Fields); } if (fieldPath.FinalField.SelfModel == null) { return(new ViewIntersectionField[0]); } return(fieldPath.FinalField.SelfModel.Fields); }
public virtual UniqueFieldPath this[IFieldPath key] { get { var ufp = _paths.Find(m => m.Subject.Equals(key[0].Subject)); if (ufp == null) { throw new KeyNotFoundException(String.Format("FieldPath starting at {0} not found in unique field path", key[0].ToString())); } return(ufp[key]); } }
/// <summary> /// Works with DateValues. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> /// <param name="path"></param> /// <param name="values"></param> /// <returns></returns> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) return null; if (values[0] is DateValue) { var date = (DateValue)values[0]; return new SimpleParameter(path, ">=", date.Lower); } return null; }
private IntersectedFields <EntityModel, EntityField, TypeModel, PropertyInfoField> BuildIntersectedFields( EntityField referenceField, IFieldPath <EntityModel, EntityField> referenceKey, IFieldPath <TypeModel, PropertyInfoField> modelField ) { // to obey generic type constraints we need to use reflection // so there's no use in using the ill-suited generic dispatch pattern here var factory = Activator.CreateInstance( typeof(Factory <,>).MakeGenericType(referenceField.FieldDataType, referenceKey.FinalField.FieldDataType), TypeInstanceFactory, Schema ) as Factory; return(factory.BuildIntersectedFields(referenceKey, modelField)); }
void SelectedFieldChanged(object sender, EventArgs e) { var d = ((FieldPathComboItem)sender); var path = new FieldPath(); foreach (var f in Items) { path.Add(f.SelectedField); if (f == d) // end of the road (either truncated or the last field changed) { SelectedPath = path; return; } } }
/// <summary> /// Works with values which are strings. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) { return(null); } var v = values[0]; if (v is string) { return(new LikeParameter(path, (string)v, Mode)); } return(null); }
/// <summary> /// Works with DateValues. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) { return(null); } if (values[0] is DateValue) { var date = (DateValue)values[0]; return(new SqlSimpleParameter(path, ">=", date.Upper)); } return(null); }
private IGraphReader <ViewIntersectionModel, ViewIntersectionField> GetNodeReader( IFieldPath <ViewIntersectionModel, ViewIntersectionField> fieldPath ) { int offset = 0; var reader = _rootReader; foreach (var pathSegment in fieldPath.Fields) { offset++; if (pathSegment is IConvertedViewField convertedViewField) { reader = convertedViewField.ConvertToReader(reader, offset); } } return(reader); }
/// <summary> /// Works with values that are BetweenValue objects. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) return null; var v = values[0] as BetweenValue; if (v != null) { if (v.From != null && v.To != null) return new BetweenParameter(path, v.From, v.To); else if (v.To == null) return new SimpleParameter(path, ">=", v.From); else if (v.From == null) return new SimpleParameter(path, "<=", v.To); } return null; }
/// <summary> /// Works with any value that can be interpreted by the data provider being used. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null) return Other.Build(path, null); Junction j = (Type == JunctionType.Conjunction ? (Junction)new Conjunction() : new Disjunction()); foreach (var v in values) { var p = Other.Build(path, v); if (p != null) j.Add(p); } if (j.Count == 0) return null; else if (j.Count == 1) return j[0]; return j; }
public List <object> GetList(IFieldPath path) { var generator = GetListGenerator(); generator.Path = path; if (Regex.IsMatch(path.Last.List.Source, @"^select.*[`'\[\s]id", RegexOptions.IgnoreCase)) { generator.IdColumn = "ID"; generator.ValueColumn = "Value"; } HashSet <object> set = new HashSet <object>(); using (var conn = CreateConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { //cmd.CommandTimeout = CommandTimeout; generator.UpdateCommand(cmd); using (var reader = cmd.ExecuteReader()) { int idx = -1; try { idx = reader.GetOrdinal("ID"); } catch { } while (reader.Read()) { // assumes either 1 or 2 columns. If 2, one will be ID column var item = reader.GetValue(idx != -1 ? 1 - idx : 0); if (!set.Contains(item)) { set.Add(item); } } } } } return(new List <object>(set)); }
public T Read <T>(IFieldPath <EntityModel, EntityField> fieldPath) { if (typeof(T).IsEnum) { return((T)(object)Read <int>(fieldPath)); } var ord = _queryResult.GetOrdinal(fieldPath.FinalField.ProjectionAlias); if (_queryResult.IsDBNull(ord)) { return(default(T)); } var typeReader = QueryTypeReaders.GetTypeReader <T>(); if (typeReader == null) { throw new InvalidOperationException($"Type `{typeof(T).FullName}` not supported."); } return(typeReader(_queryResult, ord)); }
/// <summary> /// Creates a builder that can be used as a default for a field path. /// </summary> /// <param name="path"></param> /// <returns></returns> public virtual IParameterBuilder GetDefault(IFieldPath path) { IParameterBuilder b; if (path.Last.DataType == typeof(string)) { b = new LikeBuilder(MatchMode.Anywhere); } else if (path.Last.DataType == typeof(DateTime)) { b = new DateBetweenBuilder(); } else if (IsNumeric(path.Last.DataType)) { b = new BetweenBuilder(); } else { b = new SimpleBuilder("="); } return(new JunctionBuilder(JunctionType.Disjunction, b)); }
/// <summary> /// Works with BetweenValues of DateValues. /// Only processes the first value. Use JunctionBuilder to combine multiple. /// </summary> /// <param name="path"></param> /// <param name="values"></param> /// <returns></returns> public override IParameter Build(IFieldPath path, params object[] values) { if (values == null || values.Length == 0) { return(null); } var v = values[0] as BetweenValue; if (v != null) { var from = ((BetweenValue)v).From as DateValue; var to = ((BetweenValue)v).To as DateValue; if (from == null && to == null) { return(null); } else if (from != null && to != null) { return(new SqlConjunction() .Parameter(new SqlSimpleParameter(path, ">=", from.Lower)) .Parameter(new SqlSimpleParameter(path, "<", to.Upper))); } else if (to == null) { return(new SqlSimpleParameter(path, ">=", from.Lower)); } else if (from == null) { return(new SqlSimpleParameter(path, "<", to.Upper)); } } return(null); }
public Action GetList(IFieldPath path, IDbServiceAsyncCallback <List <object> > callback) //ListCallback callback) { var worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.DoWork += (s1, e1) => { e1.Result = GetList(path); e1.Cancel = worker.CancellationPending; }; worker.RunWorkerCompleted += (s2, e2) => { worker.Dispose(); // cancellation assumes the SearchWorker property has been set null if (e2.Cancelled) { return; } if (e2.Error != null) { //MessageBox.Show("There was an error when trying to perform the search.\n\n" + e2.Error.Message, "Search", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); callback.Exception = e2.Error; } else { callback.Results = e2.Result as List <object>; //callback(path, e2.Result as List<object>); } callback.Callback(callback); }; worker.RunWorkerAsync(); return(new Action(worker.CancelAsync)); }
/// <summary> /// Use a column in the select list, sort and group by it too. /// </summary> /// <param name="path"></param> /// <param name="direction"></param> /// <returns></returns> public virtual SqlGenerator ColumnOrderByGroupBy(IFieldPath path, SortDirection direction) { Column(path); OrderBy(path, direction); GroupBy(path); return this; }
/// <summary> /// Add another field path to this path. Will ensure it's still a valid path from root to last. /// </summary> /// <param name="other"></param> public void Add(IFieldPath other) { foreach (var f in other) Add(f); }
/// <summary> /// Define a column to group by. Any additional joins that are required to use these columns will be included. /// Can be called multiple times. /// </summary> public virtual SqlGenerator GroupBy(IFieldPath path) { _groupBy.Add(path); return this; }
/// <summary> /// Ignores values and just creates SimpleParameters that do or don't equal Value. /// </summary> public override IParameter Build(IFieldPath path, params object[] values) { return new SimpleParameter(path, (Value ? "<>" : "="), 0); }
/// <summary> /// Creates a list of builders relevant to the given field path. /// </summary> /// <param name="path"></param> /// <returns></returns> public virtual IList<ParameterBuilder> Build(IFieldPath path) { var builders = new List<ParameterBuilder>(); if (path.Last.DataType == typeof(bool)) { builders.Add(new BooleanBuilder(true)); builders.Add(new BooleanBuilder(false)); builders.Add(new NullBuilder()); builders.Add(new NotBuilder(new NullBuilder()) { Label = "is not null" }); } else if (path.Last.DataType == typeof(string)) { builders.Add(new SimpleBuilder("=")); builders.Add(new LikeBuilder(MatchMode.Anywhere)); builders.Add(new LikeBuilder(MatchMode.Start)); builders.Add(new LikeBuilder(MatchMode.End)); builders.Add(new NotBuilder(new SimpleBuilder("="))); builders.Add(new NotBuilder(new LikeBuilder(MatchMode.Anywhere)) { Label = "does not contain" }); builders.Add(new NotBuilder(new LikeBuilder(MatchMode.Start)) { Label = "does not start with" }); builders.Add(new NotBuilder(new LikeBuilder(MatchMode.End)) { Label = "does not end with" }); builders.Add(new NullBuilder()); builders.Add(new NotBuilder(new NullBuilder()) { Label = "is not null" }); } else if (path.Last.DataType == typeof(DateTime)) { builders.Add(new DateEqualsBuilder()); builders.Add(new NotBuilder(new DateEqualsBuilder())); builders.Add(new DateGtBuilder()); builders.Add(new DateGtEqualBuilder()); builders.Add(new DateLtBuilder()); builders.Add(new DateLtEqualBuilder()); builders.Add(new DateBetweenBuilder()); builders.Add(new NotBuilder(new DateBetweenBuilder())); builders.Add(new NullBuilder()); builders.Add(new NotBuilder(new NullBuilder()) { Label = "is not null" }); } else if (IsNumeric(path.Last.DataType)) { builders.Add(new SimpleBuilder("=")); builders.Add(new NotBuilder(new SimpleBuilder("="))); builders.Add(new SimpleBuilder(">")); builders.Add(new SimpleBuilder(">=")); builders.Add(new SimpleBuilder("<")); builders.Add(new SimpleBuilder("<=")); builders.Add(new BetweenBuilder()); builders.Add(new NotBuilder(new BetweenBuilder())); builders.Add(new NullBuilder()); builders.Add(new NotBuilder(new NullBuilder()) { Label = "is not null" }); } else { // catch all - but if someone is using custom types they can extend the factory and deal with it builders.Add(new SimpleBuilder("=")); builders.Add(new NotBuilder(new SimpleBuilder("="))); builders.Add(new NullBuilder()); builders.Add(new NotBuilder(new NullBuilder()) { Label = "is not null" }); } // pretty much always a disjunction when combining multiple values for (int i = 0; i < builders.Count; i++) builders[i] = new JunctionBuilder(JunctionType.Disjunction, builders[i]); return builders; }
public LikeParameter(IFieldPath path, string value) : this(path, value, MatchMode.Anywhere) { }
/// <summary> /// Uses a column in the select list and also group by it. /// </summary> /// <param name="path"></param> /// <returns></returns> public virtual SqlGenerator ColumnGroupBy(IFieldPath path) { Column(path); GroupBy(path); return this; }
public SimpleParameter(IFieldPath path, string op, object value) { Path = path; Operator = op; Value = value; }
public bool ContainsKey(IFieldPath path) { return _listCache.ContainsKey(path); }
public ListRequestedArgs(IFieldPath path) { Path = path; }
public BetweenParameter(IFieldPath path, object lo, object hi) { _path = path; _lo = lo; _hi = hi; }
/// <summary> /// Uses a column in the select list. Any additional joins that are required to use these columns will be included. /// Can be called multiple times. /// </summary> public virtual SqlGenerator Column(IFieldPath path) { _columns.Add(path); return this; }
public LikeParameter(IFieldPath path, string value, MatchMode mode) { Path = path; Value = value; Mode = mode; }
public SqlString AddField(IFieldPath path) { Parts.Add(path); return this; }
/// <summary> /// Builds a parameter for the given path with the list of values parsed from the UI. /// </summary> /// <param name="path"></param> /// <param name="values"></param> /// <returns></returns> public abstract IParameter Build(IFieldPath path, params object[] values);
public SqlListGenerator Path(IFieldPath path) { _path = path; return this; }
/// <summary> /// Creates a builder that can be used as a default for a field path. /// </summary> /// <param name="path"></param> /// <returns></returns> public virtual ParameterBuilder GetDefault(IFieldPath path) { ParameterBuilder b; if (path.Last.DataType == typeof(string)) b = new LikeBuilder(MatchMode.Anywhere); else if (path.Last.DataType == typeof(DateTime)) b = new DateBetweenBuilder(); else if (IsNumeric(path.Last.DataType)) b = new BetweenBuilder(); else b = new SimpleBuilder("="); return new JunctionBuilder(JunctionType.Disjunction, b); }
/// <summary> /// Define a column to sort by. Any additional joins that are required to use these columns will be included. /// Can be called multiple times. /// </summary> public virtual SqlGenerator OrderBy(IFieldPath path, SortDirection direction) { _orderBy.Add(new OrderedField(path, (direction == SortDirection.Ascending ? "ASC" : "DESC"))); return this; }
public OrderedField(IFieldPath path, string direction) { Path = path; Direction = direction; }
public override IParameter Build(IFieldPath path, params object[] values) { return null; }
public SqlString AddField(IFieldPath path) { Parts.Add(path); return(this); }
public NullParameter(IFieldPath path) { Path = path; }