summaryrefslogtreecommitdiff
path: root/Gestor.Application/Helpers/HttpHelper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Application/Helpers/HttpHelper.cs')
-rw-r--r--Gestor.Application/Helpers/HttpHelper.cs103
1 files changed, 103 insertions, 0 deletions
diff --git a/Gestor.Application/Helpers/HttpHelper.cs b/Gestor.Application/Helpers/HttpHelper.cs
new file mode 100644
index 0000000..e042d1b
--- /dev/null
+++ b/Gestor.Application/Helpers/HttpHelper.cs
@@ -0,0 +1,103 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Net.Http;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.Helpers
+{
+ public static class HttpHelper
+ {
+ public static Uri AddQuery<T>(this Uri uri, string name, T value)
+ {
+ //
+ // Current member / type: System.Uri Gestor.Application.Helpers.HttpHelper::AddQuery(System.Uri,System.String,T)
+ // File path: C:\AggerSeguros\Gestor.Application.exe
+ //
+ // Product version: 0.0.0.0
+ // Exception in: System.Uri AddQuery(System.Uri,System.String,T)
+ //
+ // Managed pointer usage not in SSA
+ // at Telerik.JustDecompiler.Steps.ManagedPointersRemovalStep.CheckForAssignment(BinaryExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\ManagedPointersRemovalStep.cs:line 100
+ // at Telerik.JustDecompiler.Steps.ManagedPointersRemovalStep.VisitBinaryExpression(BinaryExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\ManagedPointersRemovalStep.cs:line 80
+ // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351
+ // at Telerik.JustDecompiler.Steps.ManagedPointersRemovalStep.VisitExpressions() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\ManagedPointersRemovalStep.cs:line 41
+ // at Telerik.JustDecompiler.Steps.ManagedPointersRemovalStep.Process(DecompilationContext context, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\ManagedPointersRemovalStep.cs:line 29
+ // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100
+ // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72
+ // at Telerik.JustDecompiler.Decompiler.Extensions.Decompile(MethodBody body, ILanguage language, DecompilationContext& context, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 61
+ // at Telerik.JustDecompiler.Decompiler.WriterContextServices.BaseWriterContextService.DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\WriterContextServices\BaseWriterContextService.cs:line 133
+ //
+ // mailto: JustDecompilePublicFeedback@telerik.com
+
+ }
+
+ public static Dictionary<string, string> ParseQueryString(this Uri uri)
+ {
+ int num = uri.Query.IndexOf('?') + 1;
+ return (
+ from o in uri.Query.Substring(num).Split(new char[] { '&' })
+ select o.Split(new char[] { '=' }) into items
+ where (int)items.Length == 2
+ select items).ToDictionary<string[], string, string>((string[] pair) => pair[0], (string[] pair) => pair[1]);
+ }
+
+ public static Uri SetQuery(this Uri uri, string name, string value, bool escapeValue = true)
+ {
+ UriBuilder uriBuilder = new UriBuilder(uri);
+ Dictionary<string, string> strs = uri.ParseQueryString();
+ string str = (escapeValue ? Uri.EscapeDataString(value) : value);
+ if (strs.ContainsKey(name))
+ {
+ strs.Remove(name);
+ }
+ strs.Add(name, str);
+ List<string> list = (
+ from x in strs
+ select string.Concat(x.Key, "=", x.Value)).ToList<string>();
+ uriBuilder.Query = string.Join("&", list);
+ return uriBuilder.Uri;
+ }
+
+ public static string ToBase64BasicEncode(this string value)
+ {
+ return string.Concat("Basic ", Convert.ToBase64String(Encoding.UTF8.GetBytes(value)));
+ }
+
+ public static StringContent ToHttpContent<T>(this T content, Encoding encoding = null, string mediaType = "application/json")
+ {
+ return new StringContent(JsonConvert.SerializeObject(content), Encoding.UTF8, mediaType);
+ }
+
+ public static JObject ToJObject(this string jsonString)
+ {
+ JObject jObject;
+ try
+ {
+ jObject = JObject.Parse(jsonString);
+ }
+ catch (Exception exception)
+ {
+ jObject = null;
+ }
+ return jObject;
+ }
+
+ public static JObject ToJObject(this HttpContent content)
+ {
+ return content.ReadAsStringAsync().Result.ToJObject();
+ }
+
+ public static Uri ToUri(this string uri)
+ {
+ Uri uri1;
+ Uri.TryCreate(uri, UriKind.Absolute, out uri1);
+ return uri1;
+ }
+ }
+} \ No newline at end of file