static void Main(string[] args) { bool running = true; while (running) { var option = Console.ReadLine(); if (option == "1") { if (inst == null) { inst = CyberSourceClass.PaymentProcessor; } Thread runner = new Thread(new ThreadStart(startTransaction)); runner.Start(); } if (option == "0") { Environment.Exit(0); } else { RequestWrapper incomingRequest = JsonConvert.DeserializeObject <RequestWrapper>(option); if (incomingRequest.request is LoginRequest) { LoginRequest request = (LoginRequest)incomingRequest.request; LoginService service = new LoginService(request); IBaseResponse result = service.parseRequest(); ResponseWrapper wrapper = new ResponseWrapper(result); Console.WriteLine(JsonConvert.SerializeObject(wrapper)); } } } }
public async Task <IBaseResponse <T> > GetAndParse <T>(string url, JsonConverter[] customConverters) { IBaseResponse <T> response = BootStrapper.Resolve <IBaseResponse <T> >(); try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Configuration.MobileApiUrl + url); webRequest.Method = "GET"; webRequest.Accept = "application/json, text/json"; #if __ANDROID__ webRequest.UserAgent = "Xtrade-android"; #else webRequest.UserAgent = "Xtrade-iOS"; #endif webRequest.Timeout = Configuration.TimeoutInterval; webRequest.ReadWriteTimeout = Configuration.TimeoutInterval; this.GenerateHttpHeaders(webRequest); HttpWebResponse webResponse = null; await Task.Run(() => { webResponse = (HttpWebResponse)webRequest.GetResponse(); }); if (webResponse != null && webResponse.StatusCode == HttpStatusCode.OK) { response.Result = await this.DeflateAndParseContent <T>(webResponse, customConverters, null); } } catch (ResponseException re) { SetResponseErrors(response, ResponseExceptionMessage, re.Code); } catch (WebException we) { HttpWebResponse responseException = we.Response as HttpWebResponse; if (responseException != null) { if (responseException.StatusCode == HttpStatusCode.BadRequest || responseException.StatusCode == HttpStatusCode.Unauthorized) { SetResponseErrors(response, "Not Authorised", CommonConstants.UnauthorisedErrorCode); } else { SetResponseErrors(response, "Web Service call failed", CommonConstants.ResponseNotOkErrorCode + (int)responseException.StatusCode); } } else { SetResponseErrors(response, we.Message, CommonConstants.WebServiceExceptionErrorCode); } } catch (Exception ex) { SetResponseErrors(response, ex.Message, CommonConstants.GeneralExceptionErrorCode); } return(response); }
public static TOut Join <TOut>(this IBaseResponse response, IBaseResponse source) where TOut : IBaseResponse { response.Message = $@"{response.Message}{Environment.NewLine}{source.Message}"; ((List <Failure>)response.Errors) .AddRange(source.Errors); return((TOut)response); }
public static Result <TData, OkraError> ToResult <TData>(this IBaseResponse <TData> response) { var result = response.Status != "success" ? Result.Failure <TData, OkraError>(new OkraError { Status = response.Status, Message = response.Message }) : Result.Success <TData, OkraError>(response.Data); return(result); }
/// <summary> /// Sets the exception meta data. /// </summary> /// <param name="ex">The ex.</param> /// <param name="scResponse">The sc response.</param> protected virtual void SetExceptionMetaData(Exception ex, IBaseResponse scResponse) { if (ex == null) { return; } if (scResponse.Info == null) { scResponse.Info = new SitecoreWebResponseInfo(); } scResponse.Info.ErrorMessage = ex.Message; scResponse.Info.StackTrace = ex.StackTrace; }
private async Task RefreshRates() { this.IsBusy = true; IBaseResponse <IRatesWrapper> newRatesResponse = await this._webServiceManager.GetAndParse <IRatesWrapper>("exchange-rates", new JsonConverter[] { new RateConverter(), new RatesWrapperConverter() }); if (newRatesResponse != null && newRatesResponse.IsValid() && newRatesResponse.Result.Value != null && newRatesResponse.Result.Value.Count > 0) { this.AllRates.ReplaceRange(newRatesResponse.Result.Value.OrderedRatesList()); await this._xtradeRepository.InsertRatesAsync(this.AllRates); this.IsBusy = false; this.OnRefreshFinish?.Invoke(this, "Rates updated"); } else { this.IsBusy = false; this.OnRefreshFinish?.Invoke(this, "Could not refresh exchange rates"); } }
private async Task RefreshSelectedRate() { IsBusy = true; IBaseResponse <IRatesWrapper> newRatesResponse = await this._webServiceManager.GetAndParse <IRatesWrapper>("exchange-rates?currencyCode=" + this._selectedRate.CurrencyCode, new JsonConverter[] { new RateConverter(), new RatesWrapperConverter() }); if (newRatesResponse != null && newRatesResponse.IsValid() && newRatesResponse.Result.Value != null && newRatesResponse.Result.Value.Count > 0) { this.SelectedRate = newRatesResponse.Result.Value.FirstOrDefault(); await this._xtradeRepository.InsertRateAsync(this._selectedRate); this.IsBusy = false; this.OnRefreshFinish?.Invoke(this, "Rate updated"); } else { this.IsBusy = false; this.OnRefreshFinish?.Invoke(this, "Could not refresh exchange rate"); } }
public async void RefreshSelectedRate() { this.IsDataRefreshing = true; IBaseResponse <IRatesWrapper> newRatesResponse = await this._webServiceManager.GetAndParse <IRatesWrapper>("exchange-rates?currencyCode=" + this._selectedRateCode, new JsonConverter[] { new RateConverter(), new RatesWrapperConverter() }); if (newRatesResponse != null && newRatesResponse.IsValid() && newRatesResponse.Result.Value != null && newRatesResponse.Result.Value.Count > 0) { this.SelectedRate = newRatesResponse.Result.Value.FirstOrDefault(); await this._xtradeRepository.InsertRateAsync(this.SelectedRate); this.OnViewModelDataChanged?.Invoke(this, null); this.IsDataRefreshing = false; this.OnRefreshSuccess?.Invoke(this, "Rate updated"); } else { this.IsDataRefreshing = false; this.OnRefreshError?.Invoke(this, "Could not refresh exchange rate"); } }
public async void RefreshRates() { this.IsDataRefreshing = true; IBaseResponse <IRatesWrapper> newRatesResponse = await this._webServiceManager.GetAndParse <IRatesWrapper>("exchange-rates", new JsonConverter[] { new RateConverter(), new RatesWrapperConverter() }); if (newRatesResponse != null && newRatesResponse.IsValid() && newRatesResponse.Result.Value != null && newRatesResponse.Result.Value.Count > 0) { this.AllRates = newRatesResponse.Result.Value.OrderedRatesList(); await this._xtradeRepository.InsertRatesAsync(this.AllRates); this.OnViewModelDataChanged?.Invoke(this, null); this.IsDataRefreshing = false; this.OnRefreshSuccess?.Invoke(this, "Rates updated"); } else { this.IsDataRefreshing = false; this.OnRefreshError?.Invoke(this, "Could not refresh exchange rates"); } }
public BlogNewsService(IBaseResponse <BlogNews> response) : base(response) { }
public static IActionResult CreateResponse(this ControllerBase controller, IBaseResponse response) => response.IsSucceeded ? controller.Ok(response) : controller.StatusCode((int)response.Error.StatusCode, response);
public ActionResult Error(IBaseResponse response) { return(View(response)); }
public void ExceptionHandle(IBaseResponse response, Exception e) { response.OK = false; response.Message = e.Message; response.Code = e.GetType().Name; }
public ResponseWrapper(IBaseResponse newResponse) { response = newResponse; }
private static void SetResponseErrors <T>(IBaseResponse <T> response, string description, int code) { response.ErrorMessage = description; response.ErrorCode = code; }
public BlogBaseService(IBaseResponse <T> response) { baseResponse = response; }
public BlogAuthorService(IBaseResponse <Author> response) : base(response) { }
public IBaseResponse MemberJobAlertDelete(int jobAlertId) { IBaseResponse deleteResponse = _BLconnector.MemberJobAlertDelete(jobAlertId); return(deleteResponse); }
public BlogTypeInfoService(IBaseResponse <BlogTypeInfo> response) : base(response) { }