Beispiel #1
0
 void ITopicOwned.SetOwner(Topic owner) {
   if (_owner != owner) {
     if (_owner != null) {
       _owner.Unsubscribe("+", _owner_changed);
       Change_A(null);
       Change_B(null);
       _parent = null;
     }
     _owner = owner as DVar<PiWire>;
     if (_owner != null) {
       _owner.saved = true;
       var dc = _owner.Get<string>("_declarer");
       dc.saved = true;
       dc.value = "Wire";
       if (_owner.parent != null && _owner.parent.valueType == typeof(PiLogram)) {
         _parent = (_owner.parent as DVar<PiLogram>).value;
       }
       _owner.Subscribe("+", _owner_changed);
       if (exec) {
         Change_A(_a);
         Change_B(_b);
       }
     }
   }
 }
Beispiel #2
0
    public void Init() {
      Topic.root.Subscribe("/etc/PLC/#", L_dummy);
      Topic.root.Subscribe("/etc/declarers/#", L_dummy);
      string path=Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
      _id=Topic.root.Get<string>("/local/cfg/id");

      #region Load statements
      var catalog = new AggregateCatalog();
      catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
      catalog.Catalogs.Add(new DirectoryCatalog(path));
      var _container = new CompositionContainer(catalog);
      try {
        _container.ComposeParts(this);
      }
      catch(CompositionException ex) {
        Log.Error("Load statements - {0}", ex.ToString());
        return;
      }
      #endregion Load statements

      foreach(var i in _statement) {
        PiStatement.AddStatemen(i.Metadata.declarer, i.Value.GetType());
        i.Value.Load();
      }
      _statement=null;
    }
Beispiel #3
0
    public SetupView() {
      InitializeComponent();
      {
        System.Drawing.Icon img = System.Drawing.SystemIcons.Shield;

        System.Drawing.Bitmap bitmap = img.ToBitmap();
        IntPtr hBitmap = bitmap.GetHbitmap();

        System.Windows.Media.ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                  hBitmap, IntPtr.Zero, Int32Rect.Empty,
                  System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
        imUAK.Source=wpfBitmap;
      }

      _clUser=Topic.root.Get<string>("/local/cfg/Client/_username");
      _clUser.saved=true;
      if(!string.IsNullOrEmpty(_clUser.value)) {
        this.Username.Text=_clUser.value;
      } else {
        this.Username.Text="local";
      }
      _clPass=Topic.root.Get<string>("/local/cfg/Client/_password");
      _clPass.saved=true;
      if(!string.IsNullOrEmpty(_clPass.value)) {
        this.Password.Text=_clPass.value;
      }
      _clUrl=Topic.root.Get<string>("/local/cfg/Client/_URL");
      _clUrl.saved=true;
      if(string.IsNullOrWhiteSpace(_clUrl.value)) {
        RemoteUrl.Text=_enterUrlText;
      } else {
        RemoteUrl.Text=_clUrl.value;
      }
    }
Beispiel #4
0
 public void Calculate(DVar<PiStatement> model, Topic source) {
   if(source==_csv) {
     Import();
     Rebuild();
   } else if((source==_yRef || source==_match) && _match.value) {
     double y2=_cubSpl.Func(_x.value);
     double yo=_yRef.value-y2;
     if(double.IsNaN(y2) || Math.Abs(yo)>_ye.value) {
       double xo=Math.Round(_x.value/_xe.value)*_xe.value;
       double y1;
       if(_data.TryGetValue(xo, out y1) && !double.IsNaN(y2)) {
           y1+=yo/10;
       } else {
         y1=_yRef.value;
       }
       if(!double.IsNaN(y1)) {
         _data[xo]=y1;
       }
       //Log.Debug("{2}({0}, {1})", xo, y1, model.path);
       _upd++;
       Rebuild();
       _y.value=_cubSpl.Func(_x.value);
     }
   } else if(source==_x) {
     _y.value=_cubSpl.Func(_x.value);
     if(_upd>2) {
       Export();
       _upd=0;
     }
   }
 }
    public void Init() {
      Topic.paused=true;
      _sign=Topic.root.Get("/local/cfg/PersistentStorage");
      _verbose=Topic.root.Get<bool>("/local/cfg/PersistentStorage/verbose");

      if(!Directory.Exists("../data")) {
        Directory.CreateDirectory("../data");
      }
      _file=new FileStream("../data/persist.xdb", FileMode.OpenOrCreate, FileAccess.ReadWrite);
      if(_file.Length<0x40) {
        _file.Write(new byte[0x40], 0, 0x40);
        _file.Flush(true);
        _nextBak=DateTime.Now.AddHours(1);
      } else {
        Load();
      }
      _fileLength=_file.Length;
      _work=new AutoResetEvent(false);
      _thread=new Thread(new ThreadStart(PrThread));
      _thread.Priority=ThreadPriority.Lowest;
      _now=DateTime.Now;
      if(_nextBak<_now) {
        Backup();
      }
      _thread.Start();
      Topic.root.Subscribe("/#", MqChanged);
    }
