Example #1
0
        public async Task <ApiResponse> DoRequestAsync(string method, string url, object parameters)
        {
            try {
                IDictionary <string, string> dictionaryParameters = ConvertationHelper.ParametersToDictionary(parameters);
                string data = string.Join("&", dictionaryParameters
                                          .Select(pair => string.Concat(UrlHelper.UrlEncode(pair.Key), "=", UrlHelper.UrlEncode(pair.Value))));

                var request = (HttpWebRequest)HttpWebRequest.Create(url + "?" + data);
                request.ContentType   = "application/json; charset=utf-8";
                request.ContentLength = 0;
                request.KeepAlive     = true;
                request.Method        = method;
                request.Headers.Set("X-API-KEY", "343b1ae9-fb57-45fd-90f0-g1e097f9d621");

                string token = ApplicationPropertiesHelper.GetToken();

                request.Headers.Set("Authorization", "Bearer " + token);
                var response = (HttpWebResponse)(request.GetResponseAsync().Result);

                using (var stream = response.GetResponseStream()) {
                    using (StreamReader reader = new StreamReader(stream)) {
                        await reader.ReadToEndAsync();

                        return(ApiResponse.Ok());
                    }
                }
            }
            catch (Exception ex) {
                return(ApiResponse.Fail(ex.Message));
            }
        }
Example #2
0
        public async Task <ApiResponse> DoPostFileAsync(string url, byte[] image, object parameters)
        {
            try {
                HttpClient client = new HttpClient();
                IDictionary <string, string> dictionaryParameters = ConvertationHelper.ParametersToDictionary(parameters);
                string data = string.Join("&", dictionaryParameters.Select(pair => string.Concat(UrlHelper.UrlEncode(pair.Key), "=", UrlHelper.UrlEncode(pair.Value))));

                ByteArrayContent         byteContent = new ByteArrayContent(image);
                MultipartFormDataContent content     = new MultipartFormDataContent();
                content.Add(byteContent, "image", "filename.ext");

                string token = ApplicationPropertiesHelper.GetToken();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var response = await client.PostAsync(url + "?" + data, content);

                return(ApiResponse.Ok());
            } catch (Exception ex) {
                return(ApiResponse.Fail(ex.Message));
            }
        }
        private bool CheckCamlCompareOperation(XElement node, ListItemEmulator listItem)
        {
            var operation = OperationHelper.ParseOperation(node);

            var leftOperand   = listItem[operation.FieldName];
            var parsedValue   = SpecialConvert(operation.ValueType, operation.Value);
            var typeFromModel = new ConvertationHelper <T>().GetType(operation.FieldName);
            var rightOperand  = Convert.ChangeType(parsedValue, typeFromModel);
            var operationType = operation.OperationType;

            if (operationType == "Contains" || operationType == "BeginsWith" || (operationType == "Eq" && typeFromModel == typeof(string)))
            {
                if (operationType == "Contains")
                {
                    return(("" + leftOperand).IndexOf("" + rightOperand, StringComparison.OrdinalIgnoreCase) >= 0);
                }
                if (operationType == "BeginsWith")
                {
                    return(("" + leftOperand).IndexOf("" + rightOperand, StringComparison.OrdinalIgnoreCase) == 0);
                }

                if (operationType == "Eq")
                {
                    return(("" + leftOperand).ToUpper() == ("" + rightOperand).ToUpper());
                }
            }

            if (operationType == "Eq" || operationType == "Neq")
            {
                if (operationType == "Eq")
                {
                    return(rightOperand.Equals(leftOperand));
                }
                else
                {
                    return(!rightOperand.Equals(leftOperand));
                }
            }
            else
            {
                var rightComparible = (IComparable)rightOperand;
                var index           = rightComparible.CompareTo(leftOperand);
                if (operationType == "Gt")
                {
                    return(index < 0);
                }
                if (operationType == "Geq")
                {
                    return(index <= 0);
                }
                if (operationType == "Lt")
                {
                    return(index > 0);
                }
                if (operationType == "Leq")
                {
                    return(index >= 0);
                }
            }
            return(false);
        }