public async Task <IActionResult> Get()
 {
     if (!tcpClient.IsConnect())
     {
         return(BadRequest(ServerNotConnected));
     }
     byte[] image;
     // Open connection with the givven externalUrlServer.
     using HttpClient httpClient = new HttpClient();
     httpClient.Timeout          = new TimeSpan(0, 0, 10);
     try
     {
         image = await GetImageFromServer(httpClient);
     }
     catch (ArgumentNullException)
     {
         return(NotFound(ScreenshotController.ArgumentNullMessage));
     }
     catch (HttpRequestException e2)
     {
         return(MyNotFound(e2.Message, HttpRequestMessage));
     }
     catch (TaskCanceledException e3)
     {
         return(MyNotFound(e3.Message, TaskCanceledMessage));
     }
     // This http is not connect.
     catch (Exception)
     {
         return(NotFound(RegularException));
     }
     return(ReturnImageWithoutExceptions(image));
 }
Esempio n. 2
0
 // Function that send information to server while the server is connected.
 public void ProcessCommands()
 {
     while (client.IsConnect())
     {
         foreach (AsyncCommand command in _queueCommand.GetConsumingEnumerable())
         {
             OneIterationOfProcessCommands(command);
         }
     }
 }
Esempio n. 3
0
 public async Task <IActionResult> Get()
 {
     // If the request url is not correct, send appropirate message.
     if (!CheckUrlRequest())
     {
         return(BadRequest(NoSuchUrl));
     }
     // The url is correct but we need to check if the server is connected.
     if (!tcpClient.IsConnect())
     {
         return(BadRequest(ServerNotConnected));
     }
     // The server is connected, so open connection with the givven externalUrlServer.
     using HttpClient httpClient = new HttpClient();
     httpClient.Timeout          = new TimeSpan(0, 0, 10);
     return(await GetImage(httpClient));
 }