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 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 Handler(WebServiceHandler e) { //#if Android // Log.wtf("ApplicationSnapshotStorage", new { e.Context.Request.Path }.ToString()); // Log.i("ApplicationSnapshotStorage", new { e.Context.Request.Path }.ToString()); // Console.WriteLine("ApplicationSnapshotStorage " + new { e.Context.Request.Path }.ToString()); // e.Context.Response.ContentType = "text/html"; // e.Context.Response.Write("Android intercept"); // e.CompleteRequest(); // return; //#endif #region /view-source+ if (e.Context.Request.Path.StartsWith(prefix)) { var AppSnapshotKey = int.Parse(e.Context.Request.Path.SkipUntilLastOrEmpty(prefix)); Console.WriteLine("snapshot_SelectBytes"); snapshot.SelectBytes(AppSnapshotKey, AppSnapshotContent => { e.Context.Response.ContentType = "text/html; charset=UTF-8"; e.Context.Response.Write(AppSnapshotContent); e.CompleteRequest(); } ); return; } #endregion }
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'> </head> <body style='overflow: hidden;'> <link rel='stylesheet' href='assets/Abstractatech.ActionScript.ConsoleFormPackage/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_1894895233' name='__embed_1894895233' allowfullscreeninteractive='true' allowfullscreen='true' allownetworking='all' allowscriptaccess='always' width='500' height='380' src='assets/Abstractatech.ActionScript.ConsoleFormPackage.Application/Abstractatech.ActionScript.ConsoleFormPackage.ApplicationSprite.swf' style='width: 784px; height: 787px;'></div> </body> "); h.CompleteRequest(); } }
public void DownloadSDK(WebServiceHandler h) { var HostUri = new { Host = h.Context.Request.Headers["Host"].TakeUntilIfAny(":"), Port = int.Parse(h.Context.Request.Headers["Host"].SkipUntilIfAny(":")) }; //#if DEBUG // if (InternalMulticast == null) // InternalMulticast = new WithClickOnceLANLauncher.ApplicationWebServiceMulticast // { // Host = HostUri.Host, // Port = HostUri.Port, // }; //#else // if (InternalMulticast == null) // InternalMulticast = new AndroidApplicationWebServiceMulticast // { // Host = HostUri.Host, // Port = HostUri.Port, // }; //#endif //DownloadSDKFunction.DownloadSDK(h); }
// 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 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 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 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 Hander(WebServiceHandler h) { if (AtHandler == null) { AtHandler = new AtHandler(); } }
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 Hander(WebServiceHandler h) { if (__crazy_workaround == null) { Console.WriteLine("__crazy_workaround"); __crazy_workaround = new __InitializeAndroidActivity(); } }
public void Serve(WebServiceHandler h) { if (h.Context.Request.Path == "/serve") { h.Context.Response.Write("hello"); h.CompleteRequest(); } }
// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151231/tdjdosboxe 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 Hander(WebServiceHandler h) { if (ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext is Activity) { if (__crazy_workaround == null) { Console.WriteLine("__crazy_workaround"); __crazy_workaround = new __InitializeAndroidActivity(); } } }
public /* will not be part of web service itself */ void Handler(WebServiceHandler h) { var Host = h.Context.Request.Headers["Host"].TakeUntilIfAny(":"); h.Context.Response.ContentType = "text/plain"; h.Context.Response.Write( new { h.Context.Request.UserHostAddress, Host } ); //h.cont //h.Context.Request.UserHostAddress h.CompleteRequest(); }
public void Handler(WebServiceHandler h) { h.Context.Request.Cookies["status"].With( status => { Console.WriteLine("status: " + status.Value); } ); h.Context.Response.SetCookie(new System.Web.HttpCookie("message", "check credentials!")); }
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 void Handler(WebServiceHandler h) { var f = h.GetFiles().FirstOrDefault(k => k.Name.SkipUntilLastOrEmpty("/") == h.Context.Request.Path.SkipUntilLastOrEmpty("/")); if (f != null) { if (h.Context.Request.Path != "/" + f.Name) { h.Context.Response.Redirect("/" + f.Name); h.CompleteRequest(); return; } } }
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 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); } ); }
// refactor this into separate partial class file public void Handler(WebServiceHandler h) { var io = "/io"; var path = h.Context.Request.Path; if (path.StartsWith(io)) { var filepath = path.SkipUntilIfAny(io); // is this still a problem? filepath = filepath.Replace("%20", " "); var file = new File(filepath); if (file.exists()) if (file.isFile()) if (path.EndsWith(".jpg")) { var bytes = System.IO.File.ReadAllBytes(filepath); h.Context.Response.ContentType = "image/jpg"; // http://www.webscalingblog.com/performance/caching-http-headers-cache-control-max-age.html h.Context.Response.AddHeader("Cache-Control", "max-age=2592000"); // send all the bytes h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length); h.CompleteRequest(); return; } h.Context.Response.ContentType = "text/html"; h.Context.Response.Write("what ya lookin for?"); h.Context.Response.Write(new XElement("pre", filepath).ToString()); h.CompleteRequest(); return; } }
public void Handler(WebServiceHandler h) { // https://developers.google.com/appengine/docs/java/mail/receiving // http://localhost:22209/_ah/admin/inboundmail // /_ah/mail/ var prefix = "/_ah/mail/"; if (h.Context.Request.Path.StartsWith(prefix)) { var to = h.Context.Request.Path.SkipUntilOrEmpty(prefix); Console.WriteLine(new { to }); //h.Context.Request.InputStream 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(); } }
public static bool IsDefaultPathOrSpecialPath(string e) { if (WebServiceHandler.InternalIsDefaultPath(e)) { return(true); } if (e == "/jsc") { return(true); } if (e == "/xml") { return(true); } return(false); }
public void InternalHandler(WebServiceHandler h) { if (h.IsDefaultPath) return; #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 }
public void DownloadSDK(WebServiceHandler h) { DownloadSDKFunction.DownloadSDK(h); }
//[MethodImplAttributes] public /* will not be part of web service itself */ void Handler(WebServiceHandler h) { Console.WriteLine("enter Handler"); //script: error JSC1000: Java : // BCL needs another method, please define it. // Cannot call type without script attribute : // System.Threading.Monitor for Void Enter(System.Object, Boolean ByRef) used at // ExperimentalCompositeFileStream.ApplicationWebService.Handler at offset 0018. // If the use of this method is intended, an implementation should be provided with the attribute [Script(Implements=typeof(...)] set. You may have mistyped it. //System.InvalidOperationException: Java : // BCL needs another method, please define it. //lock (HandlerSync) { Console.WriteLine("enter Handler lock"); //Error 2 The type arguments for method 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. X:\jsc.svn\examples\javascript\android\ExperimentalCompositeFileStream\ExperimentalCompositeFileStream\ApplicationWebService.cs 33 22 ExperimentalCompositeFileStream //enter GetBytes //{ Name = ExperimentalCompositeFileStream.Application.exe.js } //{ Name = ScriptCoreLib.dll.js } //{ Name = Application.htm } //{ Name = assets/ExperimentalCompositeFileStream/App.css } //{ Name = assets/ScriptCoreLib/jsc.ico } //{ Name = assets/ScriptCoreLib/jsc.png } //{ Name = assets/ScriptCoreLib/loading.gif } //{ Name = assets/ScriptCoreLib/Windows Ding.wav } //{ Name = ExperimentalCompositeFileStream.Application.exe.jsgz } //exit GetBytes var e = new Stopwatch(); e.Start(); var c = new XCompositeStream( h.GetFiles().Select(k => { Console.WriteLine(new { k.Name }); return new Func<Stream>( () => { Console.WriteLine(new { k.Name }); return (Stream)File.OpenRead(k.Name); } ); } ) ); var count = 0; var buffer = new byte[1024 * 40]; foreach (var y in c.GetBytes(buffer)) { //if (count % (1024 * 40) == 0) //{ // //I/System.Console(12919): Caused by: java.lang.NullPointerException // //I/System.Console(12919): at ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__NetworkStream.Flush(__NetworkStream.java:58) count += y; // I/System.Console(15969): before ReadByte { Length = 40960 } //I/System.Console(15969): after ReadByte { y = 40960 } //I/System.Console(15969): { count = 0 } //I/System.Console(15969): before ReadByte { Length = 40960 } //I/System.Console(15969): after ReadByte { y = 19844 } //I/System.Console(15969): { count = 0 } //I/System.Console(15969): before ReadByte { Length = 40960 } //I/System.Console(15969): after ReadByte { y = -1 } //I/System.Console(15969): before dispose Console.WriteLine(new { count }); //} } // 26sec h.Context.Response.Write(new { count, e.ElapsedMilliseconds }.ToString()); h.CompleteRequest(); } // { count = 1806719 } }
public /* will not be part of web service itself */ void SensorySync_Handler(WebServiceHandler h) { // X:\jsc.svn\examples\javascript\ServerSideEventExperiment\ServerSideEventExperiment\ApplicationWebService.cs var Accepts = h.Context.Request.Headers["Accept"]; if (Accepts != null) if (Accepts.Contains(EventSourceGenerator.ContentType)) { var s = new EventSourceGenerator(h); var status = s["status"]; // lets start talking to db new SensorySync().With( SensorySync => { if (s.id == 0) { // ah. first time. // lets ask the database then. var last_ms = SensorySync.Last(); if (last_ms > 0) { s.id = last_ms; // well the database gave as the last id. // for the client // ther will be no data until new events tho } else { // well the client doesnt know // and the database is empty. // tell the client to come back at a later time s.retry = 250; status("android device is quiet..."); h.CompleteRequest(); return; } } s.retry = 1000 / 60; var DoNextFrame = true; var RetryCount = 60; Action AtFrame = delegate { // wait for next frame DoNextFrame = false; Thread.Sleep(s.retry); SensorySync.Sum(s.id, reader => { // can we use dynamic xelement here instead? long last_ms = reader.ms, x = reader.x, y = reader.y, goleft = reader.goleft, goup = reader.goup, goright = reader.goright, godown = reader.godown; if (last_ms > 0) { status("Yea!"); var data = new XElement("yield", // can xattribute support long? new XAttribute("last_ms", "" + last_ms), new XAttribute("x", "" + x), new XAttribute("y", "" + y), new XAttribute("goleft", "" + goleft), new XAttribute("goup", "" + goup), new XAttribute("goright", "" + goright), new XAttribute("godown", "" + godown) ); DoNextFrame = true; s.id = last_ms; s.postMessage(data); } else { //Thread.Sleep(300); if (RetryCount > 0) { RetryCount--; DoNextFrame = true; } // try again at the next frame? } } ); }; while (DoNextFrame) { AtFrame(); } //Thread.Sleep(1000); status("android device is quiet..."); h.CompleteRequest(); } ); return; } }
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(); // cloud make it a nop for server? or jvm or android Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(h.Context.Request.HttpMethod + " " + h.Context.Request.Path); Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Green; h.Context.Request.Headers.AllKeys.WithEach( k => Console.WriteLine(k + ": " + h.Context.Request.Headers[k]) ); #region application/opensearchdescription+xml if (h.Context.Request.Path == "/opensearchdescription") { //Firefox could not download the search plugin from: //http://192.168.1.100:3148/opensearch h.Context.Response.ContentType = "application/opensearchdescription+xml"; // http://www.dailymotion.com/en/factory/opensearch //new EngineURL: template is not a valid URI! // _parseURL: failed to add 192.168.1.100:2155/?{searchTerms} as a URL // form input will need ?s= h.Context.Response.Write( @"<OpenSearchDescription xmlns='http://a9.com/-/spec/opensearch/1.1/' xmlns:moz='http://www.mozilla.org/2006/browser/search/'> <ShortName>OpenSearchExperiment</ShortName> <Description> Search OpenSearchExperiment </Description> <InputEncoding>UTF-8</InputEncoding> <Image width='16' height='16' type='image/x-icon'>/favicon.ico</Image> <Url type='text/html' method='get' template='http://" + HostUri.Host + ":" + HostUri.Port + @"/?s={searchTerms}'/> </OpenSearchDescription> " ); h.CompleteRequest(); return; } #endregion }
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 static void InternalApplication_BeginRequest(InternalGlobal g) { // is it ROSLYN friendly? no? // need to compile it by 2012? var BeginRequestStopwatch = Stopwatch.StartNew(); var that = g.InternalApplication; var Context = that.Context; var Path = Context.Request.Path; #region WriteFile var CurrentFile = g.ToCurrentFile(); if (CurrentFile != null) { // http://betterexplained.com/articles/how-to-optimize-your-site-with-http-caching/ //// http://www.mombu.com/programming/xbase/t-outputcache-directive-vs-responsecachesetcacheability-624773.html g.Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); g.Response.Cache.SetExpires(DateTime.Now.AddMinutes(15)); //g.EndRequest += // (_s, _e) => // { //Console.WriteLine("cache " + CurrentFile.Name); // // http://forums.asp.net/t/1123505.aspx // HttpApplication application = (HttpApplication)_s; // HttpContext context = application.Context; //g.Response.ExpiresAbsolute = DateTime.Now.AddDays(1); //context.Response.AddHeader("pragma", "no-cache"); //g.Response.AddHeader("cache-control", "public"); g.Response.AddHeader("Content-Length", "" + CurrentFile.Length); var ContentType = "application/octet-stream"; var n = CurrentFile.Name; // http://www.webmaster-toolkit.com/mime-types.shtml if (n.EndsWith(".gif")) { ContentType = "image/gif"; } else if (n.EndsWith(".htm")) { ContentType = "text/html"; } else if (n.EndsWith(".png")) { ContentType = "image/png"; } else if (n.EndsWith(".jpg")) { ContentType = "image/jpg"; } else if (n.EndsWith(".svg")) { ContentType = "image/svg+xml"; } else if (n.EndsWith(".js")) { ContentType = "application/x-javascript"; } else if (n.EndsWith(".mp3")) { ContentType = "audio/mpeg3"; } else if (n.EndsWith(".wav")) { ContentType = "audio/wav"; } else if (n.EndsWith(".mid")) { ContentType = "audio/midi"; } else if (n.EndsWith(".css")) { ContentType = "text/css"; } that.Response.ContentType = ContentType; // to root Context.Response.WriteFile("/" + CurrentFile.Name); that.CompleteRequest(); //context.Response.CacheControl = "no-cache"; //}; // fake lag //if (that.Request.Path.EndsWith(".js")) // System.Threading.Thread.Sleep(1000); return; } #endregion StringAction Write = e => { // could we take the method pointer implicitly? Context.Response.Write(e); }; StringAction WriteLine = e => { // could we take the method pointer implicitly? Write(e + Environment.NewLine); }; var WebMethods = g.GetWebMethods(); // X:\jsc.svn\examples\javascript\test\TestBaseFieldSync\TestBaseFieldSync\ApplicationWebService.cs #region WriteInternalFields InternalFields -> AppendCookie Action <InternalWebMethodInfo> WriteInternalFields = x => { // does 304 check also look at // fields? // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201403/20140323 // X:\jsc.svn\examples\javascript\forms\FormsDataBindingForEnabled\FormsDataBindingForEnabled\ApplicationWebService.cs if (x.InternalFields == null) { return; } // typename instead? var c = new HttpCookie("InternalFields"); // X:\jsc.svn\examples\javascript\Test\TestWebServiceTaskFields\TestWebServiceTaskFields\ApplicationWebService.cs // X:\jsc.svn\examples\javascript\test\TestNullObjectFromWebService\TestNullObjectFromWebService\ApplicationWebService.cs foreach (string InternalFieldName in x.InternalFields.Keys.ToArray()) { var value = x.InternalFields[InternalFieldName]; Console.WriteLine(new { InternalFieldName, value }); if (value != null) { // for /xml post if (Context.Request.HttpMethod == "POST") { // GetParameterValue: { key = _0600000e_field_elapsed } that.Context.Response.AddHeader( ".field " + InternalFieldName, value ); } else { // for / get c[InternalFieldName] = value; } } } // Set-Cookie:InternalFields=field_Foo=7; path=/ //that.Context.Response.AppendCookie(c); if (Context.Request.HttpMethod == "POST") { } else { that.Context.Response.SetCookie(c); } }; #endregion var IsComplete = false; #region handler = WebServiceHandler var handler = new WebServiceHandler { Context = that.Context, CompleteRequest = delegate { IsComplete = true; that.CompleteRequest(); }, Applications = g.GetScriptApplications(), // tested by // X:\jsc.svn\examples\javascript\synergy\webgl\EvilChopperByPer\EvilChopperByPer\ApplicationWebService.cs // X:\jsc.svn\examples\javascript\synergy\webgl\WebGLDoomByInt13h\WebGLDoomByInt13h\ApplicationWebService.cs GetFiles = g.GetFiles, #region Default Default = delegate { that.Response.ContentType = "text/html"; // todo: jsc: PHP workaround required var apps = g.GetScriptApplications(); var app = apps[0]; var Host = that.Context.Request.Headers["Host"].TakeUntilIfAny(":"); var CacheManifest = false; //var CacheManifest = true; // should disable that for android webview? //if (Host == that.Context.Request.UserHostAddress) // CacheManifest = false; //// webdev? //if ("127.0.0.1" == that.Context.Request.UserHostAddress) // CacheManifest = false; // X:\jsc.svn\examples\javascript\test\TestServiceWorkerAssetCache\TestServiceWorkerAssetCache\Application.cs app.WriteTo(Write, CacheManifest); IsComplete = true; that.CompleteRequest(); }, #endregion Diagnostics = delegate { that.Response.ContentType = "text/html"; WriteDiagnostics(g, Write, WebMethods); IsComplete = true; that.CompleteRequest(); }, Redirect = delegate { that.Response.Redirect("/#" + that.Request.Path); IsComplete = true; that.CompleteRequest(); } }; #endregion #region handler.WriteSource handler.WriteSource = app => { handler.Context.Response.ContentType = "text/javascript"; g.Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); // are we not part of AppCache? g.Response.Cache.SetExpires(DateTime.Now.AddMinutes(15)); //Console.WriteLine("IsConstructor WriteInternalFields"); var Constructor = new InternalWebMethodInfo { IsConstructor = true }; // Method not found: '?'. // Additional information: Attempt by method 'mscorlib.<02000005IEnumerable\+ConvertToString>.ConvertToString(System.Collections.Generic.IEnumerable`1<TestIEnumerableForService.foo>)' // to access method '<>f__AnonymousType6`1<System.__Canon>..ctor(System.__Canon)' failed. g.Invoke(Constructor); WriteInternalFields(Constructor); #region GetFiles var ff = g.GetFiles(); // jsc packages js files? not for long:P will switch to gzip at some point! var app_references = app.References.Select( // why wont Single work correctly? // are we embedding one file multiple times? item => ff.First(k => k.Name == item.AssemblyFile || k.Name == item.AssemblyFile + ".js") ).ToArray(); #endregion app_references.WithEachIndex( (app_ref, index) => { // will this work an all platforms? // need to test! g.Response.AddHeader("X-Reference-" + index, app_ref.Name + " " + app_ref.Length); } ); // tested by // X:\jsc.svn\examples\javascript\android\com.abstractatech.adminshell\com.abstractatech.adminshell\ApplicationWebService.cs #region DiagnosticsMakeItSlowAndAddSalt if (app.DiagnosticsMakeItSlowAndAddSalt) { Console.WriteLine("enter DiagnosticsMakeItSlowAndAddSalt"); handler.Context.Response.ContentType = "application/octet-stream"; #region composite var composite = new CompositeStream( app_references.Select( k => { return(new Func <Stream>( () => { Console.WriteLine("composite: " + new { k.Name }); return (Stream)File.OpenRead(k.Name); } )); } ) ); #endregion Console.WriteLine("encrypting... "); //var x = new MemoryStream(); var buffer = new byte[1024 * 40]; //var count = composite.GetBytes(buffer).Count(); #region count var count = 0; foreach (var y in composite.GetBytes(buffer)) { count += y; Console.WriteLine(new { count }); } #endregion // encrypting... { count = 58 } Console.WriteLine("encrypting by splitting bytes... " + new { count }); var time = new Stopwatch(); time.Start(); var bytesleft = count; g.Response.AddHeader("Content-Length", "" + (count * 2)); g.Response.AddHeader("X-DiagnosticsMakeItSlowAndAddSalt", "ok"); // lets write DiagnosticsMakeItSlowAndAddSalt //enter DiagnosticsMakeItSlowAndAddSalt //encrypting... //enter GetBytes //exit GetBytes //encrypting... { count = 2282136 } //enter GetBytes // ? // needs to work in .net then in android! var xbuffer = new byte[buffer.Length * 2]; foreach (var length in composite.GetBytes(buffer)) { Console.WriteLine("before flush of " + new { length }); for (int i = 0; i < length; i++) { var item = buffer[i]; var lo = (byte)(item & 0xf); var hi = (byte)((item & 0xf0) >> 4); xbuffer[i * 2 + 0] = lo; xbuffer[i * 2 + 1] = hi; //h.Context.Response.OutputStream.WriteByte(lo); //h.Context.Response.OutputStream.WriteByte(hi); bytesleft--; } handler.Context.Response.OutputStream.Write(xbuffer, 0, length * 2); handler.Context.Response.Flush(); var timetarget = 8000 - time.ElapsedMilliseconds; // Caused by: java.lang.ArithmeticException: divide by zero //at ScriptCoreLib.Ultra.WebService.InternalGlobalExtensions___c__DisplayClasse._InternalApplication_BeginRequest_b__7(InternalGlobalExtensions___c__DisplayClasse.java:235) //var ms = (int)(timetarget / bytesleft); Console.WriteLine("." + new { bytesleft //, ms }); //if (timetarget > 0) //{ // Thread.Sleep(ms); //} } Console.WriteLine("will upload done " + new { time.ElapsedMilliseconds }); return; } #endregion #region GZipAssemblyFile // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201301/20130103 var AcceptEncoding = handler.Context.Request.Headers["Accept-Encoding"]; if (!string.IsNullOrEmpty(AcceptEncoding)) { if (AcceptEncoding.Contains("gzip")) { g.Response.AddHeader("Content-Encoding", "gzip"); g.Response.WriteFile("/" + app.GZipAssemblyFile); handler.CompleteRequest(); return; } } #endregion g.Response.AddHeader("X-Comment", "gzip was disabled"); #region the old way var app_size = app_references.Sum(k => k.Length); // Accept-Encoding:gzip,deflate,sdch g.Response.AddHeader("Content-Length", "" + app_size); //g.Response.AddHeader("X-GZipAssemblyFile", "" + app.GZipAssemblyFile); foreach (var item in app_references) { // asp.net needs absolute paths handler.Context.Response.WriteFile("/" + item.Name); } #endregion handler.CompleteRequest(); }; #endregion #region WebMethodMetadataToken if (Context.Request.HttpMethod == "POST") { // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Net\WebClient.cs // who sets WebMethodMetadataToken ? // X:\jsc.svn\core\ScriptCoreLib.Ultra\ScriptCoreLib.Ultra\JavaScript\Remoting\InternalWebMethodRequest.cs // C:\Users\Arvo\AppData\Local\Temp\6796$ScriptCoreLib.Ultra.dll$v4.0.30319$NoDynamic\ScriptCoreLib.JavaScript.Remoting.InternalWebMethodRequest.cs // X:\jsc.svn\examples\javascript\css\Test\TestLongWebMethod\TestLongWebMethod\Application.cs // tested by // X:\jsc.svn\examples\javascript\Test\TestWebMethodIPAddress\TestWebMethodIPAddress\ApplicationWebService.cs // X:\jsc.internal.svn\compiler\jsc.meta\jsc.meta\Library\Templates\JavaScript\InternalWebMethodRequest.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201401/20140110-xml //var WebMethodMetadataToken = Context.Request.QueryString[InternalWebMethodInfo.QueryKey]; var WebMethodMetadataToken = Context.Request.Form["WebMethodMetadataToken"]; //var value_Form = that.InternalContext.Request.Form[key]; handler.WebMethod = InternalWebMethodInfo.First( WebMethods, WebMethodMetadataToken ); } #endregion g.Serve(handler); if (IsComplete) { return; } #region POST if (Context.Request.HttpMethod == "POST") { // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/04-monese/2014/201401/20140101 //Console.WriteLine("about to load params for " + new { handler.WebMethod }); if (handler.WebMethod == null) { // let user defined handler handle it.. } else { // is it also supposed to load the fields? handler.WebMethod.LoadParameters(that.Context); Console.WriteLine("enter invoke " + new { handler.WebMethod }); //about to load params for { WebMethod = { IsConstructor = false, MetadataToken = 06000002, Name = Insert, TypeFullName = WebCamAvatarsExperiment.ApplicationWebService, Parameters = 1 } } //about to invoke { WebMethod = { IsConstructor = false, MetadataToken = 06000002, Name = Insert, TypeFullName = WebCamAvatarsExperiment.ApplicationWebService, Parameters = 1 } } // when can we invoke the webmethod and not be at /xml? //try //{ // where is the code gen? // X:\jsc.internal.svn\compiler\jsc.meta\jsc.meta\Commands\Rewrite\RewriteToJavaScriptDocument.WebService.cs // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/04-monese/2014/201401/20140107-dev/test var WebMethodStopwatch = Stopwatch.StartNew(); // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201404/20140405/task // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201405/20140517 // defined by X:\jsc.internal.svn\compiler\jsc.meta\jsc.meta\Commands\Rewrite\RewriteToJavaScriptDocument.WebService.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201408/20140811 // public abstract void Invoke(InternalWebMethodInfo e); g.Invoke(handler.WebMethod); // BeginRequestStopwatch //that.Response.AddHeader("X-BeginRequestStopwatch", "" + BeginRequestStopwatch.ElapsedMilliseconds); // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/04-monese/2014/201401/20140110-stats that.Response.AddHeader("X-ElapsedMilliseconds", "" + WebMethodStopwatch.ElapsedMilliseconds); if (handler.WebMethod.AtElapsedMilliseconds != null) { handler.WebMethod.AtElapsedMilliseconds(WebMethodStopwatch.ElapsedMilliseconds); } //that.Response.AddHeader("X-WebMethodStopwatch", "" + SQLiteConnectionStringBuilderExtensions.ElapsedMilliseconds); //} //catch (Exception err) //{ // Console.WriteLine("boom! " + new { err }); //} //Console.WriteLine("exit invoke " + new { handler.WebMethod }); //if (that.Context.Request.Path == "/xml") if (that.Context.Request.Path != "/jsc") { // the diagnostics needs more attention down the road. WriteInternalFields(handler.WebMethod); // no yields // why is handler.WebMethod.Results null?? #region 204 if (handler.WebMethod.Results.Length == 0) { if (handler.WebMethod.TaskResult == null) { // or should we send binary zip for webworker? // NoContent g.Context.Response.StatusCode = 204; g.Context.Response.Flush(); that.CompleteRequest(); return; } } #endregion WriteXDocument(g, Write, handler.WebMethod); that.CompleteRequest(); return; } that.Response.ContentType = "text/html"; WriteDiagnosticsResults(Write, handler.WebMethod); WriteDiagnostics(g, Write, WebMethods); that.CompleteRequest(); return; } } #endregion if (IsComplete) { return; } #region /favicon.ico if (Path == "/favicon.ico") { Context.Response.WriteFile("assets/ScriptCoreLib/jsc.ico"); that.CompleteRequest(); return; } #endregion #region /robots.txt if (Path == "/robots.txt") { Context.Response.StatusCode = 404; that.CompleteRequest(); return; } #endregion #region /crossdomain.xml if (Path == "/crossdomain.xml") { // X:\jsc.svn\core\ScriptCoreLib.Ultra.Library\ScriptCoreLib.Ultra.Library\Ultra\WebService\InternalGlobalExtensions.InternalApplication_BeginRequest.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201401/20140109-webclient // http://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html // X:\jsc.smokescreen.svn\market\appengine\xmoneseAIR\xmoneseAIR\ApplicationCanvas.cs Context.Response.Write(@"<?xml version='1.0'?> <!-- http://www.osmf.org/crossdomain.xml --> <!DOCTYPE cross-domain-policy SYSTEM 'http://www.adobe.com/xml/dtds/cross-domain-policy.dtd'> <cross-domain-policy> <allow-access-from domain='*' /> <site-control permitted-cross-domain-policies='all'/> </cross-domain-policy>"); that.CompleteRequest(); return; } #endregion // cache manifest will not be needed // after ServiceWorker becomes useful // 20141230 // X:\jsc.svn\examples\javascript\test\TestServiceWorkerAssetCache\TestServiceWorkerAssetCache\Application.cs #region WriteCacheManifest if (Path == "/" + WebApplicationCacheManifest.ManifestName) { // <html manifest="cache-manifest"> //WriteCacheManifest(g, that, WriteLine); Context.Response.StatusCode = 404; that.CompleteRequest(); return; } #endregion if (that.Request.Path == "/jsc") { handler.Diagnostics(); return; } #region /view-source if (that.Request.Path == "/view-source") { var app = handler.Applications[0]; // can we just invoke a ctor? // and have the fields returne? handler.WriteSource(app); return; } #endregion if (handler.IsDefaultPath) { handler.Default(); return; } if (Context.Request.HttpMethod == "POST") { // we dont know what to do with this POST.. Context.Response.StatusCode = 404; that.CompleteRequest(); return; } // we could invoke web service handler now? handler.Redirect(); //h.Diagnostics(); }
public abstract void Serve(WebServiceHandler h);