public IEnumerable<MyAlphaEntity> GetAll(ODataQueryOperation operation) { for (int i = 0; i < 5; i++) { yield return GetOne(Guid.NewGuid().ToString()); } }
/// <summary> /// Executes the ExecuteProjectionTyped method to a given <see cref="IEnumerable"/> object. /// </summary> /// <param name="operation">The <see cref="ODataQueryOperation"/> value.</param> /// <param name="enumerable">An <see cref="IEnumerable"/> object.</param> /// <returns>The projected result of the projection.</returns> public static IEnumerable ExecuteProjection(ODataQueryOperation operation, IEnumerable <object> enumerable) { var executorType = typeof(ODataOperationExecutionHelper); var projectionMethod = executorType.GetMethod("ExecuteProjectionTyped", BindingFlags.Public | BindingFlags.Static); var genericMethod = projectionMethod.MakeGenericMethod(operation.ProjectedType); return((IEnumerable)genericMethod.Invoke(executorType, new object[] { operation.ProjectionExpression, enumerable })); }
public IEnumerable<WorkItem> GetAll(ODataQueryOperation operation) { if (operation == null) { throw new ArgumentNullException("operation"); } var parameters = new WorkItemFilterExpressionVisitor(operation.FilterExpression).Eval(); return this.proxy.GetWorkItemsByProjectCollection(parameters); }
public IEnumerable<Changeset> GetAll(ODataQueryOperation operation) { if (operation == null) { throw new ArgumentNullException("operation"); } var parameters = new ChangesetFilterExpressionVisitor(operation.FilterExpression).Eval(); int topRequestValue = this.GetTopRequestValue(operation, parameters); return this.proxy.GetChangesetsByProjectCollection(parameters, topRequestValue); }
/// <summary> /// Gets the count treshold to minimize the number of elements retrieved from TFS /// </summary> private int GetTopRequestValue(ODataQueryOperation operation) { int topRequestValue = int.MaxValue; if (operation.IsCountRequest) { if (!string.IsNullOrEmpty(operation.ContinuationToken)) { var parts = operation.ContinuationToken.Split(':').Select(int.Parse); topRequestValue = parts.First() + parts.Last() + 1; } } else { if (operation.TopCount > 0) { topRequestValue = operation.TopCount + operation.SkipCount + 1; } } return topRequestValue; }
private static Func <ParameterInfo, string> ParameterSelector(ODataQueryOperation operation) { return(parameter => { var selectOneOperation = operation as ODataSelectOneQueryOperation; if (selectOneOperation != null) { // Pass #1: Check for a single ID property. if (parameter.Name.Equals("id", StringComparison.OrdinalIgnoreCase)) { return selectOneOperation.Key; } // Pass #2: Check for a key value. if (selectOneOperation.Keys.Keys.SingleOrDefault(k => k.Equals(parameter.Name, StringComparison.InvariantCultureIgnoreCase)) != null) { return selectOneOperation.Keys.SingleOrDefault(o => o.Key.Equals(parameter.Name, StringComparison.InvariantCultureIgnoreCase)).Value; } } // Pass #3: Check for a context parameter. return operation.ContextParameters.SingleOrDefault(d => d.Key.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)).Value; }); }
/// <summary> /// A fluent interface to resolve repository information. /// </summary> /// <param name="operation">An <see cref="ODataQueryOperation"/>.</param> /// <returns>A new instance of the <see cref=" ODataOperationResolver"/> class.</returns> public static ODataOperationResolver For(ODataQueryOperation operation) { return(new ODataOperationResolver(operation)); }
/// <summary> /// Initializes a new instance of the ODataOperationResolver class. /// </summary> /// <param name="operation">An <see cref="ODataQueryOperation"/>.</param> protected ODataOperationResolver(ODataQueryOperation operation) { this.operation = operation; }
/// <summary> /// Gets the count treshold to minimize the number of elements retrieved from TFS /// </summary> private int GetTopRequestValue(ODataQueryOperation operation, FilterNode parameters) { int topRequestValue = int.MaxValue; if (parameters == null || !parameters.Any(p => p.Key.Equals("Owner") || p.Key.Equals("CreationDate") || p.Key.Equals("Comment") || p.Key.Equals("ArtifactUri"))) { if (operation.IsCountRequest) { if (!string.IsNullOrEmpty(operation.ContinuationToken)) { var parts = operation.ContinuationToken.Split(':').Select(int.Parse); topRequestValue = parts.First() + parts.Last() + 1; } } else { if (operation.TopCount > 0) { topRequestValue = operation.TopCount + operation.SkipCount + 1; } } } return topRequestValue; }
public IEnumerable<MapRegion> GetAll(ODataQueryOperation operation) { return null; }
public abstract object GetOne(ODataSelectOneQueryOperation operation);
public IEnumerable<GeoSuggestion> GetAll(ODataQueryOperation operation) { return new GeoSuggestion[0]; }
public IEnumerable<Station> GetAll(ODataQueryOperation operation) { return new Station[0]; }
/// <summary> /// Executes an <see cref="ODataQueryOperation"/>. /// </summary> /// <param name="operation">The <see cref="ODataQueryOperation"/> to be executed..</param> /// <returns>The result of the OData expression execution.</returns> public virtual object ExecuteQuery(ODataQueryOperation operation) { try { if (operation == null) { throw new NotSupportedException(); } if (operation is ODataCompoundQueryOperation) { var compoundQuery = operation as ODataCompoundQueryOperation; var item = (this.ExecuteQuery(compoundQuery.AnonymousGetManyOperation) as IEnumerable <object>).First(); compoundQuery.OfType = item.GetType(); compoundQuery.Keys = item.DataServiceKeys(); } operation.ContextParameters = this.ContextParameters; if (!this.SkipTakeBasedPaging) { operation.ContinuationToken = this.ContinuationToken; } else { var parts = this.ContinuationToken.Split(':').Select(int.Parse); operation.SkipCount = parts.First(); operation.TopCount = parts.Last(); } var repository = ODataOperationResolver.For(operation).Repository(this.resolver); var method = ODataOperationResolver.For(operation).Method(repository); var arguments = ODataOperationResolver.For(operation).Arguments(method); var temp = method.Invoke(repository, arguments); if (temp == null) { return(null); } if (temp.GetType() == typeof(long) && operation.IsCountRequest && operation.OfType.GetAttribute <CollectionCountAttribute>() != null) { return(temp); } var manyOperation = operation as ODataSelectManyQueryOperation; if (temp.GetType() == typeof(long) && operation.IsCountRequest && manyOperation.NavigationPropertyInfo.GetAttribute <ForeignPropertyCountAttribute>() != null) { return(temp); } if (manyOperation != null && manyOperation.NavigationPropertyInfo.GetAttribute <ForeignPropertyAttribute>() == null) { temp = manyOperation.NavigationPropertyInfo.GetValue(temp, null); } var elementType = manyOperation == null ? operation.OfType : manyOperation.NavigationPropertyType; var result = (IEnumerable <object>)ODataOperationExecutionHelper.EvalEnumerable(temp.WrapIntoEnumerable(), elementType); var behavior = repository.GetBehavior(method); if (!behavior.HandlesEverything) { if (!behavior.HandlesFilter && operation.FilterExpression != null) { result = (IEnumerable <object>)ODataOperationExecutionHelper.ExecuteLinq2ObjectsImplementation("Where", result, operation.FilterExpression); } while (!behavior.HandlesOrderBy && operation.OrderStack != null && operation.OrderStack.Count > 0) { var orderExpression = operation.OrderStack.Pop(); result = (IEnumerable <object>)ODataOperationExecutionHelper.ExecuteLinq2ObjectsImplementation(orderExpression.OrderMethodName, result, orderExpression.Expression); } if (!behavior.HandlesSkip && operation.SkipCount > 0) { result = (IEnumerable <object>)ODataOperationExecutionHelper.ExecuteLinq2ObjectsImplementation("Skip", result, operation.SkipCount); } if (!behavior.HandlesTop && operation.TopCount > 0) { result = (IEnumerable <object>)ODataOperationExecutionHelper.ExecuteLinq2ObjectsImplementation("Take", result, operation.TopCount); } } if (operation.IsCountRequest) { return(result.LongCount()); } if (operation.ProjectionExpression != null) { result = (IEnumerable <object>)ODataOperationExecutionHelper.ExecuteProjection(operation, result); } return(result); } catch (Exception ex) { var realException = ex is TargetInvocationException ? ex.InnerException : ex; if (!(realException is DataServiceException)) { realException = new DataServiceException(500, "Internal Server Error", realException.Message, "en-US", realException); } throw realException; } }
public object MockEntityWithCollectionCountAttributeCount(ODataQueryOperation operation) { throw new NotImplementedException(); }
public object GetAll(ODataQueryOperation operation) { throw new NotImplementedException(); }