private async Task <EntityResponsResult> GetResult(RequestFound req, int pauseSecond = 5) { if (req == null || string.IsNullOrEmpty(req.Token)) { return(null); } int count = 60; string error = null; EntityResponsResult result = null; return(await Task.Run(() => { while (count-- > 0) { Thread.Sleep(pauseSecond * 1000); error = string.Empty; try { var res = _repository.Status(req.Token, _key); if (string.IsNullOrEmpty(res.Exception) == false) { error = res.Exception; } else { req.StatusRequest.Progress = res.Progress; if (CheckResultStatus(res) == false) { error = "Не выполнено"; } else { result = _repository.Result(req.Token, _key); if (string.IsNullOrEmpty(result.Exception) == false) { error = result.Exception; } else { error = null; break; } } } } catch (Exception ex) { error = ex.Message; } } req.ErrorRequest(error); return result; }).ConfigureAwait(false)); }
private Task AppendSaveFile(RequestFound req, EntityResponsResult result) { return(Task.Run(() => { if (result != null) { //req.FileResult = _createFile.AppendXlsx(ServiceConvert.ConvertEntityResultsToStrings(result), req.Query.FirstField); req.FileResult = _createFile.AppendCsv(ServiceConvert.ConvertEntityResultsToStrings(result), req.Query.FirstField); req.StopRequest(); } })); }
private Task SaveFile(RequestFound req, EntityResponsResult result) { return(Task.Run(() => { if (result != null) { if (result.CollectionQuery[0].CollectionResult.Any() == false) { req.ErrorRequest("Ничего не найдено"); } else { req.FileResult = _createFile.CreateXlsx(ServiceConvert.ConvertEntityResultsToStrings(result), req.Query.FirstField); req.StopRequest(); } } })); }
public EntityResponsResult Result(string token, string key) { var url = $"result?token={key}&task={token}"; var str = _httpService.RequestGet(url, HttpService.EnumContentType.Json); var res = JsonConvert.DeserializeObject <JsonResponsResult>(str); var result = new EntityResponsResult() { Exception = res.Exception, Code = res.Code, CollectionQuery = res.Response.Result.Select(x => { return(new EntityQuery() { Type = (int)x.Query.Type, Firstname = x.Query.Params.Firstname, Lastname = x.Query.Params.Lastname, Name = x.Query.Params.Name, Number = x.Query.Params.Number, Region = x.Query.Params.Region, Id = x.Query.Params.Id, Status = x.Status, Error = x.Result.FluffyResult?.Message, CollectionResult = x.Result.PurpleResultArray?.Select(y => { return new EntityResult() { Bailiff = y.Bailiff, Department = y.Department, Details = y.Details, End = y.IpEnd, Name = y.Name, Production = y.ExeProduction, Subject = y.Subject }; }).ToList() }); }).ToList() }; return(result); }
public static IEnumerable <string> ConvertEntityResultsToStrings(EntityResponsResult result) { var list = new List <string>() { $"id;{EntityResult.GetStringPropery()}" }; foreach (var item in result?.CollectionQuery) { if (item.CollectionResult != null && item.CollectionResult.Any()) { list.AddRange(item.CollectionResult.Select(x => { return($"{item.Id};{x}"); })); } else { list.Add($"{item.Id};Ничего не найдено"); } } return(list); }