Ejemplo n.º 1
0
        public static async Task <T> postTable <T>(this T entidad) where T : IEntidadBase
        {
            if (string.IsNullOrEmpty(entidad.nombreTabla))
            {
                entidad.nombreTabla = entidad.GetType().Name.eliminarCaracteresEspeciales().ToLower();
            }

            if (string.IsNullOrEmpty(entidad.PartitionKey))
            {
                entidad.PartitionKey = entidad.GetType().FullName.ToLower();
            }

            if (string.IsNullOrEmpty(entidad.RowKey))
            {
                string row = string.Format("{0}{1}{2}tick{3}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Ticks);
                entidad.RowKey = entidad.GetType().Namespace.ToLower() + row;
            }


            try
            {
                T      valorRetorno;
                string json = JsonConvert.SerializeObject(entidad, Formatting.Indented,
                                                          new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });

                HttpClientHandler handler  = new HttpClientHandler();
                var httpClient             = new HttpClient(handler);
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Path_Servicio.obtenerUrlServicio() + "table");
                request.Content = new StringContent(json);
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Hefesoft.Standard.Static.Variables_Globales.Bearer);

                MediaTypeHeaderValue contentType = request.Content.Headers.ContentType;
                contentType.MediaType = "application/json";

                request.Content.Headers.ContentType = contentType;

                if (handler.SupportsTransferEncodingChunked())
                {
                    request.Headers.TransferEncodingChunked = true;
                }
                HttpResponseMessage response = await httpClient.SendAsync(request);

                var resultadoString = response.Content.ReadAsStringAsync().Result;

                valorRetorno = JsonConvert.DeserializeObject <T>(resultadoString);

                return(valorRetorno);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public static async Task <T> getTableByPartitionAndRowKey <T>(this T entidad, string rowKey) where T : IEntidadBase
        {
            T valor_retorno = default(T);

            if (string.IsNullOrEmpty(entidad.nombreTabla))
            {
                entidad.nombreTabla = entidad.GetType().Name.eliminarCaracteresEspeciales().ToLower();
            }

            if (string.IsNullOrEmpty(entidad.PartitionKey))
            {
                entidad.PartitionKey = entidad.GetType().FullName.ToLower();
            }

            string json       = JsonConvert.SerializeObject(entidad);
            string parameters = string.Format("table/?nombreTabla={0}&partitionKey={1}&rowKey={2}", entidad.nombreTabla, entidad.PartitionKey, rowKey);

            HttpClientHandler handler  = new HttpClientHandler();
            var httpClient             = new HttpClient(handler);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Path_Servicio.obtenerUrlServicio() + parameters);

            if (handler.SupportsTransferEncodingChunked())
            {
                request.Headers.TransferEncodingChunked = true;
            }
            HttpResponseMessage response = await httpClient.SendAsync(request);

            try
            {
                var resultadoString = response.Content.ReadAsStringAsync().Result;
                valor_retorno = JsonConvert.DeserializeObject <T>(resultadoString);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(valor_retorno);
        }
Ejemplo n.º 3
0
        public async Task <string> registerPushService(PushAzureService push)
        {
            try
            {
                string json = JsonConvert.SerializeObject(push, Formatting.Indented,
                                                          new JsonSerializerSettings
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });

                HttpClientHandler handler  = new HttpClientHandler();
                var httpClient             = new HttpClient(handler);
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Path_Servicio.obtenerUrlServicio() + "Register");

                request.Headers.Authorization = new AuthenticationHeaderValue(Hefesoft.Standard.Static.Variables_Globales.Bearer);
                request.Content = new StringContent(json);
                MediaTypeHeaderValue contentType = request.Content.Headers.ContentType;
                contentType.MediaType = "application/json";



                request.Content.Headers.ContentType = contentType;

                if (handler.SupportsTransferEncodingChunked())
                {
                    request.Headers.TransferEncodingChunked = true;
                }
                HttpResponseMessage response = await httpClient.SendAsync(request);

                var resultadoString = response.Content.ReadAsStringAsync().Result;

                var idHub = JsonConvert.DeserializeObject <string>(resultadoString);
                return(idHub);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        private static async Task <T> doGetParameters <T>(T valorRetorno, string parameters) where T : IEntidadBase
        {
            HttpClientHandler handler  = new HttpClientHandler();
            var httpClient             = new HttpClient(handler);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Path_Servicio.obtenerUrlServicio() + parameters);

            if (handler.SupportsTransferEncodingChunked())
            {
                request.Headers.TransferEncodingChunked = true;
            }
            HttpResponseMessage response = await httpClient.SendAsync(request);

            try
            {
                var resultadoString = response.Content.ReadAsStringAsync().Result;
                valorRetorno = JsonConvert.DeserializeObject <T>(resultadoString);
            }
            catch
            {
            }
            return(valorRetorno);
        }
Ejemplo n.º 5
0
        private static async Task <string> doPost(string json)
        {
            HttpClientHandler handler  = new HttpClientHandler();
            var httpClient             = new HttpClient(handler);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Path_Servicio.obtenerUrlServicio() + "blob");

            request.Content = new StringContent(json);
            MediaTypeHeaderValue contentType = request.Content.Headers.ContentType;

            contentType.MediaType = "application/json";

            request.Content.Headers.ContentType = contentType;

            if (handler.SupportsTransferEncodingChunked())
            {
                request.Headers.TransferEncodingChunked = true;
            }
            HttpResponseMessage response = await httpClient.SendAsync(request);

            var resultadoString = response.Content.ReadAsStringAsync().Result;

            return(resultadoString);
        }