public DataPackageTests.T2GServiceInterface.Notification.systemInfoStruct ConvertToNotification() { DataPackageTests.T2GServiceInterface.Notification.systemInfoStruct newObject = new DataPackageTests.T2GServiceInterface.Notification.systemInfoStruct(); newObject.communicationLink = (DataPackageTests.T2GServiceInterface.Notification.commLinkEnum)communicationLink; newObject.isOnline = isOnline; newObject.missionId = missionId; newObject.status = status; newObject.systemId = systemId; newObject.vehiclePhysicalId = vehiclePhysicalId; return(newObject); }
/// <summary> /// Updates the information on a system. /// </summary> /// <param name="systemId">The system identifier.</param> /// <param name="vehicleId">The vehicle identifier.</param> /// <param name="isOnline">The online status of the system.</param> /// <param name="status">The status.</param> /// <param name="missionId">The mission identifier.</param> /// <param name="communicationLink">The communication link.</param> public void UpdateSystem(string systemId, int vehicleId, bool isOnline, uint status, string missionId, CommLinkEnum communicationLink, string IPAddress) { SystemInfoStruct newSystemInfo = new SystemInfoStruct(); newSystemInfo.communicationLink = communicationLink; newSystemInfo.isOnline = isOnline; newSystemInfo.missionId = missionId; newSystemInfo.status = status; newSystemInfo.systemId = systemId; newSystemInfo.IPAddress = IPAddress; newSystemInfo.vehiclePhysicalId = Convert.ToUInt16(vehicleId); bool onlineStatusChanged = false; lock (_systemInfoLock) { SystemInfoStruct existingSystemInfo; if (_systems.TryGetValue(systemId, out existingSystemInfo)) { if (!(existingSystemInfo.vehiclePhysicalId != vehicleId || existingSystemInfo.isOnline != isOnline || existingSystemInfo.status != status || existingSystemInfo.missionId != missionId || existingSystemInfo.communicationLink != communicationLink || existingSystemInfo.IPAddress != IPAddress)) { newSystemInfo = null; } else if (existingSystemInfo.isOnline != isOnline) { onlineStatusChanged = true; } } else { onlineStatusChanged = true; } if (newSystemInfo != null) { _systems[systemId] = newSystemInfo; } } // Notify about changes if (newSystemInfo != null) { List <string> urlsToNotify; lock (_sessionLock) { urlsToNotify = _sessions.Values.Where(s => s.NotificationEnabled && !string.IsNullOrEmpty(s.NotificationUrl)).Select(s => s.NotificationUrl).Distinct().ToList(); } if (urlsToNotify.Count > 0) { DataPackageTests.T2GServiceInterface.Notification.systemInfoStruct systemInfoNotification = newSystemInfo.ConvertToNotification(); foreach (string url in urlsToNotify) { EndpointAddress address = new EndpointAddress(url); using (NotificationClient client = new NotificationClient("NotificationClient", address)) { try { client.Open(); client.onSystemChangedNotification(systemInfoNotification); } finally { if (client.State == CommunicationState.Faulted) { client.Abort(); } } } } } if (onlineStatusChanged) { OnlineStatusChangedHandler handlers = OnlineStatusChanged; if (handlers != null) { handlers(newSystemInfo.systemId, newSystemInfo.isOnline); } } } }