Exemplo n.º 1
0
            public static void Fill(Topic t, JSValue state, JSValue manifest, Topic prim)
            {
                t._manifest = (manifest == null || manifest.IsNull)?JSObject.CreateObject():manifest;
                if (!t._manifest["attr"].IsNumber)
                {
                    t._manifest = JsLib.SetField(t._manifest, "attr", new JST.Number(0));
                }

                var c = Perform.Create(t, Perform.Art.create, prim);

                _repo.DoCmd(c, false);

                if (state != null)
                {
                    SetValue(t, state);
                }
            }
Exemplo n.º 2
0
            public override void SetLocation(Vector loc, bool save)
            {
                int topCell = (int)(loc.Y / CELL_SIZE + 0.5);

                if (topCell < 0)
                {
                    topCell = 0;
                }
                int leftCell = (int)(loc.X / CELL_SIZE);

                if (leftCell < 0)
                {
                    leftCell = 0;
                }

                if (save)
                {
                    var lo = JsLib.GetField(model.Manifest, "Logram");
                    int xo, yo;
                    xo = JsLib.OfInt(JsLib.GetField(lo, "left"), 0);
                    yo = JsLib.OfInt(JsLib.GetField(lo, "top"), 0);

                    if (xo == leftCell && yo == topCell) // refresh wires
                    {
                        this.Dispatcher.BeginInvoke(new Action <int>(this.Render), System.Windows.Threading.DispatcherPriority.DataBind, 3);
                    }
                    else
                    {
                        lo = JsLib.SetField(lo, "top", topCell);
                        lo = JsLib.SetField(lo, "left", leftCell);
                        model.SetField("Logram", lo);
                    }
                }
                else
                {
                    this.Offset = new Vector(leftCell * CELL_SIZE, (topCell - 0.5) * CELL_SIZE);
                    foreach (var p in _pins)
                    {
                        p.Render(2);
                    }
                }
            }
Exemplo n.º 3
0
            public static bool SetField(Perform cmd)
            {
                Topic   t = cmd.src;
                bool    r;
                JSValue oc;

                if (t._mfst_pu == null)
                {
                    r          = true;
                    oc         = t._manifest ?? JSValue.Null;
                    t._mfst_pu = cmd;
                }
                else
                {
                    r  = false;
                    oc = t._mfst_pu.f_v;
                    if (cmd.prim != t._mfst_pu.prim)
                    {
                        t._mfst_pu.prim = null; // inform all subscribers
                    }
                }
                t._mfst_pu.f_v = JsLib.SetField(oc, cmd.o as string, cmd.f_v);
                return(r);
            }
Exemplo n.º 4
0
        private static void Import(XElement xElement, Topic owner, string path)
        {
            if (xElement == null || ((xElement.Attribute("n") == null || owner == null) && path == null))
            {
                return;
            }
            Version ver;
            Topic   cur = null;
            bool    setVersion;

            if (xElement.Attribute("ver") != null && Version.TryParse(xElement.Attribute("ver").Value, out ver))
            {
                if (owner == null ? Topic.root.Exist(path, out cur) : owner.Exist(xElement.Attribute("n").Value, out cur))
                {
                    Version oldVer;
                    var     ov_js = cur.GetField("version");
                    string  ov_s;
                    if (ov_js.ValueType == JSValueType.String && (ov_s = ov_js.Value as string) != null && ov_s.StartsWith("¤VR") && Version.TryParse(ov_s.Substring(3), out oldVer) && oldVer >= ver)
                    {
                        return; // don't import older version
                    }
                }
                setVersion = true;
            }
            else
            {
                ver        = default(Version);
                setVersion = false;
            }
            JSValue state = null, manifest = null;

            if (xElement.Attribute("m") != null)
            {
                try {
                    manifest = JsLib.ParseJson(xElement.Attribute("m").Value);
                }
                catch (Exception ex) {
                    Log.Warning("Import({0}).m - {1}", xElement.ToString(), ex.Message);
                }
            }
            if (setVersion)
            {
                manifest = JsLib.SetField(manifest, "version", "¤VR" + ver.ToString());
            }

            if (xElement.Attribute("s") != null)
            {
                try {
                    state = JsLib.ParseJson(xElement.Attribute("s").Value);
                }
                catch (Exception ex) {
                    Log.Warning("Import({0}).s - {1}", xElement.ToString(), ex.Message);
                }
            }


            if (owner == null)
            {
                cur = Topic.I.Get(Topic.root, path, true, null, false, false);
            }
            else
            {
                cur = Topic.I.Get(owner, xElement.Attribute("n").Value, true, null, false, false);
            }
            Topic.I.Fill(cur, state, manifest, null);
            foreach (var xNext in xElement.Elements("i"))
            {
                Import(xNext, cur, null);
            }
        }
