/// <summary>Send Notification to Ground App, specific to Element Id.</summary>
 /// <param name="requestId">The RequestId for the corresponding request.</param>
 /// <param name="pStatus">Status : Completed/Failed/Processing.</param>
 /// <param name="pElementId">The concerned ElementId.</param>
 public static void SendElementIdNotificationToGroundApp(string requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum pStatus, string pElementId)
 {
     //String.Format(CultureInfo.CurrentCulture, Logs.INFO_NOTIFICATIONTOAPPGROUND, pElementId, requestId, pStatus)
     LogManager.WriteLog(TraceType.INFO, String.Format(CultureInfo.CurrentCulture, Logs.INFO_NOTIFICATIONTOAPPGROUND, pElementId, requestId, pStatus), "PIS.Ground.DataPackage.LiveVideoControl.sendElementIdNotificationToGroundApp", null, EventIdEnum.LiveVideoControl);
     try
     {
         // serialize ElementId.
         System.Xml.Serialization.XmlSerializer xmlSzr = new System.Xml.Serialization.XmlSerializer(typeof(string));
         StringWriter lstr = new StringWriter();
         xmlSzr.Serialize(lstr, pElementId);
         LiveVideoControlService.SendNotificationToGroundApp(new Guid(requestId), pStatus, lstr.ToString());
     }
     catch (FormatException)
     {
         // serialize ElementId.
         System.Xml.Serialization.XmlSerializer xmlSzr = new System.Xml.Serialization.XmlSerializer(typeof(string));
         StringWriter lstr = new StringWriter();
         xmlSzr.Serialize(lstr, pElementId);
         LiveVideoControlService.SendNotificationToGroundApp(Guid.Empty, pStatus, lstr.ToString());
     }
     catch (Exception ex)
     {
         LogManager.WriteLog(
             TraceType.ERROR,
             ex.Message,
             "PIS.Ground.LiveVideoControl.LiveVideoControlService.sendNotificationToGroundApp",
             ex,
             EventIdEnum.DataPackage);
     }
 }
        private static void SendStartStreamingCommandToProperStatusElements(string url)
        {
            try
            {
                // Get the list of all currently available trains
                ElementList <AvailableElementData> elements = new ElementList <AvailableElementData>();
                T2GManagerErrorEnum rqstResult = _t2gManager.GetAvailableElementDataList(out elements);

                switch (rqstResult)
                {
                case T2GManagerErrorEnum.eSuccess:
                    // Send notification to all clients
                    LiveVideoControlService.SendNotificationToGroundApp(
                        Guid.Empty,
                        PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlAutomaticMode,
                        url);

                    // Send a start command to each train that is online and in mission
                    foreach (AvailableElementData element in elements)
                    {
                        TargetAddressType target = new TargetAddressType();
                        target.Type = AddressTypeEnum.Element;
                        target.Id   = element.ElementNumber;

                        _dicVideoHistory[target]            = url;
                        _dicVideoHistorySentService[target] = null;

                        if (element.OnlineStatus == true && element.MissionState == MissionStateEnum.MI)
                        {
                            ServiceInfo availableService;
                            if (_t2gManager.GetAvailableServiceData(element.ElementNumber, (int)eServiceID.eSrvSIF_LiveVideoControlServer, out availableService) == T2GManagerErrorEnum.eSuccess)
                            {
                                _dicVideoHistorySentService[target] = availableService;
                            }

                            SendStartStreamingCommand(Guid.Empty, target, url);
                        }
                    }
                    break;

                case T2GManagerErrorEnum.eT2GServerOffline:
                    LogManager.WriteLog(TraceType.ERROR, "T2G Server: Offline",
                                        "PIS.Ground.LiveVideoControl.LiveVideoControlService.ProcessAutomaticMode",
                                        null, EventIdEnum.LiveVideoControl);
                    break;

                default:
                    LogManager.WriteLog(TraceType.ERROR, "Element not found",
                                        "PIS.Ground.LiveVideoControl.LiveVideoControlService.ProcessAutomaticMode", null, EventIdEnum.LiveVideoControl);
                    break;
                }
            }
            catch (System.Exception exception)
            {
                LogManager.WriteLog(TraceType.EXCEPTION, exception.Message,
                                    "PIS.Ground.LiveVideoControl.LiveVideoControlService.ProcessAutomaticMode", exception, EventIdEnum.LiveVideoControl);
            }
        }
        /// <summary>Command to select the automatic or manual starting mode for the video streaming.
        ///          If the specified URL is empty or null, manual mode is selected.
        ///          Otherwise, automatic mode is selected</summary>
        /// <param name="sessionId">Identifier for the session.</param>
        /// <param name="url">URL of the stream to be used in automatic mode.</param>
        /// <returns>Return statement of the request (Success, failed,...) with URL and request id.</returns>
        LiveVideoControlResult ILiveVideoControlService.ChangeCommandMode(Guid sessionId, string url)
        {
            LiveVideoControlResult result = new LiveVideoControlResult();

            result.RequestId  = Guid.Empty;
            result.ResultCode = LiveVideoControlErrorEnum.InternalError;

            if (_sessionManager.IsSessionValid(sessionId))
            {
                // Checking if the specified url contains an non empty string
                if (string.IsNullOrEmpty(url) || url.Trim().Length == 0)
                {
                    // If empty url, it means we want to clear the automatic mode
                    if (ClearAutomaticMode())
                    {
                        // Notify all clients that we are entering the manual mode
                        LiveVideoControlService.SendNotificationToGroundApp(
                            Guid.Empty,
                            PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlManualMode,
                            null);
                    }
                    result.ResultCode = LiveVideoControlErrorEnum.RequestAccepted;
                }
                else
                {
                    // If non empty url, it means we want to enter the automatic mode
                    lock (_automaticModeLock)
                    {
                        if (SetAutomaticMode(url))
                        {
                            // Send notifications and start commands
                            result = ProcessAutomaticMode(url);

                            // If the command failed, restore the manual mode
                            if (result.ResultCode != LiveVideoControlErrorEnum.RequestAccepted)
                            {
                                ClearAutomaticMode();
                            }
                        }
                        else
                        {
                            // We are already in automatic mode. Get the current url used.
                            string currentAutomaticURL;
                            GetAutomaticMode(out currentAutomaticURL);
                            result.Url        = currentAutomaticURL;
                            result.ResultCode = LiveVideoControlErrorEnum.AutomaticModeActivated;
                        }
                    }
                }
            }
            else
            {
                result.ResultCode = LiveVideoControlErrorEnum.InvalidSessionId;
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NotificationGroundService"/> class.
        /// </summary>
        public NotificationGroundService()
        {
            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = "LiveVideo.NotificationGroundService";
            }

            LiveVideoControlService.Initialize();
        }
        /// <summary>Sends a video streaming status request.</summary>
        /// <param name="requestId">Request ID for the corresponding request.</param>
        private static void SendVideoStreamingStatusRequest(Guid requestId)
        {
            ElementList <AvailableElementData> availableElementData = new ElementList <AvailableElementData>();
            T2GManagerErrorEnum result = _t2gManager.GetAvailableElementDataList(out availableElementData);

            switch (result)
            {
            case T2GManagerErrorEnum.eSuccess:
                foreach (AvailableElementData element in availableElementData)
                {
                    ServiceInfo serviceInfo;
                    result = _t2gManager.GetAvailableServiceData(element.ElementNumber, (int)eServiceID.eSrvSIF_LiveVideoControlServer, out serviceInfo);
                    switch (result)
                    {
                    case T2GManagerErrorEnum.eSuccess:
                        ProcessSendVideoStreamingStatusRequestContext request = new ProcessSendVideoStreamingStatusRequestContext(
                            element.ElementNumber,
                            requestId,
                            serviceInfo);
                        _requestProcessor.AddRequest(request);
                        break;

                    case T2GManagerErrorEnum.eT2GServerOffline:
                        LiveVideoControlService.SendNotificationToGroundApp(requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlT2GServerOffline, string.Empty);
                        break;

                    case T2GManagerErrorEnum.eElementNotFound:
                        LiveVideoControlService.SendNotificationToGroundApp(requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlElementNotFound, element.ElementNumber);
                        break;

                    case T2GManagerErrorEnum.eServiceInfoNotFound:
                        LiveVideoControlService.SendNotificationToGroundApp(requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlServiceNotFound, element.ElementNumber);
                        break;

                    default:
                        break;
                    }
                }

                break;

            case T2GManagerErrorEnum.eT2GServerOffline:
                LiveVideoControlService.SendNotificationToGroundApp(requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlT2GServerOffline, string.Empty);
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// LiveVideoControlService Web service method "StopVideoStreamingCommand" that cancels all
        /// predefined and free-text messages at addressee.
        /// </summary>
        /// <param name="sessionId">The session identifier.</param>
        /// <param name="targetAddress">Addressee information.</param>
        /// <returns>Response <see cref="LiveVideoControlResult"/>.</returns>
        LiveVideoControlResult ILiveVideoControlService.StopVideoStreamingCommand(
            Guid sessionId,
            TargetAddressType targetAddress)
        {
            LiveVideoControlResult result = new LiveVideoControlResult();

            result.RequestId  = Guid.Empty;
            result.ResultCode = LiveVideoControlErrorEnum.RequestAccepted;

            _dicVideoHistory.Remove(targetAddress);
            _dicVideoHistorySentService.Remove(targetAddress);

            if (_sessionManager.IsSessionValid(sessionId))
            {
                string automaticModeURL;

                if (GetAutomaticMode(out automaticModeURL) == false)
                {
                    Guid   requestId = Guid.Empty;
                    string error     = _sessionManager.GenerateRequestID(sessionId, out requestId);

                    if (requestId != Guid.Empty)
                    {
                        ElementList <AvailableElementData> elements;
                        T2GManagerErrorEnum rqstResult = _t2gManager.GetAvailableElementDataByTargetAddress(targetAddress, out elements);
                        switch (rqstResult)
                        {
                        case T2GManagerErrorEnum.eSuccess:
                        {
                            List <RequestContext> newRequests = new List <RequestContext>();
                            foreach (AvailableElementData element in elements)
                            {
                                LiveVideoControlService.SendNotificationToGroundApp(requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlDistributionProcessing, element.ElementNumber);

                                ProcessStopVideoStreamingCommandRequestContext request = new ProcessStopVideoStreamingCommandRequestContext(
                                    element.ElementNumber,
                                    requestId,
                                    sessionId);

                                newRequests.Add(request);
                            }

                            _requestProcessor.AddRequestRange(newRequests);
                            result.RequestId  = requestId;
                            result.ResultCode = LiveVideoControlErrorEnum.RequestAccepted;
                        }

                        break;

                        case T2GManagerErrorEnum.eT2GServerOffline:
                            result.ResultCode = LiveVideoControlErrorEnum.T2GServerOffline;
                            break;

                        case T2GManagerErrorEnum.eElementNotFound:
                            result.ResultCode = LiveVideoControlService.GetInvalidTargetAddressResponse(targetAddress);
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        LogManager.WriteLog(TraceType.ERROR, error, "PIS.Ground.LiveVideoControl.LiveVideoControlService.StopVideoStreamingCommand", null, EventIdEnum.LiveVideoControl);
                        result.ResultCode = LiveVideoControlErrorEnum.InvalidRequestID;
                    }
                }
                else
                {
                    result.Url        = automaticModeURL;
                    result.ResultCode = LiveVideoControlErrorEnum.AutomaticModeActivated;
                }
            }
            else
            {
                result.ResultCode = LiveVideoControlErrorEnum.InvalidSessionId;
            }

            return(result);
        }
        /// <summary>Sends a start streaming command.</summary>
        /// <param name="sessionId">The session identifier.</param>
        /// <param name="targetAddress">Addressee information.</param>
        /// <param name="url">The streaming URL to be used.</param>
        /// <returns>Response <see cref="LiveVideoControlElementListResult"/>.</returns>
        private static LiveVideoControlResult SendStartStreamingCommand(
            Guid sessionId,
            TargetAddressType targetAddress,
            string url)
        {
            LiveVideoControlResult result = new LiveVideoControlResult();

            result.RequestId  = Guid.Empty;
            result.ResultCode = LiveVideoControlErrorEnum.InternalError;
            Guid   requestId = Guid.Empty;
            string error;

            if (sessionId != Guid.Empty)
            {
                error = _sessionManager.GenerateRequestID(sessionId, out requestId);
            }
            else
            {
                error = _sessionManager.GenerateRequestID(out requestId);
            }

            if (requestId != Guid.Empty)
            {
                ElementList <AvailableElementData> elements;
                T2GManagerErrorEnum rqstResult = _t2gManager.GetAvailableElementDataByTargetAddress(targetAddress, out elements);

                switch (rqstResult)
                {
                case T2GManagerErrorEnum.eSuccess:
                    Guid notificationRequestId        = requestId;
                    List <RequestContext> newRequests = new List <RequestContext>();
                    foreach (AvailableElementData element in elements)
                    {
                        if (_dicVideoHistorySentService.ContainsKey(targetAddress))
                        {
                            ServiceInfo availableService;
                            if (_t2gManager.GetAvailableServiceData(element.ElementNumber, (int)eServiceID.eSrvSIF_LiveVideoControlServer, out availableService) == T2GManagerErrorEnum.eSuccess)
                            {
                                _dicVideoHistorySentService[targetAddress] = availableService;
                            }
                        }

                        LiveVideoControlService.SendNotificationToGroundApp(requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.LiveVideoControlDistributionProcessing, element.ElementNumber);
                        ProcessStartVideoStreamingCommandRequestContext request = new ProcessStartVideoStreamingCommandRequestContext(
                            element.ElementNumber,
                            requestId,
                            sessionId,
                            url);

                        newRequests.Add(request);
                    }

                    _requestProcessor.AddRequestRange(newRequests);
                    result.RequestId  = requestId;
                    result.ResultCode = LiveVideoControlErrorEnum.RequestAccepted;
                    break;

                case T2GManagerErrorEnum.eT2GServerOffline:
                    LogManager.WriteLog(TraceType.ERROR, "T2G Offline", "PIS.Ground.LiveVideoControl.LiveVideoControlService.SendStartStreamingCommand", null, EventIdEnum.LiveVideoControl);
                    result.ResultCode = LiveVideoControlErrorEnum.T2GServerOffline;
                    break;

                case T2GManagerErrorEnum.eElementNotFound:
                    LogManager.WriteLog(TraceType.ERROR, "Element not found", "PIS.Ground.LiveVideoControl.LiveVideoControlService.SendStartStreamingCommand", null, EventIdEnum.LiveVideoControl);
                    result.ResultCode = LiveVideoControlService.GetInvalidTargetAddressResponse(targetAddress);
                    break;

                default:
                    LogManager.WriteLog(TraceType.ERROR, "Problem looking for an element. T2GClient returned: " + rqstResult.ToString(),
                                        "PIS.Ground.LiveVideoControl.LiveVideoControlService.SendStartStreamingCommand", null, EventIdEnum.LiveVideoControl);
                    result.ResultCode = LiveVideoControlErrorEnum.InternalError;
                    break;
                }
            }
            else
            {
                LogManager.WriteLog(TraceType.ERROR, error, "PIS.Ground.LiveVideoControl.LiveVideoControlService.SendStartStreamingCommand", null, EventIdEnum.LiveVideoControl);
                result.ResultCode = LiveVideoControlErrorEnum.InvalidRequestID;
            }

            return(result);
        }
        /// <summary>LiveVideoControlService web service method "GetAvailableElementList".</summary>
        /// <param name="sessionId">The session identifier.</param>
        /// <returns>Response <see cref="LiveVideoControlElementListResult"/>.</returns>
        LiveVideoControlElementListResult ILiveVideoControlService.GetAvailableElementList(Guid sessionId)
        {
            LiveVideoControlElementListResult lResult = new LiveVideoControlElementListResult();

            lResult.ResultCode = LiveVideoControlErrorEnum.ElementListNotAvailable;

            if (LiveVideoControlService._sessionManager.IsSessionValid(sessionId))
            {
                // Get the list of all trains
                //
                ElementList <AvailableElementData> lElementList;
                T2GManagerErrorEnum lT2GResult = _t2gManager.GetAvailableElementDataList(out lElementList);

                if (lT2GResult == T2GManagerErrorEnum.eSuccess)
                {
                    var         lLiveVideoServiceElementList = new ElementList <AvailableElementData>();
                    ServiceInfo lServiceInfo;
                    bool        lT2GDisconnection = false;

                    // For each train...
                    //
                    foreach (AvailableElementData lElement in lElementList)
                    {
                        // ...get information related to the live video streaming service
                        //
                        lT2GResult = _t2gManager.GetAvailableServiceData(lElement.ElementNumber,
                                                                         (int)eServiceID.eSrvSIF_LiveVideoControlServer, out lServiceInfo);

                        switch (lT2GResult)
                        {
                        case T2GManagerErrorEnum.eSuccess:

                            // If the streaming service is provided...
                            //
                            if (lServiceInfo.IsAvailable)
                            {
                                // ...add the train to the streaming service elements list
                                lLiveVideoServiceElementList.Add(lElement);
                            }
                            break;

                        case T2GManagerErrorEnum.eT2GServerOffline:
                            lT2GDisconnection = true;
                            break;

                        default:
                            break;
                        }

                        // Since we need T2G to build the list of streaming service elements...
                        if (lT2GDisconnection)
                        {
                            // ...stop wasting time and return immediately
                            lResult.ResultCode = LiveVideoControlErrorEnum.T2GServerOffline;
                            break;
                        }
                    }

                    if (!lT2GDisconnection)
                    {
                        // In case of success, return the list of train(s) that provide video steaming service
                        //
                        lResult.ElementList = lLiveVideoServiceElementList;
                        lResult.ResultCode  = LiveVideoControlErrorEnum.RequestAccepted;
                    }
                    else
                    {
                        lResult.ResultCode = LiveVideoControlErrorEnum.T2GServerOffline;
                    }
                }
                else
                {
                    lResult.ResultCode = LiveVideoControlErrorEnum.ElementListNotAvailable;
                }

                if (false == LiveVideoControlService._statusRequestedSessions.Contains(sessionId))
                {
                    LiveVideoControlService._statusRequestedSessions.Add(sessionId);
                    LiveVideoControlService._delegate(sessionId);
                }
            }
            else
            {
                lResult.ResultCode = LiveVideoControlErrorEnum.InvalidSessionId;
            }

            return(lResult);
        }
Esempio n. 9
0
        /// <summary>Sends a notification.</summary>
        /// <param name="request">The input request.</param>
        /// <returns>An empty response.</returns>
        public SendNotificationResponse SendNotification(SendNotificationRequest request)
        {
            LiveVideoControlService.SendElementIdNotificationToGroundApp(request.RequestId, (PIS.Ground.GroundCore.AppGround.NotificationIdEnum)request.NotificationId, request.ElementId);

            return(new SendNotificationResponse());            // Always an empty response
        }