Exemplo n.º 1
0
        public void Tick1()
        {
            if (_owner.disposed && !Disposed)
            {
                Disposed = true;
                foreach (var p in _pins.Where(z => z.Owner.parent != _owner))
                {
                    p.DeleteLink(this);
                }
                _pins.Clear();
                if (_ctx != null)
                {
                    JsExtLib.ClearTimeout(_ctx);
                }
                _ctx      = null;
                _self     = null;
                _calcFunc = null;
                return;
            }
            var ln = 0;

            foreach (var p in _pins.Where(z => z.Source != this && z.Layer > 0))
            {
                if (ln < p.Layer)
                {
                    ln = p.Layer;
                }
            }
            ln++;
            if (_layer != ln)
            {
                List <ILoItem> route = new List <ILoItem>();
                foreach (var p in _pins.Where(z => z.Source != this && z.Layer > 0))
                {
                    if (p.Route != null)
                    {
                        route.AddRange(p.Route);
                    }
                }
                route.Add(this);
                Route  = route.ToArray();
                _layer = ln;
                foreach (var p in _pins.Where(z => z.Source == this))
                {
                    _pl.EnqueueIn(p);
                }
                //Log.Debug(this.ToString());
            }
        }
Exemplo n.º 2
0
 static PiDeclarer() {
   ctor= new Module("function Construct(){ return Function.apply(null, arguments); }").Context.GetVariable("Construct").Value as JST.Function;
 }
Exemplo n.º 3
0
        public void ManifestChanged()
        {
            JSC.JSValue jSrc;
            var         jType = _owner.GetField("type");
            Topic       tt;

            if (jType.ValueType == JSC.JSValueType.String && jType.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(jType.Value as string, out tt) &&
                _typeT != tt && (jSrc = JsLib.GetField(tt.GetState(), "src")).ValueType == JSC.JSValueType.String)
            {
                _typeT = tt;
            }
            else
            {
                jSrc = null;
            }
            if (jSrc != null)
            {
                try {
                    _ctx = new JSC.Context(JsExtLib.Context);
                    _ctx.DefineVariable("setTimeout").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetTimeout)));
                    _ctx.DefineVariable("setInterval").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetInterval)));
                    _ctx.DefineVariable("setAlarm").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, JSC.JSValue, JSC.JSValue>(SetAlarm)));

                    var f = _ctx.Eval(jSrc.Value as string) as JSL.Function;
                    if (f != null)
                    {
                        if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly)
                        {
                            this._self = JSC.JSObject.create(new JSC.Arguments {
                                f.prototype
                            });
                        }
                        else
                        {
                            this._self = JSC.JSObject.CreateObject();
                        }
                        var cf = _self.GetProperty("Calculate");
                        _calcFunc = (cf as JSL.Function) ?? (cf.Value as JSL.Function);

                        _self["GetState"] = JSC.JSValue.Marshal(new Func <string, JSC.JSValue>(GetState));
                        _self["SetState"] = JSC.JSValue.Marshal(new Action <string, JSC.JSValue>(SetState));
                        _self["GetField"] = JSC.JSValue.Marshal(new Func <string, string, JSC.JSValue>(GetField));

                        if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly)
                        {
                            _self = f.Construct(_self, new JSC.Arguments());
                        }
                        else
                        {
                            f.Call(_self, new JSC.Arguments()); // Call constructor
                        }
                    }
                }
                catch (Exception ex) {
                    Log.Warning("{0}.ctor() - {1}", _owner.path, ex.Message);
                }
            }
            else
            {
                if (!_owner.disposed)
                {
                    Log.Warning("{0} constructor is not defined", _owner.path);
                }
            }
        }