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; } } }
private void Imb_OnStatusUpdate(TConnection aConnection, string aModelUniqueClientID, string aModelName, int aProgress, int aStatus) { if (aStatus != 0 && Disconnected != null) Disconnected(this, null); UpdateStatus(); }
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); } }
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; }
private void ImbOnOnDisconnect(TConnection aConnection) { if (Disconnected != null) Disconnected(this, null); }
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); }
private void connection_UpdateConnectionStatus(TConnection aConnection) { Dispatcher.BeginInvoke(new USDomainPlugin.TUpdateConnectionStatus(UpdateConnectionStatus), null); }
//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]; }
public TEventEntry(TConnection aConnection, Int32 aID, string aEventName) { connection = aConnection; ID = aID; FEventName = aEventName; FParent = null; FIsPublished = false; FIsSubscribed = false; FSubscribers = false; FPublishers = false; }
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; } } }