public static void Export(string filename, Topic t, bool configOnly) { if (filename == null || t == null) { throw new ArgumentNullException(); } XDocument doc = new XDocument(new XElement("xst", new XAttribute("path", t.path))); doc.Declaration = new XDeclaration("1.0", "utf-8", "yes"); var s = t.GetState(); if (s.Exists && (t.CheckAttribute(Topic.Attribute.Saved, Topic.Attribute.Config) || (!configOnly && t.CheckAttribute(Topic.Attribute.Saved, Topic.Attribute.DB)))) { doc.Root.Add(new XAttribute("s", JsLib.Stringify(s))); } var m = t.GetField(null); doc.Root.Add(new XAttribute("m", JsLib.Stringify(m))); foreach (Topic c in t.children) { Export(doc.Root, c, configOnly); } using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(filename, Encoding.UTF8)) { writer.Formatting = System.Xml.Formatting.Indented; writer.QuoteChar = '\''; doc.WriteTo(writer); writer.Flush(); } }
private void Changed(Perform p, SubRec sr) { if (Client == null || Client.status != MqClient.Status.Connected) { Disconnected(); Log.Warning("{0}.Changed({1}) - Client OFFLINE", Owner.path, p.ToString()); return; } if ((p.art == Perform.Art.subscribe || ((p.art == Perform.Art.changedState || p.art == Perform.Art.create) && p.prim != Owner)) && !p.src.CheckAttribute(Topic.Attribute.Internal)) { var rp = remotePrefix + p.src.path.Substring(Owner.path.Length); var payload = JsLib.Stringify(p.src.GetState() ?? JSC.JSValue.Null); if (!string.IsNullOrEmpty(rp) && payload != null) { Client.Send(new MqPublish(rp, payload) { Retained = _retainedEn }); } } else if (p.art == Perform.Art.subAck && _subEn) { Client.Subscribe(this); } }
private static void Export(XElement x, Topic t, bool configOnly) { if (x == null || t == null) { return; } XElement xCur = new XElement("i", new XAttribute("n", t.name)); foreach (Topic c in t.children) { Export(xCur, c, configOnly); } if (!configOnly || xCur.HasElements || t.CheckAttribute(Topic.Attribute.Saved, Topic.Attribute.Config)) { var s = t.GetState(); if (s.Exists && (t.CheckAttribute(Topic.Attribute.Saved, Topic.Attribute.Config) || (!configOnly && t.CheckAttribute(Topic.Attribute.Saved, Topic.Attribute.DB)))) { var state_json = JsLib.Stringify(s); if (state_json != null) { xCur.Add(new XAttribute("s", state_json)); } } var m = t.GetField(null); var manifest_json = JsLib.Stringify(m); if (manifest_json != null) { xCur.Add(new XAttribute("m", manifest_json)); } x.Add(xCur); } }
private void WrapPanel_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { LBDesc tag; if (_selectedImage != null && (tag = _selectedImage.Tag as LBDesc) != null) { _readyToDrag = false; if (uiLogram.Model != null) { string name; string prefix = JsLib.OfString(tag.owner.State["namePrefix"], "U"); if (uiLogram.Model.children != null) { int i = 1; do { name = prefix + i.ToString("D02"); i++; } while(uiLogram.Model.children.Any(z => z.name == name)); } else { name = prefix + "01"; } uiLogram.Model.CreateAsync(name, tag.owner.State["default"], tag.owner.State["manifest"]); } _selectedImage = null; } }
private void ChildChanged(DTopic.Art a, DTopic t) { if (t.parent == _model) { if (JsLib.OfString(JsLib.GetField(t.Manifest, "cctor.LoBlock"), null) != null) { if (a == DTopic.Art.addChild) { var b = _visuals.OfType <loBlock>().FirstOrDefault(z => z.GetModel() == t); if (b == null) { loBlock.Create(t, this); } } } else { if (a == DTopic.Art.addChild) { var p = _visuals.OfType <loVariable>().FirstOrDefault(z => z.GetModel() == t); if (p == null) { loVariable.Create(t, this); TopicLoaded(t); } } } } }
public void SendArr(JST.Array arr, bool rep = true) { var ms = JsLib.Stringify(arr); int len = Encoding.UTF8.GetByteCount(ms); int st = 1; int tmp = len; while (tmp > 0x7F) { tmp = tmp >> 7; st++; } var buf = new byte[len + st + 2]; Encoding.UTF8.GetBytes(ms, 0, ms.Length, buf, st + 1); tmp = len; buf[0] = 0; for (int i = st; i > 0; i--) { buf[i] = (byte)((tmp & 0x7F) | (i < st ? 0x80 : 0)); tmp = tmp >> 7; } buf[buf.Length - 1] = 0xFF; if (this._socket.Connected) { this._stream.Write(buf, 0, buf.Length); if (verbose && rep) { Log.Debug("{0}.Send({1})", this.ToString(), ms); } } }
private void ModelChanged(DTopic.Art a, DTopic t) { if (t == _model) { if (a == DTopic.Art.type) { this.Width = JsLib.OfInt(JsLib.GetField(_model.Manifest, "Logram.width"), 32 * CELL_SIZE); this.Height = JsLib.OfInt(JsLib.GetField(_model.Manifest, "Logram.height"), 18 * CELL_SIZE); } } else if (t.parent == _model) { if (a == DTopic.Art.addChild) { t.GetAsync(null).ContinueWith(MChildrenLoad, TaskScheduler.FromCurrentSynchronizationContext()); } else if (a == DTopic.Art.RemoveChild) { foreach (var it in _visuals.OfType <loElement>().Where(z => z.GetModel() == t).ToArray()) { it.Dispose(); } } } }
public void SetValue(JSC.JSValue value, Topic prim) { if (!JsLib.Equal(_value, value)) { _value_new = value; _prim = prim; _pl.EnqueuePr(this); } }
private void SubChanged(Perform p, SubRec sr) { var vj = JsLib.Stringify(p.src.GetState()); Send(string.Concat("P\t", p.src.path, "\t", vj)); if (WebUI_Pl.verbose) { X13.Log.Debug("ws.snd({0}, {1})", p.src.path, vj); } }
private void miTrace_Click(object sender, RoutedEventArgs e) { DTopic t; var mi = sender as MenuItem; if (mi == null || (t = mi.Tag as DTopic) == null) { return; } bool ic = JsLib.ofBool(JsLib.GetField(t.Manifest, "Logram.trace"), false); t.SetField("Logram.trace", !ic); }
private void ExportI1(XElement x, bool isRoot = false) { XElement xCur = isRoot ? x : new XElement("i", new XAttribute("n", this.name)); var tmp = JsLib.GetField(this._manifest, "attr"); if (tmp.IsNumber && (((int)tmp) & 0x0C) != 0 && this._state.Exists) { xCur.Add(new XAttribute("s", JsLib.Stringify(this._state))); } tmp = JsLib.GetField(this._manifest, "version"); string vs; Version v; if (tmp.ValueType == JSC.JSValueType.String && !string.IsNullOrEmpty(vs = tmp.Value as string) && vs.StartsWith("¤VR") && Version.TryParse(vs.Substring(3), out v)) { tmp = JsLib.Clone(this._manifest); tmp.DeleteProperty("version"); xCur.Add(new XAttribute("m", JsLib.Stringify(tmp))); if (!isRoot) { xCur.Add(new XAttribute("ver", v.ToString())); } } else { xCur.Add(new XAttribute("m", JsLib.Stringify(this._manifest))); } if (isRoot) { var now = DateTime.Now; xCur.Add(new XAttribute("ver", (new Version(0, 4, (now.Year % 100) * 100 + now.Month, now.Day * 1000 + (int)(now.TimeOfDay.TotalDays * 1000)).ToString()))); } else { x.Add(xCur); } if (this._children != null) { var ch = this._children.ToArray(); for (int i = 0; i < ch.Length; i++) { var tt = ch[i].GetAsync(null); tt.Wait(); if (tt.IsCompleted && !tt.IsFaulted && tt.Result != null) { tt.Result.ExportI1(xCur); } } } }
internal static int ProcessPublish(string path, string json, Session ses) { Topic cur = Topic.root.Get(path, true, ses == null?null:ses.owner); if (string.IsNullOrEmpty(json) || json == "null") // Remove { cur.Remove(); } else { cur.SetState(JsLib.ParseJson(json), ses == null?null:ses.owner); } return(200); }
private void DeleteLI(loItem el) { loBinding b = el as loBinding; DTopic t; if (b != null && (t = b.Output.GetModel()) != null) { t.SetField("cctor.LoBind", null); } else if ((t = el.GetModel()) != null && (t.Manifest == null || (JsLib.OfInt(t.Manifest, "attr", 0) & 1) != 1)) { t.Delete(); } }
public ObservableCollection <Control> MenuItems(DTopic t, loItem ctrl) { var l = new ObservableCollection <Control>(); JSC.JSValue v1; MenuItem mi; mi = new MenuItem() { Header = "Open in new tab", Tag = t }; mi.Click += miOpen_Click; l.Add(mi); mi = new MenuItem() { Header = "Show in Workspace", Tag = t }; mi.Click += miShow_Click; l.Add(mi); l.Add(new Separator()); if (ctrl is loPin) { bool ic = JsLib.ofBool(JsLib.GetField(t.Manifest, "Logram.trace"), false); mi = new MenuItem() { Header = "Trace", Tag = t, IsCheckable = true, IsChecked = ic }; mi.Click += miTrace_Click; l.Add(mi); l.Add(new Separator()); } if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.Object) { var ad = new Dictionary <string, JSC.JSValue>(); Jso2Acts(v1, ad); FillContextMenu(t, l, ad); } else if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.String) { t.GetAsync(v1.Value as string).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext()); } else { t.Connection.CoreTypes.GetAsync(null).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext()); } return(l); }
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); } }
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); } } }
public void ManifestChanged() { string ss = JsLib.OfString(_owner.GetField("cctor.LoBind"), null); Topic st; LoVariable sv; if (ss != null && _owner.Exist(ss, out st)) { sv = _src as LoVariable; if (sv == null || sv._owner != st) { sv = _pl.GetVariable(st); } } else { sv = null; } Source = sv; }
private void Create(Topic parent, string path, JSC.JSValue state, JSC.JSValue manifest) { var t = Topic.I.Get(parent, path, true, _owner, false, false); Topic.I.Fill(t, state, manifest, _owner); JSC.JSValue typeS, typeV, ChL; Topic typeT; if (manifest != null && (typeS = manifest["type"]).ValueType == JSC.JSValueType.String && !string.IsNullOrWhiteSpace(typeS.Value as string) && Topic.root.Get("/$YS/TYPES").Exist(typeS.Value as string, out typeT) && (typeV = typeT.GetState()) != null && typeV.ValueType == JSC.JSValueType.Object && typeV.Value != null && (ChL = typeV["Children"]).ValueType == JSC.JSValueType.Object && ChL.Value != null) { foreach (var ch in ChL) { if ((JsLib.OfInt(JsLib.GetField(ch.Value, "manifest.attr"), 0) & (int)Topic.Attribute.Required) != 0) { Create(t, ch.Key, ch.Value["default"], ch.Value["manifest"]); } } } }
public LoVariable GetPin(Topic t) { LoVariable v; v = _pins.FirstOrDefault(z => z.Owner == t); if (v == null) { v = _pl.GetVariable(t); var ddr = _typeT != null?JsLib.OfInt(_typeT.GetState(), "Children." + t.name + ".ddr", 0) : 0; if (t.parent != _owner || ddr <= 0) { v.AddLink(this); } else { v.Source = this; } _pins.Add(v); } return(v); }
public void Publish(string path, string payload) { if (!_subEn) { return; } string lp = (path.Length > remotePrefix.Length) ? path.Substring(remotePrefix.Length + 1) : string.Empty; try { var o = JsLib.ParseJson(payload); var t = Owner.Get(lp, true, Owner); if (!t.CheckAttribute(Topic.Attribute.Internal)) { t.SetState(o, Owner); } } catch (Exception ex) { if (_pl.verbose) { Log.Warning("{0}{1} R {2} - {3}", Client, path, payload, ex.Message); } } }
public override void Render(int chLevel) { int x, y; y = JsLib.OfInt(JsLib.GetField(model.Manifest, "Logram.top"), 0); x = JsLib.OfInt(JsLib.GetField(model.Manifest, "Logram.left"), 0); double width = 0; base.OriginalLocation = new Vector(x * CELL_SIZE, (y - 0.5) * CELL_SIZE); this.Offset = OriginalLocation; using (DrawingContext dc = this.RenderOpen()) { FormattedText ft = new FormattedText(model.name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, LFont, CELL_SIZE * 0.7, Brushes.White); width = Math.Ceiling((ft.WidthIncludingTrailingWhitespace + 11) / CELL_SIZE) * CELL_SIZE; dc.DrawRoundedRectangle(_selected ? brItemSelected : brElementBody, null, new Rect(0, 1, width - 1, CELL_SIZE - 3), CELL_SIZE / 4, CELL_SIZE / 4); //-V3041 ft.MaxTextHeight = CELL_SIZE - 3; ft.MaxTextWidth = width - 11; dc.DrawText(ft, new Point(5, 1)); } if (chLevel == 3) { lv.MapRemove(this); for (int w = (int)(width / CELL_SIZE + 0.5); w >= 0; w--) { lv.MapSet(0, x + w, y, this); lv.MapSet(1, x + w, y, this); lv.MapSet(2, x + w, y, this); lv.MapSet(3, x + w, y, this); } } if (chLevel > 1) { Output.SetLocation(new Vector(width, CELL_SIZE / 2), chLevel); //-V3041 Input.SetLocation(new Vector(0, CELL_SIZE / 2), chLevel); //-V3041 } }
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); }
public override void Render(int chLevel) { int x, y; y = JsLib.OfInt(JsLib.GetField(model.Manifest, "Logram.top"), 0); x = JsLib.OfInt(JsLib.GetField(model.Manifest, "Logram.left"), 0); base.OriginalLocation = new Vector(x * CELL_SIZE, (y - 0.5) * CELL_SIZE); this.Offset = OriginalLocation; FormattedText head = new FormattedText(model.name, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.Black); FormattedText[] textIp = new FormattedText[MAX_PINS]; loPin[] pinIp = new loPin[MAX_PINS]; int cntIp = 0; FormattedText[] textOp = new FormattedText[MAX_PINS]; loPin[] pinOp = new loPin[MAX_PINS]; int cntOp = 0; int pos = 0; double wi = CELL_SIZE; double wo = CELL_SIZE; var chs = model.Manifest["Children"]; if (chs.ValueType != JSC.JSValueType.Object || chs.Value == null) { return; } foreach (var p in _pins) { var pd = chs[p.GetModel().name]; int ddr; if (pd.ValueType != JSC.JSValueType.Object || pd.Value == null || (ddr = JsLib.OfInt(pd, "ddr", 0)) == 0) { continue; } var ft = new FormattedText(p.GetModel().name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.White); double cw = 7 + ft.WidthIncludingTrailingWhitespace; if (ddr < 0) // Input { pos = -ddr - 1; if (cntIp < pos + 1) { cntIp = pos + 1; } pinIp[pos] = p; textIp[pos] = ft; if (pos == 0) { cw += 9; } wi = Math.Max(wi, cw); } else // Output { pos = ddr - 1; if (cntOp < pos + 1) { cntOp = pos + 1; } pinOp[pos] = p; textOp[pos] = ft; if (pos == 0) { cw += 9; } wo = Math.Max(wo, cw); } } double width = Math.Ceiling(Math.Max(head.WidthIncludingTrailingWhitespace, wi + wo) / CELL_SIZE) * CELL_SIZE; double height = Math.Max(cntIp * CELL_SIZE, cntOp * CELL_SIZE); if (height == 0) //-V3024 { return; } if (chLevel == 3) { lv.MapRemove(this); int cw = (int)width / CELL_SIZE; int ch = 1 + (int)height / CELL_SIZE; for (int i = cw; i >= 0; i--) { for (int j = ch - 1; j >= 0; j--) { lv.MapSet(0, x + i, y + j, this); lv.MapSet(1, x + i, y + j, this); lv.MapSet(2, x + i, y + j, this); lv.MapSet(3, x + i, y + j, this); } } } base.VisualBitmapScalingMode = BitmapScalingMode.HighQuality; using (DrawingContext dc = this.RenderOpen()) { dc.DrawRectangle(Brushes.White, null, new Rect(-2, 2, width + 4, height + CELL_SIZE - 2)); dc.DrawRectangle(_selected ? brItemSelected : brElementBody, null, new Rect(0, CELL_SIZE, width, height)); dc.DrawText(head, new Point((width - head.WidthIncludingTrailingWhitespace) / 2, 1)); int i; for (i = 0; i < cntIp; i++) { if (textIp[i] != null && pinIp[i] != null) { if (i == 0) { wi = Math.Max((width - CELL_SIZE) / 2, Math.Ceiling((2 * textIp[i].WidthIncludingTrailingWhitespace) / CELL_SIZE) * CELL_SIZE / 2); } dc.DrawText(textIp[i], new Point(7, (i + 1) * CELL_SIZE + 1)); } } dc.DrawImage(App.GetIcon(JsLib.OfString(model.Manifest["icon"], null)), new Rect(wi, CELL_SIZE, CELL_SIZE, CELL_SIZE)); int inW = (int)width / CELL_SIZE; for (i = 0; i < cntOp; i++) { if (textOp[i] != null && pinOp[i] != null) { dc.DrawText(textOp[i], new Point(width - 7 - textOp[i].WidthIncludingTrailingWhitespace, (i + 1) * CELL_SIZE + 1)); } } } if (chLevel > 0) { int i; for (i = 0; i < cntIp; i++) { if (pinIp[i] != null) { pinIp[i].SetLocation(new Vector(0, i * CELL_SIZE + CELL_SIZE * 1.5), chLevel); } } for (i = 0; i < cntOp; i++) { if (pinOp[i] != null) { pinOp[i].SetLocation(new Vector(width, i * CELL_SIZE + CELL_SIZE * 1.5), chLevel); } } } }
public override void Render(int chLevel) { if (model == null || model.State == null || model.Manifest == null) { return; } if (_mode != 0 && chLevel == 3) { var src_s = JsLib.OfString(JsLib.GetField(model.Manifest, "cctor.LoBind"), null); if (src_s == null) { _mode = 1; } else if (_source == null || _source.path != src_s || (_mode == 2 && _srcBinding == null && lv._dataIsLoaded)) { model.GetAsync(src_s).ContinueWith(SourceLoaded, TaskScheduler.FromCurrentSynchronizationContext()); return; } if (_mode != 2 && _srcBinding != null) { _source = null; _srcBinding.Dispose(); _srcBinding = null; } } this.Offset = _owner.Offset + _ownerOffset; if (chLevel == 3) { lv.MapRemove(this); lv.MapSet(_mode == 0 ? 3 : 0, (int)(Offset.X / CELL_SIZE + 0.5), (int)(Offset.Y / CELL_SIZE + 0.5), this); } var tc = model.State.ValueType; Brush br; switch (tc) { case JSC.JSValueType.Object: if (model.State is ByteArray || model.State.Value is ByteArray) { br = brByteArray; } else { br = Brushes.MediumOrchid; } break; case JSC.JSValueType.String: br = Brushes.Gold; break; case JSC.JSValueType.Double: case JSC.JSValueType.Integer: { double val = (double)model.State; br = val > 0 ? (val == 1 ? Brushes.LawnGreen : Brushes.LightSeaGreen) : (val == 0 ? brValueFalse : Brushes.DodgerBlue); //-V3024 } break; case JSC.JSValueType.Boolean: br = (bool)model.State.Value ? Brushes.LawnGreen : brValueFalse; //-V3095 break; default: br = Brushes.Black; break; } bool ic = (!(_owner is loVariable) || _mode == 0) && JsLib.ofBool(JsLib.GetField(model.Manifest, "Logram.trace"), false); if (!ic && chLevel == 1 && this.brush == br) { return; } this.brush = br; string val_s = string.Empty; if (ic) { var v = model.State; if (v != null) { switch (v.ValueType) { case JSC.JSValueType.Boolean: case JSC.JSValueType.Integer: case JSC.JSValueType.String: val_s = v.Value.ToString(); break; case JSC.JSValueType.Double: { double d = (double)v; int p = (int)Math.Log10(Math.Abs(d)); switch (p) { case -2: val_s = d.ToString("0.000##"); break; case -1: val_s = d.ToString("0.00##"); break; case 0: val_s = d.ToString("0.0##"); break; case 1: val_s = d.ToString("0.##"); break; case 2: val_s = d.ToString("0.#"); break; case 3: val_s = d.ToString("0.#"); break; case 4: val_s = d.ToString("0"); break; default: val_s = d.ToString("G4"); break; } } break; case JSC.JSValueType.Date: { var dt = (v.Value as JSL.Date).ToDateTime(); val_s = dt.ToString("yyMMdd HH:mm:ss"); break; } } } } using (DrawingContext dc = this.RenderOpen()) { if (_mode == 3) { dc.DrawRectangle(_selected ? brItemSelected : this.brush, null, new Rect(-2, -5, 4, 10)); } else { dc.DrawEllipse(_selected ? brItemSelected : this.brush, null, new Point(0, 0), 3, 3); } if (ic) { var ft = new FormattedText(val_s, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.Black); Point p; if (_mode == 0) { p = new Point(2, 2 - CELL_SIZE); } else { p = new Point(-2 - ft.WidthIncludingTrailingWhitespace, 2 - CELL_SIZE); } dc.DrawText(ft, p); } } if (_mode != 0 && _srcBinding != null && chLevel > 1) { _srcBinding.Render(chLevel); } if (_mode == 0 && chLevel > 0) { foreach (loBinding w in _connections.ToArray()) { w.Render(chLevel); } } }
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); } }
private void CheckCCtor(Perform p) { SortedList <string, JSValue> lo = null, ln = null, lc = null; JSValue to = null, tn = p.src.GetField("type"), vn; if (p.art == Perform.Art.changedField) { JSValue o = JsLib.GetField(p.old_o as JSValue, "cctor"), n = p.src.GetField("cctor"); to = JsLib.GetField(p.old_o as JSValue, "type"); if (!object.ReferenceEquals(o, n)) { JsLib.Propertys(ref lo, o); JsLib.Propertys(ref ln, n); } } else if (p.art == Perform.Art.create) { JsLib.Propertys(ref ln, p.src.GetField("cctor")); } else if (p.art == Perform.Art.remove) { JsLib.Propertys(ref lo, p.src.GetField("cctor")); } else { return; } if (!object.ReferenceEquals(to, tn)) { Topic tt; if (to != null && to.ValueType == JSValueType.String && to.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(to.Value as string, out tt)) { JsLib.Propertys(ref lo, JsLib.GetField(tt.GetState(), "cctor")); } if (tn != null && tn.ValueType == JSValueType.String && tn.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(tn.Value as string, out tt)) { JsLib.Propertys(ref ln, JsLib.GetField(tt.GetState(), "cctor")); } } if (lo != null && ln != null) { foreach (var k in lo.Where(z => ln.ContainsKey(z.Key)).Select(z => z.Key).ToArray()) { vn = ln[k]; if (!JSValue.ReferenceEquals(lo[k], vn)) { if (lc == null) { lc = new SortedList <string, JSValue>(); } lc.Add(k, vn); } lo.Remove(k); ln.Remove(k); } } if (lo != null) { ProcessCCtor(lo, p.src, Perform.Art.remove); } if (ln != null) { ProcessCCtor(ln, p.src, Perform.Art.create); } if (lc != null) { ProcessCCtor(lc, p.src, Perform.Art.changedField); } }
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); }
private void PinLoaded(Task <DTopic> tt) { DTopic t; if (tt.IsFaulted || !tt.IsCompleted || (t = tt.Result) == null) { return; } loPin p; var chs = model.Manifest["Children"]; if (chs.ValueType != JSC.JSValueType.Object || chs.Value == null) { lv.TopicLoaded(t); return; } var pd = chs[t.name]; int ddr; if (pd.ValueType != JSC.JSValueType.Object || pd.Value == null || (ddr = JsLib.OfInt(pd, "ddr", 0)) == 0) { lv.TopicLoaded(t); return; } p = new loPin(this, t, ddr < 0); _pins.Add(p); lv.AddVisual(p); t.changed += pin_changed; lv.TopicLoaded(t); this.Render(3); }
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); } } } }
public static void Publish(Perform cmd) { SubRec sb; Topic t = cmd.src; if ((cmd.art == Perform.Art.subscribe || cmd.art == Perform.Art.subAck) && (sb = cmd.o as SubRec) != null) { try { sb.func(cmd, sb); } catch (Exception ex) { Log.Warning("{0}.{1}({2}) - {3}", sb.func.Method.DeclaringType.Name, sb.func.Method.Name, cmd.ToString(), ex.ToString()); } } else { if (t._subRecords != null) { for (int i = t._subRecords.Count - 1; i >= 0; i--) { sb = t._subRecords[i]; if (((sb.mask & SubRec.SubMask.OnceOrAll) != SubRec.SubMask.None || ((sb.mask & SubRec.SubMask.Chldren) == SubRec.SubMask.Chldren && sb.setTopic == t.parent)) && (cmd.art != Perform.Art.changedState || (sb.mask & SubRec.SubMask.Value) == SubRec.SubMask.Value) && (cmd.art != Perform.Art.changedField || ((sb.mask & SubRec.SubMask.Field) == SubRec.SubMask.Field && !object.ReferenceEquals(JsLib.GetField(cmd.old_o as JSValue, sb.prefix ?? string.Empty), JsLib.GetField(t._manifest, sb.prefix ?? string.Empty)))) ) { try { //Log.Debug("$ {0} <= {1}", sb.ToString(), cmd.ToString()); sb.func(cmd, sb); } catch (Exception ex) { Log.Warning("{0}.{1}({2}) - {3}", sb.func.Method.DeclaringType.Name, sb.func.Method.Name, cmd.ToString(), ex.ToString()); } } } } } }