public void Start(object parameter) { // what about serviceworker? // WebWorker? // did jsc rewriter detect the threadstart correctly? var w = WorkerDomain.current.createWorker( InternalPrimordialSprite.loaderInfo.bytes ); __MethodInfo m = InternalParameterizedThreadStart.Method; #region fromWorkerConsole var fromWorkerConsole = w.createMessageChannel(Worker.current); w.setSharedProperty("fromWorkerConsole", fromWorkerConsole); fromWorkerConsole.channelMessage += e => { var data = (string)fromWorkerConsole.receive(); // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs Console.WriteLine(data); }; #endregion w.setSharedProperty("FunctionToken_TypeFullName", m._Method.FunctionToken_TypeFullName); w.setSharedProperty("FunctionToken_MethodName", m._Method.FunctionToken_MethodName); w.setSharedProperty("arg0", parameter); if (InternalBeforeStart != null) { InternalBeforeStart(w); } w.start(); //IsAlive = true; //InternalParameterizedThreadStart(e); //IsAlive = false; }
public static Delegate CreateDelegate(Type type, object firstArgument, global::System.Reflection.MethodInfo method) { // X:\jsc.svn\examples\javascript\async\Test\TestDelegateObjectScopeInspection\TestDelegateObjectScopeInspection\Application.cs // firstArgument: // The object to which the delegate is bound, or null to treat method as static // can we actually call the type.ctor? __MethodInfo m = method; // um. we are marking it as IntPtr but actually it seems we are using string. //var MethodToken = (string)(object)this.InternalMethod; // reverse of .Method var xIntPtr = (IntPtr)(object)m.InternalMethodToken; // [0] = {Void .ctor(System.Object, IntPtr)} //var yy = Activator.CreateInstance(typeof(Func<string>), // nRow, // y.Method //); // can we call CreateInstance with args? var withType = Activator.CreateInstance( type, firstArgument, xIntPtr ); //var typeless = new __MulticastDelegate( // firstArgument, // i //); return((MulticastDelegate)withType); }
private static bool InternalEquals(__MethodInfo a, __MethodInfo b) { var na = ((object)a) == null; var nb = ((object)b) == null; if (na) if (nb) return true; var ab = na ^ nb; if (ab) return false; return a.InternalMethod == b.InternalMethod; }
public ApplicationSprite() { //__Thread.InternalWorkerInvoke_4ebbe596_06000030(this); //this.__out_Method_6d788eff_06000003(); // "X:\jsc.svn\examples\actionscript\async\AsyncWorkerTask\AsyncWorkerTask.sln" // X:\jsc.svn\examples\actionscript\async\AsyncWorkerTask\AsyncWorkerTask\ApplicationSprite.cs // X:\jsc.svn\examples\actionscript\FlashWorkerExperiment\FlashWorkerExperiment\ApplicationSprite.cs // https://forums.adobe.com/thread/1164500 // this looks like chrome context capture #region worker if (!Worker.current.isPrimordial) { var sw = Stopwatch.StartNew(); // iOS workers is still on the roadmap. I don't have a release date, but I know it'll be an extended beta type of feature. // Most of the concurrency work was gated on the new AOT compiler work, which is still being actively worked on. // Lots of bug and performance fixes were added to AIR 15 and we're not stopping there. var xfromWorker = (MessageChannel)Worker.current.getSharedProperty("fromWorker"); var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName"); var FunctionToken_MethodName = (string)Worker.current.getSharedProperty("FunctionToken_MethodName"); var arg0 = (string)Worker.current.getSharedProperty("arg0"); // enter click //{ { data = message from worker { { FunctionToken_TypeFullName = TestThreadStart.TheOtherClass, FunctionToken_MethodName = Invoke_6d788eff_0600001c } }, ElapsedMilliseconds = 1713 } } IntPtr pp = __IntPtr.OfFunctionToken(null, FunctionToken_TypeFullName, FunctionToken_MethodName ); MethodInfo mm = new __MethodInfo { _Method = pp }; // t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds }; //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName }); //throw null; mm.Invoke(null, new object[] { arg0 }); // enter click //{ { ElapsedMilliseconds = 3103, data = message from worker { { ElapsedMilliseconds = 3057, SharedField = { { data = null, i = 65534, j = 3 } } } } } } // {{ ElapsedMilliseconds = 3399, data = message from worker {{ ElapsedMilliseconds = 3352, SharedField = {{ data = hello world, i = 65534, j = 3 }} }} }} xfromWorker.send("message from worker " + new { sw.ElapsedMilliseconds, TheOtherClass.SharedField }); return; } #endregion // {{ os = Windows 7, version = WIN 15,0,0,189, length = 333983, Target = null, Method = { _Target = , _Method = IntPtr { StringToken = , FunctionToken = function Function() {}, ClassToken = } } }} // start0 = new __ParameterizedThreadStart(null, __IntPtr.op_Explicit_4ebbe596_06001686(TheOtherClass.Invoke_6d788eff_0600000c)); // start0 = new __ParameterizedThreadStart(null, __IntPtr.OfFunctionToken_4ebbe596_06001687(TheOtherClass.Invoke_6d788eff_0600000c,"TestThreadStart.TheOtherClass","Invoke_6d788eff_0600000c")); ParameterizedThreadStart y = TheOtherClass.Invoke; // can we call the method // 0007 0200034c ScriptCoreLib::ScriptCoreLib.ActionScript.Extensions.ZipFileEntry + Cookie`1 //Unhandled Exception: System.AggregateException: One or more errors occurred. --->System.InvalidOperationException: internal compiler error at method // assembly: X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\bin\Debug\ScriptCoreLib.dll at // type: ScriptCoreLib.ActionScript.BCLImplementation.System.__Single, ScriptCoreLib, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null // method: CompareTo // Object reference not set to an instance of an object. // at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) // at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value) // at jsc.Script.CompilerBase. . (Type , MethodBase , LocalVariableInfo , CompilerBase ) // at jsc.Script.CompilerBase.<WriteVariableName>b__0(Type , MethodBase , LocalVariableInfo ) // Unhandled Exception: System.AggregateException: One or more errors occurred. --->System.InvalidOperationException: internal compiler error at method //assembly: X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\bin\Debug\ScriptCoreLib.dll at //type: ScriptCoreLib.ActionScript.BCLImplementation.System.__BitConverter, ScriptCoreLib, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null //method: GetBytes //Object reference not set to an instance of an object. // at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) // at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value) // at jsc.Script.CompilerBase. . (Type , MethodBase , LocalVariableInfo , CompilerBase ) //{{ os = Windows 7, version = WIN 15,0,0,189, length = 334356, Target = null, Method = { _Target = , _Method = IntPtr { StringToken = , FunctionToken = function Function() {}, ClassToken = } }, z = Type { TypeDescription = // <type name="TestThreadStart::TheOtherClass" base="Class" isDynamic="true" isFinal="true" isStatic="true"> // <extendsClass type="Class"/> // <extendsClass type="Object"/> // <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/> // <method name="Invoke_6d788eff_0600000c" declaredBy="TestThreadStart::TheOtherClass" returnType="void"> // <parameter index="1" type="Object" optional="false"/> // </method> // <factory type="TestThreadStart::TheOtherClass"> // <extendsClass type="Object"/> // </factory> //</type> } }} // {{ os = Windows 7, version = WIN 15,0,0,189, length = 334570, Target = null, Method = { _Target = , _Method = IntPtr { StringToken = , //FunctionToken = function Function() {}, ClassToken = } }, FullName = TestThreadStart::TheOtherClass, z = Type { TypeDescription = <type name="TestThreadStart::TheOtherClass" base="Class" isDynamic="true" isFinal="true" isStatic="true"> // <extendsClass type="Class"/> // <extendsClass type="Object"/> // <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/> // <method name="Invoke_6d788eff_0600000c" declaredBy="TestThreadStart::TheOtherClass" returnType="void"> // <parameter index="1" type="Object" optional="false"/> // </method> // <factory type="TestThreadStart::TheOtherClass"> // <extendsClass type="Object"/> // </factory> //</type> }, zz = Type { TypeDescription = <type name="TestThreadStart::TheOtherClass" base="Class" isDynamic="true" isFinal="true" isStatic="true"> // <extendsClass type="Class"/> // <extendsClass type="Object"/> // <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/> // <method name="Invoke_6d788eff_0600000c" declaredBy="TestThreadStart::TheOtherClass" returnType="void"> // <parameter index="1" type="Object" optional="false"/> // </method> // <factory type="TestThreadStart::TheOtherClass"> // <extendsClass type="Object"/> // </factory> //</type> } }} //var z = typeof(TheOtherClass); //var zz = Type.GetType("TestThreadStart::TheOtherClass"); //var zz = Type.GetType("TestThreadStart.TheOtherClass"); //var zMethod = z.GetMethods(); __MethodInfo p = y.Method; //{ { os = Windows 7, version = WIN 15,0,0,189, length = 335268, // FunctionToken_TypeFullName = TestThreadStart.TheOtherClass, // FunctionToken_MethodName = Invoke_6d788eff_0600000c // } } //var pt = Type.GetType(p._Method.FunctionToken_TypeFullName); //new ParameterizedThreadStart(null, pp); //new Delegate(); var t = new TextField { multiline = true, //wordWrap = true, // {{ InternalPrimordialSprite = null, os = Windows 7, version = WIN 15,0,0,189, length = 353988, FunctionToken_TypeFullName = TestThreadStart.TheOtherClass, FunctionToken_MethodName = Invoke_6d788eff_06000016 }} text = new { // did the compiler set it yet? __Thread.InternalPrimordialSprite, // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html Capabilities.os, Capabilities.version, //WorkerDomain = WorkerDomain.isSupported, //Worker = Worker.isSupported, //Worker.current.isPrimordial, this.loaderInfo.bytes.length, // {{ os = Windows 7, version = WIN 15,0,0,189, length = 333411, Target = null, Method = { InternalFunctionPointer = function Function() {} } }} //y.Target, // first step is to call a static method on the other side of thread //y.Method, //y.Method, //y.Method.DeclaringType //z.FullName, //z, p._Method.FunctionToken_TypeFullName, p._Method.FunctionToken_MethodName, }.ToString(), autoSize = TextFieldAutoSize.LEFT }; t.AttachTo(this); t.click += delegate { var sw = Stopwatch.StartNew(); t.text = "enter click"; var w = WorkerDomain.current.createWorker( this.loaderInfo.bytes ); //p._Method.FunctionToken_TypeFullName, //p._Method.FunctionToken_MethodName w.setSharedProperty("FunctionToken_TypeFullName", p._Method.FunctionToken_TypeFullName); w.setSharedProperty("FunctionToken_MethodName", p._Method.FunctionToken_MethodName); w.setSharedProperty("arg0", "hello world"); var fromWorker = w.createMessageChannel(Worker.current); w.setSharedProperty("fromWorker", fromWorker); fromWorker.channelMessage += e => { var data = (string)fromWorker.receive(); t.appendText( "\n " + new { sw.ElapsedMilliseconds, data }.ToString() ); }; t.text = "enter click"; w.start(); //try //{ // // catch {{ err = ArgumentError: Error #1063: Argument count mismatch on TestThreadStart::TheOtherClass$/Invoke_6d788eff_06000013(). Expected 1, got 0. }} // mm.Invoke(null, new object[1]); // t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds }; //} //catch (Exception err) //{ // t.text = "catch " + new { err }; //} }; }
public static object Invoke(object that) { var xType = that.GetType(); var xTypeBase = xType.BaseType; var xMe = typeof(__ClientBase <>); // enter __ClientBase Channel { xType = JVMCLRWSDLMID.sk.DigiDocServicePortTypeClient } // enter __ClientBase Channel { xType = JVMCLRWSDLMID.sk.DigiDocServicePortTypeClient, xTypeBase = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1, xMe = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1 } // enter __ClientBase Channel { xType = JVMCLRWSDLMID.sk.DigiDocServicePortTypeClient, xTypeBase = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1, xMe = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1, xTypeInterface = JVMCLRWSDLMID.sk.DigiDocServicePortType } // magic. we just inferred what TChannel is! var xTypeInterface = xType.GetInterfaces().FirstOrDefault(); //Y:\staging\web\java\ScriptCoreLibJava\BCLImplementation\System\ServiceModel\__ClientBaseGetChannel.java:57: error: illegal generic type for instanceof // base_14 = ((((Object)that) instanceof ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1<Object>) ? (ScriptCoreLibJava.BCLI //var xClientBase = that as __ClientBase<object>; var xClientBase = that as __ClientBase__remoteAddress; // , xClientBase = __ClientBase { __remoteAddress = https://tsp.demo.sk.ee:443 } } Console.WriteLine("enter __ClientBase Channel " + new { xType, xTypeBase, xMe, xTypeInterface, xClientBase }); // return __ClientBase_1<TChannel>._get_Channel_b__1(proxy, method, args); var invocationHandler = new xHandler { vinvoke = (proxy, method, args) => { // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201510/20151005 var xMethod = new __MethodInfo { InternalMethod = method }; // at ScriptCoreLib.Shared.BCLImplementation.System.Linq.__Enumerable.FirstOrDefault(__Enumerable.java:2016) var arg1 = xMethod.GetParameters().FirstOrDefault(); var arg1value = args.FirstOrDefault(); var arg1valueType = args.FirstOrDefault().GetType(); //Console.WriteLine("enter Proxy invocationHandler " + new { method = method.getName() }); //Console.WriteLine("enter Proxy invocationHandler " + new { xMethod.Name, xMethod.ReturnType, proxy, args }); Console.WriteLine("enter Proxy invocationHandler " + new { xMethod.Name, xMethod.ReturnType, arg1, arg1value, arg1valueType }); // which wsdl is in use? var xMessageContractAttribute = default(__MessageContractAttribute); foreach (var xCustomAttribute in arg1valueType.GetCustomAttributes(false)) { var locMessageContractAttribute = xCustomAttribute as __MessageContractAttribute; if (locMessageContractAttribute != null) { xMessageContractAttribute = locMessageContractAttribute; Console.WriteLine(new { xMessageContractAttribute.WrapperName, xMessageContractAttribute.WrapperNamespace }); } } #region Envelope var data = new StringBuilder(); data.Append(@"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">"); data.Append(@"<s:Body s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">"); data.Append(@"<q1:" + xMessageContractAttribute.WrapperName + @" xmlns:q1=""" + xMessageContractAttribute.WrapperNamespace + @""">"); // <q1:MobileAuthenticate xmlns:q1=""http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl""> foreach (var field in arg1valueType.GetFields()) { var fieldvalue = field.GetValue(arg1value); Console.WriteLine(new { field.Name, field.FieldType, fieldvalue }); //var x = new XElement(field.Name, fieldvalue).ToString(); var x = new XElement(field.Name, "" + fieldvalue).ToString(); if (field.FieldType == typeof(string)) { x = x.Replace(@"<" + field.Name, @"<" + field.Name + @" xsi:type=""xsd:string"""); } else if (field.FieldType == typeof(int)) { x = x.Replace(@"<" + field.Name, @"<" + field.Name + @" xsi:type=""xsd:int"""); } else if (field.FieldType == typeof(bool)) { x = x.Replace(@"<" + field.Name, @"<" + field.Name + @" xsi:type=""xsd:boolean"""); } data.Append(x); } data.Append(@"</q1:" + xMessageContractAttribute.WrapperName + @">"); data.Append(@"</s:Body>"); data.Append(@"</s:Envelope>"); #endregion // <s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> // <q1:MobileAuthenticate xmlns:q1=""http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl""> // <IDCode xsi:type=""xsd:string"">14212128025</IDCode> // <CountryCode xsi:type=""xsd:string"">EE</CountryCode> // <PhoneNo xsi:type=""xsd:string"">37200007</PhoneNo> // <Language xsi:type=""xsd:string"">EST</Language> // <ServiceName xsi:type=""xsd:string"">Testimine</ServiceName> // <MessageToDisplay xsi:type=""xsd:string"">Testimine</MessageToDisplay> // <SPChallenge xsi:type=""xsd:string"">03010400000000000000</SPChallenge> // <MessagingMode xsi:type=""xsd:string"">asynchClientServer</MessagingMode> // <AsyncConfiguration xsi:type=""xsd:int"">0</AsyncConfiguration> // <ReturnCertData xsi:type=""xsd:boolean"">true</ReturnCertData> //<ReturnRevocationData xsi:type=""xsd:boolean"">false</ReturnRevocationData> // </q1:MobileAuthenticate> // </s:Body></s:Envelope> Console.WriteLine(new { data }); //{ WrapperName = MobileAuthenticate, WrapperNamespace = http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl } //{ Name = IDCode, fieldvalue = 14212128025 } //{ Name = CountryCode, fieldvalue = EE } //{ Name = PhoneNo, fieldvalue = 37200007 } //{ Name = Language, fieldvalue = EST } //{ Name = ServiceName, fieldvalue = Testimine } //{ Name = MessageToDisplay, fieldvalue = Testimine } //{ Name = SPChallenge, fieldvalue = 03010400000000000000 } //{ Name = MessagingMode, fieldvalue = asynchClientServer } //{ Name = AsyncConfiguration, fieldvalue = 0 } //{ Name = ReturnCertData, fieldvalue = true } //{ Name = ReturnRevocationData, fieldvalue = false } // arg1 = ScriptCoreLibJava.BCLImplementation.System.Reflection.__ParameterInfo@1bb9a58, args = [Ljava.lang.Object;@1922f46 } // enter Proxy invocationHandler { Name = JVMCLRWSDLMID_sk_DigiDocServicePortType_MobileAuthenticateAsync, ReturnType = ScriptCoreLibJava.BCLImplementation.System.Threading.Tasks.__Task_1, // arg1 = ParameterInfo { Name = arg0, ParameterType = JVMCLRWSDLMID.sk.MobileAuthenticateRequest }, arg1value = JVMCLRWSDLMID.sk.MobileAuthenticateRequest@770d2e } // JVMCLRWSDLMID.sk.MobileAuthenticateRequest //System.Threading.Tasks.Task<JVMCLRWSDLMID.sk.MobileAuthenticateResponse> MobileAuthenticateAsync(JVMCLRWSDLMID.sk.MobileAuthenticateRequest request); var xResponseTypeName = arg1.ParameterType.FullName.Replace("Request", "Response"); var xResponseType = Type.GetType(xResponseTypeName); Console.WriteLine(new { xResponseType }); // { xResponseType = JVMCLRWSDLMID.sk.MobileAuthenticateResponse } // lets assume this was async call and we also know what the response will be. var c = new TaskCompletionSource <object>(); var xPOST = new __WebClient(); xPOST.Headers["Content-Type"] = "text/xml; charset=UTF-8"; xPOST.Headers["SOAPAction"] = "\"\""; var xPOSTresponse = xPOST.UploadStringTaskAsync( xClientBase.__remoteAddress.uri, "POST", data.ToString() ); xPOSTresponse.ContinueWith( task => { if (string.IsNullOrEmpty(task.Result)) { // fault? c.SetResult( null ); return; } var Envelope = XElement.Parse(task.Result); var Body = Envelope.Elements().Skip(1).FirstOrDefault(); var Response = Body.Elements().FirstOrDefault(); var fields = Response.Elements(); var Result = Activator.CreateInstance(xResponseType); var ResultFields = xResponseType.GetFields( global::System.Reflection.BindingFlags.DeclaredOnly | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Public); foreach (var ResultField in ResultFields) { var ResultValueElement = fields.FirstOrDefault(x => x.Name.LocalName == ResultField.Name); if (ResultValueElement == null) { Console.WriteLine(new { ResultField.Name, ResultField.FieldType }); } else { // { Name = Sesscode, FieldType = int, IsInt = false, Value = 158266114 } var IsInt = ResultField.FieldType == typeof(int); if (IsInt) { ResultField.SetValue(Result, int.Parse(ResultValueElement.Value)); } else if (ResultField.FieldType == typeof(string)) { ResultField.SetValue(Result, ResultValueElement.Value); } Console.WriteLine(new { ResultField.Name, ResultField.FieldType, IsInt, ResultValueElement.Value }); } } c.SetResult( Result ); } ); // enter Proxy invocationHandler { method = JVMCLRWSDLMID_sk_DigiDocServicePortType_MobileAuthenticateAsync } //{ Message = , StackTrace = java.lang.NullPointerException // at JVMCLRWSDLMID.Program.main(Program.java:55) // enter Proxy invocationHandler { Name = JVMCLRWSDLMID_sk_DigiDocServicePortType_MobileAuthenticateAsync, ReturnType = ScriptCoreLibJava.BCLImplementation.System.Threading.Tasks.__Task_1 } // task of what? //var value = Activator.CreateInstance(xMethod.ReturnType); return(c.Task); //return null; } }; // how would this work from js? var p = java.lang.reflect.Proxy.newProxyInstance( xTypeInterface.ToClass().getClassLoader(), interfaces: new[] { xTypeInterface.ToClass() }, invocationHandler: invocationHandler ); return(p); }
public static bool InternalWorkerInvoke(Sprite that) { // pop ? if (Worker.current.isPrimordial) { InternalPrimordialSprite = that; return(false); } // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs InternalWorkerSprite = that; if (__Task.InternalWorkerInvoke(that)) { // X:\jsc.svn\examples\actionscript\async\Test\TestAsyncTaskRun\TestAsyncTaskRun\ApplicationSprite.cs // Task.Run called itself return(true); } #region xfromWorkerConsole // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs var xfromWorkerConsole = (MessageChannel)Worker.current.getSharedProperty("fromWorkerConsole"); var w = new __Console.__OutWriter { AtWriteLine = z => { xfromWorkerConsole.send(z); } }; Console.SetOut(w); #endregion // X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\ApplicationSprite.cs // are we inside worker? var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName"); var FunctionToken_MethodName = (string)Worker.current.getSharedProperty("FunctionToken_MethodName"); var arg0 = (string)Worker.current.getSharedProperty("arg0"); IntPtr pp = __IntPtr.OfFunctionToken(null, FunctionToken_TypeFullName, FunctionToken_MethodName ); MethodInfo mm = new __MethodInfo { _Method = pp }; // t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds }; //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName }); //throw null; try { mm.Invoke(null, new object[] { arg0 }); } catch (Exception err) { // lets report anything back to the app // for now the best we can do is to print it to console in worker // and hope the app is showing the console in textfield //__Thread.InternalWorkerSprite.loaderInfo.uncaughtErrorEvents.uncaughtError += // does not seem to work yet? Console.WriteLine("catch " + new { err }); // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs } return(true); }
public static bool InternalWorkerInvoke(Sprite that) { var magic = (string)Worker.current.getSharedProperty("InternalWorkerInvoke"); if (magic != "Run(Func<Task<TResult>>)") { return(false); } #region xfromWorkerConsole // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs var xfromWorkerConsole = (MessageChannel)Worker.current.getSharedProperty("fromWorkerConsole"); var w = new __Console.__OutWriter { AtWriteLine = z => { xfromWorkerConsole.send(z); } }; Console.SetOut(w); #endregion var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName"); var FunctionToken_MethodName = (string)Worker.current.getSharedProperty("FunctionToken_MethodName"); IntPtr pp = __IntPtr.OfFunctionToken(null, FunctionToken_TypeFullName, FunctionToken_MethodName ); MethodInfo mm = new __MethodInfo { _Method = pp }; // t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds }; //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName }); //throw null; // we are on a worker thread. // are we able to await and then respond and terminate? var value = (Task <object>)mm.Invoke(null, new object[] { }); value.ContinueWith( task => { // is the return type transerable? // or would we have to serialize it? var xfromWorker = (MessageChannel)Worker.current.getSharedProperty("fromWorker"); // or are we to capture all fields modified within worker and only update those? xfromWorker.send(task.Result); } ); return(true); }
// X:\jsc.svn\examples\c\Test\TestThreadStart\TestThreadStart\BCLImplementation.cs // X:\jsc.svn\examples\actionscript\async\Test\TestAsyncTaskRun\TestAsyncTaskRun\ApplicationSprite.cs // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs //!! tell jsc we do ExpectScopeSharing so we would know how to sync scope fields public static Task <TResult> Run <TResult>(Func <Task <TResult> > function) { // what about nested workers? // when will we get scope sharing, two way sharing? // will we be able to also Transfer TaskCompletionSource and Progress types? if (function.Target != null) { throw new NotImplementedException("for now AIR supports only static thread starts.."); } var s = new TaskCompletionSource <TResult>(); // X:\jsc.svn\core\ScriptCoreLib\ActionScript\BCLImplementation\System\Threading\Thread.cs // each worker is a vm. we could pool them and reuse them later? var w = WorkerDomain.current.createWorker( __Thread.InternalPrimordialSprite.loaderInfo.bytes ); __MethodInfo m = function.Method; // or should we use typeof().Name ? nameof()? w.setSharedProperty("InternalWorkerInvoke", "Run(Func<Task<TResult>>)"); w.setSharedProperty("FunctionToken_TypeFullName", m._Method.FunctionToken_TypeFullName); w.setSharedProperty("FunctionToken_MethodName", m._Method.FunctionToken_MethodName); //w.setSharedProperty("arg0", e); //if (InternalBeforeStart != null) // InternalBeforeStart(w); // X:\jsc.svn\examples\actionscript\Test\TestThreadStartInternalWorkerInvoke\TestThreadStartInternalWorkerInvoke\ApplicationSprite.cs #region fromWorkerConsole var fromWorkerConsole = w.createMessageChannel(Worker.current); w.setSharedProperty("fromWorkerConsole", fromWorkerConsole); fromWorkerConsole.channelMessage += e => { var data = (string)fromWorkerConsole.receive(); // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs Console.WriteLine(data); }; #endregion var fromWorker = w.createMessageChannel(Worker.current); w.setSharedProperty("fromWorker", fromWorker); fromWorker.channelMessage += e => { var data = (TResult)fromWorker.receive(); s.SetResult(data); }; w.start(); return(s.Task); }
public static bool InternalWorkerInvoke(Sprite that) { // pop ? if (Worker.current.isPrimordial) { InternalPrimordialSprite = that; return false; } // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs InternalWorkerSprite = that; if (__Task.InternalWorkerInvoke(that)) { // X:\jsc.svn\examples\actionscript\async\Test\TestAsyncTaskRun\TestAsyncTaskRun\ApplicationSprite.cs // Task.Run called itself return true; } #region xfromWorkerConsole // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs var xfromWorkerConsole = (MessageChannel)Worker.current.getSharedProperty("fromWorkerConsole"); var w = new __Console.__OutWriter { AtWriteLine = z => { xfromWorkerConsole.send(z); } }; Console.SetOut(w); #endregion // X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\ApplicationSprite.cs // are we inside worker? var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName"); var FunctionToken_MethodName = (string)Worker.current.getSharedProperty("FunctionToken_MethodName"); var arg0 = (string)Worker.current.getSharedProperty("arg0"); IntPtr pp = __IntPtr.OfFunctionToken(null, FunctionToken_TypeFullName, FunctionToken_MethodName ); MethodInfo mm = new __MethodInfo { _Method = pp }; // t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds }; //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName }); //throw null; try { mm.Invoke(null, new object[] { arg0 }); } catch (Exception err) { // lets report anything back to the app // for now the best we can do is to print it to console in worker // and hope the app is showing the console in textfield //__Thread.InternalWorkerSprite.loaderInfo.uncaughtErrorEvents.uncaughtError += // does not seem to work yet? Console.WriteLine("catch " + new { err }); // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs } return true; }