private async void execLater(int ms, Func0 cb) { if (!runtime.IsRunning) { return; } if (ms < 10) { await Task.Yield(); } else { await Task.Delay(ms); } if (!runtime.IsRunning) { return; } using (var ctx = new FlowRuntime.DeferredContext(runtime)) { cb(); } }
public override Object loadSound(String url, Func1 onfail, Func0 onok) { var obj = new Sound(this, new Uri(base_url, url)); obj.startLoad(onfail, onok); return(obj); }
static DeserializerDelegate RetrieveDeserializer2_IList(Type type, Type ga0) { Func0 create = Accelerator.CreateStandardConstructor(type); MethodInfo m = type.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, new Type[] { ga0 }, null); if (m == null) { throw new InvalidOperationException(); } Action2 a = Accelerator.CreateAction2(m); return((JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) => { if (tokenizer.BeginReadArray()) { object list = create(); deserializer.DeserializeCollection(tokenizer, ga0, x => a(list, x)); value = list; return true; } else { value = null; return false; } }); }
public void TestCreateConstructor1() { Func0 create = Accelerator.CreateStandardConstructor(typeof(int)); Assert.IsNotNull(create); Assert.IsTrue(create() is int); }
private async void doPreload(String url, Func0 onSuccess, Func1 onError) { try { await media.getCachedObjectAsync(new Uri(base_url, url.TrimStart('/'))); if (!runtime.IsRunning) { return; } using (var ctx = new FlowRuntime.DeferredContext(runtime)) { onSuccess(); } } catch (Exception e) { if (!runtime.IsRunning) { return; } using (var ctx = new FlowRuntime.DeferredContext(runtime)) { onError(e.ToString()); } } }
private void SuspendHandleThenInvoke(Func0 func) { this.m_handleSuspending = true; this.dgvProcessors.SuspendLayout(); func(); this.dgvProcessors.ResumeLayout(); this.m_handleSuspending = false; }
public void TestCreateConstructor2() { Func0 create = Accelerator.CreateStandardConstructor(typeof(int[])); Assert.IsNotNull(create); int[] a = (int[])create(); Assert.AreEqual(0, a.Length); }
public void TestCreateConstructor3() { Assert.IsNotNull(default(ExampleStruct1)); Func0 create = Accelerator.CreateStandardConstructor(typeof(ExampleStruct1)); Assert.IsNotNull(create); Assert.IsTrue(create() is ExampleStruct1); }
public override Object playSoundFrom(Object snd, double pos, Func0 donecb) { var sound = (Sound)snd; var channel = new SoundChannel(sound, donecb); channel.start_at = pos; channel.play(); return(channel); }
public override Object playSound(Object snd, bool loop, Func0 donecb) { var sound = (Sound)snd; var channel = new SoundChannel(sound, donecb); channel.element.IsLooping = loop; channel.play(); return(channel); }
public override object timer(int ms, Func0 cb) { if (ms < 10 && runtime.queueDeferred(cb)) { return(null); } execLater(ms, cb); return(null); }
public void TestCreateStaticGetter3() { string n = nameof(ClassWithStaticFields.StaticEnumField); Func0 getValue = typeof(ClassWithStaticFields).CreateStaticGetter(n); ClassWithStaticFields.StaticEnumField = EnumForTest.Example; Assert.AreEqual(EnumForTest.Example, getValue()); ClassWithStaticFields.StaticEnumField = EnumForTest.None; Assert.AreEqual(EnumForTest.None, getValue()); }
public void TestCreateStaticGetter1() { string n = nameof(ClassWithStaticFields.StaticValueField); Func0 getValue = typeof(ClassWithStaticFields).CreateStaticGetter(n); ClassWithStaticFields.StaticValueField = 123; Assert.AreEqual(123, getValue()); ClassWithStaticFields.StaticValueField = 0; Assert.AreEqual(0, getValue()); }
public void TestCreateStaticGetter2() { string n = nameof(ClassWithStaticFields.StaticTextField); Func0 getValue = typeof(ClassWithStaticFields).CreateStaticGetter(n); ClassWithStaticFields.StaticTextField = "ABC"; Assert.AreEqual("ABC", getValue()); ClassWithStaticFields.StaticTextField = null; Assert.AreEqual(null, getValue()); }
public bool queueDeferred(Func0 cb) { if (deferred_depth <= 0) { return(false); } if (is_running) { deferred_queue.Add(cb); } return(true); }
public SoundChannel(Sound sound, Func0 donecb) { this.sound = sound; this.donecb = donecb; element = new MediaElement(); //element.Visibility = Windows.UI.Xaml.Visibility.Collapsed; element.MediaOpened += element_MediaOpened; element.MediaFailed += element_MediaFailed; element.MediaEnded += element_MediaEnded; sound.owner.container.Children.Add(element); }
public override Func0 uploadFile(String url, Object[] param, Object[] header, Object[] fileTypes, Func0 onOpen, Func2 onSelect, Func1 onData, Func1 onError, Func2 onProgress, Func0 onCancel) { // TODO Debug.WriteLine("uploadFile not implemented"); return(no_op); }
public async void startLoad(Func1 onfail, Func0 onok) { try { // Download to cache cached = await owner.cache.getCachedObjectAsync(link); if (!owner.runtime.IsRunning) { return; } // Compute length var length_str = await owner.cache.getCachedMetadataAsync(link, "sound_length", computeLength); if (!owner.runtime.IsRunning) { return; } if (!Double.TryParse(length_str, out length)) { Debug.WriteLine("Bad sound length metadata: " + length_str); } // Play auto-play channels if (pending != null) { foreach (var c in pending) { c.play(); } pending = null; } onok(); } catch (Exception e) { onfail(e.ToString()); } }
//private Timer timer_obj = null; //public void invokeCallback(Runnable cb) { // cb.run(); //} public virtual Object timer(int ms, Func0 cb) { /*if (timer_obj == null) * timer_obj = new Timer(true); * * TimerTask task = new TimerTask() { * public void run() { * invokeCallback(new Runnable() { * public void run() { * synchronized (runtime) { * cb.invoke(); * } * } * }); * } * }; * timer_obj.schedule(task, ms);*/ return(null); }
public override Func0 hostAddCallback(String name, Func0 cb) { PlatformEvent cur; if (!platform_events.TryGetValue(name, out cur)) { cur = null; } PlatformEvent ecb = () => { try { cb(); } catch (Exception e) { Debug.WriteLine(e); } }; platform_events[name] = cur + ecb; return(() => { platform_events[name] -= ecb; return null; }); }
static DeserializerDelegate RetrieveDeserializer2_object(Type type) { Func0 create = Accelerator.CreateStandardConstructor(type); var cache = JsonTypeCache.Instance.RetrieveCacheEntry(type); return((JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) => { if (tokenizer.SpecialChar == '{') { value = create(); deserializer.DeserializeObject(tokenizer, value, cache); return true; } else { tokenizer.SkipValueBody(); value = null; return false; } }); }
public static MeasuringData[] CompareNewGuid_AcceleratorReflection() { Type type = typeof(Guid); Func0 create = Accelerator.CreateStandardConstructor(type); Action a1 = () => { for (int z = 0; z < c_RepetitionCount; z++) { create(); } }; Action a2 = () => { for (int z = 0; z < c_RepetitionCount; z++) { Activator.CreateInstance(type); } }; return(TestEnvironment.Measure(a1, a2)); }
public virtual Func0 hostAddCallback(String name, Func0 cb) { return(null); }
public virtual Func0 addPlatformEventListener(string name, Func0 cb) { return(no_op); }
public override Object preloadMediaUrl(String url, Func0 onSuccess, Func1 onError) { doPreload(url, onSuccess, onError); return(null); }
public virtual Func0 addEventListener(Object stg, String name, Func0 fn) { return(null); }
public Func0PipeFunction(Func0 fn) { this.fn = fn; }
/// <summary> /// Creates a pipe function that takes no arguments from pipe. /// </summary> /// <param name="fn">A delegate that encapsulates a method that match the signature of <see cref="Func0"/>.</param> /// <returns>The constructed pipe function that can be invoked with a given pipe context.</returns> public static PipeFunction Create(Func0 fn) { CommonHelper.ConfirmNotNull(fn, "fn"); return(new Func0PipeFunction(fn)); }
public void HandledBy(Func0 handler) { SetHandledBy(handler, 0, HandlerContextParam.None); }
public override Func0 addPlatformEventListener(string name, Func0 cb) { return(hostAddCallback(name, cb)); }
public virtual Object setAccessCallback(Object stg, Func0 fn) { return(null); }