Beispiel #6
0
 public void Init(DVar<PiStatement> model) {
   _dLat=BiultInStatements.AddPin<double>(model, "Lat");
   _dLon=BiultInStatements.AddPin<double>(model, "Lon");
   _dSunrise=BiultInStatements.AddPin<DateTime>(model, "Sunrise");
   _dSunset=BiultInStatements.AddPin<DateTime>(model, "Sunset");
   _dOut=BiultInStatements.AddPin<bool>(model, "Out");
   _evnt=new Timer((o) => Calculate(null, null));
 }
Beispiel #7
0
 internal static void OpenLogram(DVar<PiLogram> doc) {
   var c=mainWindow.dockManager.Documents.Where(z => z is LogramView).Cast<LogramView>().FirstOrDefault(z => z.model==doc);
   if(c==null) {
     c=new LogramView(ExConverter.String2Name(doc.path));
   }
   c.Show(mainWindow.dockManager);
   c.Activate();
   
 }
Beispiel #8
0
 public MqClient() {
   _waitPingResp=false;
   _mq=Topic.root.Get("/local/MQ");
   ConnInfo=new MqConnect();
   ConnInfo.cleanSession=true;
   ConnInfo.keepAlive=this.KeepAlive;
   _tOut=new Timer(new TimerCallback(TimeOut));
   _settings=Topic.root.Get("/local/cfg/Client");
   _subs=new List<Topic.Subscription>();
   _now=Topic.root.Get<DateTime>("/var/now");
   _nowOffset=_settings.Get<long>("TimeOffset");
 }
Beispiel #9
0
 public void SetOwner(Topic owner) {
   if(string.IsNullOrEmpty(path) || !Topic.root.Exist(path, out _val)) {
     _val=null;
   }
   _owner=owner as DVar<PiTracer>;
   if(_val!=null) {
     if(_owner==null) {
       _val.changed-=val_changed;
     } else {
       _val.changed+=val_changed;
     }
   }
 }
Beispiel #10
0
    public MainWindow(string cfg) {
      Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
      _cfgPath=Path.GetFullPath(cfg);
      if(!Directory.Exists("../data")) {
        Directory.CreateDirectory("../data");
      }
      Topic.Import(_cfgPath, "/local/cfg");

      Topic clientSettings=Topic.root.Get("/local/cfg/Client");
      var url=clientSettings.Get<string>("_URL");
      var enable=clientSettings.Get<bool>("enable");
      enable.saved=true;
      enable.value=true;

      if(url.value=="#local") {
        StartEmbeddedEngine();
      }

      _plugins=new Plugins();

      _verbose=Topic.root.Get<bool>("/local/cfg/repository/_verbose");
      Topic.root.Subscribe("/#", root_changed);
      _plugins.Init(false);
      BrokerState="OFFLINE";
      _clState=0;   // offline
      _cl=_plugins["Client"] as MQTT.MqClient;
      _cl.StatusChg+=MqClientStatusChanged;
      _cl.KeepAlive=10;

      if(_cl.Connected) {
        MqClientStatusChanged(true);
      }

      InitializeComponent();
      DataContext = this;

      if(Settings.MainWindowWidth>0 && Settings.MainWindowHeight>0) {
        this.Width=Settings.MainWindowWidth;
        this.Height=Settings.MainWindowHeight;
        this.Left=Settings.MainWindowLeft;
        this.Top=Settings.MainWindowTop;
        this.WindowState=Settings.MainWindowState;
      } else {
        this.WindowStartupLocation=System.Windows.WindowStartupLocation.CenterScreen;
        this.Width=System.Windows.SystemParameters.PrimaryScreenWidth*0.6;
        this.Height=System.Windows.SystemParameters.PrimaryScreenHeight*0.8;
      }
      _plugins.Start();
      this.dockManager.ActiveDocumentChanged+=new EventHandler(dockManager_ActiveDocumentChanged);
    }
