public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var view = inflater.Inflate(Resource.Layout.documents_list, container, false); string content = null; Task.Run(async() => { var client = new HttpClient(new AndroidClientHandler()); client.BaseAddress = new Uri(ContainerFactory.Settings.ServerAppUrl); var request = new HttpRequestMessage(HttpMethod.Get, $"/odata/Sin/DocumentiPersona?$filter=Persona/CfPersona eq '{_authenticationService.CfPersona}'&$select=Descrizione,Anno"); request.Headers.Add("Authorization", $"Bearer {_authenticationService.Token.access_token}"); request.Headers.Add("Accept", "application/json"); using (var response = await client.SendAsync(request)) { if (response.IsSuccessStatusCode) { content = await response.Content.ReadAsStringAsync(); documents = JsonConvert.DeserializeObject <ODataResult <IEnumerable <PersonDocument> > >(content); var listView = view.FindViewById <ListView>(Resource.Id.listDocuments); listView.Adapter = new PersonDocumentAdapter(inflater, documents.value); listView.ItemClick += ItemOnClick; } } }).Wait(); return(view); }
public Object ParseAsync(HttpResponseMessage response) { using (Stream stream = response.Content.ReadAsStreamAsync().Result) { var responseMessage = new ODataResponseMessage(stream); var context = new ODataDeserializerContext() { Model = Model, Request = response.RequestMessage }; using (var messageReader = new ODataMessageReader(responseMessage, _settings, Model)) { ODataResult result = GetODataResult(messageReader); while (result.ODataReader.Read()) { if (result.ODataReader.State == ODataReaderState.EntryEnd) { var entry = (ODataEntry)result.ODataReader.Item; var entityType = (IEdmEntityType)Model.FindType(entry.TypeName); var entityTypeReference = new EdmEntityTypeReference(entityType, false); var navigationLinks = new ODataEntryWithNavigationLinks(entry); result.AddResult(_deserializer.ReadEntry(navigationLinks, entityTypeReference, context)); } } return(result.Result); } } }
public IActionResult GetById(Guid id) { return(ActionHelper.TryCatchWithLoggerGeneric <IActionResult>(() => { ApplicationModel selectedApplication = Applications.FirstOrDefault(x => x.Id == id); if (selectedApplication == null) { _logger.LogWarning("GetById -> {0} not found", id); return NotFound(); } string claimId = User.Claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.Jti)?.Value; string currentToken = _jwtService.Clone(_dataProtectionService.Protect(claimId), true); if (string.IsNullOrEmpty(currentToken)) { return Unauthorized(); } selectedApplication.Url = $"{selectedApplication.Url}?jwt_token={currentToken}"; ODataResult <ApplicationModel> results = new ODataResult <ApplicationModel> { value = new List <ApplicationModel>() { selectedApplication } }; return Ok(results); }, _logger)); }
public IActionResult GetAll() { return(ActionHelper.TryCatchWithLoggerGeneric <IActionResult>(() => { ODataResult <ApplicationModel> results = new ODataResult <ApplicationModel> { value = Applications.OrderBy(o => o.Name).ToList() }; return Ok(results); }, _logger)); }
private void WriteFeed(object graph, ODataWriter writer, ODataSerializerContext writeContext) { ODataSerializer entrySerializer = SerializerProvider.GetEdmTypeSerializer(_edmCollectionType.ElementType()); if (entrySerializer == null) { throw Error.NotSupported(SRResources.TypeCannotBeSerialized, _edmCollectionType.ElementType(), typeof(ODataMediaTypeFormatter).Name); } Contract.Assert(entrySerializer.ODataPayloadKind == ODataPayloadKind.Entry); IEnumerable enumerable = graph as IEnumerable; // Data to serialize if (enumerable != null) { ODataFeed feed = new ODataFeed(); if (writeContext.EntitySet != null) { IEntitySetLinkBuilder linkBuilder = SerializerProvider.EdmModel.GetEntitySetLinkBuilder(writeContext.EntitySet); Uri feedSelfLink = linkBuilder.BuildFeedSelfLink(new FeedContext(writeContext.EntitySet, writeContext.UrlHelper, graph)); if (feedSelfLink != null) { feed.SetAnnotation(new AtomFeedMetadata() { SelfLink = new AtomLinkMetadata() { Relation = SelfLinkRelation, Href = feedSelfLink } }); } } // TODO: Bug 467590: remove the hardcoded feed id. Get support for it from the model builder ? feed.Id = FeedNamespace + _edmCollectionType.FullName(); // If we have more OData format specific information apply it now. ODataResult odataFeedAnnotations = graph as ODataResult; if (odataFeedAnnotations != null) { feed.Count = odataFeedAnnotations.Count; feed.NextPageLink = odataFeedAnnotations.NextPageLink; } writer.WriteStart(feed); foreach (object entry in enumerable) { entrySerializer.WriteObjectInline(entry, writer, writeContext); } writer.WriteEnd(); } }
public void WriteObjectInline_Writes_InlineCountAndNextLink() { // Arrange var mockSerializerProvider = new Mock <ODataSerializerProvider>(MockBehavior.Strict, _model); var mockCustomerSerializer = new Mock <ODataSerializer>(MockBehavior.Strict, ODataPayloadKind.Entry); var mockWriter = new Mock <ODataWriter>(); Uri expectedNextLink = new Uri("http://nextlink.com"); long expectedInlineCount = 1000; var result = new ODataResult <Customer>( _customers, expectedNextLink, expectedInlineCount ); mockSerializerProvider .Setup(p => p.GetODataPayloadSerializer(typeof(Customer))) .Returns(mockCustomerSerializer.Object); mockCustomerSerializer .Setup(s => s.WriteObjectInline(_customers[0], It.IsAny <ODataWriter>(), _writeContext)) .Verifiable(); mockCustomerSerializer .Setup(s => s.WriteObjectInline(_customers[1], It.IsAny <ODataWriter>(), _writeContext)) .Verifiable(); mockWriter .Setup(m => m.WriteStart(It.IsAny <ODataFeed>())) .Callback((ODataFeed feed) => { Assert.Equal(expectedNextLink, feed.NextPageLink); Assert.Equal(expectedInlineCount, feed.Count); }); _serializer = new ODataFeedSerializer(_customersType, mockSerializerProvider.Object); _serializer.WriteObjectInline(result, mockWriter.Object, _writeContext); // Assert mockSerializerProvider.Verify(); mockCustomerSerializer.Verify(); mockWriter.Verify(); }
public void WriteObjectInline_Writes_InlineCountAndNextLink() { // Arrange var mockSerializerProvider = new Mock<ODataSerializerProvider>(MockBehavior.Strict, _model); var mockCustomerSerializer = new Mock<ODataSerializer>(MockBehavior.Strict, ODataPayloadKind.Entry); var mockWriter = new Mock<ODataWriter>(); Uri expectedNextLink = new Uri("http://nextlink.com"); long expectedInlineCount = 1000; var result = new ODataResult<Customer>( _customers, expectedNextLink, expectedInlineCount ); mockSerializerProvider .Setup(p => p.CreateEdmTypeSerializer(_customersType.ElementType())) .Returns(mockCustomerSerializer.Object); mockCustomerSerializer .Setup(s => s.WriteObjectInline(_customers[0], It.IsAny<ODataWriter>(), _writeContext)) .Verifiable(); mockCustomerSerializer .Setup(s => s.WriteObjectInline(_customers[1], It.IsAny<ODataWriter>(), _writeContext)) .Verifiable(); mockWriter .Setup(m => m.WriteStart(It.IsAny<ODataFeed>())) .Callback((ODataFeed feed) => { Assert.Equal(expectedNextLink, feed.NextPageLink); Assert.Equal(expectedInlineCount, feed.Count); }); _serializer = new ODataFeedSerializer(_customersType, mockSerializerProvider.Object); _serializer.WriteObjectInline(result, mockWriter.Object, _writeContext); // Assert mockSerializerProvider.Verify(); mockCustomerSerializer.Verify(); mockWriter.Verify(); }
private void WriteFeed(object graph, ODataWriter writer, ODataSerializerContext writeContext) { IEnumerable enumerable = graph as IEnumerable; // Data to serialize if (enumerable != null) { ODataFeed feed = new ODataFeed(); if (writeContext.EntitySet != null) { IEntitySetLinkBuilder linkBuilder = SerializerProvider.EdmModel.GetEntitySetLinkBuilder(writeContext.EntitySet); FeedContext feedContext = new FeedContext { EntitySet = writeContext.EntitySet, UrlHelper = writeContext.UrlHelper, PathHandler = writeContext.PathHandler, FeedInstance = graph }; Uri feedSelfLink = linkBuilder.BuildFeedSelfLink(feedContext); if (feedSelfLink != null) { feed.SetAnnotation(new AtomFeedMetadata() { SelfLink = new AtomLinkMetadata() { Relation = SelfLinkRelation, Href = feedSelfLink } }); } } // TODO: Bug 467590: remove the hardcoded feed id. Get support for it from the model builder ? feed.Id = FeedNamespace + _edmCollectionType.FullName(); // If we have more OData format specific information apply it now. ODataResult odataFeedAnnotations = graph as ODataResult; if (odataFeedAnnotations != null) { feed.Count = odataFeedAnnotations.Count; feed.NextPageLink = odataFeedAnnotations.NextPageLink; } else { object nextPageLinkPropertyValue; HttpRequestMessage request = writeContext.Request; if (request != null && request.Properties.TryGetValue(ODataQueryOptions.NextPageLinkPropertyKey, out nextPageLinkPropertyValue)) { Uri nextPageLink = nextPageLinkPropertyValue as Uri; if (nextPageLink != null) { feed.NextPageLink = nextPageLink; } } } writer.WriteStart(feed); foreach (object entry in enumerable) { if (entry == null) { throw Error.NotSupported(SRResources.NullElementInCollection); } ODataSerializer entrySerializer = SerializerProvider.GetODataPayloadSerializer(entry.GetType()); if (entrySerializer == null) { throw Error.NotSupported(SRResources.TypeCannotBeSerialized, entry.GetType(), typeof(ODataMediaTypeFormatter).Name); } Contract.Assert(entrySerializer.ODataPayloadKind == ODataPayloadKind.Entry); entrySerializer.WriteObjectInline(entry, writer, writeContext); } writer.WriteEnd(); } }