Exemplo n.º 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);
       }
     }
   }
 }
Exemplo n.º 2
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);
      }
    }
Exemplo n.º 3
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);
   }
 }