Beispiel #11
0
    public void Calculate(DVar<PiStatement> model, Topic source) {
      var DR = Math.PI / 180;
      var RD = 1 / DR;
      var B5 = DR * _dLat.value;
      var L5 = _dLon.value;
      var Now = DateTime.Now;
      var H=TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalHours;
      var L0 = 4.8771 + .0172 * (Now.DayOfYear + .5 - L5 / 360);
      var C = .03342 * Math.Sin(L0 + 1.345);
      var C2 = RD * (Math.Atan(Math.Tan(L0 + C)) - Math.Atan(.9175 * Math.Tan(L0 + C)) - C);
      var SD = .3978 * Math.Sin(L0 + C);
      var CD = Math.Sqrt(1 - SD * SD);
      var SC = (SD * Math.Sin(B5) + .0145) / (Math.Cos(B5) * CD);

      if(Math.Abs(SC) <= 1) {
        // calculate sunrise 
        var C3 = RD * Math.Atan(SC / Math.Sqrt(1 - SC * SC));
        var R1 = 6 + H - ((L5%15) + C2 + C3) / 15;
        _dSunrise.value  = Now.Date.AddHours(R1);
        // calculate sunset
        var S1 = 18 + H - ((L5%15) + C2 - C3) / 15;
        _dSunset.value = Now.Date.AddHours(S1);
      } else {
        if(SC > 1) {
          // sun is up all day ...
          // Set Sunset to be in the future ...
          _dSunset.value = Now.Date.AddDays(1);
          // Set Sunrise to be in the past ...
          _dSunrise.value = Now.Date;
        }
        if(SC < -1) {
          // sun is down all day ...
          // Set Sunrise and Sunset to be in the future ...
          _dSunrise.value = Now.Date.AddDays(1);
          _dSunset.value = Now.AddDays(2);
        }
      }
      if(Now<_dSunrise.value) {
        _dOut.value=false;
        _evnt.Change(_dSunrise.value.AddSeconds(2)-Now, TimeSpan.FromDays(1));
      } else if(Now<_dSunset.value) {
        _dOut.value=true;
        _evnt.Change(_dSunset.value.AddSeconds(2)-Now, TimeSpan.FromDays(1));
      } else {
        _dOut.value=false;
        _evnt.Change(_dSunrise.value.AddHours(23)-Now, TimeSpan.FromDays(1));
      }
    }
Beispiel #12
0
 public void Init(DVar<PiStatement> model) {
   _data=new SortedList<double, double>();
   _cubSpl=new CubicSpline();
   _x=BiultInStatements.AddPin<double>(model, "X");
   _xe=BiultInStatements.AddPin<double>(model, "_xEpsilon");
   if(_xe.value==0) {
     _xe.value=1;
   }
   _yRef=BiultInStatements.AddPin<double>(model, "YRef");
   _match=BiultInStatements.AddPin<bool>(model, "Match");
   _ye=BiultInStatements.AddPin<double>(model, "_yEpsilon");
   if(_ye.value==0) {
     _ye.value=1;
   }
   _y=BiultInStatements.AddPin<double>(model, "Y");
   _csv=BiultInStatements.AddPin<string>(model, "_csv");
   _upd=0;
 }
