Ejemplo n.º 1
0
 public Task <T> WaitResponseAsync <T>()
 {
     try
     {
         //TimerSet();
         return(Task.Run(async() =>
         {
             if (!isBlocked)
             {
                 isBlocked = true;
                 await PWaitResponseAsync();
             }
             isBlocked = false;
             if (isError)
             {
                 throw new Exception("Превышено время ожидания ответа от сервера");
             }
             return ClientAuction.DeserializeFromString <T>(Response);
         }));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         throw (ex);
     }
 }
Ejemplo n.º 2
0
 public bool SetProductPhoto(int id, byte[] imageBt)
 {
     CreateRequest("PreSetProductPhoto", imageBt.Length);
     ClientAuction.SendMessageInBytes(imageBt);
     CreateRequest("SetProductPhoto", id);
     return(WaitResponse <bool>());
 }
Ejemplo n.º 3
0
 public async Task <bool> SetProductPhotoAsync(int id, byte[] imageBt)
 {
     CreateRequest("PreSetProductPhoto", imageBt.Length);
     ClientAuction.SendMessageInBytes(imageBt);
     CreateRequest("SetProductPhoto", id);
     return(await WaitResponseAsync <bool>());
 }
Ejemplo n.º 4
0
        private T WaitResponse <T>()
        {
            try
            {
                lock (locker)
                {
                    if (!isBlocked)
                    {
                        isBlocked = true;
                        System.Threading.Monitor.Wait(locker);
                    }

                    isBlocked = false;
                    if (isError)
                    {
                        throw new Exception("Превышено время ожидания ответа от сервера");
                    }
                    return(ClientAuction.DeserializeFromString <T>(Response));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw (ex);
            }
        }
Ejemplo n.º 5
0
 public string GetPhoto()
 {
     try
     {
         string message = GetFirstMessage();
         ClientAuction.IsRecieveImage = true;
         methods.CreateRequest("GetPhotoSt2");
         ClientAuction.RecieveImage(ClientAuction.DeserializeFromString <int>(message));
         methods.Response = "true";
         methods.PulseLocker();
         return(null);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(null);
     }
 }
Ejemplo n.º 6
0
 public void CreateRequest <T>(string methodName, T reqObj)
 {
     try
     {
         if (!ClientAuction.Stream.CanWrite)
         {
             if (!ServerConnector.ConnectToServer())
             {
                 throw new Exception("Сервер не доступен");
             }
         }
         string  parametr = ClientAuction.SerializeToString(reqObj);
         Request request  = new Request(parametr, methodName);
         Response = null;
         ClientAuction.SendMessage(ClientAuction.SerializeToString(request));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         throw (ex);
     }
 }