public JsonContentNegotiator(JsonMediaTypeFormatter formatter) { _jsonFormatter = formatter; _jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }
public HttpContentBodyReader(HttpContent content, JsonMediaTypeFormatter formatter) { _content = content; _formatter = formatter; }
public static void Configure(JsonMediaTypeFormatter formatter) { formatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; formatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }
//private async Task<HttpResponseMessage> SendRequest<T>(Methods method, string uri, IEnumerable<HttpStatusCode> successstatusCode, T body = null, string apiName = null) where T : class //{ // return await ExecuteRequest<object>(method, uri,body, successstatusCode, null, apiName).ConfigureAwait(false); //} public async Task <HttpResponseMessage> SendRequest <T>(Methods method, string uri, T body = null, string APIName = null) where T : class { var Json = new JsonSerializerSettings(); Json.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); Json.NullValueHandling = NullValueHandling.Ignore; var Formatter = new JsonMediaTypeFormatter { SerializerSettings = Json }; HttpResponseMessage response; using (httpclient = new HttpClient(createHandler()) { BaseAddress = new Uri("http://localhost:13892/") }) { if (!string.IsNullOrEmpty(accessToken)) { httpclient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken); httpclient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/Json")); } switch (method) { case Methods.Get: response = await httpclient.GetAsync(uri); break; case Methods.Post: if (body != null) { response = await httpclient.PostAsync(uri, body, Formatter); } else { response = await httpclient.PostAsync(uri, new StringContent(string.Empty)); } break; case Methods.Put: if (body != null) { response = await httpclient.PutAsync(uri, body, Formatter); } else { response = await httpclient.PutAsync(uri, new StringContent(string.Empty)); } break; case Methods.Delete: if (body != null) { response = await httpclient.SendAsync(new HttpRequestMessage(HttpMethod.Delete, uri) { Content = new ObjectContent <T>(body, new JsonMediaTypeFormatter()) }); } else { response = await httpclient.DeleteAsync(uri); } break; default: throw new ArgumentOutOfRangeException("Method"); } } httpclient.DefaultRequestHeaders.Authorization = null; return(response); }
public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory) { Console.WriteLine(@"Configure : " + DateTime.Now.ToString("hh.mm.ss.ffffff")); loggerFactory.AddEventSourceLogger(); KuduWebUtil.MigrateToNetCorePatch(_webAppRuntimeEnvironment); if (_hostingEnvironment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(15) }; app.UseWebSockets(webSocketOptions); var containsRelativePath = new Func <HttpContext, bool>(i => i.Request.Path.Value.StartsWith("/Default", StringComparison.OrdinalIgnoreCase)); app.MapWhen(containsRelativePath, application => application.Run(async context => { await context.Response.WriteAsync("Kestrel Running"); })); var containsRelativePath2 = new Func <HttpContext, bool>(i => i.Request.Path.Value.StartsWith("/info", StringComparison.OrdinalIgnoreCase)); app.MapWhen(containsRelativePath2, application => application.Run(async context => { await context.Response.WriteAsync("{\"Version\":\"" + Constants.KuduBuild + "\"}"); })); app.UseResponseCompression(); var containsRelativePath3 = new Func <HttpContext, bool>(i => i.Request.Path.Value.StartsWith("/AppServiceTunnel/Tunnel.ashx", StringComparison.OrdinalIgnoreCase)); app.MapWhen(containsRelativePath3, builder => builder.UseMiddleware <DebugExtensionMiddleware>()); app.UseTraceMiddleware(); applicationLifetime.ApplicationStopping.Register(OnShutdown); app.UseStaticFiles(); ProxyRequestIfRelativeUrlMatches(@"/webssh", "http", "127.0.0.1", "3000", app); var configuration = app.ApplicationServices.GetRequiredService <IServerConfiguration>(); // CORE TODO any equivalent for this? Needed? //var configuration = kernel.Get<IServerConfiguration>(); //GlobalConfiguration.Configuration.Formatters.Clear(); //GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; var jsonFormatter = new JsonMediaTypeFormatter(); // CORE TODO concept of "deprecation" in routes for traces, Do we need this for linux ? // Push url foreach (var url in new[] { "/git-receive-pack", $"/{configuration.GitServerRoot}/git-receive-pack" }) { app.Map(url, appBranch => appBranch.RunReceivePackHandler()); } // Fetch hook app.Map("/deploy", appBranch => appBranch.RunFetchHandler()); // Log streaming app.Map("/api/logstream", appBranch => appBranch.RunLogStreamHandler()); // Clone url foreach (var url in new[] { "/git-upload-pack", $"/{configuration.GitServerRoot}/git-upload-pack" }) { app.Map(url, appBranch => appBranch.RunUploadPackHandler()); } // Custom GIT repositories, which can be served from any directory that has a git repo foreach (var url in new[] { "/git-custom-repository", "/git/{*path}" }) { app.Map(url, appBranch => appBranch.RunCustomGitRepositoryHandler()); } // Sets up the file server to web app's wwwroot KuduWebUtil.SetupFileServer(app, _webAppRuntimeEnvironment.WebRootPath, "/wwwroot"); // Sets up the file server to LogFiles KuduWebUtil.SetupFileServer(app, Path.Combine(_webAppRuntimeEnvironment.LogFilesPath, "kudu", "deployment"), "/deploymentlogs"); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Kudu API Docs"); }); app.UseMvc(routes => { Console.WriteLine(@"Setting Up Routes : " + DateTime.Now.ToString("hh.mm.ss.ffffff")); routes.MapRouteAnalyzer("/routes"); // Add routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); // Git Service routes.MapRoute("git-info-refs-root", "info/refs", new { controller = "InfoRefs", action = "Execute" }); routes.MapRoute("git-info-refs", configuration.GitServerRoot + "/info/refs", new { controller = "InfoRefs", action = "Execute" }); // Scm (deployment repository) routes.MapHttpRouteDual("scm-info", "scm/info", new { controller = "LiveScm", action = "GetRepositoryInfo" }); routes.MapHttpRouteDual("scm-clean", "scm/clean", new { controller = "LiveScm", action = "Clean" }); routes.MapHttpRouteDual("scm-delete", "scm", new { controller = "LiveScm", action = "Delete" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); // Scm files editor routes.MapHttpRouteDual("scm-get-files", "scmvfs/{*path}", new { controller = "LiveScmEditor", action = "GetItem" }, new { verb = new HttpMethodRouteConstraint("GET", "HEAD") }); routes.MapHttpRouteDual("scm-put-files", "scmvfs/{*path}", new { controller = "LiveScmEditor", action = "PutItem" }, new { verb = new HttpMethodRouteConstraint("PUT") }); routes.MapHttpRouteDual("scm-delete-files", "scmvfs/{*path}", new { controller = "LiveScmEditor", action = "DeleteItem" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); // Live files editor routes.MapHttpRouteDual("vfs-get-files", "vfs/{*path}", new { controller = "Vfs", action = "GetItem" }, new { verb = new HttpMethodRouteConstraint("GET", "HEAD") }); routes.MapHttpRouteDual("vfs-put-files", "vfs/{*path}", new { controller = "Vfs", action = "PutItem" }, new { verb = new HttpMethodRouteConstraint("PUT") }); routes.MapHttpRouteDual("vfs-delete-files", "vfs/{*path}", new { controller = "Vfs", action = "DeleteItem" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); // Zip file handler routes.MapHttpRouteDual("zip-get-files", "zip/{*path}", new { controller = "Zip", action = "GetItem" }, new { verb = new HttpMethodRouteConstraint("GET", "HEAD") }); routes.MapHttpRouteDual("zip-put-files", "zip/{*path}", new { controller = "Zip", action = "PutItem" }, new { verb = new HttpMethodRouteConstraint("PUT") }); // Zip push deployment routes.MapRoute("zip-push-deploy", "api/zipdeploy", new { controller = "PushDeployment", action = "ZipPushDeploy" }, new { verb = new HttpMethodRouteConstraint("POST") }); routes.MapRoute("zip-war-deploy", "api/wardeploy", new { controller = "PushDeployment", action = "WarPushDeploy" }, new { verb = new HttpMethodRouteConstraint("POST") }); // Live Command Line routes.MapHttpRouteDual("execute-command", "command", new { controller = "Command", action = "ExecuteCommand" }, new { verb = new HttpMethodRouteConstraint("POST") }); // Deployments routes.MapHttpRouteDual("all-deployments", "deployments", new { controller = "Deployment", action = "GetDeployResults" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpRouteDual("one-deployment-get", "deployments/{id}", new { controller = "Deployment", action = "GetResult" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpRouteDual("one-deployment-put", "deployments/{id?}", new { controller = "Deployment", action = "Deploy" }, new { verb = new HttpMethodRouteConstraint("PUT") }); routes.MapHttpRouteDual("one-deployment-delete", "deployments/{id}", new { controller = "Deployment", action = "Delete" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); routes.MapHttpRouteDual("one-deployment-log", "deployments/{id}/log", new { controller = "Deployment", action = "GetLogEntry" }); routes.MapHttpRouteDual("one-deployment-log-details", "deployments/{id}/log/{logId}", new { controller = "Deployment", action = "GetLogEntryDetails" }); // Deployment script routes.MapRoute("get-deployment-script", "api/deploymentscript", new { controller = "Deployment", action = "GetDeploymentScript" }, new { verb = new HttpMethodRouteConstraint("GET") }); // IsDeploying status routes.MapRoute("is-deployment-underway", "api/isdeploying", new { controller = "Deployment", action = "IsDeploying" }, new { verb = new HttpMethodRouteConstraint("GET") }); // SSHKey routes.MapHttpRouteDual("get-sshkey", "api/sshkey", new { controller = "SSHKey", action = "GetPublicKey" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpRouteDual("put-sshkey", "api/sshkey", new { controller = "SSHKey", action = "SetPrivateKey" }, new { verb = new HttpMethodRouteConstraint("PUT") }); routes.MapHttpRouteDual("delete-sshkey", "api/sshkey", new { controller = "SSHKey", action = "DeleteKeyPair" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); // Environment routes.MapHttpRouteDual("get-env", "environment", new { controller = "Environment", action = "Get" }, new { verb = new HttpMethodRouteConstraint("GET") }); // Settings routes.MapHttpRouteDual("set-setting", "settings", new { controller = "Settings", action = "Set" }, new { verb = new HttpMethodRouteConstraint("POST") }); routes.MapHttpRouteDual("get-all-settings", "settings", new { controller = "Settings", action = "GetAll" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpRouteDual("get-setting", "settings/{key}", new { controller = "Settings", action = "Get" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpRouteDual("delete-setting", "settings/{key}", new { controller = "Settings", action = "Delete" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); // Diagnostics routes.MapHttpRouteDual("diagnostics", "dump", new { controller = "Diagnostics", action = "GetLog" }); routes.MapHttpRouteDual("diagnostics-set-setting", "diagnostics/settings", new { controller = "Diagnostics", action = "Set" }, new { verb = new HttpMethodRouteConstraint("POST") }); routes.MapHttpRouteDual("diagnostics-get-all-settings", "diagnostics/settings", new { controller = "Diagnostics", action = "GetAll" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpRouteDual("diagnostics-get-setting", "diagnostics/settings/{key}", new { controller = "Diagnostics", action = "Get" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpRouteDual("diagnostics-delete-setting", "diagnostics/settings/{key}", new { controller = "Diagnostics", action = "Delete" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); // Logs foreach (var url in new[] { "/logstream", "/logstream/{*path}" }) { app.Map(url, appBranch => appBranch.RunLogStreamHandler()); } routes.MapHttpRouteDual("recent-logs", "api/logs/recent", new { controller = "Diagnostics", action = "GetRecentLogs" }, new { verb = new HttpMethodRouteConstraint("GET") }); // Enable these for Linux and Windows Containers. if (!OSDetector.IsOnWindows() || (OSDetector.IsOnWindows() && EnvironmentHelper.IsWindowsContainers())) { routes.MapRoute("current-docker-logs-zip", "api/logs/docker/zip", new { controller = "Diagnostics", action = "GetDockerLogsZip" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapRoute("current-docker-logs", "api/logs/docker", new { controller = "Diagnostics", action = "GetDockerLogs" }, new { verb = new HttpMethodRouteConstraint("GET") }); } var processControllerName = OSDetector.IsOnWindows() ? "Process" : "LinuxProcess"; // Processes routes.MapHttpProcessesRoute("all-processes", "", new { controller = processControllerName, action = "GetAllProcesses" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpProcessesRoute("one-process-get", "/{id}", new { controller = processControllerName, action = "GetProcess" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpProcessesRoute("one-process-delete", "/{id}", new { controller = processControllerName, action = "KillProcess" }, new { verb = new HttpMethodRouteConstraint("DELETE") }); routes.MapHttpProcessesRoute("one-process-dump", "/{id}/dump", new { controller = processControllerName, action = "MiniDump" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpProcessesRoute("start-process-profile", "/{id}/profile/start", new { controller = processControllerName, action = "StartProfileAsync" }, new { verb = new HttpMethodRouteConstraint("POST") }); routes.MapHttpProcessesRoute("stop-process-profile", "/{id}/profile/stop", new { controller = processControllerName, action = "StopProfileAsync" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpProcessesRoute("all-threads", "/{id}/threads", new { controller = processControllerName, action = "GetAllThreads" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpProcessesRoute("one-process-thread", "/{processId}/threads/{threadId}", new { controller = processControllerName, action = "GetThread" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpProcessesRoute("all-modules", "/{id}/modules", new { controller = processControllerName, action = "GetAllModules" }, new { verb = new HttpMethodRouteConstraint("GET") }); routes.MapHttpProcessesRoute("one-process-module", "/{id}/modules/{baseAddress}", new { controller = processControllerName, action = "GetModule" }, new { verb = new HttpMethodRouteConstraint("GET") }); // Runtime routes.MapHttpRouteDual("runtime", "diagnostics/runtime", new { controller = "Runtime", action = "GetRuntimeVersions" }, new { verb = new HttpMethodRouteConstraint("GET") }); // Docker Hook Endpoint if (!OSDetector.IsOnWindows() || (OSDetector.IsOnWindows() && EnvironmentHelper.IsWindowsContainers())) { routes.MapHttpRouteDual("docker", "docker/hook", new { controller = "Docker", action = "ReceiveHook" }, new { verb = new HttpMethodRouteConstraint("POST") }); } // catch all unregistered url to properly handle not found // routes.MapRoute("error-404", "{*path}", new {controller = "Error404", action = "Handle"}); }); Console.WriteLine(@"Exiting Configure : " + DateTime.Now.ToString("hh.mm.ss.ffffff")); }
public override void OnAuthorization(HttpActionContext actionContext) { JsonMediaTypeFormatter jsonMediaTypeFormatter = new JsonMediaTypeFormatter(); try { log.Debug("HealthCheckAuthorizationFilterAttribute OnActionExecuted"); /* * var healthCheckSettingsAccessor = new HealthCheckSettingsAccessor(); * var healthCheckSettings = healthCheckSettingsAccessor.GetHealthCheckSettings(); * * var tenants = CoreContext.TenantManager.GetTenants().Where(t => t.TenantId != healthCheckSettings.FakeTenantId).ToList(); * * if (!CoreContext.TenantManager.GetTenantQuota(tenants.First().TenantId).HealthCheck) * { * log.Debug("There is no correct license for HealthCheck."); * * actionContext.Response = new HttpResponseMessage(HttpStatusCode.Forbidden) * { * Content = new ObjectContent<object>(HealthCheckResource.ErrorNotAllowedOption, jsonMediaTypeFormatter) * }; * * return; * } */ string authorizationHeaderValue = null; foreach (var header in actionContext.Request.Headers) { if (header.Key == "Authorization") { if (header.Value == null) { log.Error("User Unauthorized, Authorization header.Value is null"); actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); return; } foreach (var headerValue in header.Value) { authorizationHeaderValue = headerValue; } break; } } if (authorizationHeaderValue == null) { log.Error("User Unauthorized, authorizationHeaderValue is null"); actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); return; } var authorization = authorizationHeaderValue.Split(','); if (authorization.Length != 2) { log.ErrorFormat("User Unauthorized, authorization is null or authorization.Length = {0}", authorization.Length); actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized); return; } var portalInfo = authorization[0].Split(' '); if (portalInfo.Length == 2) { authorization[0] = portalInfo[1]; } CoreContext.TenantManager.SetCurrentTenant(authorization[0]); SecurityContext.AuthenticateMe(authorization[1]); ResolveUserCulture(); } catch (Exception ex) { log.ErrorFormat("Unexpected error on HealthCheckAuthorizationFilterAttribute: {0} {1}", ex.ToString(), ex.InnerException != null ? ex.InnerException.Message : string.Empty); actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized) { Content = new ObjectContent <object>(ex.ToString(), jsonMediaTypeFormatter) }; } }
public QiuxunApiContentNegotiator(JsonMediaTypeFormatter formatter) { this.jsonFormatter = formatter; this.compatibleJsonFormatter = new JsonMediaTypeFormatter(); this.compatibleJsonFormatter.SerializerSettings.Converters.Add(new CompatibleLongTypeConvert()); }
public MediaTypeFormatterTest() { _formatter = new JsonMediaTypeFormatter(); _content = new SystemTextJsonHttpContent(_formatter.SerializerOptions); }
public static void RegisterRoutes(IKernel kernel, RouteCollection routes) { var configuration = kernel.Get <IServerConfiguration>(); GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly; var jsonFormatter = new JsonMediaTypeFormatter(); GlobalConfiguration.Configuration.Formatters.Add(jsonFormatter); GlobalConfiguration.Configuration.DependencyResolver = new NinjectWebApiDependencyResolver(kernel); GlobalConfiguration.Configuration.Filters.Add(new TraceExceptionFilterAttribute()); // Git Service routes.MapHttpRoute("git-info-refs-root", "info/refs", new { controller = "InfoRefs", action = "Execute" }); routes.MapHttpRoute("git-info-refs", configuration.GitServerRoot + "/info/refs", new { controller = "InfoRefs", action = "Execute" }); // Push url routes.MapHandler <ReceivePackHandler>(kernel, "git-receive-pack-root", "git-receive-pack"); routes.MapHandler <ReceivePackHandler>(kernel, "git-receive-pack", configuration.GitServerRoot + "/git-receive-pack"); // Fetch Hook routes.MapHandler <FetchHandler>(kernel, "fetch", "deploy"); // Clone url routes.MapHandler <UploadPackHandler>(kernel, "git-upload-pack-root", "git-upload-pack"); routes.MapHandler <UploadPackHandler>(kernel, "git-upload-pack", configuration.GitServerRoot + "/git-upload-pack"); // Custom GIT repositories, which can be served from any directory that has a git repo routes.MapHandler <CustomGitRepositoryHandler>(kernel, "git-custom-repository", "git/{*path}"); // Scm (deployment repository) routes.MapHttpRoute("scm-info", "scm/info", new { controller = "LiveScm", action = "GetRepositoryInfo" }); routes.MapHttpRoute("scm-clean", "scm/clean", new { controller = "LiveScm", action = "Clean" }); routes.MapHttpRoute("scm-delete", "scm", new { controller = "LiveScm", action = "Delete" }, new { verb = new HttpMethodConstraint("DELETE") }); // Scm files editor routes.MapHttpRoute("scm-get-files", "scmvfs/{*path}", new { controller = "LiveScmEditor", action = "GetItem" }, new { verb = new HttpMethodConstraint("GET", "HEAD") }); routes.MapHttpRoute("scm-put-files", "scmvfs/{*path}", new { controller = "LiveScmEditor", action = "PutItem" }, new { verb = new HttpMethodConstraint("PUT") }); routes.MapHttpRoute("scm-delete-files", "scmvfs/{*path}", new { controller = "LiveScmEditor", action = "DeleteItem" }, new { verb = new HttpMethodConstraint("DELETE") }); // Live files editor routes.MapHttpRoute("vfs-get-files", "vfs/{*path}", new { controller = "Vfs", action = "GetItem" }, new { verb = new HttpMethodConstraint("GET", "HEAD") }); routes.MapHttpRoute("vfs-put-files", "vfs/{*path}", new { controller = "Vfs", action = "PutItem" }, new { verb = new HttpMethodConstraint("PUT") }); routes.MapHttpRoute("vfs-delete-files", "vfs/{*path}", new { controller = "Vfs", action = "DeleteItem" }, new { verb = new HttpMethodConstraint("DELETE") }); // Zip file handler routes.MapHttpRoute("zip-get-files", "zip/{*path}", new { controller = "Zip", action = "GetItem" }, new { verb = new HttpMethodConstraint("GET", "HEAD") }); routes.MapHttpRoute("zip-put-files", "zip/{*path}", new { controller = "Zip", action = "PutItem" }, new { verb = new HttpMethodConstraint("PUT") }); // Live Command Line routes.MapHttpRoute("execute-command", "command", new { controller = "Command", action = "ExecuteCommand" }, new { verb = new HttpMethodConstraint("POST") }); // Deployments routes.MapHttpRoute("all-deployments", "deployments", new { controller = "Deployment", action = "GetDeployResults" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("one-deployment-get", "deployments/{id}", new { controller = "Deployment", action = "GetResult" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("one-deployment-put", "deployments/{id}", new { controller = "Deployment", action = "Deploy", id = RouteParameter.Optional }, new { verb = new HttpMethodConstraint("PUT") }); routes.MapHttpRoute("one-deployment-delete", "deployments/{id}", new { controller = "Deployment", action = "Delete" }, new { verb = new HttpMethodConstraint("DELETE") }); routes.MapHttpRoute("one-deployment-log", "deployments/{id}/log", new { controller = "Deployment", action = "GetLogEntry" }); routes.MapHttpRoute("one-deployment-log-details", "deployments/{id}/log/{logId}", new { controller = "Deployment", action = "GetLogEntryDetails" }); // SSHKey routes.MapHttpRoute("get-sshkey", "sshkey", new { controller = "SSHKey", action = "GetPublicKey" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("put-sshkey", "sshkey", new { controller = "SSHKey", action = "SetPrivateKey" }, new { verb = new HttpMethodConstraint("PUT") }); routes.MapHttpRoute("delete-sshkey", "sshkey", new { controller = "SSHKey", action = "DeleteKeyPair" }, new { verb = new HttpMethodConstraint("DELETE") }); // Environment routes.MapHttpRoute("get-env", "environment", new { controller = "Environment", action = "Get" }, new { verb = new HttpMethodConstraint("GET") }); // Settings routes.MapHttpRoute("set-setting", "settings", new { controller = "Settings", action = "Set" }, new { verb = new HttpMethodConstraint("POST") }); routes.MapHttpRoute("get-all-settings", "settings", new { controller = "Settings", action = "GetAll" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("get-setting", "settings/{key}", new { controller = "Settings", action = "Get" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("delete-setting", "settings/{key}", new { controller = "Settings", action = "Delete" }, new { verb = new HttpMethodConstraint("DELETE") }); // Diagnostics routes.MapHttpRoute("diagnostics", "dump", new { controller = "Diagnostics", action = "GetLog" }); routes.MapHttpRoute("diagnostics-set-setting", "diagnostics/settings", new { controller = "Diagnostics", action = "Set" }, new { verb = new HttpMethodConstraint("POST") }); routes.MapHttpRoute("diagnostics-get-all-settings", "diagnostics/settings", new { controller = "Diagnostics", action = "GetAll" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("diagnostics-get-setting", "diagnostics/settings/{key}", new { controller = "Diagnostics", action = "Get" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("diagnostics-delete-setting", "diagnostics/settings/{key}", new { controller = "Diagnostics", action = "Delete" }, new { verb = new HttpMethodConstraint("DELETE") }); // LogStream routes.MapHandler <LogStreamHandler>(kernel, "logstream", "logstream/{*path}"); // Processes routes.MapHttpRoute("all-processes", "diagnostics/processes", new { controller = "Process", action = "GetAllProcesses" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("one-process-get", "diagnostics/processes/{id}", new { controller = "Process", action = "GetProcess" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("one-process-delete", "diagnostics/processes/{id}", new { controller = "Process", action = "KillProcess" }, new { verb = new HttpMethodConstraint("DELETE") }); routes.MapHttpRoute("one-process-dump", "diagnostics/processes/{id}/dump", new { controller = "Process", action = "MiniDump" }, new { verb = new HttpMethodConstraint("GET") }); if (ProcessExtensions.SupportGCDump) { routes.MapHttpRoute("one-process-gcdump", "diagnostics/processes/{id}/gcdump", new { controller = "Process", action = "GCDump" }, new { verb = new HttpMethodConstraint("GET") }); } routes.MapHttpRoute("all-threads", "diagnostics/processes/{id}/threads", new { controller = "Process", action = "GetAllThreads" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("one-process-thread", "diagnostics/processes/{processId}/threads/{threadId}", new { controller = "Process", action = "GetThread" }, new { verb = new HttpMethodConstraint("GET") }); // Runtime routes.MapHttpRoute("runtime", "diagnostics/runtime", new { controller = "Runtime", action = "GetRuntimeVersions" }, new { verb = new HttpMethodConstraint("GET") }); // Hooks routes.MapHttpRoute("unsubscribe-hook", "hooks/{id}", new { controller = "WebHooks", action = "Unsubscribe" }, new { verb = new HttpMethodConstraint("DELETE") }); routes.MapHttpRoute("get-hook", "hooks/{id}", new { controller = "WebHooks", action = "GetWebHook" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("publish-hooks", "hooks/publish/{hookEventType}", new { controller = "WebHooks", action = "PublishEvent" }, new { verb = new HttpMethodConstraint("POST") }); routes.MapHttpRoute("get-hooks", "hooks", new { controller = "WebHooks", action = "GetWebHooks" }, new { verb = new HttpMethodConstraint("GET") }); routes.MapHttpRoute("subscribe-hook", "hooks", new { controller = "WebHooks", action = "Subscribe" }, new { verb = new HttpMethodConstraint("POST") }); }
public JsonContentNegotiator(JsonMediaTypeFormatter formatter) { _jsonFormatter = formatter; _jsonFormatter.SerializerSettings.ContractResolver = new LowercaseContractResolver(); }
public async void Insert_Company() { if (SelectedCompany.NAME == "" || SelectedCompany.NAME == null) { } else if (SelectedCompany.SHOPNAME == "" || SelectedCompany.SHOPNAME == null) { } else if (SelectedCompany.PREFIX_NUM == "" || SelectedCompany.PREFIX_NUM == null) { } else if (SelectedCompany.TIN_NUMBER == "" || SelectedCompany.TIN_NUMBER == null) { } else if (SelectedCompany.ADDRESS_1 == "" || SelectedCompany.ADDRESS_1 == null) { } else if (SelectedCompany.STATE == "" || SelectedCompany.STATE == null) { } else if (SelectedCompany.CITY == "" || SelectedCompany.CITY == null) { } else if (SelectedCompany.PIN == "" || SelectedCompany.PIN == null) { } else if (SelectedCompany.EMAIL == "" || SelectedCompany.EMAIL == null) { } else if (SelectedCompany.BANK_NAME == "" || SelectedCompany.EMAIL == null) { } else if (SelectedCompany.BANK_CODE == "" || SelectedCompany.EMAIL == null) { } else if (SelectedCompany.BRANCH_NAME == "" || SelectedCompany.EMAIL == null) { } //else if (SelectedCompany.ACCOUNT_NUMBER.ToString() == "" || SelectedCompany.ACCOUNT_NUMBER == null) //{ //} else { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(GlobalData.gblApiAdress); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter(); //client.Timeout = new TimeSpan(500000000000); HttpContent content = new ObjectContent <CompanyModel>(SelectedCompany, jsonFormatter); var response = await client.PostAsync("api/CompanyAPI/CreateCompany/", content); if (response.StatusCode.ToString() == "OK") { //GetCompany(); Close(); } else { SelectedCompany = new CompanyModel(); } } }