public NewViewEventArgs(IWebBrowserView view, BrowserWindowStartMode startMode, TargetAddressType addressType)
 {
     ArgumentUtility.CheckNotNull ("view", view);
       StartMode = startMode;
       AddressType = addressType;
       View = view;
 }
Example #2
0
        /// <summary>
        /// Search AvailableElementData By TargetAddress (By Element, MissionOperatorCode, or MissionId)
        /// </summary>
        /// <param name="targetAddress">Target address.</param>
        /// <param name="lstAvailableElementData">[out] Information describing the list available element.</param>
        /// <returns>List of AvailableElementData matching TargetAddress criteria.</returns>
        public T2GManagerErrorEnum GetAvailableElementDataByTargetAddress(TargetAddressType targetAddress, out ElementList <AvailableElementData> lstAvailableElementData)
        {
            T2GManagerErrorEnum lReturn = T2GManagerErrorEnum.eFailed;

            lstAvailableElementData = new ElementList <AvailableElementData>();

            if (targetAddress != null && !string.IsNullOrEmpty(targetAddress.Id))
            {
                // Resolve target elements
                switch (targetAddress.Type)
                {
                case AddressTypeEnum.Element:
                    AvailableElementData element = new AvailableElementData();
                    lReturn = GetAvailableElementDataByElementNumber(targetAddress.Id, out element);
                    if (lReturn == T2GManagerErrorEnum.eSuccess)
                    {
                        lstAvailableElementData.Add(element);
                    }
                    break;

                case AddressTypeEnum.MissionOperatorCode:
                    lReturn = GetAvailableElementDataListByMissionOperatorCode(targetAddress.Id, out lstAvailableElementData);
                    break;

                case AddressTypeEnum.MissionCode:
                    lReturn = GetAvailableElementDataListByMissionCode(targetAddress.Id, out lstAvailableElementData);
                    break;
                }
            }

            return(lReturn);
        }
        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);
            }
        }
        protected override void Dispatch(IExtendedWebBrowser browser, BrowserWindowTarget target, BrowserWindowStartMode startMode, string targetName, TargetAddressType addressType)
        {
            var webBrowser = (TridentWebBrowser) browser;
              IWebBrowserView view;
              Guid id;
              if(!Guid.TryParse (targetName, out id))
            id = new Guid();

              if (target == BrowserWindowTarget.PopUp)
            view = new PopUpWindow (webBrowser, id);
              else
            view = new BrowserTab (webBrowser, id, _states);
              ViewCreationDone (view, startMode, addressType);
        }
        public NavigationEventArgs(
            BrowserWindowStartMode startMode,
            bool cancel,
            Uri uri,
            string target,
            BrowserWindowTarget windowTarget,
            TargetAddressType addressType)
        {
            ArgumentUtility.CheckNotNull ("target", target);
              ArgumentUtility.CheckNotNull ("uri", uri);
              ArgumentUtility.CheckNotNull ("windowTarget", windowTarget);

              StartMode = startMode;
              Cancel = cancel;
              Url = uri;
              TargetName = target;
              BrowserWindowTarget = windowTarget;
              AddressType = addressType;
        }
        /// <summary>
        /// LiveVideoControlService Web service method "StartVideoStreamingCommand" that sends a
        /// scheduled message to addressee.
        /// </summary>
        /// <param name="sessionId">The session identifier.</param>
        /// <param name="targetAddress">Addressee information.</param>
        /// <param name="url">The request timeout.</param>
        /// <returns>Response <see cref="LiveVideoControlResult"/>.</returns>
        LiveVideoControlResult ILiveVideoControlService.StartVideoStreamingCommand(
            Guid sessionId,
            TargetAddressType targetAddress,
            string url)
        {
            LiveVideoControlResult result = new LiveVideoControlResult();

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

            string automaticModeURL;

            if (_sessionManager.IsSessionValid(sessionId))
            {
                if (GetAutomaticMode(out automaticModeURL) == false)
                {
                    _dicVideoHistory[targetAddress]            = url;
                    _dicVideoHistorySentService[targetAddress] = null;

                    result = SendStartStreamingCommand(
                        sessionId,
                        targetAddress,
                        url
                        );
                }
                else
                {
                    result.Url        = automaticModeURL;
                    result.ResultCode = LiveVideoControlErrorEnum.AutomaticModeActivated;
                }
            }
            else
            {
                result.ResultCode = LiveVideoControlErrorEnum.InvalidSessionId;
            }

            return(result);
        }
        /// <summary>Gets invalid target address response.</summary>
        /// <param name="targetAddress">Addressee information.</param>
        /// <returns>The invalid target address response.</returns>
        private static LiveVideoControlErrorEnum GetInvalidTargetAddressResponse(TargetAddressType targetAddress)
        {
            LiveVideoControlErrorEnum result = LiveVideoControlErrorEnum.UnknownElementId;

            if (targetAddress != null)
            {
                switch (targetAddress.Type)
                {
                case AddressTypeEnum.Element:
                    result = LiveVideoControlErrorEnum.UnknownElementId;
                    break;

                case AddressTypeEnum.MissionCode:
                    result = LiveVideoControlErrorEnum.UnknownMissionId;
                    break;

                case AddressTypeEnum.MissionOperatorCode:
                    result = LiveVideoControlErrorEnum.UnknownMissionId;
                    break;
                }
            }

            return(result);
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the TargetAddress class.
 /// </summary>
 /// <param name="address">The target address.</param>
 /// <param name="addressType">The type of the target address.</param>
 public TargetAddress(QualifiedAddress address, TargetAddressType addressType)
 {
     this.Address     = address;
     this.AddressType = addressType;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="targetAddress"></param>
        /// <param name="requestTimeout"></param>
        /// <returns></returns>
        public GetReportResponse GetReport(Guid sessionId, TargetAddressType targetAddress, uint requestTimeout)
        {
            GetReportResponse result = new GetReportResponse();

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

            if (requestTimeout <= MAX_REQUEST_TIMEOUT)
            {
                if (_sessionManager.IsSessionValid(sessionId))
                {
                    Guid requestId = Guid.Empty;
                    _sessionManager.GenerateRequestID(sessionId, out requestId);

                    if (requestId != Guid.Empty)                     // TODO requires modification to method GenerateRequestID
                    {
                        ElementList <AvailableElementData> elements;
                        T2GManagerErrorEnum lRqstResult = _t2gManager.GetAvailableElementDataByTargetAddress(targetAddress, out elements);
                        switch (lRqstResult)
                        {
                        case T2GManagerErrorEnum.eSuccess:
                            // Queue to request list
                            foreach (AvailableElementData element in elements)
                            {
                                SendNotificationToGroundApp(requestId, PIS.Ground.GroundCore.AppGround.NotificationIdEnum.InfotainmentDownloadProcessing, element.ElementNumber);

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

                                lock (_lock)
                                {
                                    _newRequests.Add(request);
                                }
                            }

                            // Signal thread and start transmitting
                            _transmitEvent.Set();

                            result.RequestId  = requestId;
                            result.ResultCode = ResultCodeEnum.RequestAccepted;
                            break;

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

                        case T2GManagerErrorEnum.eElementNotFound:
                            switch (targetAddress.Type)
                            {
                            case AddressTypeEnum.Element:
                                result.ResultCode = ResultCodeEnum.UnknownElementId;
                                break;

                            case AddressTypeEnum.MissionCode:
                                result.ResultCode = ResultCodeEnum.UnknownMissionId;
                                break;

                            case AddressTypeEnum.MissionOperatorCode:
                                result.ResultCode = ResultCodeEnum.UnknownMissionId;
                                break;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        result.ResultCode = ResultCodeEnum.InvalidSessionId;
                    }
                }
                else
                {
                    result.ResultCode = ResultCodeEnum.InvalidSessionId;
                }
            }
            else
            {
                result.ResultCode = ResultCodeEnum.InvalidRequestTimeout;
            }

            return(result);
        }
        /// <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>
        /// 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);
                                }
                            }
                        }
                    }
                }
            }
        }
 protected void ViewCreationDone(IWebBrowserView view, BrowserWindowStartMode startMode, TargetAddressType addressType)
 {
     if (ViewCreated != null)
     ViewCreated (this, new NewViewEventArgs (view, startMode, addressType));
 }
 protected abstract void Dispatch(
 IExtendedWebBrowser browser, BrowserWindowTarget target, BrowserWindowStartMode startMode, string targetName, TargetAddressType addressType);