示例#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);
     }
 }
示例#2
0
 public bool SetProductPhoto(int id, byte[] imageBt)
 {
     CreateRequest("PreSetProductPhoto", imageBt.Length);
     ClientAuction.SendMessageInBytes(imageBt);
     CreateRequest("SetProductPhoto", id);
     return(WaitResponse <bool>());
 }
示例#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>());
 }
示例#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);
            }
        }
示例#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);
     }
 }
示例#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);
     }
 }