/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // X:\jsc.svn\examples\javascript\WebGL\WebGLSVGAnonymous\WebGLSVGAnonymous\Application.cs // X:\jsc.svn\examples\javascript\WebGL\WebGLVRCreativeLeadership\WebGLVRCreativeLeadership\Application.cs // X:\jsc.svn\examples\javascript\WebGL\WebGLSVGSprite\WebGLSVGSprite\Application.cs var l = new NotificationLayout().layout; l.AttachToDocument(); new { }.With( async delegate { var retry = new IHTMLButton { "retry" }.AttachToDocument(); do { new IHTMLHorizontalRule().AttachToDocument(); Task<ISVGSVGElement> n = l; var svg = await n; svg.AttachToDocument(); IHTMLImage i = svg; i.AttachToDocument(); var c = new CanvasRenderingContext2D(svg.clientWidth, svg.clientHeight); // http://www.w3schools.com/tags/canvas_fillstyle.asp c.fillStyle = "red"; c.fillRect(0, 0, svg.clientWidth, svg.clientHeight); // rather than to overload drawimage lets do an operator which is more exotic for the api // at some point the canvas may implement the html drawing obseleting this workaround c.drawImage(i, 0, 0, svg.clientWidth, svg.clientHeight); c.canvas.AttachToDocument(); } while (await retry.async.onclick); } ); }
public UltraApplication(IHTMLElement e) { new IHTMLDiv { innerHTML = "Hello world" }.AttachToDocument(); var GetTime = new IHTMLButton { innerText = "GetTime" }.AttachToDocument(); GetTime.onclick += delegate { new AlphaWebService().GetTime("[client time]: " + DateTime.Now + " [server time]", x => { new IHTMLDiv { innerText = x }.AttachToDocument(); } ); }; var url = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.text, "http://example.com"); url.AttachToDocument(); var DownloadData = new IHTMLButton { innerText = "DownloadData" }.AttachToDocument(); DownloadData.onclick += delegate { new AlphaWebService().DownloadData(url.value, x => { new IHTMLPre { innerText = url.value + Environment.NewLine + Environment.NewLine + x }.AttachToDocument(); } ); }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { var x = new IHTMLButton { "other button" }.AttachToDocument(); //02000014 TestByRefTaskAwaiter.Application+ctor>b__2>d__8+<MoveNext>06000009 //{ Location = // assembly: S:\TestByRefTaskAwaiter.Application.exe // type: TestByRefTaskAwaiter.Application+ctor>b__2>d__8+<MoveNext>06000009, TestByRefTaskAwaiter.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null // offset: 0x000a // method:Int32 <001d> nop.try(<MoveNext>06000009, ctor>b__2>d__8 ByRef, System.Runtime.CompilerServices.TaskAwaiter`1[System.Object] ByRef, System.Runtime.CompilerServices.TaskAwaiter`1[System.Object] ByRef) } //script: error JSC1000: Method: <001d> nop.try, Type: TestByRefTaskAwaiter.Application+ctor>b__2>d__8+<MoveNext>06000009; emmiting failed : System.NotImplementedException: { ParameterType = TestByRefTaskAwaiter.Application+ctor>b__2>d__8&, p = [0x000f] brtrue.s +0 -1{[0x000a] ca // at jsc.IdentWriter.JavaScript_WriteParameters(Prestatement p, ILInstruction i, ILFlowStackItem[] s, Int32 offset, MethodBase m) in x:\jsc.internal.svn\compiler\jsc\Languages\IdentWriter.cs:line 833 // at jsc.IL2ScriptGenerator.OpCode_call_override(IdentWriter w, Prestatement p, ILInstruction i, ILFlowStackItem[] s, MethodBase m) in x:\jsc.internal.svn\compiler\jsc\Languages\JavaScript\IL2ScriptGenerator.cs:line 379 new IHTMLButton { "go" }.AttachToDocument().WhenClicked( async button => { // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/04-monese/2014/201402/201402 Func<Task> GetFBUserProperties = delegate { return "".AsResult(); }; await GetFBUserProperties(); } ); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { new IHTMLPre { new { Native.document.location.protocol, Native.document.location.host } }.AttachToDocument(); // NFC ? new IHTMLPre { new { Native.window.navigator.userAgent } }.AttachToDocument(); new { }.With( async delegate { new IHTMLButton { "ReadAll" }.AttachToDocument().onclick += async delegate { new IHTMLHorizontalRule { }.AttachToDocument(); foreach (var row in await base.ReadAll()) { new IHTMLPre { new { row.Key, row.z } }.AttachToDocument(); } }; new IHTMLButton { "TakeLastOne" }.AttachToDocument().onclick += async delegate { new IHTMLHorizontalRule { }.AttachToDocument(); var row = await base.TakeLastOne(); new IHTMLPre { new { row.Key, row.z } }.AttachToDocument(); }; new IHTMLButton { "TakeOne" }.AttachToDocument().onclick += async delegate { new IHTMLHorizontalRule { }.AttachToDocument(); var row = await base.TakeOne(); new IHTMLPre { new { row.Key, row.z } }.AttachToDocument(); }; var AddAndCount = new IHTMLButton { "AddAndCount" }.AttachToDocument(); var content = new { Native.document.location.protocol, Native.document.location.host, Native.window.navigator.userAgent }.ToString(); // show it new IHTMLPre { () => new { content } }.AttachToDocument(); while (await AddAndCount.async.onclick) { var count = await base.AddAndCount( new XElement("hello", content) ); // keep our data content = "the one after " + new { count, Native.document.location.protocol, Native.document.location.host, Native.window.navigator.userAgent }; new IHTMLPre { new { count } }.AttachToDocument(); } } ); }
// code creates class, we create element. public __Button() { InternalDisplayObject = new IHTMLElement(ElementName); var s = InternalDisplayObject.createShadowRoot(); var button = new IHTMLButton(); button.AttachTo(s); button.onclick += delegate { InternalRaiseClick(); }; this.InternalVirtualSetContent = value => { // what aboout? shadow dom ContentElement? // X:\jsc.svn\examples\javascript\Avalon\Test\TestShadowTextBox\TestShadowTextBox\ApplicationCanvas.cs button.innerText = "" + value; }; }
private static void Spawn(double Rotation) { var z = new IHTMLDiv().AttachToDocument(); var r = new IHTMLDiv().AttachTo(z); z.style.position = IStyle.PositionEnum.relative; var i = new IHTMLImage(Assets.Path + "/Preview.png").AttachTo(r); var b = new IHTMLButton().AttachTo(r); b.innerText = "hello world"; b.style.SetLocation(20, 20); z.style.SetLocation(100, 100); var costheta = Math.Cos(Rotation); var sintheta = Math.Sin(Rotation); var M11 = costheta; var M12 = -sintheta; var M21 = sintheta; var M22 = costheta; z.style.SetMatrixTransform( M11, M21, M12, M22, 0, 0 ); }
static void InitializeContnt(IDefaultPage page) { Action<dynamic> stream = x => { object time = x.time; object i = x.i; Native.document.title = new { time, i }.ToString(); Console.WriteLine(new { time, i }.ToString()); page.Content.innerText = new { time, i }.ToString(); }; dynamic window = Native.window; window.stream = stream; var stop = new IHTMLButton("Stop").AttachToDocument(); var iframe = new IHTMLIFrame { src = "/stream" }.AttachToDocument(); iframe.Hide(); page.Start.disabled = true; stop.onclick += delegate { stop.Orphanize(); page.Start.disabled = false; iframe.Orphanize(); }; Native.document.body.style.cursor = IStyle.CursorEnum.@default; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { new { }.With( async delegate { var stop = new IHTMLButton { "stop" }.AttachToDocument().async.onclick; var sw = Stopwatch.StartNew(); new IHTMLPre { () => new { stop.IsCompleted, sw.ElapsedMilliseconds } }.AttachToDocument(); while (true) { await Task.Delay(1000 / 15); if (stop.IsCompleted) { sw.Stop(); return; } } } ); }
// reference: // http://apike.ca/prog_svg_basic.html // http://apike.ca/prog_svg_shapes.html // http://www.milescript.org/graphicsdemo.html // http://canarlake.org/index.cgi?theme=svg // http://srufaculty.sru.edu/david.dailey/svg/SVGAnimations.htm // http://srufaculty.sru.edu/david.dailey/svg/svg_questions.htm // http://www.w3.org/TR/2000/CR-SVG-20001102/masking.html#ObjectAndGroupOpacityProperties // http://jmvidal.cse.sc.edu/talks/canvassvg/gradient.xml?style=White // http://www.treebuilder.de/default.asp?file=163540.xml // http://www.ibm.com/developerworks/library/x-svgint/ // http://starkravingfinkle.org/projects/richdraw/richdraw_demo.htm // http://www.dynamicdrive.com/dynamicindex11/editor.htm // http://draw.labs.autodesk.com/ADDraw/draw.html // http://yeonisalive.net/javascript/MindWeb001.php public VectorExample() { Native.Document.body.style.backgroundColor = Color.System.ThreeDFace; "h2".AttachToDocument().innerText = "svg + vml example"; #region CreateButton Func<Action, string, IHTMLButton> CreateButton = (h, text) => { var btn = new IHTMLButton(text); btn.AttachToDocument(); Action onclick = delegate { h(); btn.Dispose(); }; btn.onclick += delegate { // onclick(); try { onclick(); } catch (Exception ex) { btn.style.color = Color.Red; btn.innerText = "error: " + ex.Message; } }; return btn; }; #endregion var b1 = CreateButton(Test1, "svg hello world"); b1.disabled = !ISVGElementBase.Settings.IsSupported; var b2 = CreateButton(Test2, "svg advanced"); b2.disabled = !ISVGElementBase.Settings.IsSupported; var b3 = CreateButton(Test3, "vml (IE) hello world"); b3.disabled = !IVMLElementBase.Settings.IsSupported; CreateButton( delegate { b1.disabled = false; b2.disabled = false; b3.disabled = false; } , "Override detection"); }
// Summary: // Initializes a new instance of the System.Windows.Forms.TabPage class. public __TabPage() { this.__controlCollection = new __TabPageControlCollection((TabPage)this); this.__tabId = "tab" + __tabCount; __tabCount++; InternalElement = new IHTMLDiv(); InternalElement.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap; InternalElement.style.border = "1px solid gray"; InternalElement.style.borderTop = "none"; __tabButton = new IHTMLButton(this.__tabId); __tabButton.ApplyBorderStyle(global::System.Windows.Forms.BorderStyle.Fixed3D); __tabButton.style.textDecoration = "none"; __tabButton.style.color = "#42454a"; __tabButton.style.backgroundColor = "#dedbde"; __tabButton.style.top = "50%"; __tabButton.style.bottom = "50%"; int newh = __TabControl.__TAB_BAR_HEIGHT - 2; __tabButton.style.height = "" + newh; __tabButton.style.border = "ridge"; __tabButton.style.borderTop = "ridge"; __tabButton.style.borderRight = "ridge"; __tabButton.style.borderLeft = "ridge"; __tabButton.style.borderBottom = "none"; __tabButton.style.paddingBottom = "8px"; setFont(DefaultFont); Li = new IHTMLListItem(); Li.style.display = IStyle.DisplayEnum.inline; //Li.style.padding = "5px"; Li.style.marginRight = "0"; // "5px"; Li.style.Float = IStyle.FloatEnum.left; this.__isSelected = true; // 2013-09-30 // Error 5 The type 'System.Xml.Linq.XElement' is defined in // an assembly that is not referenced. You must add a // reference to assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. X:\jsc.svn\core\ScriptCoreLib.Windows.Forms\ScriptCoreLib.Windows.Forms\JavaScript\BCLImplementation\System\Windows\Forms\TabPage.cs 72 13 ScriptCoreLib.Windows.Forms Li.appendChild(__tabButton); Li.style.Float = IStyle.FloatEnum.left; __DeSelectTab(); InternalElement.style.backgroundColor = "white"; TextChanged += OnTextChanged; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { var button = new IHTMLButton(); button.innerText = "Click me"; button.WhenClicked(async b => { //Native.document.documentElement.style.cursor = IStyle.CursorEnum.wait; Native.document.documentElement.style.cursor = IStyle.CursorEnum.progress; await WebMethod2(); Native.document.documentElement.style.cursor = IStyle.CursorEnum.auto; }); button.AttachToDocument(); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { new IHTMLButton { "old, can be selected" }.AttachToDocument(); new IHTMLButton { }.AttachToDocument().css.before.content = "hi, can not be selected"; var x = new IHTMLButton { }.AttachToDocument(); // works in ff x.css.before.contentXAttribute = new XAttribute("data", "by attribute"); }
public __Button() { // shadow element? this.HTMLTarget = new IHTMLDiv { // name: "CSSButton" // it works, yet does not apply css name = "CSSButton" //className = "CSSButton" }; //this.HTMLTarget.setAttribute("name", "CSSButton"); //this.HTMLTarget.setAttribute("style-id", x); //this. this.HTMLTarget.style.display = DOM.IStyle.DisplayEnum.inline_block; this.InternalButton = new IHTMLButton().AttachTo(this.HTMLTarget); this.InternalButton.style.padding = "0"; this.InternalButton.style.position = DOM.IStyle.PositionEnum.absolute; this.InternalButton.style.left = "0"; this.InternalButton.style.top = "0"; // button is special like iframe?? // width: 40px; this.InternalButton.style.width = "100%"; this.InternalButton.style.height = "100%"; this.InternalButton.style.font = DefaultFont.ToCssString(); var FlatAppearance = new __FlatButtonAppearance(); FlatAppearance.InternalBorderColorChanged += delegate { var a = this.FlatAppearance; var BorderColor = a.BorderColor; this.InternalButton.style.borderBottomColor = BorderColor.ToString(); this.InternalButton.style.borderStyle = "solid"; this.InternalButton.style.borderWidth = "1px"; }; this.FlatAppearance = (FlatButtonAppearance)(object)FlatAppearance; }
private static void AddButtonForGetTime() { var GetTime = new IHTMLButton { innerText = "GetTime" }.AttachToDocument(); GetTime.onclick += delegate { new AlphaWebService().GetTime("[client time]: " + DateTime.Now + " [server time]", x => { new IHTMLDiv { innerText = x }.AttachToDocument(); } ); }; }
void CreateDisposableButton(string e, Action a) { var btn = new IHTMLButton(e); this.Control.appendChild(btn); btn.onclick += delegate { a(); Control.Orphanize(); }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { var b = new IHTMLButton { innerText = "Button"}; b.AttachToDocument(); page.datepicker.onchange += delegate { DateTime d = page.datepicker; new IHTMLPre { innerText = d.ToString() }.AttachToDocument(); }; b.onclick += delegate { DateTime d = page.datepicker; new IHTMLPre { innerText = d.ToString() }.AttachToDocument(); }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IDefaultPage page) { Action</*dynamic*/ IHTMLInput, string, Func<IHTMLScript>> apply = (btn, text, js) => { btn.disabled = true; var Content = js(); Content.AttachToHead(); var DisableScript = new IHTMLButton { innerText = "disable " + text }; DisableScript.AttachTo(page.Content); DisableScript.onclick += delegate { DisableScript.Orphanize(); Content.Orphanize(); btn.disabled = false; }; }; page.Bar.onclick += delegate { apply(page.Bar, "Boo.js", () => new WithJavaScript.JavaScript.Bar().Content); }; page.Foo.onclick += delegate { apply(page.Foo, "Foo.js", () => new WithJavaScript.JavaScript.Foo().Content); }; @"Hello world".ToDocumentTitle(); // Send data from JavaScript to the server tier service.WebMethod2( @"A string from JavaScript.", value => value.ToDocumentTitle() ); }
public UltraApplication(IHTMLElement e) { new IHTMLDiv { innerHTML = "Hello world" }.AttachToDocument(); var GetTime = new IHTMLButton { innerText = "GetTime" }.AttachToDocument(); GetTime.onclick += delegate { new AlphaWebService().GetTime("[client time]: " + DateTime.Now + " [server time]", x => { new IHTMLDiv { innerText = x }.AttachToDocument(); } ); }; }
public TipRotator(TipDocument _Data) { this.Data = _Data; if (this.Data == null) this.Data = DefaultData; var div = new IHTMLDiv(); var header = new IHTMLElement(IHTMLElement.HTMLElementEnum.h3, this.Data.Topic).AttachTo(div); var randomized = this.Data.Tips.Randomize(); var current = randomized.First(); var content = new IHTMLElement(IHTMLElement.HTMLElementEnum.p).AttachTo(div); var next = new IHTMLButton("Next Tip").AttachTo(div); var src = "assets/ClickOnce/Button_19.gif"; var img = new IHTMLImage(this.Data.Location + src).AttachTo(next); img.style.verticalAlign = "middle"; Action GoNext = delegate { current = randomized.Next(i => i == current); content.innerText = current.Content; content.style.color = current.Color; }; GoNext(); next.onclick += delegate { GoNext(); }; div.AttachTo(Native.Document.body); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { new IHTMLButton { "go" }.AttachToDocument().WhenClicked( async button => { new IHTMLPre { "enter go" }.AttachToDocument(); var c = new IHTMLButton { "continue" }.AttachToDocument(); await base.DelayedClickHandler(c.async.onclick); c.Orphanize(); new IHTMLPre { "exit go" }.AttachToDocument(); } ); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_CSS_animations IStyleSheet.all[".foo"].style.transition = "color 3000ms linear"; IStyleSheet.all[".foo"].style.color = "red"; var x = new IHTMLButton { "go" }.AttachToDocument(); // transition not creating animationstart events? x.onanimationstart += delegate { new IHTMLPre { "onanimationstart" }.AttachToDocument(); }; x.onanimationiteration += delegate { new IHTMLPre { "onanimationiteration" }.AttachToDocument(); }; x.onanimationend += delegate { new IHTMLPre { "onanimationend" }.AttachToDocument(); }; x.onclick += e => { e.Element.className = "foo"; }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { var c = "mymenu"; var css = Native.css[" ." + c]; new IHTMLPre { new { css.rule } }.AttachToDocument(); css.style.color = "blue"; new IHTMLButton { className = c, innerText = "menu1" }.AttachToDocument().With( async e => { while (await e.async.onclick) { css.style.display = IStyle.DisplayEnum.none; var back = new IHTMLButton { "go back from " + new { e.innerText } }.AttachToDocument(); await back.async.onclick; back.Orphanize(); css.style.display = IStyle.DisplayEnum.empty; } } ); new IHTMLButton { className = c, innerText = "menu2" }.AttachToDocument().With( async e => { while (await e.async.onclick) { css.style.display = IStyle.DisplayEnum.none; var back = new IHTMLButton { "go back from " + new { e.innerText } }.AttachToDocument(); await back.async.onclick; back.Orphanize(); css.style.display = IStyle.DisplayEnum.empty; } } ); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // can we do the same with onclick already? new IHTMLButton { "encrypt" }.AttachToDocument().WhenClicked( async btn => { var data = Encoding.UTF8.GetBytes("hello world"); var enc = await this.Encrypt(data); // shall we show the encrypted bytes? // what about encrypte png/gif? // what about doing this in the worker thread? new IHTMLElement(IHTMLElement.HTMLElementEnum.hr).AttachToDocument(); foreach (var item in enc.bytes) { new IHTMLCode { " 0x" + item.ToString("x2") }.AttachToDocument(); } new IHTMLElement(IHTMLElement.HTMLElementEnum.hr).AttachToDocument(); var decrypt = new IHTMLButton { "decrypt" }.AttachToDocument(); await decrypt.async.onclick; decrypt.Orphanize(); var xdata = await this.Decrypt(enc); var xstring = Encoding.UTF8.GetString(xdata); new IHTMLPre { new { xstring } }.AttachToDocument(); } ); }
void CreateDisposableButton(string e, Action a) { var btn = new IHTMLButton(e); var div = new IHTMLDiv(btn); div.style.margin = "1em"; this.Control.appendChild(div); btn.onclick += delegate { Control.Dispose(); a(); }; }
public UltraApplication(IHTMLElement e) { var note1 = new IHTMLDiv { innerHTML = "Notice: If flash does not respond to events, you need to clear your cache." }.AttachToDocument(); note1.style.color = Color.Red; var s = new UltraSprite(); s.AttachSpriteToDocument(); var SayHello = new IHTMLButton { innerText = "Say Hello to flash!" }.AttachToDocument(); SayHello.onclick += delegate { s.AppendLine("Hello from javascript"); s.WhenReady( delegate { s.AppendLine("What about using the web service?"); } ); }; s.AppendLine("This call is delayed until flash is loaded (1)"); s.AppendLine("This call is delayed until flash is loaded (2)"); s.AppendLine("This call is delayed until flash is loaded (3)"); s.WhenReady( delegate { s.AppendLine("What about using the web service?"); } ); s.AppendLine("This call is delayed until flash is loaded (4)"); ButtonsForWebService(); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { Native.body.style.backgroundColor = "yellow"; // cool we are running on ubuntu! // did we get a SSL client certificate too? // what about mysql? new { }.With( async delegate { var a = new IHTMLButton { "InvokeAdvertise" }.AttachToDocument(); while (await a.async.onclick) { await InvokeAdvertise(); } } ); new { }.With( async delegate { var a = new IHTMLButton { "InvokeAdvertise2" }.AttachToDocument(); while (await a.async.onclick) { await InvokeAdvertise2(); } } ); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { var x = new IHTMLButton { "x" }.AttachToDocument(); var y = new IHTMLButton { "y" }.AttachToDocument(); x.setAttribute("bar", "foo"); y.setAttribute("foo", "bar"); new IHTMLContent { }.AttachTo(Native.body.shadow).With( async content => { // http://www.w3.org/TR/shadow-dom/#dfn-matching-criteria content.select = "[foo=bar]"; await y.async.onclick; content.select = "[bar=foo]"; } ); }
public TextEditorDemo() { Control.AttachToDocument(); var text = new TextEditor(Control); text.InnerHTML = "<p>jsc:javascript <b>TextEditor</b></p>"; text.IsFadeEnabled = false; var cookie = new Cookie("TextData"); var save = new IHTMLButton("save to cookie"); var load = new IHTMLButton("load from cookie"); save.onclick += delegate { cookie.Value = text.InnerHTML; }; load.onclick += delegate { text.InnerHTML = cookie.Value; }; this.Control.appendChild(save, load); }
private static void ButtonsForWebService() { AddButtonForGetTime(); var url = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.text, "http://example.com"); url.AttachToDocument(); var DownloadData = new IHTMLButton { innerText = "DownloadData" }.AttachToDocument(); DownloadData.onclick += delegate { new AlphaWebService().DownloadData(url.value, x => { new IHTMLPre { innerText = url.value + Environment.NewLine + Environment.NewLine + x }.AttachToDocument(); } ); }; }
private void ContinueBuildingApplication() { var note1 = new IHTMLPre { innerHTML = @"Notice: If flash does not respond to events, you need to clear your cache. + Chrome flash in 'localhost' on Cassini always fails? - If so Try http://127.0.0.1 or http://COMPUTERNAME + Opera does not pass delegates? + IE cannot return from javascript to flash + Web page could be delivered within flash package + Javascript rewrite could omit unused types and methods " }.AttachToDocument(); note1.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.pre; note1.style.fontSize = "small"; note1.style.color = Color.Red; var s = new UltraSprite(); s.AttachSpriteToDocument(); var SayHello = new IHTMLButton { innerText = "Say Hello to flash!" }.AttachToDocument(); SayHello.onclick += delegate { s.AppendLine("Hello from javascript"); s.WhenReady( delegate { s.AppendLine("What about using the web service?"); } ); }; s.AppendLine("This call is delayed until flash is loaded (1)"); s.AppendLine("This call is delayed until flash is loaded (2)"); s.AppendLine("This call is delayed until flash is loaded (3)"); s.WhenReady( delegate { s.AppendLine("What about using the web service?"); } ); // passing the interface to flash is delayed until it is loaded, using the getter will fault s.WebService = new AlphaWebService(); s.WebServiceEnabled = this; s.AppendLine("This call is delayed until flash is loaded (4)"); new IHTMLBreak().AttachToDocument(); this.WebServiceEnabled = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.checkbox); var WebServiceEnabledLabel = new IHTMLLabel("WebService is enabled for flash", this.WebServiceEnabled); new IHTMLDiv( WebServiceEnabledLabel, WebServiceEnabled ).AttachToDocument(); ButtonsForWebService(); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IDefaultPage page) { // Initialize MySprite1 var s = new MySprite1(); s.Ready += delegate { new IHTMLDiv { innerText = "Ready!" }.AttachTo(page.Content); }; s.VideoPlayerReady += delegate { new IHTMLDiv { innerText = "VideoPlayerReady!" }.AttachTo(page.Content); }; s.Inspecting += doc => { new IHTMLPre { innerText = doc.ToString() }.AttachTo(page.Content); }; new IHTMLButton("Load from textbox").AttachTo(page.Content).With( btn => { btn.onclick += delegate { s.LoadTargetContent(page.SWFAddress.value); }; } ); new IHTMLButton("LoadOdoSketch").AttachTo(page.Content).With( btn => { btn.onclick += delegate { s.LoadTargetContent(); }; } ); new IHTMLButton("Load youtube player").AttachTo(page.Content).With(btn => { btn.onclick += delegate { s.LoadTargetContent( "http://www.youtube.com/apiplayer?version=3" ); }; }); new IHTMLButton("loadVideoById").AttachTo(page.Content).With(btn => { btn.onclick += delegate { s.loadVideoById(); }; }); new IHTMLButton("load youtube swf").AttachTo(page.Content).With(btn => { btn.onclick += delegate { s.LoadTargetContent( "http://www.youtube.com/v/eK9lNtxH8-E?version=3" ); }; }); var LoadVideo2 = new IHTMLButton("load playlist swf").AttachTo(page.Content); LoadVideo2.onclick += delegate { s.LoadTargetContent( "http://www.youtube.com/p/642A6CB03EFE7893?hl=en_GB&fs=1" ); }; var playVideo = new IHTMLButton("playVideo").AttachTo(page.Content); playVideo.onclick += delegate { s.playVideo(); }; var Inspect = new IHTMLButton("Inspect").AttachTo(page.Content); Inspect.onclick += delegate { s.Inspect(); }; var Clean = new IHTMLButton("Clean").AttachTo(page.Content); Clean.onclick += delegate { s.Clean(); }; s.AttachSpriteTo(page.Content); @"Hello world".ToDocumentTitle(); // Send data from JavaScript to the server tier service.WebMethod2( @"A string from JavaScript.", value => value.ToDocumentTitle() ); }
public Application(IApp page) { Native.body.Clear(); // X:\jsc.svn\examples\javascript\WebMessagingExample\WebMessagingExample\Application.cs Console.WriteLine( new { Native.window.parent } ); #region NewStateMachineI.MoveNext if (Native.window.parent != Native.window) { // we are an iframe? new { }.With( async delegate { var sw = Stopwatch.StartNew(); Console.WriteLine("postMessageAsync ... "); // start the handshake // we gain intellisense, but the type is partal, likely not respawned, acivated, initialized var m = await Native.window.parent.postMessageAsync <ShadowIAsyncStateMachine>(); var that = m.data; Console.WriteLine("postMessageAsync in " + new { sw.ElapsedMilliseconds, m.data.TypeName, m.data.state }); // ElapsedMilliseconds = 12, data = [object Object] }} // ElapsedMilliseconds = 13, TypeName = <Namespace>.___ctor_b__1_1_d, state = 0 }} // will we find the type based on typename? // or do we need typeindex? var types = typeof(Application).Assembly.GetTypes(); Console.WriteLine(new { sw.ElapsedMilliseconds, types = types.Length }); // X:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs var xAsyncStateMachineType = types.FirstOrDefault( item => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(item); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return(item.FullName == m.data.TypeName); } return(false); } ); // postMessageAsync in {{ ElapsedMilliseconds = 18, TypeName = <Namespace>.___ctor_b__1_1_d, state = 0 }} //{{ types = 77 }} //{{ FullName = <Namespace>.___ctor_b__1_0_d, isIAsyncStateMachine = true }} //{{ FullName = <Namespace>.___ctor_b__1_1_d, isIAsyncStateMachine = true }} //{{ FullName = <Namespace>.___cctor_b__1_d, isIAsyncStateMachine = true }} //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); Console.WriteLine("GetUninitializedObject " + new { sw.ElapsedMilliseconds, xAsyncStateMachineType }); var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType); var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine; Console.WriteLine(" " + new { sw.ElapsedMilliseconds, NewStateMachine, isIAsyncStateMachine }); // {{ ElapsedMilliseconds = 30, NewStateMachine = [object Object] }} //var NewStateMachine = Activator.CreateInstance(xAsyncStateMachineType); //var NewStateMachineI = NewStateMachine as IAsyncStateMachine; // bugcheck, as operator broken? var NewStateMachineI = (IAsyncStateMachine)NewStateMachine; Console.WriteLine(new { sw.ElapsedMilliseconds, NewStateMachineI }); Func <string, string> DecoratedString = x => x.Replace("-", "_").Replace("+", "_").Replace("<", "_").Replace(">", "_"); #region 1__state xAsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).WithEach( AsyncStateMachineSourceField => { // we need to populate the data for the debugger? //var SourceField_value = AsyncStateMachineSourceField.GetValue(NewStateMachine); // it is a new type. Console.WriteLine(new { AsyncStateMachineSourceField }); if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { AsyncStateMachineSourceField.SetValue( NewStateMachineI, that.state ); } // field names/ tokens need to be encrypted like typeinfo. // or, are we supposed to initialize a string value here? // cannot move List via onmessage that easly... //var xStringField = that.StringFields.FirstOrDefault( // f => DecoratedString(f.FieldName) == DecoratedString(AsyncStateMachineSourceField.Name) // ); //if (xStringField != null) //{ // // once we are to go back to client. we need to reverse it? // AsyncStateMachineSourceField.SetValue( // NewStateMachineI, // xStringField.value // ); // // next xml? // // before lets send our strings back with the new state! // // what about exceptions? //} } ); #endregion // run it? Console.WriteLine(new { sw.ElapsedMilliseconds } +" call MoveNext.."); NewStateMachineI.MoveNext(); Console.WriteLine(new { sw.ElapsedMilliseconds } +" call MoveNext.. done"); } ); return; } #endregion // we are a window/tab? // X:\jsc.svn\examples\javascript\chrome\NestedIFrameExperiment\NestedIFrameExperiment\Application.cs new IHTMLButton { "click to switch" }.AttachToDocument().onclick += async delegate { Native.body.style.backgroundColor = "yellow"; new IHTMLPre { "on UI thread " + new { Native.document.location.href, Native.window.Width } }.AttachToDocument(); // could we sync // iprogress? // a chrome extenstion could inject itself like it to any tab? await default(HopToIFrame); // what about reload // css effects on iframe? // no scope data was synced at this point... // perhaps we should send struct data via postmessage and reattach interface methods later? // TypeError: Cannot set property 'sw' of null //var sw = Stopwatch.StartNew(); Native.window.history.replaceState(null, "iframe2", "/iframe2"); Native.body.style.borderLeft = "1em solid blue"; new IHTMLPre { "on iframe thread " + new { Native.document.location.href, Native.window.Width } , () => new { sw.ElapsedMilliseconds } }.AttachToDocument(); var b2 = new IHTMLButton { "click to switch to nested frame 2" }.AttachToDocument(); await b2.async.onclick; b2.disabled = true; // nested fram wont show up if url is the same as parent? await default(HopToIFrame); Native.body.style.borderLeft = "1em solid red"; new IHTMLPre { "on neste iframe thread " + new { Native.document.location.href, Native.window.Width } }.AttachToDocument(); // hop to parent? }; }
public HulaGirl(IHTMLElement e) { IHTMLImage[] Frames = new HTML.Pages.FramesImages().Images; e.insertNextSibling(Control); Control.innerHTML = "hello world (javascript) : " /* base.SpawnString*/; Control.onmouseover += delegate { Style.color = Color.Blue; }; Control.onmouseout += delegate { Style.color = Color.None; }; Style.cursor = IStyle.CursorEnum.pointer; var btn = IHTMLButton.Create("go!", delegate { Control.innerHTML = "you clicked me!"; } ); var img = Frames[52]; img.AttachToDocument(); var _width = 120; var _height = 100; var _zoom = 1.0; Native.Document.body.onmousewheel += ev => { _zoom += 0.1 * ev.WheelDirection; img.style.width = (_width * _zoom) + "px"; img.style.height = (_height * _zoom) + "px"; }; var index = 0; new Timer( delegate { index++; if (index >= Frames.Length) { index = 0; } img.Orphanize(); img = Frames[index].AttachToDocument(); img.style.width = (_width * _zoom) + "px"; img.style.height = (_height * _zoom) + "px"; }, 0, 1000 / 24); //var bytes = frames.Sum(x => x.Length); //Console.WriteLine(new { bytes }); // Error 4 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. X:\jsc.svn\examples\javascript\HulaGirl\HulaGirl\Library\HulaGirl.cs 89 26 HulaGirl //var frames = await Task.WhenAll(Frames.Select(k => k.bytes)); new IHTMLButton { innerText = "gif" }.AttachToDocument().WhenClicked( async xbtn => { Action <int> y = xindex => { xbtn.innerText = new { xindex, Frames.Length }.ToString(); }; Console.WriteLine("are we loaded yet? " + new { Frames.Length }); // Error 4 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. X:\jsc.svn\examples\javascript\HulaGirl\HulaGirl\Library\HulaGirl.cs 89 26 HulaGirl //var bytes = await Task.WhenAll(frames); //var bytes = await Task.WhenAll(Frames.Select(k => k.bytes)); //byte[][] bytes = await frames; //frames = (from f in Frames select f.bytes).ToArray(); // why do we have to use static? //bytes = await Task.WhenAll(frames); // Error 5 Cannot await 'System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<byte[]>>' X:\jsc.svn\examples\javascript\HulaGirl\HulaGirl\Library\HulaGirl.cs 117 34 HulaGirl var bytes = await from f in Frames select f.bytes; //bytes.DebuggerBreakIfMissing(); //Console.WriteLine("are we loaded yet? yes " + new { bytes.Length }); //Console.WriteLine(new { bytes.Length }); var a = new { Frames.First().width, Frames.First().height }; Console.WriteLine(new { a }); var src = await new GIFEncoderWorker( a.width, a.height, delay: 1000 / 24, //transparentColor: 0x0, frames: bytes , AtFrame: y ); Console.WriteLine("done!"); new IHTMLImage { src = src }.AttachToDocument(); } ); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201308/20130826-domainmemory // see also: x:\jsc.svn\examples\javascript\Test\TestThreadStart\TestThreadStart\Application.cs var counter = 0; var btn = new IHTMLButton { innerText = "spawn new thread" }; Native.window.onframe += delegate { btn.innerText = "spawn new thread" + new { loc0 }; }; btn.AttachToDocument().WhenClicked( delegate { counter++; Console.WriteLine(new { loc0, Thread.CurrentThread.ManagedThreadId }); loc0 = "click " + new { counter }; //Thread.CurrentContext.DoCallBack( // delegate // { // // now what? // } //); //new Task().run new Worker( worker => { Console.WriteLine("should not send changes!"); loc0 = loc0; Console.WriteLine("should not send changes?"); // should a trigger see that we changed a static field? loc0 += ", working..."; Console.WriteLine(new { loc0, Thread.CurrentThread.ManagedThreadId }); var s = new Stopwatch(); s.Start(); // spin the cpu // how long do we have to, in order for task manager to notice? // this should keep one cpu utilized atleast at 70% for (int i = 0; i < 5; i++) { var xs = new Stopwatch(); xs.Start(); while (xs.ElapsedMilliseconds < 1000) { ; } Console.WriteLine("."); loc0 += " " + new { i }; } Console.WriteLine("working ... done " + new { s.Elapsed, Thread.CurrentThread.ManagedThreadId }); loc0 += " done!"; worker.postMessage("done!"); //worker.close(); } ).onmessage += e => { Console.WriteLine("onmessage: " + e.data); }; } ); }
private IHTMLDiv InitializeSuggestMovie(ExternalContext Context, List <MovieItemWithPoster> KnownMovies, IHTMLDiv Toolbar, IHTMLDiv Shadow) { #region SuggestMovie var SuggestionDialog = new IHTMLDiv().AttachTo(Context); SuggestionDialog.style.position = "absolute"; SuggestionDialog.style.left = "50%"; SuggestionDialog.style.top = "50%"; SuggestionDialog.style.marginLeft = (-400 - -40) + "px"; SuggestionDialog.style.marginTop = (-300 - -40) + "px"; SuggestionDialog.style.backgroundColor = "black"; SuggestionDialog.style.width = (800 + -40 * 2) + "px"; SuggestionDialog.style.height = (600 + -40 * 2) + "px"; SuggestionDialog.style.color = "white"; SuggestionDialog.style.display = "none"; SuggestionDialog.style.overflow = "auto"; var InputSection = new IHTMLDiv { innerHTML = "<h2>What do you like to do?</h2>" }.AttachTo(SuggestionDialog); var OuputSection = new IHTMLDiv { innerHTML = "<h2>Here what I think!</h2>" }.AttachTo(SuggestionDialog); var Reasonbox = new IHTMLDiv().AttachTo(OuputSection); OuputSection.style.display = "none"; var GroupSelectedOptionChanged = default(Action); var GroupSelectedOptions = new List <Func <MovieItem, bool> >(); var Reasoning = new List <Func <string> >(); #region AddSuggestionGroup Func <Func <string, string, Func <MovieItem, bool>, Action> > AddSuggestionGroup = () => { var Group = new IHTMLDiv { innerHTML = "<h3>Step " + (GroupSelectedOptions.Count + 1) + "</h3>" }.AttachTo(InputSection); var GroupContent = new IHTMLDiv().AttachTo(InputSection); var GroupSelectedOption = default(Func <MovieItem, bool>); var CurrentReason = ""; Reasoning.Add(() => CurrentReason); GroupSelectedOptions.Add(k => GroupSelectedOption(k)); GroupContent.style.marginLeft = "3em"; var GroupSelectedOptionButton = default(IHTMLButton); Func <string, string, Func <MovieItem, bool>, Action> GroupOption = (text, reason, filter) => { var btn = new IHTMLButton { innerHTML = text }.AttachTo(GroupContent); btn.style.display = "block"; Action a = delegate { CurrentReason = reason; if (GroupSelectedOptionButton != null) { GroupSelectedOptionButton.style.color = ""; } GroupSelectedOptionButton = btn; GroupSelectedOptionButton.style.color = "blue"; GroupSelectedOption = filter; if (GroupSelectedOptionChanged != null) { GroupSelectedOptionChanged(); } }; btn.onclick += a; return(a); }; return(GroupOption); }; #endregion AddSuggestionGroup().Apply( g => { var ForChildren = new[] { "Animation" }; var ForFamily = new[] { "Animation", "Comedy", "Family", "Fantasy" }; var ForAdults = new[] { "Adventure", "Drama", "Fantasy", "Mystery", "Thriller", "Action", "Crime" }; g( "There are some kids over here", "Kids love cartoons.", k => ForChildren.Any(x => k.IMDBGenres.ToLower().Contains(x.ToLower())) ); g( "My family is in the room, keep it decent", "You can feel comfortable watching comedy with your family.", k => ForFamily.Any(x => k.IMDBGenres.ToLower().Contains(x.ToLower())) ); g( "There are only some dudes in the room", "A beer and a thriller - just for you.", k => ForAdults.Any(x => k.IMDBGenres.ToLower().Contains(x.ToLower())) ); g( "Neither", "Cartoons and horror movies coming straight up!", k => true )(); } ); AddSuggestionGroup().Apply( g => { var Year = DateTime.Now.Year; var ForGeeks = new[] { "" + (Year), "" + (Year + 1), }; var ForRecent = new[] { "" + (Year + 1), "" + (Year), "" + (Year - 1), "" + (Year - 2), }; g( "I am looking for new stuff", "You should only be interested in new movies.", k => ForGeeks.Any(x => k.SmartTitle.ToLower().Contains(x.ToLower())) ); g( "I haven't watched that much tv recently!", "You should only be interested in recent movies.", k => ForRecent.Any(x => k.SmartTitle.ToLower().Contains(x.ToLower())) ); g( "I do not like recent movies at all!", "You like older movies!", k => ForRecent.Any(x => !k.SmartTitle.ToLower().Contains(x.ToLower())) ); g( "Neither", "It does not matter to you how old the movie is.", k => true )(); } ); AddSuggestionGroup().Apply( g => { g("I am looking for having a good time", "I guess you do not like movies without story? Me too! They are a waste of my and your time!", k => k.Raiting > 0.65 ); g( "I want to suggest someething really bad to a friend", "Why watch something great if you could watch something really bad?", k => k.Raiting < 0.7 ); g( "I cannot decide between options above", "You don't trust others raiting the movies and would like to do it yourself.", k => true )(); } ); AddSuggestionGroup().Apply( g => { g("I cannot watch tv very long", "TV shows are known to be short so thats what you get.", k => k.SmartTitle.ToLower().StartsWith("tv show:")); g("30 minutes is not enough for me", "You are going to skip the TV shows and see the movies.", k => k.SmartTitle.ToLower().StartsWith("movie:")); g("I cannot decide between options above", "You are going to watch tv shows and movies.", k => true)(); } ); new IHTMLDiv { innerHTML = "<hr />" }.AttachTo(InputSection); var NextButton = new IHTMLButton { innerHTML = "Next »" }.AttachTo(InputSection); NextButton.onclick += delegate { GroupSelectedOptionChanged(); InputSection.style.display = "none"; OuputSection.style.display = "block"; }; new IHTMLDiv { innerHTML = "<hr />" }.AttachTo(OuputSection); var BackButton = new IHTMLButton { innerHTML = "« Back" }.AttachTo(OuputSection); BackButton.onclick += delegate { OuputSection.style.display = "none"; InputSection.style.display = "block"; }; var CloseButton = new IHTMLButton { innerHTML = "Hide this dialog" }.AttachTo(OuputSection); CloseButton.onclick += delegate { SuggestionDialog.style.display = "none"; Shadow.style.display = "none"; }; this.KnownMoviesFilter = k => GroupSelectedOptions.All(x => x(k)); GroupSelectedOptionChanged += delegate { var w = new StringBuilder(); Reasoning.ForEach(i => w.AppendLine(i())); var c = KnownMovies.Count(k => this.KnownMoviesFilter(k.Movie)); if (c > 0) { if (c > 1) { w.AppendLine("There are " + c + " things I am able to suggest you."); } else { w.AppendLine("There is only one thing I was able to suggest you."); } w.AppendLine("I might be interested in " + KnownMovies.Random(k => this.KnownMoviesFilter(k.Movie)).Movie.SmartTitle); } else { w.AppendLine("Oops. There are no such things here at this time. Maybe later? Maybe change your anwsers instead?"); } Reasonbox.innerHTML = w.ToString(); foreach (var k in KnownMovies) { if (this.KnownMoviesFilter(k.Movie)) { k.Poster.style.display = ""; } else { k.Poster.style.display = "none"; } } }; GroupSelectedOptionChanged(); var SuggestMovie = new IHTMLSpan { innerHTML = "» suggest a movie" }.AttachTo(Toolbar); SuggestMovie.style.Apply( s => { s.border = "1px dotted white"; s.cursor = "pointer"; s.backgroundColor = "black"; s.color = "white"; s.marginLeft = "1em"; } ); SuggestMovie.onclick += delegate { // clear if any and return Shadow.style.display = "block"; SuggestionDialog.style.display = "block"; }; #endregion return(SuggestionDialog); }
public GuessingGame(IHTMLElement e) { // e.innerHTML = @"<h1> Try to guess a 5-figure integer </h1> "; e.appendChild(HintControl, StatusControl, NumberBar); StatusControl.style.color = Color.Blue; Control = e; ResetButton.onclick += delegate { new GuessingGame(Control); }; MyGame.Changed += delegate { HintControl.innerHTML = "<h2>You have guessed " + MyGame.GuessedValues.length + " times"; StatusControl.innerHTML = MyGame.MaskedValue; if (MyGame.Done) { NumberBar.FadeOut(); StatusControl.innerHTML += "<hr /> game over"; Control.appendChild(ResetButton); } }; MyGame.RaiseChanged(); for (int i = 0; i < 10; i++) { IHTMLButton btn = new IHTMLButton(i + ""); int ux = i; btn.onclick += delegate { MyGame.Guessed(ux); btn.FadeOut(); }; NumberBar.appendChild(btn); } Style.textAlign = IStyle.TextAlignEnum.center; Style.backgroundColor = Color.System.ButtonFace; Style.borderColor = Color.Gray; Style.borderWidth = "1px"; Style.borderStyle = "dotted"; Style.padding = "8px"; }
public MatrixTransformCExample() { var btn = new IHTMLButton("+"); { var r = new XRectangle(); r.Element.style.SetLocation(400, 50); r.Content.style.SetSize(400, 100); r.Element.style.Opacity = 0.3; } { var r = new XRectangle { Text = "center" }; r.Element.style.SetLocation(400, 50); r.Content.style.SetSize(400, 100); var angle = 22; // rotate at top left r.ApplyMatrix(0, 0, angle.DegreesToRadians(), 0, 0); btn.onclick += delegate { angle += 5; r.ApplyMatrix(0, 0, angle.DegreesToRadians(), 0, 0); }; } { var r = new XRectangle { Text = "center offset to left" }; r.Element.style.SetLocation(400, 50); r.Content.style.SetSize(400, 100); r.Content.style.backgroundColor = "blue"; var angle = 22; // rotate at top left r.ApplyMatrix(0, 0, angle.DegreesToRadians(), -400, 0); btn.onclick += delegate { angle += 5; r.ApplyMatrix(0, 0, angle.DegreesToRadians(), -400, 0); }; } { var r = new XRectangle(); r.Element.style.SetLocation(400, 200); r.Content.style.SetSize(400, 100); r.Element.style.Opacity = 0.3; } { var r = new XRectangle { Text = "left top" }; r.Element.style.SetLocation(400, 200); r.Content.style.SetSize(400, 100); var angle = 22; // rotate at center r.ApplyMatrix(-200, -50, angle.DegreesToRadians(), 0, 0); btn.onclick += delegate { angle += 5; r.ApplyMatrix(-200, -50, angle.DegreesToRadians(), 0, 0); }; } { var r = new XRectangle(); r.Element.style.SetLocation(400, 550); r.Content.style.SetSize(400, 100); r.Element.style.Opacity = 0.3; } { var r = new XRectangle { Text = "right bottom" }; r.Element.style.SetLocation(400, 550); r.Content.style.SetSize(400, 100); var angle = 22; // rotate at center r.ApplyMatrix(200, 50, angle.DegreesToRadians(), 0, 0); btn.onclick += delegate { angle += 5; r.ApplyMatrix(200, 50, angle.DegreesToRadians(), 0, 0); }; } { var r = new XRectangle { Text = "right bottom offset right" }; r.Content.style.backgroundColor = "blue"; r.Element.style.SetLocation(400, 550); r.Content.style.SetSize(400, 100); var angle = 22; // rotate at center r.ApplyMatrix(200, 50, angle.DegreesToRadians(), 400, 0); btn.onclick += delegate { angle += 5; r.ApplyMatrix(200, 50, angle.DegreesToRadians(), 400, 0); }; } btn.AttachToDocument(); btn.style.SetLocation(32, 32); }
static Application() { new IHTMLPre { new { Native.document.currentScript.src } }.AttachToDocument(); #region HopToIFrame HopToIFrame.VirtualOnCompleted = async(that, continuation) => { new IHTMLPre { "enter HopToIFrame.VirtualOnCompleted.." }.AttachToDocument(); var r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation); // X:\jsc.svn\examples\javascript\Test\TestSwitchToIFrame\TestSwitchToIFrame\Application.cs //var m = await that.frame.contentWindow.async.onmessage; var m = await that.frame.async.onmessage; //new IHTMLPre { // " VirtualOnCompleted postMessageAsync " + new { r.shadowstate.state } //}.AttachToDocument(); // um. we need to tell that iframe, where to jump to.. //var firstmessageback = that.frame.contentWindow.postMessageAsync(r.shadowstate); m.postMessage(r.shadowstate); that.frame.ownerDocument.defaultView.onmessage += e => { if (e.source != that.frame.contentWindow) { return; } var shadowstate = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)e.data; // are we jumping into a new statemachine? new IHTMLPre { "iframe is about to jump to parent " + new { shadowstate.state } }.AttachToDocument(); // about to invoke #region xAsyncStateMachineType var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault( item => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(item); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return(item.FullName == shadowstate.TypeName); } return(false); } ); #endregion var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType); var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine; var NewStateMachineI = (IAsyncStateMachine)NewStateMachine; #region 1__state xAsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).WithEach( AsyncStateMachineSourceField => { Console.WriteLine(new { AsyncStateMachineSourceField }); if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { AsyncStateMachineSourceField.SetValue( NewStateMachineI, shadowstate.state ); } } ); #endregion Console.WriteLine("invoke MoveNext"); NewStateMachineI.MoveNext(); }; }; #endregion #region HopToParent HopToParent.VirtualOnCompleted = async(that, continuation) => { // the state is in a member variable? var r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation); // should not be a zero state // or do we have statemachine name clash? new IHTMLPre { "enter HopToParent.VirtualOnCompleted.. " + new { r.shadowstate.state } }.AttachToDocument(); //Native.window.parent.postMessage(r.shadowstate); // we actually wont use the response yet.. }; #endregion // fsharpy look vctor = (IApp page) => { // {{ href = blob:https%3A//192.168.1.196%3A27831/bafa8242-82bd-44ef-8581-9f76f909cd86 }} new IHTMLPre { new { Native.document.location.href } }.AttachToDocument(); if (Native.window.parent != Native.window) { // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs // inside iframe new { }.With( async delegate { // start the handshake // we gain intellisense, but the type is partal, likely not respawned, acivated, initialized //var m = await Native.window.parent.postMessageAsync<TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine>(); // new IHTMLPre { // "inside iframe awaiting onmessage" //}.AttachToDocument(); var m = await Native.window.parent.postMessageAsync <TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine>(); var shadowstate = m.data; //var m = await Native.window.parent.async.onmessage; //var shadowstate = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)m.data; new IHTMLPre { new { shadowstate.state } }.AttachToDocument(); // about to invoke #region xAsyncStateMachineType var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault( item => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(item); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return(item.FullName == shadowstate.TypeName); } return(false); } ); #endregion var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType); var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine; var NewStateMachineI = (IAsyncStateMachine)NewStateMachine; #region 1__state xAsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).WithEach( AsyncStateMachineSourceField => { Console.WriteLine(new { AsyncStateMachineSourceField }); if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { AsyncStateMachineSourceField.SetValue( NewStateMachineI, shadowstate.state ); } } ); #endregion NewStateMachineI.MoveNext(); // we can now send one hop back? } ); return; } var codetask = new WebClient().DownloadStringTaskAsync( new Uri(Worker.ScriptApplicationSource, UriKind.Relative) ); #region click to switch // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201510/20151026 new IHTMLButton { "click to switch" }.AttachToDocument().onclick += async delegate { Native.body.style.backgroundColor = "yellow"; // can we compile shaders in frames in parallel? var code = await codetask; var aFileParts = new[] { code }; var oMyBlob = new Blob(aFileParts, new { type = "text/javascript" }); //var url = oMyBlob.ToObjectURL(); var url = URL.createObjectURL(oMyBlob); var frame = new IHTMLIFrame { new XElement("script", new XAttribute("src", url), " ") }.AttachToDocument(); // can we our code in that blank document? // not fired for blank? await frame.async.onload; ////var x = frame.ownerDocument.createElement(IHTMLElement.HTMLElementEnum.button); ////x.AttachTo(frame.ownerDocument.documentElement); Native.body.style.backgroundColor = "cyan"; await(HopToIFrame) frame; var f = new IHTMLButton { "in the frame! click to notify parent" }.AttachToDocument(); // 134ms TypeError: Cannot set property 'outerscope' of null //var outerscope = "outerscope"; f.onclick += async delegate { var innerscope = "innerscope"; // can we jump back? // can we ask how many frames are there? // can we jump in any other frame? // if we jump back to another statemachine, can we reference the outer statemachine? // can we call the server? new IHTMLPre { "inside iframe about to jump to parent " + new { //outerscope, innerscope } }.AttachToDocument(); // never completes? await default(HopToParent); // cant see it? Console.WriteLine("are we back?"); new IHTMLPre { "iframe onclick, inside parent now" }.AttachToDocument(); // can we jump back? would we know where to jump back to? //await default(HopToIFrame); }; }; #endregion }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // X:\jsc.svn\examples\javascript\async\AsyncWindowUncaughtError\AsyncWindowUncaughtError\ApplicationWebService.cs // intellitrace // a self debugging programe? // can we have buttons for debugging? // https://www.youtube.com/watch?v=4vtKRE9an_I // could we have live patching, remote debugging via udp? var Next = new IHTMLButton { "Next" }.AttachToDocument(); Next.disabled = true; Func <Task> Next_onclick = async delegate { Next.disabled = false; await Next.async.onclick; Next.disabled = true; }; trace trace = async(string filepath, int linenumber, string line) => { // could we go backwards in time too? // like intellitrace? var debugged = new IHTMLPre { }.AttachToDocument(); // should we allow chaning constants? // by patching const load opcodes? var l = new IHTMLSpan { "" + linenumber }.AttachToDocument(); l.title = filepath; l.style.marginRight = "2em"; l.style.color = "darkcyan"; l.AttachTo(debugged); // could we use css to do syntax highlight? var prefixToHide = "await trace();"; // perhaps the next step would be to send us the origina stack usage IL // we see in the jsc reflector? var c = new IHTMLSpan { line.Replace(prefixToHide, "") }; c.style.marginRight = "2em"; //c.style.color = "blue"; c.style.backgroundColor = "yellow"; c.AttachTo(debugged); await Next_onclick(); c.style.backgroundColor = ""; }; interactive <string> __string = async(string data, string filepath, int linenumber, string line) => { var i = new IHTMLInput { value = data }.AttachToDocument(); await Next_onclick(); return(i.value); }; //Func<> Func <string, Task <string> > program = // a simulaton of a program async data => { await trace(); new IHTMLPre { await __string("hello") }.AttachToDocument(); await trace(); new IHTMLPre { await __string("world") }.AttachToDocument(); await trace(); return("done!"); }; new IHTMLButton { "Step Into" }.AttachToDocument().onclick += async e => { new IHTMLHorizontalRule().AttachToDocument(); e.Element.disabled = true; var value = await program("data"); e.Element.disabled = false; new IHTMLPre { new { value } }.AttachToDocument(); }; new IHTMLButton { "Run" }.AttachToDocument().onclick += async e => { // enum to string? new IHTMLHorizontalRule().AttachToDocument(); var x = Next_onclick; // slow down the program Next_onclick = async delegate { await Task.Delay(300); }; e.Element.disabled = true; var value = await program("data"); e.Element.disabled = false; Next_onclick = x; new IHTMLPre { new { value } }.AttachToDocument(); }; }
public Application(IHTMLElement e) { Native.Document.title = "IntelliSense1"; var c = new IHTMLDiv { }.AttachToDocument(); c.onmouseover += delegate { c.style.backgroundColor = "#efefff"; }; c.onmouseout += delegate { c.style.backgroundColor = ""; }; c.style.margin = "2em"; c.style.padding = "2em"; c.style.border = "1px solid #777777"; c.style.borderLeft = "2em solid #777777"; new IHTMLDiv { new IHTMLAnchor { innerText = "Write javascript, flash and java applets within a C# project.", href = "http://www.jsc-solutions.net" } }.AttachTo(c); { var btn = new IHTMLButton { innerText = "UltraWebService" }.AttachTo(c); btn.onclick += delegate { new UltraWebService().GetTime("time: ", result => { new IHTMLDiv { innerText = result }.AttachTo(c); } ); }; } var Editor = new IHTMLDiv().AttachToDocument(); Editor.style.position = IStyle.PositionEnum.relative; Editor.style.backgroundColor = "#efefef"; Editor.style.SetSize(400, 200); //Editor.style.overflow = IStyle.OverflowEnum.auto; var CodeShadowContainer = new IHTMLDiv().AttachTo(Editor); var CodeShadowSize = new IHTMLSpan().AttachTo(CodeShadowContainer); var CodeShadow = new IHTMLSpan().AttachTo(CodeShadowContainer); var CodeShadowLine = new IHTMLSpan().AttachTo(CodeShadowContainer); var CodeShadowMenu = new IHTMLDiv().AttachTo(CodeShadowContainer); CodeShadowMenu.style.backgroundColor = "red"; var Code = new IHTMLTextArea().AttachTo(Editor); Code.style.SetLocation(0, 0, 400, 200); CodeShadowSize.style.position = IStyle.PositionEnum.absolute; CodeShadowSize.style.SetLocation(0, 0); CodeShadow.style.position = IStyle.PositionEnum.absolute; CodeShadow.style.SetLocation(0, 0); CodeShadowLine.style.position = IStyle.PositionEnum.absolute; CodeShadowLine.style.SetLocation(0, 0); CodeShadowContainer.style.SetLocation(0, 0, 400, 200); Action Update = delegate { CodeShadowSize.innerText = Code.value; var n = Code.value.Substring(0, Code.SelectionStart).Replace("\r", ""); CodeShadow.innerText = n; CodeShadowLine.innerText = n.SkipUntilLastIfAny("\n"); //var w = CodeShadowSize.offsetWidth; //if (w < 400) // w = 400; //var h = CodeShadowSize.offsetHeight; //if (h < 200) // h = 200; //Code.style.SetSize(w, h); if (n.EndsWith(".")) { CodeShadowMenu.style.SetLocation( CodeShadowLine.offsetWidth, CodeShadow.offsetHeight, 64, 32 ); } else { CodeShadowMenu.style.SetLocation( CodeShadowLine.offsetWidth, CodeShadow.offsetHeight, 12, 12 ); } }; Code.onkeyup += delegate { Update(); }; Code.onchange += delegate { Update(); }; Code.onmouseup += delegate { Update(); }; Action <IStyle> SetStyle = style => { style.padding = "0"; style.margin = "0"; style.display = IStyle.DisplayEnum.inline; style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana; style.fontSize = "1em"; // http://www.tagindex.net/css/form/line_height.html // http://www.eskimo.com/~bloo/indexdot/css/properties/dimension/lineheight.htm style.lineHeight = "200%"; // http://www.w3schools.com/CSS/pr_text_white-space.asp style.whiteSpace = IStyle.WhiteSpaceEnum.pre; //style.textWrap = }; Code.style.border = "0"; // http://www.idocs.com/tags/forms/_TEXTAREA_WRAP.html Code.wrap = "off"; Code.style.overflow = IStyle.OverflowEnum.hidden; Code.style.backgroundColor = JSColor.Transparent; //if (IsMicrosoftInternetExplorer) //{ // CodeShadow.style.lineHeight = "125%"; //} CodeShadow.style.color = "gray"; CodeShadow.style.backgroundColor = "yellow"; CodeShadowLine.style.color = "gray"; CodeShadowLine.style.backgroundColor = "cyan"; SetStyle(Code); SetStyle(CodeShadowSize); SetStyle(CodeShadow); SetStyle(CodeShadowLine); Code.value = "hello1\nhello2\nhello3 WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n..."; Update(); }
// setting the stage... refresh? async void Document_onclick(IEvent obj) { Native.body.Clear(); StartILChangeDetector(); var backgroundColor = "blue"; var color = "white"; // adding a new variable here, it wont show up as a field for us to send over. // so where is it defined? how can we introduce a new variable without a process restart? var buttonText = "new button"; await default(HopToService); //Debugger.Break(); // is t better if we do ENC on first await? var x = System.Reflection.MethodInfo.GetCurrentMethod(); // can we add a comment without current statment jumping to the end? // yes? // loc = "C:\\Users\\Arvo\\AppData\\Local\\Temp\\Temporary ASP.NET Files\\root\\3ea1022a\\80f01a9\\assembly\\dl3\\c9dda0a3\\6fdc1561_446ad001\\TestEditAndContinueWithColor.exe" var loc = x.DeclaringType.Assembly.Location; // can we add a new type now? // watch // + typeof(ManualPauseAddClass) null System.Type var xx = typeof(ApplicationWebService); // xx_TypesBeforeENC = {System.Type[7]} var xx_TypesBeforeENC = xx.Assembly.GetTypes(); var xx_ENCGetString = hex(new Func <string>(ENCGetString).Method.GetMethodBody().GetILAsByteArray()); // //Additional information: Token 3a010070 is not a valid string token in the scope of module TestEditAndContinueWithColor.exe. //var xx_ldstr = xx.Assembly.ManifestModule.ResolveString(0x7000013a); // changng a constant will add a new constant! // how would we know which method changed? // Additional information: Token 7000043a is not a valid string token in the scope of module TestEditAndContinueWithColor.exe. var xx_ldstr = xx.Assembly.ManifestModule.ResolveString(0x7000043d); // um we see new IL but cant see new text? but its there! // xx_ldstr = "hello world" // xx_ENCGetString = "72 3d 04 00 70 0a 2b 00 06 2a " // xx_ENCGetString = "72 3a 01 00 70 0a 2b 00 06 2a " // xx_ENCGetString = "72 3a 01 00 70 0a 2b 00 06 2a " // // "72 3a 01 00 70 ldstr // 0a stloc // 2b 00 br +0 // 06 ldloc // 2a ret " // now go change xx_ENCGetString Debugger.Break(); // ENC changes should be done only if a break is reached. otherwise out of sync it seems? // where is the example we did to control webgl on the server? // do we have to add a local ahead of time to debug it? #if !XENC1 xx = typeof(ManualPauseAddClass); #endif // jsc could spawn a blank app while it is loading the actual app.. // xx_TypesAfterENC = {System.Type[8]} var xx_TypesAfterENC = xx.Assembly.GetTypes(); var xx_AfterENCGetString = hex(new Func <string>(ENCGetString).Method.GetMethodBody().GetILAsByteArray()); color = "yellow"; //backgroundColor = "red"; backgroundColor = "blue"; buttonText = $"buttonText set by the server xx_ldstr: {xx_ldstr} xx_TypesBeforeENC: {xx_TypesBeforeENC.Length} xx_TypesAfterENC: {xx_TypesAfterENC.Length} before {xx_ENCGetString} after {xx_AfterENCGetString}"; await default(HopFromService); Native.document.body.style.backgroundColor = backgroundColor; Native.document.body.style.color = color; var button = new IHTMLButton { buttonText }.AttachToDocument(); // by adding code here. would non server side transver over to the live instance yet? var clickCount = 0; nextClick: var e = await button.async.onclick; clickCount++; // prevent document onclick e.stopPropagation(); var sw = Stopwatch.StartNew(); await default(HopToService); // Message "Cannot evaluate a security function." string // "C:\Users\Arvo\AppData\Local\Temp\Temporary ASP.NET Files\root\3ea1022a\80f01a9\assembly\dl3\c9dda0a3\f83b653a_406ad001\TestEditAndContinueWithColor.EXE" // + typeof(ManualPauseAddClass) null System.Type // ManualPauseAddClass error CS0119: 'ManualPauseAddClass' is a type, which is not valid in the given context //Debugger.Break(); //var x = System.Reflection.MethodInfo.GetCurrentMethod(); //var loc = x.DeclaringType.Assembly.Location; // where are we loaded? // loc = "C:\\Users\\Arvo\\AppData\\Local\\Temp\\Temporary ASP.NET Files\\root\\3ea1022a\\80f01a9\\assembly\\dl3\\c9dda0a3\\38a710a3_436ad001\\TestEditAndContinueWithColor.exe" //+x { Void MoveNext()} //System.Reflection.MethodBase { System.Reflection.RuntimeMethodInfo} //x.DeclaringType.AssemblyQualifiedName "TestEditAndContinueWithColor.Application+<Document_onclick>d__2, TestEditAndContinueWithColor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" string // C:\Users\Arvo\AppData\Local\Temp\Temporary ASP.NET Files\root\3ea1022a\80f01a9\assembly\dl3\c9dda0a3\9c8a23ef_416ad001\TestEditAndContinueWithColor.exe // is the module being replaced at the first edit? ; // remember, jsc will compile this for the client too.. // can we add a new method and see its IL? //Func<string> GetString = ManualPauseAddClass.GetString; // where is that new method defined? // next statement wont work //var value = GetString(); // hy does the hop take 1400ms? // what other information do we have available? // GetCurrentMethod buttonText = //value + @" - set by the server!" //+ @" //GetCurrentMethod: " + System.Reflection.MethodInfo.GetCurrentMethod().Name + @" //GetCurrentMethod DeclaringType:" + System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName ; await default(HopFromService); button.innerText = buttonText + " (#" + clickCount + " " + sw.ElapsedMilliseconds + "ms)"; // signify an update button.style.color = "blue"; goto nextClick; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { //new IHTMLPre { () => "loaded at " + new { DateTime.Now } }.AttachToDocument(); new IHTMLPre { "loaded at " + new { DateTime.Now } }.AttachToDocument(); Native.css[IHTMLElement.HTMLElementEnum.a].style.display = IStyle.DisplayEnum.block; new { }.With( async delegate { var foo = new IHTMLAnchor { href = "#foo", innerText = "#foo" }.AttachToDocument(); var a = new AsyncHash { hash = "#foo" }; new IHTMLButton { "go foo" }.AttachToDocument().onclick += delegate { Native.document.location.hash = a.hash; }; while (await a.onenter) { new IHTMLPre { "onenter" }.AttachToDocument(); foo.style.backgroundColor = "yellow"; await a.onexit; new IHTMLPre { "onexit" }.AttachToDocument(); foo.style.backgroundColor = ""; } } ); new { }.With( async delegate { var bar = new IHTMLAnchor { href = "#bar", innerText = "#bar" }.AttachToDocument(); var a = new AsyncHash { hash = "#bar" }; new IHTMLButton { "go bar" }.AttachToDocument().onclick += delegate { //Native.document.location.hash = a.hash; a.Go(); }; while (await a.onenter) { //new IHTMLPre { "onenter" }.AttachToDocument(); bar.style.backgroundColor = "cyan"; // using var goback = new IHTMLButton { "go back" }.AttachToDocument(); goback.onclick += delegate { //Native.document.location.hash = a.hash; //a.Go(); Native.window.history.back(); }; await a.onexit; goback.Dispose(); //new IHTMLPre { "onexit" }.AttachToDocument(); bar.style.backgroundColor = ""; } } ); new IHTMLAnchor { href = "", innerText = "go home with reload" }.AttachToDocument(); //new IHTMLAnchor { href = "/", innerText = "go home" }.AttachToDocument(); new IHTMLAnchor { href = "#", innerText = "go home" }.AttachToDocument(); Native.window.onhashchange += delegate { new IHTMLPre { new { Native.document.location.hash } }.AttachToDocument(); }; // await hash of // await cancel }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { new IHTMLButton { "check" }.AttachToDocument().onclick += async delegate { var lastupload = await base.getlastupload(); lastupload.WithEachIndex( (x, index) => { foreach (var header in x.Headers) { //Console.WriteLine(new { index, header }); new IHTMLPre { new { index, header } }.AttachToDocument(); } //Console.WriteLine(new { index, x.Content }); new IHTMLPre { new { index, x.Content } }.AttachToDocument(); } ); }; new { }.With( async delegate { // http://footle.org/2007/07/31/binary-multipart-posts-in-javascript/ // https://msdn.microsoft.com/en-us/library/ms527355(v=exchg.10).aspx var send = new IHTMLButton { "send" }.AttachToDocument(); while (await send.async.onclick) { // is it useful? //var f = new FormData(); //f.append("hello", "world"); //f.append("foo", "bar"); // http://stackoverflow.com/questions/5165337/xmlhttprequest-overridemimetype-for-outgoing-data var x = new IXMLHttpRequest(ScriptCoreLib.Shared.HTTPMethodEnum.POST, "/upload", true); var doubleDash = "--"; var boundary = "12345678901234567890"; var wRequestPayload = new StringBuilder(); wRequestPayload.Append(@"--12345678901234567890 Content-Type: text/xml; charset=UTF-8 <xml1>hello</xml1> --12345678901234567890 Content-type: text/xml e-x: 34 e-y: pp <xml1>world</xml1> --12345678901234567890--" ); var data = wRequestPayload.ToString(); x.setRequestHeader("Content-Type", "multipart/related; boundary=" + boundary); // java stream hangs if we try to read past data? //x.setRequestHeader("Content-Length", "" + data.Length); x.send(data); } //x.overrideMimeType() } ); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IDefault page) { @"Hello world".ToDocumentTitle(); var output = new IHTMLTextArea().AttachToDocument(); var gexf = new XElement("gexf"); gexf.Add( new XElement("meta", new XElement("creator", "jsc"), new XElement("description", "NASDAQSNA") ) ); var graph = new XElement("graph", new XAttribute("mode", "static"), new XAttribute("defaultedgetype", "directed") ); gexf.Add(graph); var nodes = new XElement("nodes"); graph.Add(nodes); var edges = new XElement("edges"); graph.Add(edges); output.value = gexf.ToString(); output.onfocus += delegate { output.value = gexf.ToString(); }; output.onmouseover += delegate { output.value = gexf.ToString(); }; var NumericNodeIdLookup = new List <string>(); Func <string, int> GetNumericNodeId = k => { if (!NumericNodeIdLookup.Contains(k)) { NumericNodeIdLookup.Add(k); } return(NumericNodeIdLookup.IndexOf(k)); }; #region AddRelatedCompanies Func <IHTMLDiv, string, Action, Task> AddRelatedCompanies = null; AddRelatedCompanies = (c, qid, done) => { var nqid = GetNumericNodeId(qid).ToString(); var cc = new IHTMLDiv(); cc.style.marginLeft = "2em"; var service = new ApplicationWebService { qid = qid, yield = (id, CompanyName, Price) => { var nid = GetNumericNodeId(id).ToString(); if (nodes.Elements().Any(k => k.Attribute("id").Name.LocalName == nid)) { } else { nodes.Add( new XElement("node", new XAttribute("id", nid), new XAttribute("label", CompanyName) ) ); } var btn = new IHTMLButton { innerText = id + " " + CompanyName + " " + Price }; btn.style.display = IStyle.DisplayEnum.block; if (qid == id) { btn.disabled = true; if (c == null) { btn.AttachToDocument(); cc.AttachToDocument(); } else { //btn.AttachTo(c); cc.AttachTo(c); } if (done != null) { done(); } } else { edges.Add( new XElement("edge", new XAttribute("source", nqid), new XAttribute("target", nid) ) ); btn.AttachTo(cc); var ccc = new IHTMLDiv(); ccc.AttachTo(cc); int cx = 0; ccc.ToggleVisible(); btn.WhenClicked( async delegate { if (cx == 0) { btn.style.color = JSColor.Red; await AddRelatedCompanies(ccc, id, delegate { btn.style.color = JSColor.Blue; } ); } cx++; ccc.ToggleVisible(); } ); } } }; return(service.GetRelatedCompanies()); }; #endregion AddRelatedCompanies(null, "NASDAQ:FB", null); AddRelatedCompanies(null, "NASDAQ:GOOG", null); }
//public const string Alias = "Class1"; //public const string DefaultData = "Class1Data"; /// <summary> /// Creates a new control /// </summary> /// <param name="DataElement">The hidden data element</param> public SimpleRollover() { // wallpapers at http://labnol.blogspot.com/2006/11/download-windows-vista-wallpapers.html // * broken at the moment #region AnimateCharacterColors System.Func<string, INode> AnimateCharacterColors = (text) => { var s = new IHTMLSpan(); var l = new global::System.Collections.Generic.List<IHTMLSpan>(); foreach (char c in text) { var y = new string(c, 1); var x = new IHTMLSpan(y); if (y == " ") { s.appendChild(" "); } else { l.Add(x); s.appendChild(x); } } new Timer( t => { var len = l.Count + 40; if (t.Counter % len < l.Count) { if (t.Counter % (len * 2) < l.Count) { l[t.Counter % len].style.visibility = IStyle.VisibilityEnum.hidden; } else { l[t.Counter % len].style.visibility = IStyle.VisibilityEnum.visible; } } }, 6000, 200); return s; }; #endregion // */ var u = new IHTMLDiv(); //u.style.backgroundColor = Color.Green; u.style.position = IStyle.PositionEnum.absolute; u.style.left = "0"; u.style.top = "0"; u.style.height = "100%"; u.style.width = "100%"; u.style.overflow = IStyle.OverflowEnum.auto; var styles = new XStyles { dark = new IStyleSheet(), light = new IStyleSheet(), switchbutton = new IHTMLAnchor("", "day/night"), counter = 0 }; styles.switchbutton.onclick += ev => { ev.PreventDefault(); styles.counter++; if (styles.counter % 2 == 1) { styles.dark.disabled = false; styles.light.disabled = true; } else { styles.dark.disabled = true; styles.light.disabled = false; } }; var ad = new IHTMLDiv( new IHTMLSpan( AnimateCharacterColors( "this application was written in c# and then translated to javascript by jsc to run in your browser" ) ), new IHTMLAnchor("http://zproxy.wordpress.com", "visit blog"), new IHTMLAnchor("http://jsc.sf.net", "get more examples"), styles.switchbutton ) { className = "ad1" }; u.appendChild(ad); var sheet = new IStyleSheet(); sheet.AddRule(".ad1", r => { r.style.marginTop = "1em"; r.style.color = Color.White; r.style.fontFamily = IStyle.FontFamilyEnum.Verdana; } ); sheet.AddRule(".ad1 > *", r => { r.style.padding = "1em"; r.style.marginTop = "1em"; } ); sheet.AddRule(".ad1 > span", r => { r.style.Float = IStyle.FloatEnum.right; } ); sheet.AddRule(".ad1 > a", r => { r.style.Float = IStyle.FloatEnum.left; r.style.color = Color.White; r.style.textDecoration = "none"; } ); sheet.AddRule(".ad1 a:hover", r => { r.style.color = Color.Yellow; } ); sheet.AddRule("html", r => { r.style.overflow = IStyle.OverflowEnum.hidden; } ); sheet.AddRule("body", r => { r.style.overflow = IStyle.OverflowEnum.hidden; r.style.padding = "0"; r.style.margin = "0"; //r.style.backgroundImage = "url(assets/vista.jpg)"; } ); styles.dark.AddRule("body").style.backgroundColor = JSColor.Black; styles.dark.AddRule("body").style.backgroundPosition = "center top"; styles.light.AddRule("body").style.backgroundColor = JSColor.Black; styles.light.AddRule("body").style.backgroundPosition = "center top"; new global::SimpleRollover.HTML.Images.FromAssets.vistax().ToBackground( styles.dark.AddRule("body").style, false ); new global::SimpleRollover.HTML.Images.FromAssets.vista().ToBackground( styles.dark.AddRule(".effect1").style ); styles.dark.AddRule(".moon1").style.backgroundColor = Color.Yellow; new global::SimpleRollover.HTML.Images.FromAssets.vista().ToBackground( styles.light.AddRule("body").style, false ); new global::SimpleRollover.HTML.Images.FromAssets.vistax().ToBackground( styles.light.AddRule(".effect1").style ); styles.light.AddRule(".moon1").style.backgroundColor = Color.Red; sheet.AddRule(".special1", r => { r.style.background = "none"; r.style.border = "0"; r.style.width = "100%"; r.style.marginTop = "4em"; } ); sheet.AddRule(".content1", r => { r.style.backgroundColor = Color.White; r.style.padding = "1em"; r.style.marginLeft = "4em"; r.style.marginRight = "4em"; r.style.Opacity = 0.5; r.style.border = "1px solid gray"; } ); sheet.AddRule(".special1 img", "border: 0", 0); sheet.AddRule(".special1:hover", "background: url(" + new global::SimpleRollover.HTML.Images.FromAssets.Untitled_3().src + ") repeat-x", 1); sheet.AddRule(".special1 .hot").style.display = IStyle.DisplayEnum.none; sheet.AddRule(".special1:hover .hot").style.display = IStyle.DisplayEnum.inline; sheet.AddRule(".special1 .cold", "display: inline;", 1); sheet.AddRule(".special1:hover .cold", "display: none;", 1); var states = new XState[] { }.AsEnumerable(); // new XState { // Show = default(System.Action), // Hide = default(System.Action), // Selected = false } //}.Where(p => false); Action<IHTMLImage, IHTMLImage, string> Spawn = async (icold, ihot, i2) => { var cold = await icold; var hot = await ihot; //((IHTMLImage)i[0]).InvokeOnComplete(cold => //((IHTMLImage)i[1]).InvokeOnComplete(hot => // { cold.className = "cold"; hot.className = "hot"; var btn = new IHTMLButton() { className = "special1" }; btn.appendChild(cold, hot); var content = new IHTMLElement(IHTMLElement.HTMLElementEnum.pre); content.innerHTML = "..."; content.className = "content1"; var tween = new TweenDataDouble(); var tween_max = 16; tween.ValueChanged += delegate { content.style.Opacity = tween.Value / tween_max; content.style.height = tween.Value + "em"; content.style.overflow = IStyle.OverflowEnum.hidden; }; tween.Done += delegate { if (tween.Value > 0) content.style.overflow = IStyle.OverflowEnum.auto; }; tween.Value = 0; var state = new XState { Show = (System.Action)(() => { tween.Value = tween_max; } ), Hide = (System.Action)(() => tween.Value = 0), Selected = false }; //try //{ // new IXMLHttpRequest(HTTPMethodEnum.GET, i[2], // request => content.innerHTML = request.responseText // ); //} //catch //{ content.innerText = i2; //} states = states.Concat(new[] { state }); btn.onclick += delegate { foreach (var v in states) { if (v == state) { v.Selected = !v.Selected; if (v.Selected) { v.Show(); } else { v.Hide(); } } else { v.Selected = false; v.Hide(); } } }; u.appendChild(btn, content); }; SpawnCursor(); u.AttachToDocument(); Spawn( new global::SimpleRollover.HTML.Images.FromAssets.Untitled_1_03(), new global::SimpleRollover.HTML.Images.FromAssets.Untitled_2_03(), "This application was written in C#." ); Spawn( new global::SimpleRollover.HTML.Images.FromAssets.Untitled_1_07(), new global::SimpleRollover.HTML.Images.FromAssets.Untitled_2_07(), "This application was cross compiled into JavaScript." ); }
//public const string Alias = "Class1"; //public const string DefaultData = "Class1Data"; /// <summary> /// Creates a new control /// </summary> /// <param name="DataElement">The hidden data element</param> public SimpleRollover() { // wallpapers at http://labnol.blogspot.com/2006/11/download-windows-vista-wallpapers.html // * broken at the moment #region AnimateCharacterColors System.Func <string, INode> AnimateCharacterColors = (text) => { var s = new IHTMLSpan(); var l = new global::System.Collections.Generic.List <IHTMLSpan>(); foreach (char c in text) { var y = new string(c, 1); var x = new IHTMLSpan(y); if (y == " ") { s.appendChild(" "); } else { l.Add(x); s.appendChild(x); } } new Timer( t => { var len = l.Count + 40; if (t.Counter % len < l.Count) { if (t.Counter % (len * 2) < l.Count) { l[t.Counter % len].style.visibility = IStyle.VisibilityEnum.hidden; } else { l[t.Counter % len].style.visibility = IStyle.VisibilityEnum.visible; } } }, 6000, 200); return(s); }; #endregion // */ var u = new IHTMLDiv(); //u.style.backgroundColor = Color.Green; u.style.position = IStyle.PositionEnum.absolute; u.style.left = "0"; u.style.top = "0"; u.style.height = "100%"; u.style.width = "100%"; u.style.overflow = IStyle.OverflowEnum.auto; var styles = new XStyles { dark = new IStyleSheet(), light = new IStyleSheet(), switchbutton = new IHTMLAnchor("", "day/night"), counter = 0 }; styles.switchbutton.onclick += ev => { ev.PreventDefault(); styles.counter++; if (styles.counter % 2 == 1) { styles.dark.disabled = false; styles.light.disabled = true; } else { styles.dark.disabled = true; styles.light.disabled = false; } }; var ad = new IHTMLDiv( new IHTMLSpan( AnimateCharacterColors( "this application was written in c# and then translated to javascript by jsc to run in your browser" ) ), new IHTMLAnchor("http://zproxy.wordpress.com", "visit blog"), new IHTMLAnchor("http://jsc.sf.net", "get more examples"), styles.switchbutton ) { className = "ad1" }; u.appendChild(ad); var sheet = new IStyleSheet(); sheet.AddRule(".ad1", r => { r.style.marginTop = "1em"; r.style.color = Color.White; r.style.fontFamily = IStyle.FontFamilyEnum.Verdana; } ); sheet.AddRule(".ad1 > *", r => { r.style.padding = "1em"; r.style.marginTop = "1em"; } ); sheet.AddRule(".ad1 > span", r => { r.style.Float = IStyle.FloatEnum.right; } ); sheet.AddRule(".ad1 > a", r => { r.style.Float = IStyle.FloatEnum.left; r.style.color = Color.White; r.style.textDecoration = "none"; } ); sheet.AddRule(".ad1 a:hover", r => { r.style.color = Color.Yellow; } ); sheet.AddRule("html", r => { r.style.overflow = IStyle.OverflowEnum.hidden; } ); sheet.AddRule("body", r => { r.style.overflow = IStyle.OverflowEnum.hidden; r.style.padding = "0"; r.style.margin = "0"; //r.style.backgroundImage = "url(assets/vista.jpg)"; } ); styles.dark.AddRule("body").style.backgroundColor = JSColor.Black; styles.dark.AddRule("body").style.backgroundPosition = "center top"; styles.light.AddRule("body").style.backgroundColor = JSColor.Black; styles.light.AddRule("body").style.backgroundPosition = "center top"; new global::SimpleRollover.HTML.Images.FromAssets.vistax().ToBackground( styles.dark.AddRule("body").style, false ); new global::SimpleRollover.HTML.Images.FromAssets.vista().ToBackground( styles.dark.AddRule(".effect1").style ); styles.dark.AddRule(".moon1").style.backgroundColor = Color.Yellow; new global::SimpleRollover.HTML.Images.FromAssets.vista().ToBackground( styles.light.AddRule("body").style, false ); new global::SimpleRollover.HTML.Images.FromAssets.vistax().ToBackground( styles.light.AddRule(".effect1").style ); styles.light.AddRule(".moon1").style.backgroundColor = Color.Red; sheet.AddRule(".special1", r => { r.style.background = "none"; r.style.border = "0"; r.style.width = "100%"; r.style.marginTop = "4em"; } ); sheet.AddRule(".content1", r => { r.style.backgroundColor = Color.White; r.style.padding = "1em"; r.style.marginLeft = "4em"; r.style.marginRight = "4em"; r.style.Opacity = 0.5; r.style.border = "1px solid gray"; } ); sheet.AddRule(".special1 img", "border: 0", 0); sheet.AddRule(".special1:hover", "background: url(" + new global::SimpleRollover.HTML.Images.FromAssets.Untitled_3().src + ") repeat-x", 1); sheet.AddRule(".special1 .hot").style.display = IStyle.DisplayEnum.none; sheet.AddRule(".special1:hover .hot").style.display = IStyle.DisplayEnum.inline; sheet.AddRule(".special1 .cold", "display: inline;", 1); sheet.AddRule(".special1:hover .cold", "display: none;", 1); var states = new XState[] { }.AsEnumerable(); // new XState { // Show = default(System.Action), // Hide = default(System.Action), // Selected = false } //}.Where(p => false); Action <IHTMLImage, IHTMLImage, string> Spawn = async(icold, ihot, i2) => { var cold = await icold; var hot = await ihot; //((IHTMLImage)i[0]).InvokeOnComplete(cold => //((IHTMLImage)i[1]).InvokeOnComplete(hot => // { cold.className = "cold"; hot.className = "hot"; var btn = new IHTMLButton() { className = "special1" }; btn.appendChild(cold, hot); var content = new IHTMLElement(IHTMLElement.HTMLElementEnum.pre); content.innerHTML = "..."; content.className = "content1"; var tween = new TweenDataDouble(); var tween_max = 16; tween.ValueChanged += delegate { content.style.Opacity = tween.Value / tween_max; content.style.height = tween.Value + "em"; content.style.overflow = IStyle.OverflowEnum.hidden; }; tween.Done += delegate { if (tween.Value > 0) { content.style.overflow = IStyle.OverflowEnum.auto; } }; tween.Value = 0; var state = new XState { Show = (System.Action)(() => { tween.Value = tween_max; } ), Hide = (System.Action)(() => tween.Value = 0), Selected = false }; //try //{ // new IXMLHttpRequest(HTTPMethodEnum.GET, i[2], // request => content.innerHTML = request.responseText // ); //} //catch //{ content.innerText = i2; //} states = states.Concat(new[] { state }); btn.onclick += delegate { foreach (var v in states) { if (v == state) { v.Selected = !v.Selected; if (v.Selected) { v.Show(); } else { v.Hide(); } } else { v.Selected = false; v.Hide(); } } }; u.appendChild(btn, content); }; SpawnCursor(); u.AttachToDocument(); Spawn( new global::SimpleRollover.HTML.Images.FromAssets.Untitled_1_03(), new global::SimpleRollover.HTML.Images.FromAssets.Untitled_2_03(), "This application was written in C#." ); Spawn( new global::SimpleRollover.HTML.Images.FromAssets.Untitled_1_07(), new global::SimpleRollover.HTML.Images.FromAssets.Untitled_2_07(), "This application was cross compiled into JavaScript." ); }