/// <summary>
        /// Handle stop hosting message received from host to client to stop controlling the slideshow
        /// </summary>
        /// <returns>success</returns>
        private bool StopHostingSessionHandle()
        {
            bool success = false;

            try
            {
                if (_appServiceConnection != null)
                {
                    _appServiceConnection.ServiceClosed -= _appServiceConnection_ServiceClosed;
                    _appServiceConnection = null;

                    if (Status == ConnectedServiceStatus.HostingConnected)
                    {
                        Status = ConnectedServiceStatus.HostingNotConnected;
                    }
                }

                if (_remoteSystem != null)
                {
                    _remoteSystem.MessageReceived -= _remoteSystem_MessageReceived;
                    _remoteSystem = null;

                    Status = ConnectedServiceStatus.IdleForeground;
                }

                HostingConnectionStoped?.Invoke(this, null);
                success = true;
            }
            catch (Exception ex)
            {
                success = false;
            }

            return(success);
        }
        public void Dispose()
        {
            if (_appServiceConnection != null)
            {
                _appServiceConnection.Dispose();
                _appServiceConnection = null;
            }

            if (_remoteSystem != null)
            {
                _remoteSystem.Dispose();
                _remoteSystem = null;
            }

            Rome.Dispose();
        }
        /// <summary>
        /// Initiates the second screen experience on the client if the system is showing a slideshow
        /// </summary>
        /// <param name="system"></param>
        /// <returns>Message from system with what adventure and current slide number</returns>
        public async Task <ValueSet> ConnectToSystem(AdventureRemoteSystem system)
        {
            ValueSet message = new ValueSet();

            message.Add("query", ConnectedServiceQuery.StartHostingSession.ToString());

            var response = await system.SendMessage(message);

            if (response != null && response.ContainsKey("success") && (bool)response["success"])
            {
                var status = (ConnectedServiceStatus)Enum.Parse(typeof(ConnectedServiceStatus), (String)response["status"]);

                if (status != ConnectedServiceStatus.HostingNotConnected && status != ConnectedServiceStatus.HostingConnected)
                {
                    return(null);
                }

                message.Clear();

                if (_remoteSystem != system)
                {
                    if (_remoteSystem != null)
                    {
                        _remoteSystem.MessageReceived -= _remoteSystem_MessageReceived;
                        _remoteSystem = null;
                    }
                    _remoteSystem = system;
                    _remoteSystem.MessageReceived += _remoteSystem_MessageReceived;
                }

                response = await SendMessageFromClientAsync(message, SlideshowMessageTypeEnum.Status);

                if (response == null)
                {
                    _remoteSystem = null;
                    _remoteSystem.MessageReceived -= _remoteSystem_MessageReceived;
                    return(null);
                }

                return(response);
            }

            return(null);
        }
        /// <summary>
        /// Start the slideshow on the remote system
        /// </summary>
        /// <param name="system"></param>
        /// <param name="deepLink"></param>
        /// <returns></returns>
        public async Task <bool> ConnectToSystem(AdventureRemoteSystem system, string deepLink = "")
        {
            ValueSet message = new ValueSet();

            message.Add("query", ConnectedServiceQuery.StartHostingSession.ToString());

            var response = await system.SendMessage(message);

            if (response != null && response.ContainsKey("success") && (bool)response["success"])
            {
                var status = (ConnectedServiceStatus)Enum.Parse(typeof(ConnectedServiceStatus), (String)response["status"]);

                if (status != ConnectedServiceStatus.HostingNotConnected && status != ConnectedServiceStatus.HostingConnected)
                {
                    var launchUriStatus =
                        await RemoteLauncher.LaunchUriAsync(
                            new RemoteSystemConnectionRequest(system.RemoteSystem),
                            new Uri("adventure:" + deepLink)).AsTask().ConfigureAwait(false);

                    if (launchUriStatus != RemoteLaunchUriStatus.Success)
                    {
                        return(false);
                    }
                }
                if (_remoteSystem != system)
                {
                    if (_remoteSystem != null)
                    {
                        _remoteSystem.MessageReceived -= _remoteSystem_MessageReceived;
                        _remoteSystem = null;
                    }
                    _remoteSystem = system;
                    _remoteSystem.MessageReceived += _remoteSystem_MessageReceived;
                }

                return(true);
            }

            return(false);
        }