public void GetTitleFromServer(StringAction result) { var r = new Random(); var Targets = new[] { "javascript", "java", "actionscript", "php" }; result("jsc solutions - C# to " + Targets[r.Next(0, Targets.Length)]); // should we add timing information if we use Thread.Sleep to the results? }
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(); } }
// FakeLogin public /* will not be part of web service itself */ void Handler(WebServiceHandler h) { if (h.Context.Request.Path == "/jsc") { h.Diagnostics(); h.CompleteRequest(); return; } var apps_Application = h.Applications.FirstOrDefault(k => k.TypeName == "Application"); var apps_FakeLogin = h.Applications.FirstOrDefault(k => k.TypeName == "FakeMultimonitorDesktop"); var apps_FakeLoginScreen = h.Applications.FirstOrDefault(k => k.TypeName == "FakeLoginScreen"); var apps = new { Application = apps_Application, FakeLogin = apps_FakeLogin, FakeLoginScreen = apps_FakeLoginScreen, }; var app = apps.FakeLogin; if (h.Context.Request.Path == "/" + apps.FakeLoginScreen.TypeName) app = apps.FakeLoginScreen; if (h.Context.Request.Path == "/" + apps.FakeLoginScreen.TypeName + "/view-source") app = apps.FakeLoginScreen; if (h.Context.Request.Path == "/" + apps.Application.TypeName) app = apps.Application; if (h.Context.Request.Path == "/" + apps.Application.TypeName + "/view-source") app = apps.Application; var __explicit = "/" + app.TypeName + "/view-source"; #region IsDefaultPath var IsExplicitDefaultPath = h.Context.Request.Path == "/" + app.TypeName; if (h.IsDefaultPath || IsExplicitDefaultPath) { { var c = h.Context.Request.Cookies["FakeLoginScreen.Delay"]; if (c != null) { Console.WriteLine("FakeLoginScreen.Delay"); c.Expires = DateTime.Now; c.Value = ""; h.Context.Response.SetCookie(c); Thread.Sleep(1000); } } { var c = h.Context.Request.Cookies["FakeLoginScreen.NoContent"]; if (c != null) { Console.WriteLine("FakeLoginScreen.NoContent"); c.Expires = DateTime.Now; c.Value = ""; h.Context.Response.SetCookie(c); // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html h.Context.Response.StatusCode = 204; h.CompleteRequest(); return; } } h.Context.Response.ContentType = "text/html"; var xml = XElement.Parse(app.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("<!-- " + new { Referer, HostUri, app.domain } + " -->\r\n"); h.Context.Response.Write(xml.ToString()); h.CompleteRequest(); return; } #endregion #region /view-source var IsViewSource = h.Context.Request.Path == "/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.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 }