public void Handler(WebServiceHandler h) { if (h.Context.Request.Path == "/view-source") { // the client is interesed in code // lets also pass on the signed default fields for any serviceit uses // lets start by one var c = new HttpCookie("_fields"); // fields //IdentityToken=107584385 //192.168.43.252 /// //Session //30 c["IdentityToken"] = "" + this.IdentityToken; c["foo"] = "bar"; // Set-Cookie:_fields=IdentityToken=1783346370&foo=bar; path=/ //X-AspNet-Version:4.0.30319 //X-Reference-0:ScriptCoreLib.dll.js 1345580 //X-Reference-1:IdentityTokenFromWebService.Application.exe.js 80656 h.Context.Response.AppendCookie(c); h.Context.Response.AppendCookie(new HttpCookie("xx", "yy")); } }
public void WebService_Handler_HandleNull() { var response = WebServiceHandler.Handle <SampleModel>(GetDataException); MakeSure.That(response.Status).Is(StatusCode.Error); MakeSure.That(response.Error).Is("Test"); }
public void Handler(WebServiceHandler h) { var HostUri = new { Host = h.Context.Request.Headers["Host"].TakeUntilIfAny(":"), Port = h.Context.Request.Headers["Host"].SkipUntilOrEmpty(":") }; if (HostUri.Port == "") { HostUri = new { HostUri.Host, Port = "80" } } ; Console.WriteLine( new { h.Context.Request.Path } ); // http://isorecorder.alexfeinman.com/W7.htm // http://kbarr.net/bochs // http://www.imgburn.com/index.php?act=download if (h.Context.Request.Path == "/war1.img") { h.Context.Response.Redirect("/assets/jDOSBoxAppletWithWarcraft/war1.img"); h.CompleteRequest(); return; } if (h.Context.Request.Path == "/jDOSBoxAppletWithWarcraft.jnlp") { // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201402/20140222 h.Context.Response.ContentType = "application/x-java-jnlp-file"; // X:\jsc.smokescreen.svn\core\javascript\com.abstractatech.analytics\com.abstractatech.analytics\ApplicationWebService.cs //#### Java Web Start Error: //#### Unable to load resource: file:/assets/jDOSBoxAppletWithWarcraft.Application/jDOSBoxAppletWithWarcraft.jnlp // http://en.wikipedia.org/wiki/Java_Web_Start h.Context.Response.Write(@" <jnlp spec='1.4+' codebase='http://" + HostUri.Host + ":" + HostUri.Port + @"/' href='jDOSBoxAppletWithWarcraft.jnlp' ><information><title>jDOSBoxAppletWithWarcraft</title> <vendor>Example vendor</vendor><description>Example long description</description> <description kind='short'>Example short description</description></information> <resources><j2se href='http://java.sun.com/products/autodl/j2se' version='1.4+' /> <jar href='assets/jDOSBoxAppletWithWarcraft.Application/jDOSBoxAppletWithWarcraft.ApplicationApplet.jar'/> </resources> <application-desc main-class='jDOSBoxAppletWithWarcraft.ApplicationApplet' /> <j2se version='1.4+' ava-vm-args='' /></jnlp> "); h.CompleteRequest(); return; } } }
public void CodeGenerator(WebServiceHandler h) { const string _java = "/java/"; const string _java_zip = "/java.zip/"; if (h.Context.Request.Path.StartsWith(_java_zip)) { var TypesList = h.Context.Request.Path.Substring(_java_zip.Length); DownloadJavaZip(h, TypesList); } if (h.Context.Request.Path.StartsWith(_java)) { var Type = h.Context.Request.Path.Substring(_java.Length); var p = new global::Bulldog.Server.CodeGenerators.Java.DefinitionProvider( Type, new WebClient().DownloadString ) { Server = "www.jsc-solutions.net" }; h.Context.Response.ContentType = "text/plain"; h.Context.Response.Write(p.GetString()); h.CompleteRequest(); } }
public void Proxy(WebServiceHandler h) { var r = h.Context.Request.Path; Console.WriteLine("get: " + r); if (h.IsDefaultPath) { h.Default(); return; } var p = "/proxy/"; if (r == "/images/eesti.jpg") { r = "/proxy/www.regio.ee" + r; } if (r.StartsWith(p)) { var f = "http://" + r.SkipUntilIfAny(p); Console.WriteLine("download: " + f); var bytes = new WebClient().DownloadData(f); h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length); h.CompleteRequest(); return; } }
public /* will not be part of web service itself */ void Handler(WebServiceHandler handler) { // X:\jsc.svn\core\ScriptCoreLib.Ultra.Library\ScriptCoreLib.Ultra.Library\Ultra\WebService\InternalGlobalExtensions.cs // http://support.microsoft.com/kb/186812 //Accept client certificates // http://en.wikipedia.org/wiki/HTTP_403 // 403.7 - Client certificate required. // http://xhr.spec.whatwg.org/ // http://www.derkeiler.com/Newsgroups/microsoft.public.inetserver.iis.security/2005-05/0021.html if (handler.WebMethod != null) { // http://blogs.msdn.com/b/friis/archive/2011/11/15/troubleshooting-403-7-client-certificate-required-errors-amp-step-by-step-to-make-sure-your-client-certificate-is-displayed-and-selected.aspx // https://code.google.com/p/chromium/issues/detail?id=261677 // https://groups.google.com/forum/#!topic/chromium-discuss/PPD4O121ado // http://www.tbs-certificats.com/FAQ/en/installer_certificat_client_google_chrome.html // http://stackoverflow.com/questions/11285905/access-to-client-certificates-and-replacing-certificate-selection-dialog-in-chro Console.WriteLine("before " + new { handler.WebMethod.MethodName }); // This operation requires IIS integrated pipeline mode. // HTTP status string is not valid. //handler.Context.Response.Status = "403 - Client certificate required"; //handler.Context.Response.Status = "403 - Client certificate required"; //handler.Context.Response.SubStatusCode = 7; //handler.Context.Response.StatusCode = 401; //handler.CompleteRequest(); } }
public void Handler(WebServiceHandler h) { // { TypeFullName = FindWebApplicationIcon.Application } if (ApplicationWebService.Preview == null) { ApplicationWebService.Preview = ""; var app = h.Applications.First(); var a = new { app.TypeFullName, app.TypeName, Namespace = app.TypeFullName.TakeUntilLastOrEmpty("." + app.TypeName) }; // file: assets/FindWebApplicationIcon/Preview.png size: 7806 var Preview = "assets/" + a.Namespace + "/Preview.png"; if (File.Exists(Preview)) { ApplicationWebService.Preview = Preview; ApplicationWebService.PreviewBase64String = "data:image/png;base64," + Convert.ToBase64String( File.ReadAllBytes(Preview) ); } Console.WriteLine(new { a, Preview }); } }
public void Handler(WebServiceHandler h) { if (h.Context.Request.Path == "/Other") { h.Context.Response.ContentType = "text/html"; h.Context.Response.Write(@" <html><head> <title>Application</title> <link rel='icon' href='assets/ScriptCoreLib/jsc.ico' sizes='32x32 96x96' type='image/vnd.microsoft.icon'> <link rel='icon' href='assets/ScriptCoreLib/jsc.png' sizes='96x96' type='image/png'> <meta name='apple-mobile-web-app-capable' content='yes'> <script>window['_GOOG_TRANS_EXT_VER'] = '1';</script></head> <body style='overflow: hidden;'> <link rel='stylesheet' href='assets/FlashBootstrapsSecondaryApplication/App.css'> <div id='ContentSize' style='overflow: hidden; position: absolute; left: 0px; right: 0px; bottom: 0px; top: 0px;'></div> <div id='Content' style='overflow: hidden; position: absolute; left: 0px; right: 0px; bottom: 0px; top: 0px;'><embed type='application/x-shockwave-flash' id='__embed_355364087' name='__embed_355364087' allowfullscreeninteractive='true' allowfullscreen='true' allownetworking='all' allowscriptaccess='always' width='500' height='380' src='assets/FlashBootstrapsSecondaryApplication.Application/FlashBootstrapsSecondaryApplication.ApplicationSprite.swf' style='width: 1600px; height: 439px;'></div> </body></html> "); h.CompleteRequest(); } }
public void Hander(WebServiceHandler h) { if (AtHandler == null) { AtHandler = new AtHandler(); } }
public void WebService_Handler_HandleSample() { var response = WebServiceHandler.Handle(GetData); MakeSure.That(response.Status).Is(StatusCode.Ok); MakeSure.That(response.Error).Is(null); MakeSure.That(response.Result.Age).Is(23); }
public void Serve(WebServiceHandler h) { if (h.Context.Request.Path == "/serve") { h.Context.Response.Write("hello"); h.CompleteRequest(); } }
/// <inheritdoc /> public Tut06() : base(nameof(Tut06)) { Logger.CurrentLogger.Instance.MinimumLoggingLevel = Logger.ELoggingLevel.Trace; serverWebServiceHandler = new WebServiceHandler(); webServiceServer = new WebServiceServer(serverWebServiceHandler); WebServiceHandler.CurrentServiceHandler.Instance.AssignRemoteEndpointToType(typeof(TestWebService), new IPEndPoint((from addr in Dns.GetHostEntry(Dns.GetHostName()).AddressList where addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork select addr).First(), webServiceServer.Port)); }
private static void DownloadSDKFile(WebServiceHandler h, string f) { Console.WriteLine("download: " + f); var bytes = System.IO.File.ReadAllBytes(f); h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length); h.CompleteRequest(); }
//public XElement client = new XElement(@"pre", new { Console.Title }.ToString()); public void InternalHandler(WebServiceHandler service) { client.Value = new { Console.Title }.ToString(); // TcpListenerExtensions // [AppDomain (TestEIDPIN2.exe, #1) -> AppDomain (50af7929-1-130598245127061492, #2)] // ouch. our ssl router is in the other AppDomain! //var x = ScriptCoreLib.Extensions.TcpListenerExtensions.RemoteCertificateValidationCallbackReplay; }
public /* will not be part of web service itself */ void InternalHandler(WebServiceHandler h) { //Console.WriteLine("enter InternalHandler"); var HeadersHost = h.Context.Request.Headers["Host"]; //Console.WriteLine("enter InternalHandler " + new { HeadersHost }); var HostUri = new { Host = HeadersHost.TakeUntilIfAny(":"), Port = HeadersHost.SkipUntilOrEmpty(":") }; #region path var path = h.Context.Request.Path; // cassini fix if (path == "/default.htm") { path = "/"; } #endregion //var adressbardomain = "192.168.43.252"; var adressbardomain = "192.168.1.75"; //http://192.168.1.75/ // XMLHttpRequest cannot load http://127.0.0.3:28071/xml. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.43.252:28071' is therefore not allowed access. // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/04-monese/2014/201401/20140106-dev-day/quota // cannot change the root url as we would change the visible address then if (path != "/") { // the io also has to stary on the main if (path != "/xml") { // the rest however, can be channeled via cloudflare or coralcache if (HostUri.Host == adressbardomain) { h.Context.Response.Redirect( "http://127.0.0." + (1 + counter++ % 254) + ":" + HostUri.Port + path ); h.CompleteRequest(); return; } } } Console.WriteLine("InternalHandler " + new { path }); }
public async Task <List <SLStation> > GetSLStations() { var url = CreateUrl(); var handler = new WebServiceHandler(); string json = await handler.GetResultFromAPIAsync(url); List <SLStation> slStations = new List <SLStation>(); try { var wrapper = new { LocationList = new { StopLocation = new List <SLStation>() } }; var deserializedResult = JsonConvert.DeserializeAnonymousType(json, wrapper); if (deserializedResult.LocationList.StopLocation != null) { slStations = deserializedResult.LocationList.StopLocation; } else { var wrapperSingleStation = new { LocationList = new { StopLocation = new SLStation() } }; var deserializedSingleStationResult = JsonConvert.DeserializeAnonymousType(json, wrapperSingleStation); if (deserializedSingleStationResult.LocationList.StopLocation != null) { slStations.Add(deserializedSingleStationResult.LocationList.StopLocation); } } } catch (Exception) { } var result = slStations .GroupBy(x => x.Id.ToString().Substring(x.Id.ToString().Length - 4, 4)) .Select(g => g.First()) .ToList(); return(result); }
public void WebService_Handler_HandleException() { var response = WebServiceHandler.Handle(GetDataExceptionDirect); Assert.AreEqual(StatusCode.Error, response.Status); Assert.AreEqual("TestDirect", response.Error); Assert.IsNull(response.Result); MakeSure.That(response.Status).Is(StatusCode.Error); MakeSure.That(response.Error).Is("TestDirect"); MakeSure.That(response.Result).Is(null); }
public void Publish(WebServiceHandler h) { var publish = h.Context.Request.Path.SkipUntilOrEmpty("/publish/"); var p = new Publish(); if (p.ContainsKey(publish)) { var f = p[publish]; var bytes = File.ReadAllBytes(f); h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length); h.CompleteRequest(); } }
public EventSourceGenerator(WebServiceHandler Handler) { this.Handler = Handler; Handler.Context.Response.ContentType = EventSourceGenerator.ContentType; // http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html // its a string actually! Handler.Context.Request.Headers["Last-Event-ID"].With( id => { __id = long.Parse(id); } ); }
public async Task <PartialViewResult> LocationStatus(Coordinate coordinate) { try { var viewModel = await WebServiceHandler.GetLocationGeneralStatusMessageAsync(coordinate); return(PartialView("_LocationStatus", viewModel)); } catch (Exception ex) { var viewModel = new LocationStatusVM { WarningLevel = -1, DisturbanceWarningMessage = ex.Message, Header = "*Error*", WeatherWarningMessage = "Error weather!" }; return(PartialView("_LocationStatus", viewModel)); } }
private static void DownloadJavaZip(WebServiceHandler h, string TypesList) { var Types = TypesList.Split(','); var zip = new ZIPFile(); foreach (var item in Types) { var w = new StringBuilder(); var p = new global::Bulldog.Server.CodeGenerators.Java.DefinitionProvider( item, new WebClient().DownloadString ) { Server = "www.jsc-solutions.net" }; zip.Add( item.Replace(".", "/") + ".cs", p.GetString() ); } // http://www.ietf.org/rfc/rfc2183.txt h.Context.Response.ContentType = ZIPFile.ContentType; h.Context.Response.AddHeader( "Content-Disposition", "attachment; filename=" + TypesList + ".zip" ); var bytes = zip.ToBytes(); h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length); h.CompleteRequest(); }
public void Handler(WebServiceHandler h) { if (h.Context.Request.Path == "/Other") { var Other = h.Applications[1]; h.Context.Response.ContentType = "text/html"; var xml = XElement.Parse(Other.PageSource); //xml.Element("h3").Value = h.Context.Request.UserAgent; xml.Element("h3").Value = h.Context.Request.Headers["User-Agent"]; xml.Element("h4").Value = h.Context.Request.Headers["Host"]; //h.Context.Response.Write( // "<script type='text/xml' class='" + Other.TypeName + "'></script>" // ); foreach (var r in Other.References) { xml.Add( new XElement("script", new XAttribute("src", r.AssemblyFile + ".js"), // android otherwise closes the tag? " " ) ); //h.Context.Response.Write( // "<script src='" + r.AssemblyFile + ".js'></script>" //); } h.Context.Response.Write(xml.ToString()); h.CompleteRequest(); } }
/// <summary> /// Compiles, builds and retrieves an instance of a remote WebServiceImplementation inherited from the given type belonging to the given WebServiceHandler. /// </summary> /// <param name="type">The type to inherit from.</param> /// <param name="webServiceHandler">The corresponding WebServiceHandler.</param> /// <returns>An object of the remote WebService.</returns> public static object GetWebServiceRequestImplementation(Type type, WebServiceHandler webServiceHandler) { if (type == null) { throw new NullReferenceException(nameof(type)); } if (webServiceHandler == null) { throw new NullReferenceException(nameof(webServiceHandler)); } if (type.IsAbstract || type.IsInterface || !type.IsPublic || type.IsSealed) { throw new IncompatibleTypeException("Only public non-abstract non-sealed Types of classes can be WebServices."); } var webservice = new RequesterWebServiceTemplate() { ClassName = type.Name, ClassType = type, Namespace = GetWebServiceRequestImplementationNamespace(), AssemblyNameSpace = type.Namespace }; return(CompileAndBuildObject(webservice.TransformText().Replace("global::", ""), type, GetWebServiceRequestImplementationNamespace() + "." + GetWebServiceRequestImplementationName(type), webServiceHandler)); }
public async Task <List <SLDisturbance> > GetSLDisturbances() { var result = new List <SLDisturbance>(); var url = CreateUrl(); var handler = new WebServiceHandler(); string json = await handler.GetResultFromAPIAsync(url); try { var wrapper = new { ResponseData = new List <SLDisturbance>() }; var deserializedResult = JsonConvert.DeserializeAnonymousType(json, wrapper); result = deserializedResult.ResponseData; } catch (Exception) { //POKÉMON! } return(result); }
// A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll //An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code //The thread 'BridgeStreamTo' (0xd0c) has exited with code 0 (0x0). // X:\jsc.internal.svn\compiler\jsc.meta\jsc.meta\Commands\Rewrite\RewriteToJavaScriptDocument.WebService.cs // X:\jsc.svn\core\ScriptCoreLib.Ultra.Library\ScriptCoreLib.Ultra.Library\Ultra\WebService\InternalGlobalExtensions.cs public void InternalHandler(WebServiceHandler h) { if (h.IsDefaultPath) { return; } Console.WriteLine("InternalHandler: " + h.Context.Request.Path); if (h.Context.Request.Path == "/Action7") { var c = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; var TextContent = h.Context.Request.Form["TextContent"]; Console.WriteLine(TextContent); foreach (HttpPostedFile item in h.Context.Request.Files.AllKeys.Select(k => h.Context.Request.Files[k])) { Console.WriteLine( new { item.FileName, item.ContentLength, item.ContentType } ); } Console.ForegroundColor = c; // close h.Context.Response.StatusCode = 204; h.CompleteRequest(); return; } }
public static void DownloadSDK(WebServiceHandler h) { const string _download = "/download/"; const string a = @"assets/PromotionWebApplicationAssets"; var path = h.Context.Request.Path; if (path == "/download") { h.Context.Response.Redirect(_download); h.CompleteRequest(); return; } if (path == "/download/") { path = "/download/publish.htm"; } if (path.StartsWith(_download)) { var f = a + "/" + path.Substring(_download.Length).Replace(" ", "_"); if (File.Exists(f)) { var data = File.ReadAllBytes(f); var ext = "." + f.SkipUntilLastOrEmpty(".").ToLower(); // http://en.wikipedia.org/wiki/Mime_type // http://msdn.microsoft.com/en-us/library/ms228998.aspx var ContentType = "application/octet-stream"; if (ext == ".application") { ContentType = "application/x-ms-application"; } else if (ext == ".manifest") { ContentType = "application/x-ms-manifest"; } else if (ext == ".htm") { ContentType = "text/html"; } h.Context.Response.ContentType = ContentType; Console.WriteLine("length: " + data.Length + " " + ContentType + " " + f); h.Context.Response.OutputStream.Write(data, 0, data.Length); } else { Console.WriteLine("missing " + f); h.Context.Response.StatusCode = 404; } //h.Context.Response.Redirect(r); h.CompleteRequest(); return; } }
public void DownloadSDK(WebServiceHandler h) { DownloadSDKFunction.DownloadSDK(h); }
public /* will not be part of web service itself */ void Handler(WebServiceHandler h) { // Content-Length:0 //Content-Type:text/html //Date:Sat, 29 Dec 2012 12:42:05 GMT //Server:Google Frontend // http://blog.restphone.com/2011/04/app-engine-debug-project-gets.html //Caused by: java.lang.NoSuchMethodError: ScriptCoreLibJava.BCLImplementation.System.Web.__HttpRequest.get_Headers()LScriptCoreLib/Shared/BCLImplementation/System/Collections/Specialized/__NameValueCollection; // at PromotionWebApplication1.ApplicationWebService___c__DisplayClass3._Handler_b__0(ApplicationWebService___c__DisplayClass3.java:46) // ... 37 more // } if (h.Context.Request.Path == "/jsc") { h.Diagnostics(); return; } if (h.Context.Request.Path == "/xxx") { h.Context.Response.Write("go away!"); h.CompleteRequest(); return; } try { Action foo = delegate { var Referer = h.Context.Request.GetHeader("Referer"); if (Referer == null) { Referer = "any"; } var HostUri = new { Host = h.Context.Request.GetHeader("Host").TakeUntilIfAny(":"), Port = h.Context.Request.GetHeader("Host").SkipUntilIfAny(":") }; var app = new { domain = "www.jsc-solutions.net", local = "127.0.0.1", referer = "", client = h.Applications.FirstOrDefault(k => k.TypeName == "Application") }; h.Context.Response.AddHeader("X-Trace", new { Referer, HostUri, app.domain } +""); //var app = apps.FirstOrDefault( // k => // { // //http://idea-remixer.tumblr.com/ // if (k.referer == Referer) // return true; // // GAE has a different value for referer and port // var r = ("http://" + k.referer + "/"); // if (r == Referer) // return true; // if (k.domain == HostUri.Host) // return true; // if (k.local == HostUri.Host) // return true; // if (h.Context.Request.Path == "/" + k.domain) // return true; // if (Referer.EndsWith("/" + k.domain)) // return true; // // default // if (k.local == "127.0.0.1") // return true; // return false; // } //); //#region /view-source // var IsViewSource = h.Context.Request.Path == "/view-source"; // var __explicit = "/" + app.domain + "/view-source"; // if (h.Context.Request.Path == __explicit) // IsViewSource = true; // if (IsViewSource) // { // h.Context.Response.ContentType = "text/javascript"; // // http://www.webscalingblog.com/performance/caching-http-headers-cache-control-max-age.html // // this will break if decision was based on referal. should use redirect instead? // h.Context.Response.AddHeader("Cache-Control", "max-age=2592000"); // // Accept-Encoding: gzip,deflate,sdch // foreach (var item in app.client.References) // { // h.Context.Response.WriteFile("" + item.AssemblyFile + ".js"); // } // h.CompleteRequest(); // return; // } // #endregion // if (h.IsDefaultPath) // { // h.Context.Response.ContentType = "text/html"; // var xml = XElement.Parse(app.client.PageSource); // var src = __explicit; // if (HostUri.Host == app.domain) // src = "/view-source"; // xml.Add( // new XElement("script", // new XAttribute("src", src), // // android otherwise closes the tag? // " " // ) // ); // h.Context.Response.Write(xml.ToString()); // h.CompleteRequest(); // } }; // woraround return support inside try block foo(); } catch (Exception ex) { h.Context.Response.Write("yikes! i did something stupid. " + new { ex.Message, ex.StackTrace }); h.CompleteRequest(); } }
// /WebServiceType.Method{event1, event2} public /* will not be part of web service itself */ void Handler(WebServiceHandler h) { // webrtc! // http://www.sitepoint.com/server-sent-events/ //Object '/d07dea9a_2384_49f8_8c01_270582d093dc/rwqwygw27obp9zsviyqgjhqt_27.rem' has been disconnected or does not exist at the server. // http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html var Accepts = h.Context.Request.Headers["Accept"]; if (Accepts != null) { if (Accepts.Contains("text/event-stream")) //if (h.Context.Request.AcceptTypes.Contains("text/event-stream")) //if (h.Context.Request.Path == "/events") { Console.WriteLine(new { h.Context.Request.Path }); if (h.Context.Request.Path == "/foo") { h.Context.Response.Redirect("/xoo", true); h.CompleteRequest(); return; } var xfoo = h.Context.Request.Headers["xfoo"]; var id = h.Context.Request.Headers["Last-Event-ID"]; Console.WriteLine(new { id }); h.Context.Response.ContentType = "text/event-stream"; // data: The information to be sent. //event: The type of event being dispatched. //id: An identifier for the event to be used when the client reconnects. //retry: How many milliseconds should lapse before the browser attempts to reconnect to the URL. var now = DateTime.Now; // its like a continuation of the last value we already sent. var xml = new XElement("id", new XAttribute("Ticks", now.Ticks), new XAttribute("Path", h.Context.Request.Path) ); h.Context.Response.Write("id: " + xml.ToString() + "\n\n"); Thread.Sleep(2000); h.Context.Response.Write("data: hello 1\n\n"); h.Context.Response.Flush(); Thread.Sleep(2000); // The default event type is "message". h.Context.Response.Write("event: foo\n"); h.Context.Response.Write("data: bar\n\n"); h.Context.Response.Flush(); Thread.Sleep(2000); h.Context.Response.Write("data: hello 2\n\n"); h.Context.Response.Flush(); Thread.Sleep(2000); h.CompleteRequest(); return; } } }
public void InternalHandler(WebServiceHandler h) { //typeof(Application) var app = h.Applications.Single(k => k.TypeName == "Application"); var originalsource = XElement.Parse(app.PageSource); var path = originalsource.Element("body").Attribute("data-source"); #region /view-source if (h.Context.Request.Path == "/view-source") { h.Context.Response.ContentType = "text/javascript"; foreach (var item in app.References) { h.Context.Response.Write("/* " + new { item.AssemblyFile, bytes = 1 } +" */\r\n"); } foreach (var item in app.References) { // asp.net needs absolute paths h.Context.Response.WriteFile("/" + item.AssemblyFile + ".js"); } h.CompleteRequest(); return; } #endregion #region IsDefaultPath always take the dev version. only available on dev machine and session tho.. sqlite? if (h.IsDefaultPath) { h.Context.Response.ContentType = "text/html"; var disksource = XElement.Parse(File.ReadAllText(path.Value)); var diskbody = disksource.Element("body"); // dont show this to browser. diskbody.Attribute("data-source").Remove(); var diskmodified = long.Parse("" + File.GetLastWriteTimeUtc(path.Value).Ticks); var diskmodifiedx = new DateTime(diskmodified); Console.WriteLine(new { diskmodified, diskmodifiedx }); diskbody.Add( new XAttribute("data-modified", "" + diskmodified) ); #region /view-source var src = "/view-source"; diskbody.Add( new XElement("script", new XAttribute("src", src), // android otherwise closes the tag? " " ) ); #endregion h.Context.Response.Write(diskbody.ToString()); h.CompleteRequest(); return; } #endregion #region /upload if (h.Context.Request.Path == "/upload") { //var TextContent = h.Context.Request.Form["TextContent"]; //Console.WriteLine(TextContent); var ok = new XElement("ok"); foreach (HttpPostedFile item in h.Context.Request.Files.AllKeys.Select(k => h.Context.Request.Files[k])) { //var bytes = item.InputStream.ReadToEnd(); var bytes = item.InputStream.ToBytes(); Console.WriteLine( new { item.ContentType, item.FileName, item.ContentLength, bytes.Length } ); } h.Context.Response.ContentType = "text/xml"; h.Context.Response.Write(ok); // close h.CompleteRequest(); return; } #endregion if (!h.Context.Request.Path.StartsWith("/assets")) { // jsc did rewrite the assets. lets guess here. we are bypassing the asset path fixups // as we do a live reload. h.Context.Response.Redirect("/assets/RuntimeHTMLDesignMode" + h.Context.Request.Path); h.CompleteRequest(); return; } }