public void Attach(int x, int y) { k6is.AttachToDocument(); piltm.AttachToDocument(); new k6is().ToBackground(k6is.style); k6is.style.backgroundRepeat = "repeat-y"; MoveTo(x, y); Native.Document.onkeydown += Native.DisabledEventHandler; Native.Document.onkeydown += new Action <IEvent>(Document_onkeypress); }
public static void SpawnEntrypointWithBrandning(this Type alias) { if (Native.window == null) { return; } Native.window.onload += delegate { IHTMLImage i = "assets/ScriptCoreLib/jsc.png"; i.style.position = IStyle.PositionEnum.absolute; i.style.right = "1em"; i.style.bottom = "1em"; i.AttachToDocument(); }; ScriptCoreLib.JavaScript.Native.Spawn(alias.Name, i => Activator.CreateInstance(alias)); }
/// <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 vid = "TXExg6Xj3aA"; var thumbnail = $"https://img.youtube.com/vi/{vid}/0.jpg"; var thumbnailImage = new IHTMLImage { // 0 pixels? useless. will extension be able to bypass? crossOrigin = "anonymous", src = thumbnail }; // naturalHeight: // 90 //naturalWidth: // 120 // {{ thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, width = 0, height = 0 }} new IHTMLPre { new { thumbnail, thumbnailImage.complete, thumbnailImage.naturalWidth, thumbnailImage.naturalHeight} }.AttachToDocument(); await thumbnailImage.async.oncomplete; //thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = false, naturalWidth = 0, naturalHeight = 0 }} // thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = true, naturalWidth = 120, naturalHeight = 90 }} //thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = true, naturalWidth = 0, naturalHeight = 0 }} thumbnailImage.style.SetSize( thumbnailImage.naturalWidth, thumbnailImage.naturalHeight ); new IHTMLPre { new { thumbnail, thumbnailImage.complete, thumbnailImage.width, thumbnailImage.naturalWidth, thumbnailImage.naturalHeight } }.AttachToDocument(); // { // { // thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = false, width = 0, height = 0 }} //{ // { // thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = true, width = 0, height = 0 }} thumbnailImage.AttachToDocument(); new IHTMLPre { new { thumbnail, thumbnailImage.complete, thumbnailImage.naturalWidth, thumbnailImage.naturalHeight } }.AttachToDocument(); var div = new IHTMLDiv { }.AttachToDocument(); // 404 image does show as a background, can we copy it? new IStyle(div) { width = 120 + "px", height = 90 + "px", //overflow = IStyle.OverflowEnum.hidden, //position = IStyle.PositionEnum.relative, backgroundImage = $"url('{thumbnail}')", }; //Image from origin 'https://img.youtube.com' has been blocked from loading by Cross - Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://192.168.1.12:15367' is therefore not allowed access.The response had HTTP status code 404. var idiv = (IHTMLImage)div; idiv.AttachToDocument(); new IHTMLPre { new { idiv.complete, idiv.width, idiv.naturalWidth, idiv.naturalHeight } }.AttachToDocument(); } ); // Severity Code Description Project File Line //Error CS7069 Reference to type 'TaskAwaiter<>' claims it is defined in 'mscorlib', but it could not be found TestCRCYTImage X:\jsc.svn\examples\javascript\test\TestCRCYTImage\TestCRCYTImage\Application.cs 56 }
/// <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 vid = "TXExg6Xj3aA"; var thumbnail = $"https://img.youtube.com/vi/{vid}/0.jpg"; var thumbnailImage = new IHTMLImage { // 0 pixels? useless. will extension be able to bypass? crossOrigin = "anonymous", src = thumbnail }; // naturalHeight: // 90 //naturalWidth: // 120 // {{ thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, width = 0, height = 0 }} new IHTMLPre { new { thumbnail, thumbnailImage.complete, thumbnailImage.naturalWidth, thumbnailImage.naturalHeight } }.AttachToDocument(); await thumbnailImage.async.oncomplete; //thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = false, naturalWidth = 0, naturalHeight = 0 }} // thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = true, naturalWidth = 120, naturalHeight = 90 }} //thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = true, naturalWidth = 0, naturalHeight = 0 }} thumbnailImage.style.SetSize( thumbnailImage.naturalWidth, thumbnailImage.naturalHeight ); new IHTMLPre { new { thumbnail, thumbnailImage.complete, thumbnailImage.width, thumbnailImage.naturalWidth, thumbnailImage.naturalHeight } }.AttachToDocument(); // { // { // thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = false, width = 0, height = 0 }} //{ // { // thumbnail = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, complete = true, width = 0, height = 0 }} thumbnailImage.AttachToDocument(); new IHTMLPre { new { thumbnail, thumbnailImage.complete, thumbnailImage.naturalWidth, thumbnailImage.naturalHeight } }.AttachToDocument(); var div = new IHTMLDiv { }.AttachToDocument(); // 404 image does show as a background, can we copy it? new IStyle(div) { width = 120 + "px", height = 90 + "px", //overflow = IStyle.OverflowEnum.hidden, //position = IStyle.PositionEnum.relative, backgroundImage = $"url('{thumbnail}')", }; //Image from origin 'https://img.youtube.com' has been blocked from loading by Cross - Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://192.168.1.12:15367' is therefore not allowed access.The response had HTTP status code 404. var idiv = (IHTMLImage)div; idiv.AttachToDocument(); new IHTMLPre { new { idiv.complete, idiv.width, idiv.naturalWidth, idiv.naturalHeight } }.AttachToDocument(); } ); // Severity Code Description Project File Line //Error CS7069 Reference to type 'TaskAwaiter<>' claims it is defined in 'mscorlib', but it could not be found TestCRCYTImage X:\jsc.svn\examples\javascript\test\TestCRCYTImage\TestCRCYTImage\Application.cs 56 }
//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 Class1(IHTMLElement DataElement) { IStyleSheet.Default.AddRule("*", "cursor: url('assets/NatureBoy/cursor.cur'), auto;", 0); IStyleSheet.Default.AddRule("body", r => { r.style.backgroundColor = Color.Gray; r.style.overflow = IStyle.OverflowEnum.hidden; r.style.padding = "0px"; } ); IStyleSheet.Default.AddRule(".stage", r => { r.style.backgroundColor = Color.White; r.style.position = IStyle.PositionEnum.absolute; r.style.left = "0px"; r.style.top = "0px"; r.style.right = "0px"; r.style.bottom = "0px"; r.style.Opacity = 0.0; } ); var bg = new IHTMLImage("assets/NatureBoy/back/IMG_0572.jpg"); bg.style.position = IStyle.PositionEnum.absolute; bg.style.SetLocation(0, 0); bg.style.width = "100%"; bg.AttachToDocument(); var stage = new IHTMLDiv { className = "stage" }; stage.AttachToDocument(); var dude4 = new Dude { ZoomFunc = y => (y + 300) / (600) }; dude4.TeleportTo(200, 200); dude4.Control.AttachToDocument(); dude4.AutoRotate(1); var dude5 = new Dude { ZoomFunc = dude4.ZoomFunc }; dude5.TeleportTo(600, 300); dude5.Control.AttachToDocument(); dude5.AutoRotateToCursor(stage); var dude6 = new Dude { ZoomFunc = dude4.ZoomFunc }; dude6.TeleportTo(300, 400); dude6.Control.AttachToDocument(); var dude7 = new Dude { ZoomFunc = dude4.ZoomFunc }; dude7.TeleportTo(200, 400); dude7.Control.AttachToDocument(); var dude8 = new Dude { ZoomFunc = dude4.ZoomFunc }; dude8.TeleportTo(250, 300); dude8.Control.AttachToDocument(); var CurrentDude = default(Dude); Action<Dude> SelectDude = i => { if (CurrentDude != null) CurrentDude.IsSelected = false; CurrentDude = i; CurrentDude.IsSelected = true; }; Action<Dude> BindSelectDude = i => i.Control.onclick += delegate { SelectDude(i); }; BindSelectDude(dude6); BindSelectDude(dude7); BindSelectDude(dude8); stage.onclick += delegate(IEvent ev) { CurrentDude.WalkTo(ev.CursorPosition); dude5.WalkTo(ev.CursorPosition); }; }
static void AttachImageToDocument(IHTMLImage img) { img.AttachToDocument(); }
public Application(IApp page) { // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151101 // first lets do some chrome extension magic. dynamic self = Native.self; dynamic self_chrome = self.chrome; #region self_chrome_tabs extension object self_chrome_tabs = self_chrome.tabs; if (self_chrome_tabs != null) { Console.WriteLine("running as extension " + new { typeof(Application).Assembly.GetName().Name }); // verified. // running as extension {{ Name = ChromeHybridCaptureAE.Application }} new { }.With( async delegate { app = (await chrome.management.getAll()).FirstOrDefault(item => item.name.StartsWith(typeof(Application).Assembly.GetName().Name)); if (app == null) { Console.WriteLine("running as extension. app not found."); return; } // running as extension {{ shortName = ChromeHybridCaptureAE.Application.exe, launchType = OPEN_AS_WINDOW }} Console.WriteLine("running as extension " + new { app.shortName, app.launchType }); chrome.runtime.connect(app.id).With( async (chrome.Port port) => { //Console.WriteLine("extension chrome.runtime.connect done " + new { port.name, port.sender.id }); //Console.WriteLine("extension chrome.runtime.connect done " + new { port.name, port.sender }); Console.WriteLine("extension chrome.runtime.connect done, click launch"); #region extension: HopToChromeApp.VirtualOnCompleted // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp HopToChromeApp.VirtualOnCompleted = async (that, continuation) => { // state 0 ? or state -1 ? Console.WriteLine("extension HopToChromeApp enter "); TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation); // now send the jump instruction... will it make it? port.postMessage(r.shadowstate); }; #endregion // is async better than event += here? var m = default(chrome.PortMessageEvent); while (m = await port.async.onmessage) { var message = m.data; // verified. #region IAsyncStateMachine // casting from anonymous object. var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message; // 12961ms extension port.onMessage {{ state = null, TypeName = null }} // or constructor id? Console.WriteLine("extension port.onMessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName }); // 12468ms extension port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }} //2015-08-22 15:49:45.729 view-source:53670 12471ms extension port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }} //2015-08-22 15:49:45.733 view-source:53670 12475ms extension port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }} //2015-08-22 15:49:45.737 view-source:53670 12479ms extension port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }} #region xAsyncStateMachineType var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault( xAsyncStateMachineTypeCandidate => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName; } return false; } ); #endregion Console.WriteLine(new { xAsyncStateMachineType }); 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, xShadowIAsyncStateMachine.state ); } var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.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 NewStateMachineI.MoveNext(); #endregion } } ); } ); return; } #endregion object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { #region running as appwindow if (!(Native.window.opener == null && Native.window.parent == Native.window.self)) { Console.WriteLine("running as appwindow"); MessagePort appwindow_to_app2 = null; // called by? 619 app:HopToChromeAppWindow #region appwindow Native.window.onmessage Native.window.onmessage += e => { // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow // appwindow Native.window.onmessage {{ data = app to appwindow! }} var message = e.data; //Console.WriteLine("appwindow Native.window.onmessage " + new { e.data }); // extension port.onMessage {{ message = from app hello to extension }} //var expando_isstring = ScriptCoreLib.JavaScript.Runtime.Expando.Of(message).IsString; // look app sent a message to extension //Console.WriteLine("app port.onMessage " + new { message }); { // DataCloneError: Failed to execute 'postMessage' on 'Window': Port at index 0 is already neutered. if (e.ports != null) foreach (var port in e.ports) { Console.WriteLine("appwindow Native.window.onmessage " + new { port }); appwindow_to_app2 = port; } } // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp // casting from anonymous object. var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message; // or constructor id? Console.WriteLine("appwindow Native.window.onmessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName }); // 12468ms extension port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }} //2015-08-22 15:49:45.729 view-source:53670 12471ms extension port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }} //2015-08-22 15:49:45.733 view-source:53670 12475ms extension port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }} //2015-08-22 15:49:45.737 view-source:53670 12479ms extension port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }} #region xAsyncStateMachineType var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault( xAsyncStateMachineTypeCandidate => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.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, xShadowIAsyncStateMachine.state ); } // X:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs // field names/ tokens need to be encrypted like typeinfo. // some do manual restore // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow // or, are we supposed to initialize a string value here? var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.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 NewStateMachineI.MoveNext(); }; #endregion #region appwindow:HopToChromeApp HopToChromeApp.VirtualOnCompleted = async (that, continuation) => { // do we have the port to send back our portal warp? // state 0 ? or state -1 ? Console.WriteLine("appwindow HopToChromeApp enter " + new { appwindow_to_app2 }); // appwindow HopToChromeApp enter {{ appwindow_to_app2 = null }} //// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow //// async dont like ref? TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation); // 29035ms extension port.onMessage {{ message = do HopToChromeExtension }} //appwindow_to_app.postMessage("do HopToChromeAppWindow " + new { r.shadowstate.TypeName, r.shadowstate.state }); // now send the jump instruction... will it make it? appwindow_to_app2.postMessage(r.shadowstate); }; #endregion return; } #endregion // running as app {{ Name = ChromeHybridCaptureAE.Application }} now reenable extension.. Console.WriteLine("running as app " + new { typeof(Application).Assembly.GetName().Name } + " now reenable extension.."); #region app:appwindow_to_app Action<object> appwindow_to_app = data => { var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)data; Console.WriteLine("app appwindow_to_app " + new { xShadowIAsyncStateMachine.TypeName }); #region xAsyncStateMachineType var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault( xAsyncStateMachineTypeCandidate => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName; } return false; } ); #endregion Console.WriteLine("app appwindow_to_app " + new { xAsyncStateMachineType }); 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, xShadowIAsyncStateMachine.state ); } // X:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs // field names/ tokens need to be encrypted like typeinfo. // some do manual restore // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow // or, are we supposed to initialize a string value here? var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.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 NewStateMachineI.MoveNext(); }; #endregion var c = new MessageChannel(); var cneutered = c; c.port1.onmessage += e => { Console.WriteLine("app HopToChromeAppWindow MessageChannel onmessage " + new { e.data }); appwindow_to_app(e.data); }; c.port1.start(); c.port2.start(); #region app:HopToChromeAppWindow HopToChromeAppWindow.VirtualOnCompleted = async (that, continuation) => { // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150824/webgliframebuffer // state 0 ? or state -1 ? Console.WriteLine("app HopToChromeAppWindow enter "); #region outputWindow if (that.window == null) { // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow if (outputWindow == null) { // https://developer.chrome.com/apps/app_window#type-CreateWindowOptions outputWindow = await chrome.app.window.create( Native.document.location.pathname, // https://developer.chrome.com/apps/app_window#type-CreateWindowOptions // this ctually works. but we wont see console on app log.. options: new { hidden = true, alwaysOnTop = true } ); ////xappwindow.setAlwaysOnTop // or can we stay hidden? //that.window.show(); await outputWindow.contentWindow.async.onload; } // reuse the window... that.window = outputWindow; } #endregion // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow // async dont like ref? TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation); // 29035ms extension port.onMessage {{ message = do HopToChromeExtension }} // Z:\jsc.svn\core\ScriptCoreLib\JavaScript\DOM\IWindow.postMessage.cs // how do we use this thing? // 15ms appwindow Native.window.onmessage: {{ ports = [object MessagePort] }} //2015-08-22 20:50:18.019 view-source:53702 17ms appwindow Native.window.onmessage: {{ port = [object MessagePort] }} //that.window.contentWindow.postMessage("do HopToChromeAppWindow " + new { r.shadowstate.TypeName, r.shadowstate.state }, transfer: c.port2); // now send the jump instruction... will it make it? if (cneutered != null) { that.window.contentWindow.postMessage(r.shadowstate, transfer: cneutered.port2); cneutered = null; } else { that.window.contentWindow.postMessage(r.shadowstate); } }; #endregion #region ConnectExternal chrome.runtime.ConnectExternal += async port => { // app chrome.runtime.ConnectExternal {{ id = jadmeogmbokffpkdfeiemjplohfgkidd }} now click launch! Console.WriteLine("app chrome.runtime.ConnectExternal " + new { port.sender.id } + " now click launch!"); new chrome.Notification( title: typeof(Application).Assembly.GetName().Name, message: "ready. click launch" ).Clicked += delegate { // https://developer.chrome.com/apps/app_runtime // management_api }; // can we have async thing here? #region HopToChromeExtension HopToChromeExtension.VirtualOnCompleted = async (that, continuation) => { // state 0 ? or state -1 ? Console.WriteLine("app HopToChromeExtension enter "); // where is it defined? // z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\ShadowIAsyncStateMachine.cs // async dont like ref? TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation); // now send the jump instruction... will it make it? port.postMessage(r.shadowstate); // how would we know to continue from current continuation? // or are we fine to rebuild the scope if we jump back? }; #endregion var m = default(chrome.PortMessageEvent); while (m = await port.async.onmessage) { //var m = await port.async.onmessage; var message = m.data; #region IAsyncStateMachine // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp // casting from anonymous object. var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message; // or constructor id? Console.WriteLine("app port.onMessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName }); // 12468ms extension port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }} //2015-08-22 15:49:45.729 view-source:53670 12471ms extension port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }} //2015-08-22 15:49:45.733 view-source:53670 12475ms extension port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }} //2015-08-22 15:49:45.737 view-source:53670 12479ms extension port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }} #region xAsyncStateMachineType var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault( xAsyncStateMachineTypeCandidate => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.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, xShadowIAsyncStateMachine.state ); } // z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs // field names/ tokens need to be encrypted like typeinfo. // some do manual restore // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow // or, are we supposed to initialize a string value here? var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.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 NewStateMachineI.MoveNext(); #endregion } }; #endregion // nuget chrome chrome.app.runtime.Launched += async delegate { { fixup: await Task.CompletedTask; } Console.WriteLine("app Launched, will hop to extension"); // verified. await default(HopToChromeExtension); // https://developer.chrome.com/extensions/management // as an extension we now can inspect our app ? Console.WriteLine("hop from app to extension " + new { app.name }); // hop from app to extension {{ name = ChromeHybridCaptureAE.Application.exe }} // what else can we do as an extension? // lets hop back? await default(HopToChromeApp); Console.WriteLine("hop from extension to app "); // ok hopping works. lets do some ui now. //// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow await default(HopToChromeAppWindow); Native.document.documentElement.style.overflow = IStyle.OverflowEnum.auto; //Native.body.style.overflow = IStyle.OverflowEnum.auto; Native.body.Clear(); (Native.body.style as dynamic).webkitUserSelect = "text"; chrome.app.window.current().show(); // now what? new IHTMLPre { "now what?" }.AttachToDocument(); // lets have some ui to do a fullsceen tab capture? // http://earth.nullschool.net/#2015/10/31/1500Z/wind/surface/level/anim=off/overlay=temp/azimuthal_equidistant=24.64,98.15,169 // http://earth.nullschool.net/#2015/10/31/2100Z/wind/surface/level/anim=off/overlay=temp/azimuthal_equidistant=24.64,98.15,169 // TypeError: Cannot set property 'uri' of null // jsc statemachine hop doesnt like scopes yet. staic it is. uri = new IHTMLInput { value = "http://earth.nullschool.net/#2015/10/31/2100Z/wind/surface/level/anim=off/overlay=temp/azimuthal_equidistant=24.64,98.15,169" }.AttachToDocument(); uri.style.width = "100%"; Console.WriteLine("appwindow: " + new { uri }); new IHTMLPre { () => new { index } }.AttachToDocument(); frameID = new IHTMLInput { type = ScriptCoreLib.Shared.HTMLInputTypeEnum.range, min = 0, //max = 3600, max = 240, valueAsNumber = 0 }.AttachToDocument().With( async i => { do { // http://earth.nullschool.net/#2015/10/01/0000Z/wind/surface/level/anim=off/overlay=temp/azimuthal_equidistant=24.64,98.15,169 index = (int)i.valueAsNumber; var hh = 3 * index; var dd = 1 + Math.Floor(hh / 24.0); uri.value = "http://earth.nullschool.net/#2015/10/" + dd.ToString().PadLeft(2, '0') + "/" + (hh % 24).ToString().PadLeft(2, '0') + "00Z/wind/surface/level/anim=off/overlay=temp/azimuthal_equidistant=24.64,98.15,169"; } while (await i.async.onchange); } ); go = new IHTMLButton { "go" }.AttachToDocument(); Console.WriteLine("appwindow: " + new { go }); go.onclick += async delegate { //Error CS0158 The label 'fixup' shadows another label by the same name in a contained scope ChromeHybridCaptureAE Z:\jsc.svn\examples\javascript\chrome\hybrid\ChromeHybridCaptureAE\Application.cs 791 { fixup: await Task.CompletedTask; } Native.body.style.backgroundColor = "yellow"; var scope_uri = uri.value; #region await default(HopToChromeExtension) await default(HopToChromeApp); Console.WriteLine("hop from appwindow to app! " + new { scope_uri }); // verify await default(HopToChromeExtension); #endregion Console.WriteLine("hop from app to extension! " + new { scope_uri }); // hop from app to extension! {{ scope_uri = http://earth.nullschool.net/#2015/10/31/2100Z/wind/surface/level/anim=off/overlay=temp/azimuthal_equidistant=24.64,98.15,169 }} var tabwindow = await chrome.windows.create(new { state = "fullscreen", url = scope_uri }); // um. unless we hop into it we wont know when its ready? //await Task.Delay(7000); await Task.Delay(5000); // Error: Invalid value for argument 2. Property 'format': Value must be one of: [jpeg, png]. at validate var captureVisibleTab = await tabwindow.id.captureVisibleTab(options: new { format = "jpeg" }); Console.WriteLine("extension captureVisibleTab " + new { captureVisibleTab.Length }); await tabwindow.id.remove(); #region await default(HopToChromeAppWindow) await default(HopToChromeApp); Console.WriteLine("app " + new { captureVisibleTab.Length }); await default(HopToChromeAppWindow); Console.WriteLine("appwindow " + new { captureVisibleTab.Length }); #endregion // appwindow {{ Length = 272711 }} var icaptureVisibleTabFull = await new IHTMLImage { src = captureVisibleTab }.async.oncomplete; // {{ width = 1920, height = 1080 }} new IHTMLPre { new { icaptureVisibleTabFull.width, icaptureVisibleTabFull.height } } ; // .AttachToDocument(); var focus = new CanvasRenderingContext2D(icaptureVisibleTabFull.height, icaptureVisibleTabFull.height); focus.drawImage(icaptureVisibleTabFull, (icaptureVisibleTabFull.width - icaptureVisibleTabFull.height) / 2, 0, icaptureVisibleTabFull.height, icaptureVisibleTabFull.height, 0, 0, icaptureVisibleTabFull.height, icaptureVisibleTabFull.height); var icaptureVisibleTab = new IHTMLImage { src = focus.canvas.toDataURL() }.AttachToDocument(); icaptureVisibleTab.style.width = "100%"; icaptureVisibleTab.AttachToDocument(); await new IHTMLButton { "save " }.AttachToDocument().async.onclick; if (dir == null) dir = (DirectoryEntry)await chrome.fileSystem.chooseEntry(new { type = "openDirectory" }); var file = index.ToString().PadLeft(5, '0') + ".jpg"; await dir.WriteAllBytes(file, focus); //frameID.valueAsNumber++; await new IHTMLButton { "automate " + new { frameID = frameID.valueAsNumber } }.AttachToDocument().async.onclick; //new IHTMLPre { uri.value }.AttachToDocument(); next: frameID.valueAsNumber++; await Native.window.async.onframe; await Native.window.async.onframe; //new IHTMLPre { uri.value }.AttachToDocument(); // go? // TypeError: Cannot read property 'id' of null scope_uri = uri.value; #region await default(HopToChromeExtension) await default(HopToChromeApp); Console.WriteLine("hop from appwindow to app! " + new { scope_uri }); // verify await default(HopToChromeExtension); #endregion var tabwindow2 = await chrome.windows.create(new { state = "fullscreen", url = scope_uri }); await Task.Delay(5000); var captureVisibleTab2 = await tabwindow2.id.captureVisibleTab(options: new { format = "jpeg" }); await tabwindow2.id.remove(); #region await default(HopToChromeAppWindow) await default(HopToChromeApp); Console.WriteLine("app " + new { captureVisibleTab.Length }); await default(HopToChromeAppWindow); Console.WriteLine("appwindow " + new { captureVisibleTab.Length }); #endregion var icaptureVisibleTabFull2 = await new IHTMLImage { src = captureVisibleTab2 }.async.oncomplete; var focus2 = new CanvasRenderingContext2D(icaptureVisibleTabFull2.height, icaptureVisibleTabFull2.height); focus2.drawImage(icaptureVisibleTabFull2, (icaptureVisibleTabFull2.width - icaptureVisibleTabFull2.height) / 2, 0, icaptureVisibleTabFull2.height, icaptureVisibleTabFull2.height, 0, 0, icaptureVisibleTabFull2.height, icaptureVisibleTabFull2.height); var icaptureVisibleTab2 = new IHTMLImage { src = focus2.canvas.toDataURL() }; var file2 = index.ToString().PadLeft(5, '0') + ".jpg"; await dir.WriteAllBytes(file2, focus2); // done? goto next; }; await default(HopToChromeApp); Console.WriteLine("hop from appwindow to app!"); }; return; } Console.WriteLine("running as content?"); }
/// <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://github.com/tumblr/jumblr new Abstractatech.ConsoleFormPackage.Library.ConsoleForm() .InitializeConsoleFormWriter() .PopupInsteadOfClosing() .Show(); // new IHTMLIFrame { src = "http://www.whatsmyip.us/", //src = "http://whatsmyip.net/", frameBorder = "0", scrolling = "no", width = 400, height = 72 }.AttachToDocument().style.SetSize( 400, 72); new IHTMLBreak().AttachToDocument(); //new IHTMLButton { innerText = "swapCache" }.AttachToDocument().WhenClicked( // delegate // { // // Uncaught InvalidStateError: Failed to execute 'swapCache' on 'ApplicationCache': there is no newer application cache to swap to. // Native.window.applicationCache.swapCache(); // } //); @"Hello world".ToDocumentTitle(); // Send data from JavaScript to the server tier service.getNumberOfCameras( cameras => { Enumerable.Range(0, int.Parse(cameras)).Select(i => new { i }).WithEach( ii => { var i = ii.i; new IHTMLBreak().AttachToDocument(); #region show me stills new IHTMLButton { innerText = "show me stills " + new { i } }.AttachToDocument().onclick += delegate { service.WebMethod2( "" + i, value => { if (!value.StartsWith("data:")) { Console.WriteLine(value); return; } new IHTMLImage { src = value }.AttachToDocument(); } ); }; #endregion #region show me animation new IHTMLButton { innerText = "show me animation" }.AttachToDocument().onclick += delegate { var img = new IHTMLImage { }.AttachToDocument(); var data = new List<string>(); service.WebMethod2( "" + i, value => { if (!value.StartsWith("data:")) { Console.WriteLine(value); return; } data.Add(value); } ); new Timer( t => { if (data.Count == 0) return; img.src = data[t.Counter % data.Count]; } ).StartInterval(1000 / 15); }; #endregion #region show me animation async new IHTMLButton { innerText = "show me animation async" }.AttachToDocument().onclick += delegate { var img = new IHTMLImage { }.AttachToDocument(); var data = new List<string>(); service.async_WebMethod2( "" + i, value => { if (!value.StartsWith("data:")) { Console.WriteLine(value); return; } data.Add(value); } ); new Timer( t => { if (data.Count == 0) return; img.src = data[t.Counter % data.Count]; } ).StartInterval(1000 / 15); }; #endregion #region show me animation async and gif it new IHTMLButton { innerText = "gif it " + new { i } }.AttachToDocument().onclick += delegate { Console.WriteLine("working..."); new IHTMLBreak().AttachToDocument(); var img = new IHTMLImage { }.AttachToDocument(); var data = new List<string>(); var gifmaxframes = 60; #region Timer new Timer( t => { if (data.Count == 0) return; if (data.Count < gifmaxframes) { img.src = data.Last(); return; } img.src = data[t.Counter % data.Count]; } ).StartInterval(1000 / 15); #endregion var c0 = new CanvasRenderingContext2D(); // no scale! c0.canvas.width = 320; c0.canvas.height = 240; c0.canvas.style.SetSize(320, 240); var c1 = new CanvasRenderingContext2D(); // no scale! c1.canvas.width = 320; c1.canvas.height = 240; c1.canvas.style.SetSize(320, 240); //c0.canvas.AttachToDocument(); // http://stackoverflow.com/questions/1864756/web-workers-and-canvas service.async_WebMethod2( "" + i, value => { if (!value.StartsWith("data:")) { Console.WriteLine(value); return; } data.Add(value); if (data.Count == gifmaxframes) { // need webworker! #region gif var st = new Stopwatch(); st.Start(); var encoder1 = new GIFEncoderAsync( 320, 240 ); //encoder1.setRepeat(0); //auto-loop //encoder1.setDelay(1000 / 15); //encoder1.start(); var encoder2 = new GIFEncoderAsync( 320, 240 ); //encoder2.setRepeat(0); //auto-loop //encoder2.setDelay(1000 / 15); //encoder2.start(); #region frames Console.WriteLine("gif " + new { st.Elapsed }); for (int datai = 0; datai < data.Count; datai++) { Console.WriteLine("gif " + new { datai, st.Elapsed }); c1.drawImage(new IHTMLImage { src = data[datai] }, 0, 0, 320, 240); encoder2.addFrame(c1); c0.drawImage(new IHTMLImage { src = data[datai] }, 0, 0, 320, 240); #region grayscale var imageData = c0.getImageData(0, 0, 320, 240); // This loop gets every pixels on the image and for (var j = 0; j < imageData.width; j++) { for (var ji = 0; ji < imageData.height; ji++) { var index = (uint)((ji * 4) * imageData.width + (j * 4)); var red = imageData.data[index]; var green = imageData.data[index + 1]; var blue = imageData.data[index + 2]; var alpha = imageData.data[index + 3]; var average = (byte)((red + green + blue) / 3); imageData.data[index] = average; imageData.data[index + 1] = average; imageData.data[index + 2] = average; //imageData.data[index + 1] = average; //imageData.data[index + 2] = average; imageData.data[index + 3] = alpha; } } // overwrite original image c0.putImageData(imageData, 0, 0, 0, 0, 320, 240); #endregion encoder1.addFrame(c0); Console.WriteLine("gif done " + new { datai, st.Elapsed }); } encoder1.finish( src => { var image = new IHTMLImage(); image.src = src; image.style.SetSize(640, 480); Console.WriteLine("gif got src" + new { st.Elapsed }); image.AttachToDocument(); } ); encoder2.finish( src => { var image = new IHTMLImage(); image.src = src; image.style.SetSize(640, 480); Console.WriteLine("gif got src" + new { st.Elapsed }); image.AttachToDocument(); } ); #endregion #endregion } } ); }; #endregion } ); } ); new IHTMLBreak().AttachToDocument(); }