Beispiel #13
0
 public void Init() {
   _verbose=_settings.Get<bool>("verbose");
   if(!Reconnect()) {
     _settings.Get<bool>("enable").value=false;
     return;
   }
   Topic.SubscriptionsChg+=Topic_SubscriptionsChg;
   Topic.root.Subscribe("/etc/system/#", PLC.PLCPlugin.L_dummy);
   Topic.root.Subscribe("/etc/repository/#", PLC.PLCPlugin.L_dummy);
   Topic.root.Subscribe("/etc/declarers/+", PLC.PLCPlugin.L_dummy);
   Topic.root.Subscribe("/etc/declarers/type/#", PLC.PLCPlugin.L_dummy);
   Topic.root.Subscribe("/etc/PLC/default", PLC.PLCPlugin.L_dummy);
   Topic.root.Subscribe("/var/now", PLC.PLCPlugin.L_dummy);
   Topic.paused=true;
   for(int i=600; i>=0; i--) {
     Thread.Sleep(50);
     if(_connected) {
       break;
     }
   }
 }
Beispiel #14
0
 void ITopicOwned.SetOwner(Topic owner) {
   if(Owner!=owner) {
     if(Owner!=null) {
       if(_via!=null) {
         _via.changed-=_via_changed;
         _via=null;
         RefreshStatements();
       }
     }
     Owner=owner as DVar<PiLogram>;
     if(Owner!=null) {
       Owner.saved=true;
       var dc=Owner.Get<string>("_declarer");
       dc.saved=true;
       dc.value="Logram";
       _via=Owner.Get<string>("_via");
       _via.changed+=_via_changed;
       RefreshStatements();
     }
   }
 }
Beispiel #15
0
 public void Calculate(DVar<PiStatement> model, Topic source) {
   if(source==_csv) {
     _cubSpl.Reset();
     string[] dat=null;
     if(File.Exists(_csv.value)) {
       try {
         dat=File.ReadAllLines(_csv.value);
       }
       catch(Exception ex) {
         Log.Warning("{0}.Load({1}) - {2}", model.path, _csv.value, ex.Message);
       }
     } else {
       Log.Warning("{0}.Load({1}) not exist", model.path, _csv.value);
     }
     if(dat==null || dat.Length==0) {
       return;
     }
     double x, y;
     string[] lt;
     for(int i=0; i<dat.Length; i++) {
       lt=dat[i].Split(';');
       if(lt==null || lt.Length!=2) {
         continue;
       }
       if(double.TryParse(lt[0], out x)) {
         if(double.TryParse(lt[1], out y)) {
           _cubSpl.AddNode(x, y);
         } else {
           Log.Warning("{0}.Load({1}) wrong Y value [{2}]{3}", model.path, _csv.value, i, dat[i]);
           continue;
         }
       } else {
         Log.Warning("{0}.Load({1}) wrong X value [{2}]{3}", model.path, _csv.value, i, dat[i]);
         continue;
       }
     }
     _cubSpl.BuildSpline();
   }
   _y.value=_cubSpl.Func(_x.value);
 }
Beispiel #16
0
    public LogView() {
      _instance=this;
      AddLogEntryDelegate=new Action<LogEntry>(AddLogEntry);

      InitializeComponent();
      this.DataContext = this;
      if(!Directory.Exists("../log")) {
        Directory.CreateDirectory("../log");
      }

      var now=DateTime.Now;
      try {
        foreach(string f in Directory.GetFiles("../log/", "*_cc.log", SearchOption.TopDirectoryOnly)) {
          if(File.GetLastWriteTime(f).AddDays(3)<now)
            File.Delete(f);
        }
      }
      catch(System.IO.IOException) {
      }
      _lfPath="../log/"+now.ToString("yyMMdd")+"_cc.log";

      _log=new X13.WOUM.BlockingQueue<LogEntry>(ProcessLog);
      Log.Write+=new Action<LogLevel, DateTime, string>(Log_Write);

      LogCollection=new ObservableCollection<LogEntry>();
      lvLog.ItemsSource=CollectionViewSource.GetDefaultView(LogCollection);
      this._showDebug=Settings.LogShowDebug;
      tbShowDebug.IsChecked=_showDebug;
      if(_showDebug) {
        (lvLog.ItemsSource as System.ComponentModel.ICollectionView).Filter=(o) => true;
      } else {
        (lvLog.ItemsSource as System.ComponentModel.ICollectionView).Filter=(o) => (o as LogEntry).ll!=LogLevel.Debug;
      }
      _lHead=Topic.root.Get<long>("/var/log");
      _oldHead=(_lHead.value+1)%100;
      _lHead.changed+=_lHead_changed;
      _lDebug=_lHead.Get<string>("A0");
      _lDebug.changed+=_lDebug_changed;
    }
