protected void UpdateCtx(Context ctx, DeserializeResponse dr) { ctx.BusReturnCode = dr.BusinessReturnCode; ctx.LastSegment = dr.LastSegment; ctx.NumSegments = dr.NumSegments; ctx.SegmentNumber = dr.SegmentNumber; ctx.TechReturnCode = dr.TechnicalReturnCode; ctx.TransactionId = dr.TransactionId; ctx.Phase = dr.Phase; }
protected bool IsRecoverySync(Context ctx, DeserializeResponse dr) { if (!dr.IsRecoverySync) { return(false); } if (RecoverySyncCount >= _maxRecoverySyncCount) { throw new RecoverySyncException($"Recovery sync failed for {ctx.Cmd.OrderType}"); } return(true); }
protected T QuerySocketPublic <T>(string action, string actionEvent, string subActionEvent, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags apiFlags = null) where T : ResponseBase { return(QuerySocket(QueryType.Public, action, actionEvent, subActionEvent, parameters, deserializer, apiFlags)); }
protected abstract T QuerySocket <T>(QueryType queryType, string action, string actionEvent, string subActionEvent, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags apiFlags = null) where T : ResponseBase;
protected T PostPublic <T>(string action, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags flags = null) where T : ResponseBase { return(QueryPublic(Method.POST, action, parameters, deserializer, flags)); }
protected T GetPrivate <T>(string action, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags flags = null) where T : ResponseBase { return(QueryPrivate(Method.GET, action, parameters, deserializer, flags)); }
private T QueryPublic <T>(Method method, string action, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags flags = null) where T : ResponseBase { return(Query(QueryType.Public, method, action, parameters, deserializer, flags)); }
protected abstract T Query <T>(QueryType queryType, Method method, string action, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags flags = null) where T : ResponseBase;
protected override T Query <T>(QueryType queryType, Method method, string action, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags flags = null) { OnInformationSending($"Łączenie z Football-Data..."); RateLimit(); var omitVersion = flags?.V(ApiFlagType.OmitVersion) == true; var uri = $"{(omitVersion ? _address : _addressWithVersion)}{action}".EnsureSuffix("/"); var request = queryType == QueryType.Private ? new FootballDataAuthenticatedRequest(method, ApiKey) : new RestRequest(method); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "application/json"); request.AddHeader("X-Response-Control", "minified"); parameters?.ForEach(p => request.AddParameter(p.Name, p.Value)); // querystring dla get var catchNum = 0; const int maxCatchNum = 3; FootballDataException fdEx = null; while (catchNum < maxCatchNum) { try { OnInformationSending($"Łączenie z Football-Data, próba {catchNum + 1} z {maxCatchNum}"); var rawResponse = new RestClient(uri).Execute(request); if (!rawResponse.StatusCode.ToInt().Between(200, 299)) // jeśli kod wskazuje błąd i json nie opisuje tego błędu to zwróć ogólny { if (rawResponse.ContentType?.Split(";").Any(m => m.EqIgnoreCase("application/json")) != true) { throw new FootballDataException($"{rawResponse.StatusCode.ToInt()}: {rawResponse.StatusDescription}"); } if (rawResponse.StatusCode.ToInt() == 410) // Gone, means API version changed, fall-through until update { return((T)typeof(T).GetConstructor(new Type[] {}).Invoke(new object[] {})); } var message = JToken.Parse(rawResponse.Content)["message"]; throw new FootballDataException($"{rawResponse.StatusCode.ToInt()}: {message}"); } if (string.IsNullOrEmpty(rawResponse.Content)) { throw new FootballDataException("Serwer zwrócił pustą zawartość, prawdopodobnie ochrona przed spamem"); } var response = deserializer == null ? JsonConvert.DeserializeObject <T>(rawResponse.Content) : deserializer(rawResponse.Content); OnInformationSending($"Otrzymano dane z Football-Data, próba {catchNum + 1} z {maxCatchNum}"); return(response); } catch (FootballDataException ex) { catchNum++; fdEx = ex; OnInformationSending($"Zapytanie zwrociło błąd, próba {catchNum + 1} z {maxCatchNum}"); } } throw fdEx; }
protected override T QuerySocket <T>(QueryType queryType, string action, string actionEvent, string subActionEvent, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags apiFlags = null) { throw new FootballDataException("Brak wsparcia dla gniazd"); }