Exemplo n.º 5
0
        private void FillContextMenu(DTopic owner, ObservableCollection <Control> l, Dictionary <string, JSC.JSValue> _acts)
        {
            JSC.JSValue v2;
            MenuItem    mi;
            MenuItem    ma = new MenuItem()
            {
                Header = "Add"
            };

            if (_acts != null)
            {
                List <RcUse> resource = new List <RcUse>();
                string       rName;
                JSC.JSValue  tmp1;
                KeyValuePair <string, JSC.JSValue> rca;
                string rcs;
                // fill used resources
                if (owner.children != null)
                {
                    foreach (var ch in owner.children)
                    {
                        if ((tmp1 = JsLib.GetField(ch.Manifest, "MQTT-SN.tag")).ValueType != JSC.JSValueType.String || string.IsNullOrEmpty(rName = tmp1.Value as string))
                        {
                            rName = ch.name;
                        }
                        rca = _acts.FirstOrDefault(z => z.Key == rName);
                        if (rca.Value == null || (tmp1 = rca.Value["rc"]).ValueType != JSC.JSValueType.String || string.IsNullOrEmpty(rcs = tmp1.Value as string))
                        {
                            continue;
                        }
                        foreach (string curRC in rcs.Split(',').Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 1))
                        {
                            int pos;
                            if (!int.TryParse(curRC.Substring(1), out pos))
                            {
                                continue;
                            }
                            for (int i = pos - resource.Count; i >= 0; i--)
                            {
                                resource.Add(RcUse.None);
                            }
                            if (curRC[0] != (char)RcUse.None && (curRC[0] != (char)RcUse.Shared || resource[pos] != RcUse.None))
                            {
                                resource[pos] = (RcUse)curRC[0];
                            }
                        }
                    }
                }
                // Add menuitems
                foreach (var kv in _acts)
                {
                    if ((bool)kv.Value["willful"])
                    {
                        continue;
                    }
                    bool busy = false;
                    if ((tmp1 = kv.Value["rc"]).ValueType == JSC.JSValueType.String && !string.IsNullOrEmpty(rcs = tmp1.Value as string)) // check used resources
                    {
                        foreach (string curRC in rcs.Split(',').Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 1))
                        {
                            int pos;
                            if (!int.TryParse(curRC.Substring(1), out pos))
                            {
                                continue;
                            }
                            if (pos < resource.Count && ((curRC[0] == (char)RcUse.Exclusive && resource[pos] != RcUse.None) || (curRC[0] == (char)RcUse.Shared && resource[pos] != RcUse.None && resource[pos] != RcUse.Shared)))
                            {
                                busy = true;
                                break;
                            }
                        }
                    }
                    if (busy)
                    {
                        continue;
                    }
                    mi = new MenuItem()
                    {
                        Header = kv.Key.Replace("_", "__"), Tag = JsLib.SetField(kv.Value, "mi_path", owner.name + "/" + kv.Key)
                    };
                    if ((v2 = kv.Value["icon"]).ValueType == JSC.JSValueType.String)
                    {
                        mi.Icon = new Image()
                        {
                            Source = App.GetIcon(v2.Value as string), Height = 16, Width = 16
                        };
                    }
                    else
                    {
                        mi.Icon = new Image()
                        {
                            Source = App.GetIcon(kv.Key), Height = 16, Width = 16
                        };
                    }
                    if ((v2 = kv.Value["hint"]).ValueType == JSC.JSValueType.String)
                    {
                        mi.ToolTip = v2.Value;
                    }
                    mi.Click += miAdd_Click;
                    if ((v2 = kv.Value["menu"]).ValueType == JSC.JSValueType.String && kv.Value.Value != null)
                    {
                        AddSubMenu(ma, v2.Value as string, mi);
                    }
                    else
                    {
                        ma.Items.Add(mi);
                    }
                }
            }
            if (ma.HasItems)
            {
                if (ma.Items.Count < 5)
                {
                    foreach (var sm in ma.Items.OfType <System.Windows.Controls.Control>())
                    {
                        l.Add(sm);
                    }
                }
                else
                {
                    l.Add(ma);
                }
                l.Add(new Separator());
            }
            //if((v2 = owner.Manifest["Action"]).ValueType == JSC.JSValueType.Object) {
            //  FillActions(l, v2);
            //}
            //Uri uri;
            //if(System.Windows.Clipboard.ContainsText(System.Windows.TextDataFormat.Text)
            //  && Uri.TryCreate(System.Windows.Clipboard.GetText(System.Windows.TextDataFormat.Text), UriKind.Absolute, out uri)
            //  && _owner.Connection.server == uri.DnsSafeHost) {
            //  mi = new MenuItem() { Header = "Paste", Icon = new Image() { Source = App.GetIcon("component/Images/Edit_Paste.png"), Width = 16, Height = 16 } };
            //  mi.Click += miPaste_Click;
            //  l.Add(mi);
            //}
            //mi = new MenuItem() { Header = "Cut", Icon = new Image() { Source = App.GetIcon("component/Images/Edit_Cut.png"), Width = 16, Height = 16 } };
            //mi.IsEnabled = !IsGroupHeader && !IsRequired;
            //mi.Click += miCut_Click;
            //l.Add(mi);
            mi = new MenuItem()
            {
                Header = "Delete", Icon = new Image()
                {
                    Source = App.GetIcon("component/Images/Edit_Delete.png"), Width = 16, Height = 16
                }, Tag = owner
            };
            mi.Click    += miDelete_Click;
            mi.IsEnabled = (owner.Manifest == null || (JsLib.OfInt(owner.Manifest["attr"], 0) & 1) != 1);
            l.Add(mi);
        }