Beispiel #17
0
 public void SetOwner(Topic owner) {
   if(_owner!=null) {
     _owner.Unsubscribe("+", STVarChanged);
   }
   _owner=owner;
   if(_owner!=null) {
     addr=int.Parse(owner.name.Substring(2));
     if(_owner.parent!=null && _owner.parent.valueType==typeof(MsDevice)) {
       _dev=(_owner.parent as DVar<MsDevice>).value;
     }
     _decl=_owner.Get<string>("_declarer", _owner);
     _owner.Subscribe("+", STVarChanged);
     if(_state!=0xB0) {
       Reset();
     }
   } else {
     _decl=null;
     _state=0xB0;
     _to.Change(-1, -1);
   }
 }
Beispiel #18
0
 public HIH61xx(Topic pin) {
   if(pin==null) {
     throw new ArgumentNullException();
   }
   if(pin.name=="HIH61_T") {
     _T=pin as DVar<double>;
     if(_T==null) {
       throw new ArgumentException();
     }
     _H=_T.parent.Get<double>("HIH61_H");
   } else if(pin.name=="HIH61_H") {
     _H=pin as DVar<double>;
     if(_H==null) {
       throw new ArgumentException();
     }
     _T=_H.parent.Get<double>("HIH61_T");
   } else {
     throw new ArgumentException();
   }
   _present=_T.Get<bool>("present");
   _present.saved=false;
   _present.value=false;
   Reset();
 }
Beispiel #19
0
 private void CommThread(object o) {
   byte[] buf=new byte[256];
   bool escChar=false;
   int cnt=-1;
   int len=-1;
   MsMessage msg;
   DateTime busyTime=DateTime.Now;
   try {
     while(_port!=null && _port.IsOpen) {
       if(GetPacket(_port, ref len, buf, ref cnt, ref escChar)) {
         if(len==5 && buf[1]==(byte)MsMessageType.SUBSCRIBE) {
           _advTick=DateTime.Now.AddMilliseconds(100);   // Send Advertise
         }
         MsDevice.ProcessInPacket(this, _gateAddr, buf, 0, len);
         cnt=-1;
         msg=null;
         continue;
       }
       msg=null;
       if(busyTime>DateTime.Now) {
         Thread.Sleep(0);
         continue;
       }
       lock(_sendQueue) {
         if(_sendQueue.Count>0) {
           msg=_sendQueue.Dequeue();
         }
       }
       if(msg!=null) {
         SendRaw(this, msg, _sndBuf);
         busyTime=DateTime.Now.AddMilliseconds(msg.IsRequest?20:5);
         continue;
       }
       if(_gwTopic!=null && _gwTopic.value!=null && (_gwTopic.value.state==State.Disconnected || _gwTopic.value.state==State.Lost)) {
         _gwTopic=null;
         Thread.Sleep(500);
         this.Dispose();
         Thread.Sleep(1000);
         _startScan.Set();
         return;
       }
       if(_advTick<DateTime.Now) {
         SendRaw(this, new MsAdvertise(gwIdx, 900), _sndBuf);
         _advTick=DateTime.Now.AddMinutes(15);
       }
       Thread.Sleep(15);
     }
   }
   catch(IOException) {
   }
   catch(Exception ex) {
     Log.Error("MsGSerial({0}).CommThread() - {1}", gwIdx, ex.ToString());
   }
   if(_verbose.value) {
     Log.Debug("MsGSerial({0}).CommThread - exit", gwIdx);
   }
   this.Dispose();
 }
Beispiel #20
0
 public void Init(DVar<PiStatement> model) {
   _cubSpl=new CubicSpline();
   _x=BiultInStatements.AddPin<double>(model, "X");
   _y=BiultInStatements.AddPin<double>(model, "Y");
   _csv=BiultInStatements.AddPin<string>(model, "_csv");
 }
