private async Task InitializeViewModel(LinkViewModel vm, LinkResponse link) { var domain = HostContext.AppSettings.GetString("Domain"); if (domain.IsNullOrEmpty()) { domain = new Uri(Request.GetDisplayUrl()).GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped); } vm.ShortUrl = $"{domain.AppendPath(link.Key)}"; if (vm.ScreenshotUrl.IsNullOrEmpty()) { vm.IsScreenshotReady = false; vm.ScreenshotUrl = HostContext.AppSettings.GetString("DefaultScreenshotPlaceholder"); } else { vm.IsScreenshotReady = true; } var tags = await Gateway.SendAsync(new GetTagsRequest() { }); vm.Tags = tags.Select(m => { var t = m.ConvertTo <TagViewModel>(); t.IsSelected = vm.Tags?.FirstOrDefault(r => r.Key == m.Key)?.IsSelected ?? link?.Tags?.Contains(m.Key) ?? false; return(t); }) .Where(m => m.IsSelected) // for this VM, we only care about SELECTED tags .ToList(); }
public override Task <Response> HandleAsync() { log.Trace("Handle: '{0}' JobId: '{1}'", request.Handle, request.JobId); return(Task.Run <Response>(() => { LinkResponse response = null; Job job = jobManager.GetJob(request.JobId); if (job == null) { ResponseData responseData = GetResponseData(true, Resources.JobRequestHandler_NoSuchJob_Message); response = new LinkResponse { ExitStatus = (uint)responseData.ExitStatus, Stderr = responseData.Message, }; } else { IJobResult result = job.RunnableTask.Result; response = new LinkResponse { ExitStatus = (uint)result.ExitCode, Stderr = result.Stderr, Stdout = result.Stdout, }; } response.Info = BuildInfoResponse(); return response; })); }
public async Task <double> Update([FromQuery] int id, [FromBody] LinkResponse response) { Console.WriteLine($"Принято: id={id} response={response?.StatusCode}"); using var uow = _unitOfWorkFactory.GetUoW(); var link = _linkRepository.GetAll().FirstOrDefault(x => x.Id == id); if (link != null && response?.StatusCode != null) { link.Status = response.StatusCode; link.LinkStatus = LinkStatus.Done; uow.Commit(); return(-1); } if (link == null || link.CurrentStep >= link.CountStep) { return(-1); } link.LinkStatus = LinkStatus.Processing; link.CurrentStep++; uow.Commit(); return(link.CurrentStep == link.CountStep ? -1 : link.Tact); }
public override Task<Response> HandleAsync() { log.Trace("Handle: '{0}' JobId: '{1}'", request.Handle, request.JobId); return Task.Run<Response>(() => { LinkResponse response = null; Job job = jobManager.GetJob(request.JobId); if (job == null) { ResponseData responseData = GetResponseData(true, Resources.JobRequestHandler_NoSuchJob_Message); response = new LinkResponse { ExitStatus = (uint)responseData.ExitStatus, Stderr = responseData.Message, }; } else { IJobResult result = job.RunnableTask.Result; response = new LinkResponse { ExitStatus = (uint)result.ExitCode, Stderr = result.Stderr, Stdout = result.Stdout, }; } response.Info = BuildInfoResponse(); return response; }); }
private async Task SetResponseToRedisAsync(string href, LinkResponse response) { var serializedResponse = JsonConvert.SerializeObject(response); var encodedResponse = Encoding.UTF8.GetBytes(serializedResponse); var options = new DistributedCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromMinutes(5)) .SetAbsoluteExpiration(DateTime.Now.AddHours(6)); await _distributedCache.SetAsync(href, encodedResponse, options); Console.WriteLine($"Объект {href} с response={response} сохранен в Redis"); }
public override Task <Response> HandleAsync() { log.Trace("Handle: '{0}' JobId: '{1}'", request.Handle, request.JobId); return(Task.Run <Response>(async() => { LinkResponse response = null; Job job = jobManager.GetJob(request.JobId); if (job == null) { ResponseData responseData = GetResponseData(true, Resources.JobRequestHandler_NoSuchJob_Message); response = new LinkResponse { ExitStatus = (uint)responseData.ExitStatus, Stderr = responseData.Message, }; } else { IJobResult result = await job.RunnableTask; response = new LinkResponse { ExitStatus = (uint)result.ExitCode, Stderr = result.Stderr, Stdout = result.Stdout, }; } try { response.Info = await BuildInfoResponseAsync(); } catch (OperationCanceledException) { // If the container is shutting down the link request may be completed and unable to build an information response // via normal channels. In this case, we return a stopped info response. response.Info = new InfoResponse() { State = IronFrame.ContainerState.Stopped.ToString() }; } catch (Exception) { response.Info = new InfoResponse() { State = IronFrame.ContainerState.Stopped.ToString() }; } return response; })); }
public void Pdf_Links_Tests() { try { LinksResponse linksResponse = pdfService.Links.ReadDocumentPageLinkAnnotations("pdf-sample.pdf", 1, Utils.CloudStorage_Input_Folder); LinkResponse linkResponse = pdfService.Links.ReadDocumentPageLinkAnnotationByItsIndex("pdf-sample.pdf", 1, 1, Utils.CloudStorage_Input_Folder); } catch (Exception ex) { Assert.Fail(ex.Message); } }
private async Task <IRestResponse> LinkStepAsync(int id, LinkResponse response = null) { var uri = $"{_globalSettings.PublicHost}/api/link/step?id={id}"; var client = new RestClient(uri) { Timeout = -1 }; var request = new RestRequest(Method.PUT); if (response == null) { request.AddJsonBody("{}"); } else { request.AddJsonBody(response); } Console.WriteLine($"Отправил request=[id={id} response={response}]"); return(await client.ExecuteAsync(request)); }