Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
        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);
                }
            }
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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);
                    }
                }
            }
        }