public async Task <List <T> > Get(string url) { var apiResponse = await HttpService.GetAsync(url); if (apiResponse.Success) { return(_jsonService.Deserialize <List <T> >(apiResponse.Response, Converter.Settings)); } return(null); }
public async Task <IEnumerable <DriveItem> > GetDriveItemsAsync(string driveId, Action <string> error) { try { var json = await GetJsonFromGraphEndpoint($"{graphBaseUri}{string.Format(drivesListRootEndpoint, driveId)}", error); error($"JSON returned {json}"); return(jsonService.Deserialize <List <DriveItem> >(json)); } catch (Exception e) { error($"GetDriveItemsAsync Exception: {e.Message}"); } return(null); }
public Tree GetTree() { try { return((Tree)_jsonService.Deserialize <Tree> (File.ReadAllText(TreeFileName))); } catch (Exception e) { throw new Exception($"Failed to get tree", e); } }
public async Task <T?> Get <T>(string key, T?def = default) { var value = await Database.StringGetAsync(key); if (value.IsNullOrEmpty) { return(def); } return(_json.Deserialize <T>(value)); }
public Guid CreateTestReport(Guid projectWatcherId, TestSummary testSummary, IReadOnlyList <TestDetail> testDetails) { var request = _createTestReportDtoMapper.Map(testSummary, testDetails); var responseMessage = _httpClient.Post(_jsonService, ApiUrlHelper.GetCreateTestReportUrl(projectWatcherId), request); if (responseMessage.IsSuccessStatusCode) { _logger.LogInformation("Api accepted the request"); var responseText = responseMessage.Content.ReadAsStringAsync().GetAwaiter().GetResult(); var result = _jsonService.Deserialize <CreateTestReportResponseDto>(responseText); return(result.ReportId); } throw new Exception("Api failed to accept the request."); }
private async Task <List <DayData> > GetData() { string json = await _dataAccessService.GetDataList(); List <DayData> listDayData; if (!string.IsNullOrWhiteSpace(json)) { listDayData = (List <DayData>)_jsonService.Deserialize(json, typeof(List <DayData>)); await _dataService.UpdateInformation(listDayData); } else { listDayData = await _dataService.GetListData(); } return(listDayData); }
public override void OnReceive(Context context, Intent intent) { var serializedModel = intent.GetStringExtra(common.Extras.PRODUCT); var model = _jsonService.Deserialize <Product>(serializedModel); Toast.MakeText(context, $"Recieved Information for product {model.Id} {model.Name}", ToastLength.Long); var notificationClickedIntent = new Intent(common.Intents.GO_TO_PRODUCT_EDIT); notificationClickedIntent.PutExtra(common.Extras.ID, model.Id.ToString()); var pendingIntent = PendingIntent.GetActivity(context, _pendingIntentId++, notificationClickedIntent, PendingIntentFlags.UpdateCurrent); _notificationService.CreateNotificationChannel(_channelId, _channelName); _notificationService.SendNotificationToChannel(_channelId, context.GetString(Resource.String.product_created), Resource.Mipmap.ic_launcher, string.Format(context.GetString(Resource.String.product_created_template), model.Name, model.Price, model.Count, model.Id), pendingIntent, NotificationCompat.PriorityDefault, true); }
protected override T GetResult(UnityWebRequest request) { return(jsonService.Deserialize <T>(request.downloadHandler.text)); }
public async Task <List <ushort[]> > LoadAllEvolutionsAsync() { var json = await ReadFileAsTextAsync(EvolutionsDbFilePath); return(_jsonService.Deserialize <List <ushort[]> >(json)); }
/// <summary> /// Fetches the data from the cache /// </summary> /// <typeparam name="T">The type of item to fetch</typeparam> /// <param name="filename">The name of the cached item</param> /// <returns>A task representing the loaded data</returns> public async Task <T?> Load <T>(string filename) { using var stream = File.OpenRead(filename); return(await _json.Deserialize <T>(stream)); }
public async Task <Result> Handle(UpdateFlowCommand request, CancellationToken cancellationToken) { Result result; try { var flow = await _flowReadRepository.GetAsync(request.Id); if (flow.Version != request.Version) { throw new CommandVersionException(); } if (request.Name.HasValue) { flow.ChangeName(request.Name.Value); } if (request.Description.HasValue) { flow.SetDescription(request.Description.Value); } if (request.Image.HasValue) { flow.SetImage(request.Image.Value); } if (request.Diagram.HasValue) { flow.SetDiagram(request.Diagram.Value); } if (request.FilterContent.HasValue) { flow.SetFilterContent(request.FilterContent.Value); var filter = _jsonService.Deserialize <FlowFilter>(request.FilterContent.Value.ToString()); filter.Sources = (filter.Sources.IsEnumerableNullOrEmpty()) ? new List <FlowSource> { new FlowSource("x") } : new List <FlowSource>(filter.Sources); filter.Operations = (filter.Operations.IsEnumerableNullOrEmpty()) ? new List <FlowOperation> { new FlowOperation("x") } : new List <FlowOperation>(filter.Operations); filter.Sites = (filter.Sites.IsEnumerableNullOrEmpty()) ? new List <FlowSite> { new FlowSite("x") } : new List <FlowSite>(filter.Sites); filter.OperationalDepartments = (filter.OperationalDepartments.IsEnumerableNullOrEmpty()) ? new List <FlowOperationalDepartment> { new FlowOperationalDepartment("x") } : new List <FlowOperationalDepartment>(filter.OperationalDepartments); filter.TypePlannings = (filter.TypePlannings.IsEnumerableNullOrEmpty()) ? new List <FlowTypePlanning> { new FlowTypePlanning("x") } : new List <FlowTypePlanning>(filter.TypePlannings); filter.Customers = (filter.Customers.IsEnumerableNullOrEmpty()) ? new List <FlowCustomer> { new FlowCustomer("x") } : new List <FlowCustomer>(filter.Customers); filter.ProductionSites = (filter.ProductionSites.IsEnumerableNullOrEmpty()) ? new List <FlowProductionSite> { new FlowProductionSite("x") } : new List <FlowProductionSite>(filter.ProductionSites); filter.TransportTypes = (filter.TransportTypes.IsEnumerableNullOrEmpty()) ? new List <FlowTransportType> { new FlowTransportType("x") } : new List <FlowTransportType>(filter.TransportTypes); filter.DriverWait = (filter.DriverWait == null) ? "x" : filter.DriverWait; flow.SetFilter(filter); } flow.Version = _versionProvider.Generate(); await _flowWriteRepository.UpdateAsync(flow); result = Result.Ok(flow.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = string.Format(HandlerFailures.NotFound, "Flow"), Target = "id" } } ); } catch (CommandVersionException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotMet.Name, Message = HandlerFailures.NotMet, Target = "version" } } ); } catch (UniqueKeyException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.Conflict, Target = "name" } } ); } catch { result = Result.Fail(CustomFailures.UpdateFlowFailure); } return(result); }