Exemplo n.º 6
0
        private void LogramView_Drop(object sender, DragEventArgs e)
        {
            var pos = e.GetPosition(this);
            int y   = (int)(pos.Y / CELL_SIZE + 0.5);

            if (y < 0)
            {
                y = 0;
            }
            int x = (int)(pos.X / CELL_SIZE);

            if (x < 0)
            {
                x = 0;
            }
            DTopic t;

            if (e.Data.GetDataPresent(typeof(DTopic)) && (t = e.Data.GetData(typeof(DTopic)) as DTopic) != null)
            {
                if (JsLib.OfString(JsLib.GetField(t.Manifest, "type"), null) == "Ext/LBDescr")
                {
                    if (t.State.ValueType == JSC.JSValueType.Object && t.State.Value != null)
                    {
                        string name;
                        string prefix = JsLib.OfString(t.State["namePrefix"], "U");
                        if (Model.children != null)
                        {
                            int i = 1;
                            do
                            {
                                name = prefix + i.ToString("D02");
                                i++;
                            } while(Model.children.Any(z => z.name == name));
                        }
                        else
                        {
                            name = prefix + "01";
                        }
                        Model.CreateAsync(name, t.State["default"], JsLib.SetField(JsLib.SetField(t.State["manifest"], "Logram.top", y), "Logram.left", x));
                    }
                }
                else if ((e.AllowedEffects & DragDropEffects.Link) == DragDropEffects.Link)
                {
                    string name = t.name;
                    if (Model.children != null && Model.children.Any(z => z.name == name))
                    {
                        if (t.parent == null || (name = t.parent.name + "_" + t.name) == null || Model.children.Any(z => z.name == name))
                        {
                            int i = 1;
                            do
                            {
                                name = string.Format("{0}_{1}", t.name, i);
                                i++;
                            } while(Model.children.Any(z => z.name == name));
                        }
                    }
                    var m  = JSC.JSObject.CreateObject();
                    var ml = JSC.JSObject.CreateObject();
                    ml["top"]   = y;
                    ml["left"]  = x;
                    m["Logram"] = ml;
                    var mc = JSC.JSObject.CreateObject();
                    mc["LoBind"] = t.path;
                    m["cctor"]   = mc;
                    m["attr"]    = 0;
                    Model.CreateAsync(name, t.State, m);
                    if (string.IsNullOrEmpty(JsLib.OfString(JsLib.GetField(t.Manifest, "cctor.LoBind"), null)))
                    {
                        t.SetField("cctor.LoBind", Model.path + "/" + name);
                    }
                }
            }
        }