/// <summary>
        /// Callback called when Element Online state changes (signaled by the T2G Client).
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="args">Event information to send to registered event handlers.</param>
        public static void OnElementInfoChanged(object sender, ElementEventArgs args)
        {
            if (args != null &&
                args.SystemInformation != null &&
                args.SystemInformation.IsOnline == true &&
                args.SystemInformation.PisMission != null &&
                args.SystemInformation.PisMission.MissionState == MissionStateEnum.MI)
            {
                // Will be called multiple times for the same train.
                // Some sort of debouncing will be welcome in a future revision
                // to prevent multiple notifications to the console(s)

                if (string.IsNullOrEmpty(args.SystemInformation.SystemId) == false)
                {
                    TargetAddressType target = new TargetAddressType();
                    target.Type = AddressTypeEnum.Element;
                    target.Id   = args.SystemInformation.SystemId;

                    string automaticModeUrl;
                    if (GetAutomaticMode(out automaticModeUrl) == true)
                    {
                        LogManager.WriteLog(
                            TraceType.INFO,
                            "Automatically starting streaming on newly detected train: " + args.SystemInformation.SystemId,
                            "PIS.Ground.LiveVideoControl.LiveVideoControlService.OnElementInfoChanged",
                            null,
                            EventIdEnum.LiveVideoControl);

                        LiveVideoControlResult result =
                            SendStartStreamingCommand(Guid.Empty, target, automaticModeUrl);

                        if (result.ResultCode != LiveVideoControlErrorEnum.RequestAccepted)
                        {
                            LogManager.WriteLog(TraceType.ERROR,
                                                "Problem sending a start command with url "
                                                + automaticModeUrl
                                                + " to train "
                                                + target.Id
                                                + ". Error: "
                                                + result.ResultCode.ToString(),

                                                "PIS.Ground.LiveVideoControl.LiveVideoControlService.OnElementInfoChanged",
                                                null, EventIdEnum.LiveVideoControl);
                        }
                    }
                    else
                    {
                        // Manual Mode, resend the latest Start command if available
                        ServiceInfo lastSentService;
                        if (_dicVideoHistory.ContainsKey(target) && _dicVideoHistorySentService.TryGetValue(target, out lastSentService))
                        {
                            ServiceInfo foundService = (args.SystemInformation.ServiceList != null) ? args.SystemInformation.ServiceList.FirstOrDefault(s => s.ServiceId == (ushort)eServiceID.eSrvSIF_LiveVideoControlServer && s.IsAvailable): null;
                            bool        lServiceLiveVideoControlServerAvailable = foundService != null;

                            // If service is not available, force the sent status to value false.
                            if (!lServiceLiveVideoControlServerAvailable && lastSentService != null)
                            {
                                _dicVideoHistorySentService[target] = null;
                            }

                            // Avoiding sending multiple start notifications.
                            // The LiveVideoService have to be online
                            if (lServiceLiveVideoControlServerAvailable == true && (lastSentService == null || !foundService.Equals(lastSentService)))
                            {
                                LogManager.WriteLog(
                                    TraceType.INFO,
                                    "Re-starting streaming on newly detected train: " + args.SystemInformation.SystemId,
                                    "PIS.Ground.LiveVideoControl.LiveVideoControlService.OnElementInfoChanged",
                                    null,
                                    EventIdEnum.LiveVideoControl);

                                LiveVideoControlResult result =
                                    SendStartStreamingCommand(Guid.Empty, target, _dicVideoHistory[target]);

                                // Setting the flag that the start command was already sent
                                _dicVideoHistorySentService[target] = foundService;

                                if (result.ResultCode != LiveVideoControlErrorEnum.RequestAccepted)
                                {
                                    LogManager.WriteLog(TraceType.ERROR,
                                                        "Problem sending a start command with url "
                                                        + _dicVideoHistory[target]
                                                        + " to train "
                                                        + target.Id
                                                        + ". Error: "
                                                        + result.ResultCode.ToString(),

                                                        "PIS.Ground.LiveVideoControl.LiveVideoControlService.OnElementInfoChanged",
                                                        null, EventIdEnum.LiveVideoControl);
                                }
                            }
                        }
                    }
                }
            }
        }