Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 static unsafe extern ErrorCode GetPicture(
     byte* buf,
     int len,
     ApiFlags flag,
     [Out] out BITMAPINFO** pHBInfo,
     [Out] out byte** pHBm,
     ProgressCallback lpPrgressCallback,
     int lData
     );
Exemplo n.º 3
0
 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.");
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
0
 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;
Exemplo n.º 6
0
 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));
 }
Exemplo n.º 7
0
 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));
 }
Exemplo n.º 8
0
 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));
 }
Exemplo n.º 9
0
 protected abstract T Query <T>(QueryType queryType, Method method, string action, Parameters parameters = null, DeserializeResponse <T> deserializer = null, ApiFlags flags = null) where T : ResponseBase;
Exemplo n.º 10
0
 static unsafe extern int GetPictureInfo(
     byte* buf,
     int len,
     ApiFlags flag,
     [In, Out] ref PictureInfo lpInfo
     );
Exemplo n.º 11
0
 static unsafe extern ErrorCode GetFile(string src, int len, [Out] out byte** dest, ApiFlags flag, ProgressCallback progressCallback, int lData);
Exemplo n.º 12
0
 static unsafe extern ErrorCode GetArchiveInfo(string buf, int len, ApiFlags flag, [Out] out fileInfo** lphInf);
Exemplo n.º 13
0
        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;
        }
Exemplo n.º 14
0
 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");
 }