Inheritance: TConnectionPlatform
Beispiel #1
0
 private void Imb_OnVariable(TConnection aConnection, string aVarName, byte[] aVarValue, byte[] aPrevValue)
 {
     if (aVarName == "mapextent")
     {
         _disableMapEvents = true;
         try
         {
             string m = Encoding.UTF8.GetString(aVarValue);
             string[] s = m.Split('|');
             if (s.Length > 2)
             {
                 double lon = Convert.ToDouble(s[0], CultureInfo.InvariantCulture);
                 double lat = Convert.ToDouble(s[1], CultureInfo.InvariantCulture);
                 if (!string.IsNullOrEmpty(s[2])) Convert.ToDouble(s[2], CultureInfo.InvariantCulture);
                 AppState.ViewDef.Center = new Point(lon, lat);
                 if (s.Length > 3)
                 {
                     if (!string.IsNullOrEmpty(s[3]))
                     {
                         double r = Convert.ToDouble(s[3], CultureInfo.InvariantCulture);
                         AppState.ViewDef.Resolution = r;
                     }
                     else if (!string.IsNullOrEmpty(s[2]))
                     {
                         int l = Convert.ToInt32(s[2]);
                     }
                 }
                 else
                 {
                 }
             }
         }
         finally
         {
             _disableMapEvents = false;
         }
     }
 }
Beispiel #2
0
 private void Imb_OnStatusUpdate(TConnection aConnection, string aModelUniqueClientID, string aModelName, int aProgress, int aStatus)
 {
     if (aStatus != 0 && Disconnected != null) Disconnected(this, null);
     UpdateStatus();
 }
Beispiel #3
0
 private void Imb_OnVariable(TConnection aConnection, string aVarName, byte[] aVarValue, byte[] aPrevValue)
 {
     var value = Encoding.UTF8.GetString(aVarValue, 0, aVarValue.Length);
     Variables[aVarName] = value;
     if (aVarName.EndsWith(".status"))
     {
         ParseClient(aVarName, value);
     }
     if (aVarName.EndsWith(".group"))
     {
         ProcessImbVariableGroup(aVarName,value);
     }
 }
Beispiel #4
0
        public void Init(string host, int port, string name, int id, string federation, ImbClientStatus clientStatus, string alternativeHost, int alternativePort)
        {
            if (connecting || AppState.IsClosing) return;
            connecting = true;
            ConnectDate = DateTime.Now;
            if (Imb != null)
            {
                Imb.OnDisconnect   -= ImbOnOnDisconnect;
                Imb.OnVariable     -= Imb_OnVariable;
                Imb.OnStatusUpdate -= Imb_OnStatusUpdate;
                ClientAdded        -= CsImbClientAdded;                
            }

            Imb = new TConnection(host, port, name, id, federation);
            Imb.OnDisconnect += ImbOnOnDisconnect;
            
            Status = clientStatus;

            if (!Imb.Connected)
            {
                // try alternative host
                // TODO EV Why was this uncommented?
                //if (alternativeHost != "") Init(alternativeHost, alternativePort, name, id, federation, clientStatus, "", 0);
                connecting = false;
                reconnecting = false;
                return;
            }

            var tries = 0;
            
            while (Imb.ClientHandle == 0 && tries<1000) {Thread.Sleep(5);
                tries += 1;
            }
            reconnecting = false;
            Imb.OnVariable += Imb_OnVariable;
            Imb.OnStatusUpdate += Imb_OnStatusUpdate;
            ot.Interval = 5000;
            ot.Elapsed += (f, b) =>
            {
                try
                {
                    if (Imb.FClient.Connected)
                    {
                        Imb.SignalString(Id + ".online", "");
                    }
                    else if (!reconnecting)
                    {
                        reconnecting = true;
                        Init(host, port, name, id, federation);
                    }
                }
                catch (Exception)
                {
                    reconnecting = true;
                    Init(host, port, name, id, federation);
                }
            };
            ot.Start();
            UpdateStatus();
            if (Status.Client)
            {
                Status.Media = Imb.Subscribe(Id + ".Media");
                Status.Commands = Imb.Subscribe(Id + ".Commands");
                //Status.Positions = Imb.Subscribe(Id + ".Position");

                Status.Media.OnNormalEvent += Media_OnNormalEvent;
                Status.Media.OnBuffer += Media_OnBuffer;
                Status.Commands.OnNormalEvent += Commands_OnNormalEvent;
                //Status.Positions.OnNormalEvent += Positions_OnNormalEvent;
            }

            ClientAdded += CsImbClientAdded;

            if (Connected != null) Connected(this, null);
            connecting = false;
        }
Beispiel #5
0
 private void ImbOnOnDisconnect(TConnection aConnection)
 {
     if (Disconnected != null) Disconnected(this, null);
 }
Beispiel #6
0
 private void Imb_OnVariable(TConnection aConnection, string aVarName, byte[] aVarValue, byte[] aPrevValue)
 {
     var name = aVarName;
     var v = Encoding.UTF8.GetString(aVarValue, 0, aVarValue.Length);
     ProcessReceivedImbBusVariable(name, v);
 }
Beispiel #7
0
 private void connection_UpdateConnectionStatus(TConnection aConnection)
 {
     Dispatcher.BeginInvoke(new USDomainPlugin.TUpdateConnectionStatus(UpdateConnectionStatus), null);
 }
Beispiel #8
0
            //public string EventName[Int32 aEventID]

            public TEventEntry AddEvent(TConnection aConnection, string aEventName) {
                FCount++;
                while (FCount > FEvents.Length) {
                    if (FEvents.Length == 0)
                        Array.Resize(ref FEvents, FInitialSize);
                    else
                        Array.Resize(ref FEvents, FEvents.Length*2);
                }
                FEvents[FCount - 1] = new TEventEntry(aConnection, FCount - 1, aEventName);

                return FEvents[FCount - 1];
            }
Beispiel #9
0
 public TEventEntry(TConnection aConnection, Int32 aID, string aEventName) {
     connection    = aConnection;
     ID            = aID;
     FEventName    = aEventName;
     FParent       = null;
     FIsPublished  = false;
     FIsSubscribed = false;
     FSubscribers  = false;
     FPublishers   = false;
 }
Beispiel #10
0
    void Imb_OnVariable(TConnection aConnection, string aVarName, byte[] aVarValue, byte[] aPrevValue)
    {
      if (aVarName == "timespan-old")
      {
        string v = Encoding.UTF8.GetString(aVarValue);
        string[] vs = v.Split('|');
        if (vs.Length > 2)
        {
          Timeline.Start = new DateTime(1970, 1, 1).AddMilliseconds(Convert.ToInt64(vs[0]));
          Timeline.End = new DateTime(1970, 1, 1).AddMilliseconds(Convert.ToInt64(vs[1]));
          Timeline.ForceTimeChanged();
          Timeline.ForceTimeContentChanged();
          _ignoreNext = true;
          //_timeUpdated = true;
        }

      }
    }