private void httpServer_ProcessRequest(System.Net.HttpListenerContext ctx) { ActionResult actionResult; ctx.Response.AppendHeader("Access-Control-Allow-Origin", "*"); ctx.Response.AppendHeader("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS"); if (ctx.Request.HttpMethod == "POST") { var segments = new Uri(ctx.Request.Url.AbsoluteUri).Segments; if (segments.Length > 1 && segments[segments.Length - 2] == (ServiceName + "/") && segments[segments.Length - 1] == "ajax") { var scanFormModelBinder = new ModelBinder(GetPostData(ctx.Request)); var method = scanFormModelBinder.BindAjaxMethod(); var scanController = new ScanController(_markerAsynchrone); switch (method) { case "GetScannerParameters": actionResult = scanController.GetScannerParameters(_scannerManager, _cacheSettings, scanFormModelBinder.BindSourceIndex()); break; case "Scan": actionResult = scanController.Scan(scanFormModelBinder.BindScanForm(), _scannerManager); break; case "RestartWia": actionResult = scanController.RestartWia(); break; case "Restart": actionResult = scanController.Restart(); break; default: actionResult = DefaultResponce(ctx); break; } } else { actionResult = DefaultResponce(ctx); } } else if (ctx.Request.HttpMethod == "GET") { if (ctx.Request.Url.AbsolutePath.Length >= _procesName.Length) { var homeCtrl = new HomeController(); var method = ctx.Request.Url.AbsolutePath.Substring(_procesName.Length); switch (method) { case "download": ModelBinder MB = new ModelBinder(GetGetData(ctx.Request)); var fileParam = MB.BindDownloadFile(); if (MB.IsBase64) { actionResult = homeCtrl.ConvertToBase64File(fileParam); } else { actionResult = homeCtrl.DownloadFile(fileParam); } break; case "version": actionResult = homeCtrl.GetVersionProgram( Assembly.GetEntryAssembly().GetName().Version.ToString()); break; default: if (method == "") { method = "index.html"; } actionResult = homeCtrl.StaticFile(method); break; } } else { actionResult = DefaultResponce(ctx); } } else { actionResult = DefaultResponce(ctx); } if (actionResult.FileNameToDownload != null) { ctx.Response.AddHeader("Content-Disposition", "attachment; filename*=UTF-8''" + Uri.EscapeDataString(Uri.UnescapeDataString(actionResult.FileNameToDownload))); } if (actionResult.ContentType != null) { ctx.Response.ContentType = actionResult.ContentType; } try { ctx.Response.OutputStream.Write(actionResult.Content, 0, actionResult.Content.Length); } catch (Exception) { } }