Exemplo n.º 1
0
 public static ParameterInfo[] GetDescription(this IParameters parameters)
 {
     return(parameters
            .GetType()
            .GetProperties()
            .Where(p => p.GetCustomAttributes(false).OfType <ParameterInfo>().Any())
            .Select(p => p.GetCustomAttributes(false).OfType <ParameterInfo>().First())
            .ToArray());
 }
Exemplo n.º 2
0
 public static System.Reflection.ParameterInfo[] GetDescription(this IParameters parameters)
 {
     return(parameters.GetType()
            .GetProperties()
            .Select(x => x.GetCustomAttributes(typeof(System.Reflection.ParameterInfo), false))
            .Where(x => x.Length > 0)
            .Select(x => x[0])
            .Cast <System.Reflection.ParameterInfo>()
            .ToArray());
 }
Exemplo n.º 3
0
 public static ParameterInfo[] GetDesсription(this IParameters parameters)
 {
     return(parameters
            .GetType()
            .GetProperties()
            .Select(p => p.GetCustomAttributes(typeof(ParameterInfo), false))
            .Where(p => p.Length > 0)
            .Select(p => p[0])
            .Cast <ParameterInfo>()
            .ToArray());
 }
Exemplo n.º 4
0
        public static void SetValues(this IParameters parameters, double[] values)
        {
            var properties = parameters.GetType()
                             .GetProperties()
                             .Where(x => x.GetCustomAttributes(typeof(System.Reflection.ParameterInfo), false).Length > 0)
                             .ToArray();

            for (int i = 0; i < values.Length; i++)
            {
                properties[i].SetValue(parameters, values[i], new object[0]);
            }
        }
Exemplo n.º 5
0
        public TBuilder GetParameterBuilder(IParameters parameters)
        {
            foreach (IParametersBuilder registeredBuilder in this.registeredBuilders)
            {
                if (registeredBuilder.CanBuild(parameters.GetType()))
                {
                    return((TBuilder)registeredBuilder);
                }
            }

            return(default(TBuilder));
        }
Exemplo n.º 6
0
        public static void Parse(this IParameters parameters, double[] data)
        {
            int i = 0;

            foreach (
                var property in parameters
                .GetType()
                .GetProperties()
                .Where(p => p.GetCustomAttributes(false).OfType <ParameterInfo>().Any())
                )
            {
                property.SetValue(parameters, data[i++], new object[0]);
            }
        }
Exemplo n.º 7
0
        private void SetAndGetArray <T>(IParameters parameters, string property, params T[] value)
        {
            var prop = parameters.GetType().GetProperty(property);

            if (prop == null)
            {
                throw new ArgumentException($"Could not find property '{property}'");
            }

            prop.SetValue(parameters, value);

            var val = prop.GetValue(parameters);

            AssertEx.AreEqualLists(value?.ToList(), val?.ToIEnumerable().Cast <T>().ToList(), $"Property '{property}' was incorrect");
        }
Exemplo n.º 8
0
        private void SetAndGet(IParameters parameters, string property, object value)
        {
            var prop = parameters.GetType().GetProperty(property);

            if (prop == null)
            {
                throw new ArgumentException($"Could not find property '{property}'");
            }

            prop.SetValue(parameters, value);

            var val = prop.GetValue(parameters);

            Assert.AreEqual(value, val);
        }
        public static string ConvertToUrlEncodedString(this IParameters parameters)
        {
            var result = new Dictionary <string, string>();

            if (parameters == null)
            {
                return(string.Empty);
            }

            var parametersType = parameters.GetType();

            foreach (var prop in parametersType.GetProperties())
            {
                foreach (var customAttribute in prop.GetCustomAttributes(true))
                {
                    string propValueAsString;

                    if (prop.GetValue(parameters, null) is IEnumerable <string> )
                    {
                        propValueAsString = GetEnumerableElementsAsString((IEnumerable <string>)prop.GetValue(parameters, null));
                    }
                    else
                    {
                        propValueAsString = prop.GetValue(parameters, null)?.ToString();
                    }

                    if (string.IsNullOrEmpty(propValueAsString))
                    {
                        continue;
                    }

                    if (customAttribute is JsonPropertyAttribute jsonPropAttribute)
                    {
                        result.Add(jsonPropAttribute.PropertyName, propValueAsString);
                    }
                    else
                    {
                        result.Add(prop.Name, propValueAsString);
                    }
                }
            }

            using (var content = new FormUrlEncodedContent(result)) {
                return(content.ReadAsStringAsync().Result);
            }
        }
Exemplo n.º 10
0
        public static void SetValues(this IParameters parameters, string[] adressParameters)
        {
            var properties = parameters.GetType()
                             .GetProperties()
                             .Where(z => z.GetCustomAttributes(typeof(ParameterAttribute), false).Length > 0)
                             .ToArray();

            for (int i = 0; i < properties.Length; i++)
            {
                ParameterAttribute propertyAttribute = (ParameterAttribute)properties[i].GetCustomAttributes(typeof(ParameterAttribute), false)[0];

                string stringParameterValue = i < adressParameters.Length ? adressParameters[i] : null;
                object targetParameterValue = propertyAttribute.ParseFromString(stringParameterValue);

                properties[i].SetValue(parameters, targetParameterValue);
            }
        }
Exemplo n.º 11
0
        public async Task <Tuple <int, double> > PostContext <T>(IParameters param)
        {
            var response = await client.ExecuteAsync(new RestRequest(security.Request(param.GetType().Name), Method.POST).AddJsonBody(param, security.ContentType), source.Token);

            try
            {
                if (response != null && response.RawBytes != null && response.RawBytes.Length > 0)
                {
                    Coin += security.GetSettleTheFare(response.RawBytes.Length);
                    SendMessage(Coin);
                }
                switch (param)
                {
                case Privacies _:
                    return(new Tuple <int, double>((int)response.StatusCode, JsonConvert.DeserializeObject <double>(response.Content)));
                }
            }
            catch (Exception ex)
            {
                SendMessage(ex.StackTrace);
                SendMessage((int)response.StatusCode);
            }
            return(new Tuple <int, double>((int)response.StatusCode, Coin));
        }
Exemplo n.º 12
0
        public async Task <int> DeleteContext <T>(IParameters param)
        {
            var response = await client.ExecuteAsync <T>(new RestRequest(string.Concat(security.CoreAPI, param.GetType().Name, "/", param.Security), Method.DELETE), source.Token);

            try
            {
                if (response != null && response.RawBytes != null && response.RawBytes.Length > 0)
                {
                    Coin += security.GetSettleTheFare(response.RawBytes.Length);
                    SendMessage(Coin);
                }
                return((int)response.StatusCode);
            }
            catch (Exception ex)
            {
                SendMessage(ex.StackTrace);
                SendMessage((int)response.StatusCode);
            }
            return(int.MinValue);
        }
Exemplo n.º 13
0
        public async Task <object> GetContext <T>(IParameters param)
        {
            var response = await client.ExecuteAsync <T>(new RestRequest(string.Concat(security.CoreAPI, param.GetType().Name, "/", param.Security), Method.GET), source.Token);

            try
            {
                if (response != null && response.RawBytes != null && response.RawBytes.Length > 0)
                {
                    Coin += security.GetSettleTheFare(response.RawBytes.Length);
                    SendMessage(Coin);
                }
                switch (param)
                {
                case Privacies _:
                    return(JsonConvert.DeserializeObject <Privacies>(response.Content));
                }
            }
            catch (Exception ex)
            {
                SendMessage(ex.StackTrace);
                SendMessage((int)response.StatusCode);
            }
            return(null);
        }