Beispiel #21
0
 public BME280(Topic pin) {
   if(pin==null) {
     throw new ArgumentNullException();
   }
   if(pin.name=="BME280_T") {
     _T=pin as DVar<double>;
     if(_T==null) {
       throw new ArgumentException();
     }
     _P=_T.parent.Get<long>("BME280_P");
     _H=_T.parent.Get<double>("BME280_H");
   } else if(pin.name=="BME280_P") {
     _P=pin as DVar<long>;
     if(_P==null) {
       throw new ArgumentException();
     }
     _T=_P.parent.Get<double>("BME280_T");
     _H=_P.parent.Get<double>("BME280_H");
   } else if(pin.name=="BME280_H") {
     _H=pin as DVar<double>;
     if(_H==null) {
       throw new ArgumentException();
     }
     _P=_H.parent.Get<long>("BME280_P");
     _T=_H.parent.Get<double>("BME280_T");
   } else {
     throw new ArgumentException();
   }
   _present=_T.Get<bool>("present");
   _present.saved=false;
   _present.value=false;
   Reset();
 }
Beispiel #22
0
    void ITopicOwned.SetOwner(Topic owner) {
      if(Owner!=owner) {
        if(Owner!=null) {
          if(_subsscriptions!=null) {
            foreach(var s in _subsscriptions) {
              Owner.Unsubscribe(s.path, s.func);
            }
            _subsscriptions.Clear();
          }
          _stateVar=null;
          if(_activeTimer!=null) {
            _activeTimer.Change(Timeout.Infinite, Timeout.Infinite);
          }
        }
        Owner=owner;
        if(Owner!=null) {
          _stateVar=Owner.Get<State>(".cfg/_state");
          if(Topic.brokerMode) {
            Owner.saved=true;
            Owner.Get<string>(".cfg/_declarer").value="mqtts_cfg";
            var dc=Owner.Get<string>("_declarer", Owner);
            dc.saved=true;
            dc.value=_declarer;
            _present=Owner.Get<bool>("present", Owner);
            _present.saved=false;
            _present.value=(state==State.Connected || state==State.ASleep || state==State.AWake);

            Topic oldT;
            if(!string.IsNullOrEmpty(backName) && backName!=Owner.name && Owner.parent.Exist(backName, out oldT) && oldT.valueType==typeof(MsDevice)) {   // Device renamed
              MsDevice old=(oldT as DVar<MsDevice>).value;
              if(old!=null) {
                Addr=old.Addr;
                old._gate.Send(new MsPublish(null, PredefinedTopics["_sName"], QoS.AtLeastOnce) { Addr=Addr, MessageId=old.NextMsgId(), Data=Encoding.UTF8.GetBytes(Owner.name.Substring(0, Owner.name.Length)) });
                this.state=State.Disconnected;
              }
            }
            backName=Owner.name;
          }
        }
      }
    }
Beispiel #23
0
 static MsDevice() {
   _verbose=Topic.root.Get<bool>("/etc/MQTTS/verbose");
   _gates=new List<IMsGate>();
 }
Beispiel #24
0
 static WsSyncItem() {
   _var=Topic.root.Get("/var/WsSync");
   _verbose=Topic.root.Get<bool>("/etc/WsSync/_verbose");
 }
