public void ConstructorTest() { var flags1 = new ApiFlags <TestEnum>(new[] { new ApiEnum <TestEnum>(TestEnum.EnumValue2) }); var flags2 = new ApiFlags <TestEnum>(new[] { new ApiEnum <TestEnum>(TestEnum.EnumValue2), new ApiEnum <TestEnum>(TestEnum.EnumValue3) }); Assert.Equal(new[] { new ApiEnum <TestEnum>(TestEnum.EnumValue2) }, flags1.List); Assert.Equal(new[] { new ApiEnum <TestEnum>(TestEnum.EnumValue2), new ApiEnum <TestEnum>(TestEnum.EnumValue3) }, flags2.List); }
static unsafe extern ErrorCode GetPicture( byte* buf, int len, ApiFlags flag, [Out] out BITMAPINFO** pHBInfo, [Out] out byte** pHBm, ProgressCallback lpPrgressCallback, int lData );
public override void Write(Utf8JsonWriter writer, ApiFlags <T>?value, JsonSerializerOptions options) => throw new NotImplementedException("TODO: This should generally not be used since we only deserialize stuff from the API, and not serialize to it. Might add support later.");
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;
static unsafe extern int GetPictureInfo( byte* buf, int len, ApiFlags flag, [In, Out] ref PictureInfo lpInfo );
static unsafe extern ErrorCode GetFile(string src, int len, [Out] out byte** dest, ApiFlags flag, ProgressCallback progressCallback, int lData);
static unsafe extern ErrorCode GetArchiveInfo(string buf, int len, ApiFlags flag, [Out] out fileInfo** lphInf);
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"); }