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); } }
public bool SetProductPhoto(int id, byte[] imageBt) { CreateRequest("PreSetProductPhoto", imageBt.Length); ClientAuction.SendMessageInBytes(imageBt); CreateRequest("SetProductPhoto", id); return(WaitResponse <bool>()); }
public async Task <bool> SetProductPhotoAsync(int id, byte[] imageBt) { CreateRequest("PreSetProductPhoto", imageBt.Length); ClientAuction.SendMessageInBytes(imageBt); CreateRequest("SetProductPhoto", id); return(await WaitResponseAsync <bool>()); }
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); } }
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); } }
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); } }