Beispiel #25
0
    private void ConnectCB(IAsyncResult rez) {
      var _tcp=rez.AsyncState as TcpClient;
      try {
        _tcp.EndConnect(rez);
        _stream=new MqStreamer(_tcp, Received, SendIdle);
        _stream.isSndPaused=true;
        var re=((IPEndPoint)_stream.Socket.Client.RemoteEndPoint);
        try {
          BrokerName=Dns.GetHostEntry(re.Address).HostName;
        }
        catch(SocketException) {
          BrokerName=re.Address.ToString();
        }
        _owner=_mq.Get<MqClient>(BrokerName);
        _owner.value=this;
        _connected=false;
        string id=Topic.root.Get<string>("/local/cfg/id").value;
        if(string.IsNullOrEmpty(id)) {
          id=string.Format("{0}@{1}_{2:X4}", Environment.UserName, Environment.MachineName, System.Diagnostics.Process.GetCurrentProcess().Id);
        }
        ConnInfo.clientId=id;
        ConnInfo.userName=_settings.Get<string>("_username");
        _settings.Get<string>("_username").saved=true;
        ConnInfo.userPassword=_settings.Get<string>("_password");
        _settings.Get<string>("_password").saved=true;
        if(string.IsNullOrEmpty(ConnInfo.userName) && addr=="localhost") {
          ConnInfo.userName="******";
          ConnInfo.userPassword=string.Empty;
        }

        this.Send(ConnInfo);
        _owner.Subscribe("/#", OwnerChanged);
        _tOut.Change(3000, _keepAliveMS);       // more often than not
      }
      catch(Exception ex) {
        Log.Error("Connect to {0}:{1} failed, {2}", addr, port, ex.Message);
        if(StatusChg!=null) {
          StatusChg(false);
        }
        _tOut.Change(_keepAliveMS*5, Timeout.Infinite);
      }
    }
Beispiel #26
0
 public void Start() {
   _verbose=_cfg.Get<bool>("_verbose");
   _cfg.Subscribe("+", CfgChanged);
 }
Beispiel #27
0
 public WsSyncItem(string name, Uri uri) {
   this.name = name;
   this._uri = uri;
   _st=State.Connecting;
   _val=_var.Get(name);
   _present=_val.Get<bool>("_present");
   _present.value=false;
   _reconn = new Timer(CheckState);
   _rccnt = 1;
   Connect();
 }
Beispiel #28
0
 public void Attach(DVar<PiLogram> model) {
   if(this.model!=model) {
     this.model=model;
     var w=model.Get<long>("_width");
     if(w.value==0) {
       w.saved=true;
       w.value=24;
     }
     this.Width=w.value*LogramView.CellSize;
     var h=model.Get<long>("_height");
     if(h.value<=0) {
       h.saved=true;
       h.value=24;
     }
     this.Height=h.value*LogramView.CellSize;
     _map.Clear();
     DrawingVisual cur;
     foreach(var p in model.children.Where(z => z.valueType==typeof(Topic)).Cast<DVar<Topic>>()) {
       try {
         cur=new uiAlias(p, this);
       }
       catch(Exception ex) {
         Log.Error("create uiAlias({0}) - {1}", p.path, ex.ToString());
       }
     }
     foreach(var p in model.children.Where(z => z.valueType==typeof(PiStatement)).Cast<DVar<PiStatement>>()) {
       try {
       cur=new uiStatement(p, this);
       }
       catch(Exception ex) {
         Log.Error("create uiStatement({0}) - {1}", p.path, ex.ToString());
       }
     }
     foreach(var p in model.children.Where(z => z.valueType==typeof(PiWire)).Cast<DVar<PiWire>>()) {
       try {
       cur=new uiWire(p, this);
       }
       catch(Exception ex) {
         Log.Error("create uiWire({0}) - {1}", p.path, ex.ToString());
       }
     }
     foreach(var p in model.children.Where(z => z.valueType==typeof(PiTracer)).Cast<DVar<PiTracer>>()) {
       try {
       cur=new uiTracer(p, this);
       }
       catch(Exception ex) {
         Log.Error("create uiTracer({0}) - {1}", p.path, ex.ToString());
       }
     }
     model.Subscribe("+", ModelChanged);
   }
 }
Beispiel #29
0
 static SmartTwi() {
   _verbose=Topic.root.Get<bool>("/etc/MQTTS/verbose");
 }
Beispiel #30
0
    public void SetOwner(Topic owner) {
      if(owner!=_owner) {
        if(_owner!=null) {
          _owner.Unsubscribe("+", _owner_changed);
        }
        _parent=null;
        RefreshExec();

        _owner=owner as DVar<PiStatement>;
        if(_owner!=null) {
          if(_owner.parent!=null && _owner.parent.valueType==typeof(PiLogram)) {
            _parent=(_owner.parent as DVar<PiLogram>).value;
          }
          RefreshExec();
        }
      }
    }