internal static bool ValidateJRequest(Jrequest jRequest) { try { if (!Utility.HasValue(jRequest)) { throw new JRequestException("JRequest object is not initialized."); } if (!Utility.HasValue(jRequest.Requests) || jRequest.Requests.Count == 0) { throw new JRequestException("JRequest contains no request."); } if (jRequest.Requests.Where(r => !Utility.HasValue(r.Key)).Count() > 0) { throw new JRequestException("Invalid request key/keys have been encountered."); } if (!(jRequest.Requests.Select(r => r.Key).Distinct().Count() == jRequest.Requests.Select(r => r.Key).Count())) { throw new JRequestException("Some of the requests contain duplicate key."); } jRequest.Requests.ForEach(request => { if (!Utility.HasValue(request.URL)) { throw new JRequestException("Request URL is required."); } if (!(Uri.TryCreate(request.URL, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps || uriResult.Scheme == Uri.UriSchemeFtp))) { throw new JRequestException("Invalid URL string format found."); } var protocol = request.URL?.Split(':')[0]; request.Protocol = protocol; if (Utility.StringEquals(protocol, Protocol.http) || Utility.StringEquals(protocol, Protocol.https)) { ValidateHttpRequest(request); } else { ValidateFtpRequest(request); } }); return(true); } catch (Exception ex) { throw new JRequestException(ex.Message, ex.InnerException); } }
public static object Run(Jrequest jRequest, bool serialize = false) { Build(jRequest); var result = JRequestEngine.Run(); if (serialize) { return(JsonConvert.SerializeObject(result)); } return(result); }
private static Request GetRequest(Jrequest jRequest, string requestKey) { Request request = null; if (Utility.HasValue(requestKey)) { request = jRequest.Requests.Where(r => r.Key == requestKey).FirstOrDefault(); } return(request); }
internal static Jrequest Build(Jrequest jrequest) { try { jRequest = jrequest; Validator.ValidateJRequest(jRequest); } catch (Exception ex) { throw new JRequestException(ex.Message, ex.InnerException); } return(jRequest); }
internal static Jrequest ValidateJson(string json) { try { JToken.Parse(json);//check if json string can be parsed Jrequest jRequest = JsonConvert.DeserializeObject <Jrequest>(json); return(jRequest); } catch (JsonReaderException ex) { throw ex; } catch (Exception ex) //some other exception { throw new JRequestException(ex.Message, ex.InnerException); } }
internal static Jrequest Build(string json) { try { if (!Utility.HasValue(json)) { throw new JRequestException("The JSON string is empty."); } jRequest = Validator.ValidateJson(json); Validator.ValidateJRequest(jRequest); } catch (Exception ex) { throw new JRequestException(ex.Message, ex.InnerException); } return(jRequest); }
private static Jrequest Build(Jrequest jRequest) { return(JRequestEngine.Build(jRequest)); }