protected void StartFeed(Stack <ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations) { nodeStack.Push(new ResponseNode { Feed = new AnnotatedFeed(new List <AnnotatedEntry>()), }); }
// Async method to call Remote WCF Service static async Task <int> MainAsync(string[] args) { var annotations = new ODataFeedAnnotations(); // define uri WCF service to connect to var client = new ODataClient("http://services.odata.org/V4/TripPinServiceRW/"); var x = ODataDynamic.Expression; var duration = TimeSpan.FromHours(4); // LINQ Query var flights = await client .For(x.People) .Filter(x.Trips .All(x.PlanItems .Any(x.Duration < duration)) ) .FindEntriesAsync(); foreach (var entry in flights) { Console.WriteLine(String.Format("Person [ UserName: {0} FirstName: {1} LastName: {2} Emails: {3} Gender: {4} ]", entry.UserName, entry.FirstName, entry.LastName, entry.Emails[0], entry.Gender)); } Console.WriteLine("--- WCF Client ODATA Query Execution Completed. Press ENTER to exit. ---"); Console.ReadKey(); return(1); }
public async Task <IPageResult <T> > FindEntriesAsync() { var annotations = new ODataFeedAnnotations(); var results = await _client.FindEntriesAsync(annotations); return(new PageResult <T>(results, annotations)); }
public async Task <List <MMS.QueryService.ODATA.Models.PO.ProductVendor> > GetProductVendors(string sku) { List <MMS.QueryService.ODATA.Models.PO.ProductVendor> listofproductvendors = new List <MMS.QueryService.ODATA.Models.PO.ProductVendor>(); try { if (client == null) { client = new ODataClient(_config.Value.QueryServiceAddress); } var annotations = new ODataFeedAnnotations(); var lookupdataList = await client .For <MMS.QueryService.ODATA.Models.PO.ProductVendor>() .Filter(x => x.Sku == sku) .FindEntriesAsync(); listofproductvendors.AddRange(lookupdataList); //_logger.LogDebug("Fetching lookup data from ODataClient Finished"); } catch (Exception ex) { _logger.LogError(ex, "Failed on GetProductVendors: {message}", ex.Message); //throw; } return(listofproductvendors); }
public async Task <List <MMS.QueryService.ODATA.Models.PO.ProductHierarchy> > GetProductHierarchy(string subClass) { List <MMS.QueryService.ODATA.Models.PO.ProductHierarchy> listofproducthierarchy = new List <MMS.QueryService.ODATA.Models.PO.ProductHierarchy>(); try { if (client == null) { client = new ODataClient(_config.Value.QueryServiceAddress); } var annotations = new ODataFeedAnnotations(); var lookupdataList = await client .For <MMS.QueryService.ODATA.Models.PO.ProductHierarchy>() .Filter(x => x.SubClass == subClass) .FindEntriesAsync(); listofproducthierarchy.AddRange(lookupdataList); } catch (Exception ex) { _logger.LogError(ex, "Failed on GetProductHierarchy: {message}", ex.Message); //throw; } return(listofproducthierarchy); }
/// <summary> /// Executes a query adding to the passed collection. /// </summary> /// <typeparam name="TColl">The collection <see cref="Type"/>.</typeparam> /// <param name="coll">The collection to add items to.</param> /// <remarks>The <see cref="QueryArgs"/> <see cref="ODataArgs{T, TModel}.Paging"/> is also applied, including <see cref="PagingArgs.IsGetCount"/> where requested.</remarks> public void SelectQuery <TColl>(TColl coll) where TColl : ICollection <T> { ExecuteQuery(q => { ODataFeedAnnotations ann = null !; if (QueryArgs.Paging != null) { q = q.Skip(QueryArgs.Paging.Skip).Top(QueryArgs.Paging.Take); if (QueryArgs.Paging.IsGetCount && _odata.IsPagingGetCountSupported) { ann = new ODataFeedAnnotations(); } } foreach (var item in q.FindEntriesAsync(ann).GetAwaiter().GetResult()) { coll.Add(ODataBase.GetValue(QueryArgs, item)); } if (ann != null) { QueryArgs.Paging !.TotalCount = ann.Count; } }); }
public async Task <List <MMS.QueryService.ODATA.Models.PO.VendorAp> > GetVendorName(string vendCode) { List <MMS.QueryService.ODATA.Models.PO.VendorAp> listofproductvendors = new List <MMS.QueryService.ODATA.Models.PO.VendorAp>(); try { if (client == null) { client = new ODataClient(_config.Value.QueryServiceAddress); } var annotations = new ODataFeedAnnotations(); var lookupdataList = await client .For <MMS.QueryService.ODATA.Models.PO.VendorAp>() .Filter(x => x.VendCode == vendCode) .FindEntriesAsync(); listofproductvendors.AddRange(lookupdataList); } catch (Exception ex) { throw; } return(listofproductvendors); }
public async Task FindAllPeople() { var client = new ODataClient(new ODataClientSettings { BaseUri = _serviceUri, IncludeAnnotationsInResults = true }); var annotations = new ODataFeedAnnotations(); int count = 0; var people = await client .For <PersonWithAnnotations>("Person") .FindEntriesAsync(annotations); count += people.Count(); while (annotations.NextPageLink != null) { people = await client .For <PersonWithAnnotations>() .FindEntriesAsync(annotations.NextPageLink, annotations); count += people.Count(); foreach (var person in people) { Assert.NotNull(person.Annotations.Id); Assert.NotNull(person.Annotations.ReadLink); Assert.NotNull(person.Annotations.EditLink); } } Assert.Equal(count, annotations.Count); }
private async Task ProcessPowerPageAsync(DomainContext domainContext, int pageSize, int pageIndex) { if (pageIndex < 1) { pageIndex = 1; } var annotations = new ODataFeedAnnotations(); var powers = await domainContext .Powers .Top(pageSize) .Skip((pageIndex - 1) * pageSize) .Select(x => x.Id) .FindEntriesAsync(annotations); var count = powers.Count(); if (count == 0) { return; } // upate counters TotalCount = (int)(annotations.Count ?? 0); NumberLoaded += count; PercentageLoaded = (int)(100d * ((double)NumberLoaded / (double)TotalCount)); }
public async Task <IEnumerable <T> > ReadAsCollectionAsync(ODataFeedAnnotations annotations, CancellationToken cancellationToken) { if (ResponseMessage.IsSuccessStatusCode && ResponseMessage.StatusCode != HttpStatusCode.NoContent && (_request.Method == RestVerbs.Get || _request.ResultRequired)) { var responseReader = _session.Adapter.GetResponseReader(); var response = await responseReader .GetResponseAsync(ResponseMessage) .ConfigureAwait(false); if (cancellationToken.IsCancellationRequested) { cancellationToken.ThrowIfCancellationRequested(); } if (annotations != null && response.Feed != null) { annotations.CopyFrom(response.Feed.Annotations); } var result = response.AsEntries(_session.Settings.IncludeAnnotationsInResults); return(result.Select(x => x.ToObject <T>(TypeCache))); } else { return(Array.Empty <T>()); } }
public async Task FindAllPeople() { var client = new ODataClient(new ODataClientSettings { BaseUri = _serviceUri, IncludeAnnotationsInResults = true }); var annotations = new ODataFeedAnnotations(); int count = 0; var people = await client .For<PersonWithAnnotations>("Person") .FindEntriesAsync(annotations); count += people.Count(); while (annotations.NextPageLink != null) { people = await client .For<PersonWithAnnotations>() .FindEntriesAsync(annotations.NextPageLink, annotations); count += people.Count(); foreach (var person in people) { Assert.NotNull(person.Annotations.Id); Assert.NotNull(person.Annotations.ReadLink); Assert.NotNull(person.Annotations.EditLink); } } Assert.Equal(count, annotations.Count); }
protected void StartFeed(Stack<ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations) { nodeStack.Push(new ResponseNode { Feed = new AnnotatedFeed(new List<AnnotatedEntry>()), }); }
public async Task <ProductLabelCode> GetProductLabelDescription(string code) { ProductLabelCode productlabelCode = new ProductLabelCode(); try { if (client == null) { client = new ODataClient(_config.Value.QueryServiceAddress); } var annotations = new ODataFeedAnnotations(); var productlabelCodes = await client .For <ProductLabelCode>() .Filter(x => x.Code == code) .FindEntriesAsync(); productlabelCode = productlabelCodes?.ToList().FirstOrDefault(); } catch (Exception ex) { throw; } return(productlabelCode); }
protected void StartFeed(Stack<ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations) { nodeStack.Push(new ResponseNode { Feed = new List<IDictionary<string, object>>(), FeedAnnotations = feedAnnotations, }); }
protected void EndFeed(Stack<ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations, ref ResponseNode rootNode) { var feedNode = nodeStack.Pop(); if (nodeStack.Any()) nodeStack.Peek().Feed = feedNode.Feed; else rootNode = feedNode; feedNode.Feed.SetAnnotations(feedAnnotations); }
public async Task TotalCount() { var annotations = new ODataFeedAnnotations(); var products = await _client .For("Products") .FindEntriesAsync(annotations); Assert.Equal(77, annotations.Count); Assert.Equal(20, products.Count()); }
public async Task TotalCount() { var client = new ODataClient(CreateDefaultSettings().WithHttpMock()); var annotations = new ODataFeedAnnotations(); var products = await client .For("Products") .FindEntriesAsync(annotations); Assert.Equal(ExpectedCountOfProducts, annotations.Count); Assert.Equal(ExpectedCountOfProducts, products.Count()); }
public async Task TotalCount() { var annotations = new ODataFeedAnnotations(); var products = await _client .For("Products") .FindEntriesAsync(annotations).ConfigureAwait(false); Assert.Equal(ExpectedTotalCount, annotations.Count); Assert.Equal(ExpectedTotalCount, products.Count()); }
public void SetLinkAnnotations(ODataFeedAnnotations annotations) { if (LinkAnnotations == null) { LinkAnnotations = annotations; } else { LinkAnnotations.Merge(annotations); } }
public void SetAnnotations(ODataFeedAnnotations annotations) { if (Annotations == null) { Annotations = annotations; } else { Annotations.Merge(annotations); } }
internal void Merge(ODataFeedAnnotations src) { if (src != null) { Id ??= src.Id; Count ??= src.Count; DeltaLink ??= src.DeltaLink; NextPageLink ??= src.NextPageLink; InstanceAnnotations ??= src.InstanceAnnotations; } }
public async Task FindSinglePersonWithFeedAnnotations() { var annotations = new ODataFeedAnnotations(); var people = await _client .For<Person>() .Filter(x => x.UserName == "russellwhyte") .FindEntriesAsync(annotations); Assert.Equal(1, people.Count()); Assert.Null(annotations.NextPageLink); }
public async Task FindSinglePersonWithFeedAnnotations() { var annotations = new ODataFeedAnnotations(); var people = await _client .For <Person>() .Filter(x => x.UserName == "russellwhyte") .FindEntriesAsync(annotations); Assert.Single(people); Assert.Null(annotations.NextPageLink); }
public async Task <IEnumerable <T> > FindEntriesAsync(Uri annotatedUri, ODataFeedAnnotations annotations, CancellationToken cancellationToken) { var commandText = annotatedUri.AbsoluteUri; if (cancellationToken.IsCancellationRequested) { cancellationToken.ThrowIfCancellationRequested(); } var result = _client.FindEntriesAsync(commandText, annotations, cancellationToken); return(await FilterAndTypeColumnsAsync( result, _command.SelectedColumns, _command.DynamicPropertiesContainerName) .ConfigureAwait(false)); }
protected void EndFeed(Stack <ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations, ref ResponseNode rootNode) { var feedNode = nodeStack.Pop(); if (nodeStack.Any()) { nodeStack.Peek().Feed = feedNode.Feed; } else { rootNode = feedNode; } feedNode.Feed.SetAnnotations(feedAnnotations); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); var annotations = new ODataFeedAnnotations(); students = await OData.Client //.Filter(s => s.Name.Contains("t")) .OrderBy(s => s.Id) .Top(10) .Select(s => new { s.Id, s.Name }) .FindEntriesAsync(annotations); count = annotations.Count.GetValueOrDefault(0); }
protected virtual async Task <IEnumerable <T> > GetAllRecordsAsync <T>(IBoundClient <T> query) where T : class { var annotations = new ODataFeedAnnotations(); var entities = await query.FindEntriesAsync(annotations); var result = entities.ToList(); while (annotations.NextPageLink != null) { entities = await query.FindEntriesAsync(annotations.NextPageLink, annotations); result.AddRange(entities); } return(result); }
public async Task <IEnumerable <T> > FindEntriesAsync(ODataFeedAnnotations annotations, CancellationToken cancellationToken) { await _session.ResolveAdapterAsync(cancellationToken) .ConfigureAwait(false); var command = _command.WithCount().Resolve(_session); if (cancellationToken.IsCancellationRequested) { cancellationToken.ThrowIfCancellationRequested(); } var result = _client.FindEntriesAsync(command.Format(), annotations, cancellationToken); return(await FilterAndTypeColumnsAsync( result, _command.SelectedColumns, _command.DynamicPropertiesContainerName) .ConfigureAwait(false)); }
protected void EndFeed(Stack<ResponseNode> nodeStack, ODataFeedAnnotations feedAnnotations, ref ResponseNode rootNode) { var feedNode = nodeStack.Pop(); var entries = feedNode.Feed; if (nodeStack.Any()) nodeStack.Peek().Feed = entries; else rootNode = feedNode; if (feedNode.FeedAnnotations == null) { feedNode.FeedAnnotations = feedAnnotations; } else { feedNode.FeedAnnotations.Merge(feedAnnotations); } }
public virtual async Task TestComplexTypeGetWithCount() { using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs { UseRealServer = true })) { Token token = await testEnvironment.Server.LoginWithCredentials("ValidUserName", "ValidPassword", clientId : "TestResOwner"); ODataFeedAnnotations annotations = new ODataFeedAnnotations(); var result = (await testEnvironment.BuildTestODataClient(token).NestedObjects().GetComplexObjects2() .Take(2) .FindEntriesAsync(annotations)).ToList(); Assert.AreEqual(5, annotations.Count); Assert.AreEqual(2, result.Count); } }
internal void CopyFrom(ODataFeedAnnotations src) { if (src != null) { Id = src.Id; Count = src.Count; DeltaLink = src.DeltaLink; NextPageLink = src.NextPageLink; InstanceAnnotations = src.InstanceAnnotations; } else { Id = null; Count = null; DeltaLink = null; NextPageLink = null; InstanceAnnotations = null; } }
protected virtual async Task <BreathingSpaceBrowseResponse> BrowseActiveBreathingSpacesAsync(Guid moneyAdviserId, bool showNewestFirst) { var annotations = new ODataFeedAnnotations(); var command = _client.For <Ntt_breathingspacemoratorium>() .Expand(m => m.ntt_debtorid) .Filter(m => m._ntt_breathingspacestatusid_value == MoratoriumIdStatusMap.Active) .Filter(m => m._ntt_managingmoneyadviserorganisationid_value == moneyAdviserId); command = showNewestFirst ? command.OrderByDescending(m => m.ntt_commencementdate) : command.OrderBy(m => m.ntt_commencementdate); var list = (await command.FindEntriesAsync(annotations)) .Select(m => MapBreathingSpaceBrowseResult(m)).ToList(); return(new BreathingSpaceBrowseResponse { BreathingSpaceBrowseItems = list }); }
public async Task FindAllPeople() { var annotations = new ODataFeedAnnotations(); int count = 0; var people = await _client .For<Person>() .FindEntriesAsync(annotations); count += people.Count(); while (annotations.NextPageLink != null) { people = await _client .For<Person>() .FindEntriesAsync(annotations.NextPageLink, annotations); count += people.Count(); } Assert.Equal(count, annotations.Count); }
public async Task <List <POO> > GetPOsForVendorFromDB(string vendCode) { try { //pull data from queryservice and load //make call to queryservice _logger.LogInformation("Going to call PO Queryservice to get POs for the Vendorcode.", vendCode); if (_client == null) { _client = new ODataClient(_config.Value.QueryServiceAddress); } var annotations = new ODataFeedAnnotations(); List <POO> listofpos = new List <POO>(); var pos = await _client .For <POO>() .Filter(x => x.SubVendor.VendCode == vendCode && (x.SubVendor.ClassCode == "I" || x.SubVendor.ClassCode == "D")) .FindEntriesAsync(annotations); listofpos.AddRange(pos); while (annotations.NextPageLink != null) { listofpos.AddRange(await _client .For <POO>() .Filter(x => x.SubVendor.VendCode == vendCode) .FindEntriesAsync(annotations.NextPageLink, annotations)); } _logger.LogInformation("PO Queryservice Returned Data for the POs for VendorCode.", listofpos); return(listofpos); } catch (Exception ex) { _logger.LogError(ex, "Failed to Get POs for the VendorCode from QueryService: {Reason}", ex.Message); return(null); } }
public async Task <List <POSkus> > GetPOSkusfromDBFromPONumber(string ponumber) { try { //pull data from queryservice and load //make call to queryservice _logger.LogInformation("Going to call PO Queryservice to get POSkus for PONumber.--{ponumber}", ponumber); if (_client == null) { _client = new ODataClient(_config.Value.QueryServiceAddress); } var annotations = new ODataFeedAnnotations(); List <POSkus> listofpoSkus = new List <POSkus>(); var poSkus = await _client .For <POSkus>() .Filter(x => x.PONumber == Convert.ToInt32(ponumber)) .FindEntriesAsync(annotations); listofpoSkus.AddRange(poSkus); while (annotations.NextPageLink != null) { listofpoSkus.AddRange(await _client .For <POSkus>() .Filter(x => x.PONumber == Convert.ToInt32(ponumber)) .FindEntriesAsync(annotations.NextPageLink, annotations)); } _logger.LogInformation("PO Queryservice Returned Data for the POSkus.--{poSkus}", poSkus); return(listofpoSkus); } catch (Exception ex) { _logger.LogError(ex, "Failed to Get POskus from QueryService: {Reason}", ex.Message); return(null); } }
protected virtual async Task <BreathingSpaceBrowseResponse> BrowseSentToMoneyAdviserAsync(Guid moneyAdviserId, bool showNewestFirst) { var annotations = new ODataFeedAnnotations(); var command = _client.For <ntt_moratoriumtransferrequest>() .Expand(r => r.ntt_breathingspacemoratoriumid) .Expand(r => r.ntt_breathingspacemoratoriumid.ntt_debtorid) .Expand(r => r.ntt_owningmoneyadviceorganisationid) .Filter(r => r.ntt_owningmoneyadviceorganisationid.inss_moneyadviserorganisationid == moneyAdviserId) .Filter(r => r.statuscode == (int)TransferDebtorRequestStatusCodes.Transferred); command = showNewestFirst ? command.OrderByDescending(r => r.ntt_completedon) : command.OrderBy(r => r.ntt_completedon); var list = (await command.FindEntriesAsync(annotations)) .Select(m => MapBreathingSpaceBrowseResult(m.ntt_breathingspacemoratoriumid)).ToList(); return(new BreathingSpaceBrowseResponse { BreathingSpaceBrowseItems = list }); }
protected virtual async Task <BreathingSpaceBrowseResponse> BrowseDebtsToBeReviewedAsync(Guid moneyAdviserId, bool showNewestFirst) { var annotations = new ODataFeedAnnotations(); var reviewRequested = _options.DebtEligibilityReviewStatusId(DebtEligibilityReviewStatus.ReviewRequested); var command = _client.For <ntt_debteligibilityreview>() .Expand(d => d.ntt_DebtId.ntt_BreathingSpaceMoratoriumId) .Expand(d => d.ntt_DebtId.ntt_BreathingSpaceMoratoriumId.ntt_debtorid) .Filter(d => d._ntt_eligibilitystatusid_value == reviewRequested) .Filter(d => d.ntt_DebtId._ntt_managingmoneyadviserorganisationid_value == moneyAdviserId); command = showNewestFirst ? command.OrderByDescending(m => m.createdon) : command.OrderBy(m => m.createdon); var list = (await command.FindEntriesAsync(annotations)) .Select(m => MapBreathingSpaceBrowseResult(m.ntt_DebtId.ntt_BreathingSpaceMoratoriumId)).ToList(); return(new BreathingSpaceBrowseResponse { BreathingSpaceBrowseItems = list }); }
// Async method to call Remote WCF Service static async Task<int> MainAsync(string[] args) { var annotations = new ODataFeedAnnotations(); // define uri WCF service to connect to var client = new ODataClient("http://services.odata.org/V4/TripPinServiceRW/"); var x = ODataDynamic.Expression; var duration = TimeSpan.FromHours(4); // LINQ Query var flights = await client .For(x.People) .Filter(x.Trips .All(x.PlanItems .Any(x.Duration < duration)) ) .FindEntriesAsync(); foreach (var entry in flights) { Console.WriteLine(String.Format("Person [ UserName: {0} FirstName: {1} LastName: {2} Emails: {3} Gender: {4} ]", entry.UserName, entry.FirstName, entry.LastName, entry.Emails[0], entry.Gender)); } Console.WriteLine("--- WCF Client ODATA Query Execution Completed. Press ENTER to exit. ---"); Console.ReadKey(); return 1; }
private async Task<IPageResult<Security>> GetPagedResponse(Func<IBoundClient<Security>> request) { var annotations = new ODataFeedAnnotations(); var response = await request() .FindEntriesAsync(annotations); return new PageResult<Security> { Count = annotations.Count.HasValue ? (int)annotations.Count : 0, Value = response.ToList() }; }
protected override void MakeTaskForRequest(AsyncDataSourcePageRequest request, int retryDelay) { int actualPageSize = 0; SortDescriptionCollection sortDescriptions = null; lock (SyncLock) { actualPageSize = ActualPageSize; sortDescriptions = SortDescriptions; } ODataFeedAnnotations annotations = new ODataFeedAnnotations(); var client = _client.For(_entitySet); lock (SyncLock) { if (FilterExpressions != null && FilterExpressions.Count > 0 && _filterString == null) { StringBuilder sb = new StringBuilder(); bool first = true; foreach (var expr in FilterExpressions) { if (first) { first = false; } else { sb.Append(" AND "); } ODataDataSourceFilterExpressionVisitor visitor = new ODataDataSourceFilterExpressionVisitor(); visitor.Visit(expr); var txt = visitor.ToString(); if (FilterExpressions.Count > 1) { txt = "(" + txt + ")"; } sb.Append(txt); } _filterString = sb.ToString(); } if (_filterString != null) { client = client.Filter(_filterString); } if (SortDescriptions != null) { foreach (var sort in SortDescriptions) { if (sort.Direction == System.ComponentModel.ListSortDirection.Descending) { client = client.OrderByDescending(sort.PropertyName); } else { client = client.OrderBy(sort.PropertyName); } } } if (DesiredProperties != null && DesiredProperties.Length > 0) { client = client.Select(DesiredProperties); } } Task task; if (request.Index == SchemaRequestIndex) { task = client .Count() .FindScalarAsync<int>(); } else { task = client .Skip(request.Index * actualPageSize) .Top(actualPageSize) .FindEntriesAsync(annotations); } request.TaskHolder = new AsyncDataSourcePageTaskHolder(); request.TaskHolder.Task = task; lock (SyncLock) { Tasks.Add(request); _annotations.Add(annotations); } }
public async Task TotalCount() { var annotations = new ODataFeedAnnotations(); var products = await _client .For("Products") .FindEntriesAsync(annotations); Assert.Equal(77, annotations.Count); Assert.Equal(77, products.Count()); }