Inheritance: global::System.IDisposable
Exemplo n.º 1
0
        public XToolsApp(string[] args = null)
        {
            parsedArguments = ParseCommandLine(args);
            this.logWriter = new ConsoleLogWriter();

            ClientConfig config = new ClientConfig(ClientRole.Primary);
            config.SetServerAddress(GetArgumentOrDefault("sessionserver", "localhost"));
            config.SetLogWriter(this.logWriter);

            this.Manager = SharingManager.Create(config);
            this.syncListener = new ConsoleSyncReporter();

            this.viewerConnection = this.Manager.GetPairedConnection();
            this.serverConnection = this.Manager.GetServerConnection();
            this.SessionManager = this.Manager.GetSessionManager();

            BeginPairing();

            ViewerListener = new NetworkConnectionAdapter();
            ViewerListener.ConnectedCallback += this.OnViewerConnected;
            ViewerListener.ConnectionFailedCallback += this.OnViewerConnectionFailed;
            ViewerListener.DisconnectedCallback += this.OnViewerDisconnected;
            viewerConnection.AddListener((byte)MessageID.StatusOnly, ViewerListener);

            ServerListener = new NetworkConnectionAdapter();
            ServerListener.ConnectedCallback += this.OnSessionConnected;
            ServerListener.ConnectionFailedCallback += this.OnSessionConnectionFailed;
            ServerListener.DisconnectedCallback += this.OnSessionDisconnected;
            serverConnection.AddListener((byte)MessageID.StatusOnly, ServerListener);

            this.rootObject = this.Manager.GetRootSyncObject();
            this.rootObject.AddListener(this.syncListener);

            // Listen for new sessions
            SessionManagerListener = new XToolsSessionManagerListener();
            this.SessionManager.AddListener(SessionManagerListener);
        }
Exemplo n.º 2
0
        public void Connect(string server, string userName = "******", int port = 20602, ClientRole clientRole = ClientRole.Primary)
        {
            ClientConfig config = new ClientConfig(clientRole);
            config.SetServerAddress(server);
            config.SetServerPort(port);
            config.SetLogWriter(LogWriter);

            this.SharingManager = SharingManager.Create(config);
            this.SharingManager.SetUserName(userName);
            
            this.viewerConnection = this.SharingManager.GetPairedConnection();
            this.serverConnection = this.SharingManager.GetServerConnection();
            this.SessionManager = this.SharingManager.GetSessionManager();
            
            BeginPairing();

            ViewerListener = new NetworkConnectionAdapter();
            ViewerListener.ConnectedCallback += this.OnViewerConnected;
            ViewerListener.ConnectionFailedCallback += this.OnViewerConnectionFailed;
            ViewerListener.DisconnectedCallback += this.OnViewerDisconnected;
            viewerConnection.AddListener((byte)MessageID.StatusOnly, ViewerListener);

            ServerListener = new NetworkConnectionAdapter();
            ServerListener.ConnectedCallback += this.OnSessionConnected;
            ServerListener.ConnectionFailedCallback += this.OnSessionConnectionFailed;
            ServerListener.DisconnectedCallback += this.OnSessionDisconnected;
            serverConnection.AddListener((byte)MessageID.StatusOnly, ServerListener);

            this.syncListener = new ConsoleSyncReporter();
            this.rootObject = this.SharingManager.GetRootSyncObject();
            this.rootObject.AddListener(this.syncListener);

            SessionManagerListener = new XToolsSessionManagerListener(this.LogWriter);
            this.SessionManager.AddListener(SessionManagerListener);
            networkMessageLoop = new Timer(new TimerCallback((a) => Update()), null, 0, 1000);
        }
        void OnDisconnected(NetworkConnection connection)
        {
            Debug.LogWarning("Remote client disconnected");

            if (this.AutoReconnect)
            {
                StartPairing();
            }
        }
Exemplo n.º 4
0
        private void OnViewerDisconnected(NetworkConnection connection)
        {
            this.IsViewerConnected = false;
            LogWriteLine("App connection disconnected.");

            if (ViewerDisconnected != null)
            {
                ViewerDisconnected(connection);
            }

            BeginPairing();
        }
Exemplo n.º 5
0
        private void OnViewerConnectionFailed(NetworkConnection connection)
        {
            this.IsViewerConnected = false;
            LogWriteLine("App connection failed.");

            if (ViewerConnectionFailed != null)
            {
                ViewerConnectionFailed(connection);
            }
        }
Exemplo n.º 6
0
        private void OnSessionDisconnected(NetworkConnection connection)
        {
            this.IsServerConnected = false;
            LogWriteLine("Server connection disconnected.");

            if (SessionDisconnected != null)
            {
                SessionDisconnected(connection);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>True</c> to release both managed and unmanaged resources; <c>False</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    if (this.syncListener != null)
                    {
                        this.syncListener.Dispose();
                        this.syncListener = null;
                    }

                    if (this.viewerConnection != null)
                    {
                        this.viewerConnection.Dispose();
                        this.viewerConnection = null;
                    }

                    if (this.serverConnection != null)
                    {
                        this.serverConnection.Dispose();
                        this.serverConnection = null;
                    }

                    if (this.rootObject != null)
                    {
                        this.rootObject.Dispose();
                        this.rootObject = null;
                    }

                    if (this.SessionManager != null)
                    {
                        this.SessionManager.Dispose();
                        this.SessionManager = null;
                    }

                    if (this.Manager != null)
                    {
                        this.Manager.Dispose();
                        this.Manager = null;
                    }
                }

                this.disposed = true;
            }
        }
 public override void OnMessageReceived(NetworkConnection connection, NetworkInMessage message)
 {
     Profile.BeginRange("OnMessageReceived");
     this.MessageReceivedCallback?.Invoke(connection, message);
     Profile.EndRange();
 }
 public override void OnDisconnected(NetworkConnection connection)
 {
     Profile.BeginRange("OnDisconnected");
     this.DisconnectedCallback?.Invoke(connection);
     Profile.EndRange();
 }
Exemplo n.º 10
0
        private void CleanupNetworkObjects()
        {
            if (networkMessageLoop != null)
            {
                networkMessageLoop.Dispose();
                networkMessageLoop = null;
            }

            if (this.rootObject != null)
            {
                this.rootObject.RemoveListener(this.syncListener);
                this.rootObject.Dispose();
                this.rootObject = null;
            }

            if (this.syncListener != null)
            {
                this.syncListener.Dispose();
                this.syncListener = null;
            }

            if (viewerConnection != null)
            {
                viewerConnection.RemoveListener((byte)MessageID.StatusOnly, ViewerListener);
                viewerConnection.Disconnect();
                this.viewerConnection.Dispose();
                this.viewerConnection = null;
            }

            if (serverConnection != null)
            {
                serverConnection.RemoveListener((byte)MessageID.StatusOnly, ServerListener);
                serverConnection.Disconnect();
                this.serverConnection.Dispose();
                this.serverConnection = null;
            }

            if (this.SessionManager != null)
            {
                this.SessionManager.RemoveListener(this.SessionManagerListener);
                this.SessionManager.Dispose();
                this.SessionManager = null;
            }

            if (this.SessionManagerListener != null)
            {
                this.SessionManagerListener.Dispose();
                this.SessionManagerListener = null;
            }

            if (SharingManager != null)
            {
                SharingManager.Dispose();
                SharingManager = null;
            }
        }
Exemplo n.º 11
0
        private void OnViewerDisconnected(NetworkConnection connection)
        {
            this.IsViewerConnected = false;
            LogWriteLine("App connection disconnected.");

            ViewerDisconnected?.Invoke(connection);

            BeginPairing();
        }
Exemplo n.º 12
0
        private void OnViewerConnectionFailed(NetworkConnection connection)
        {
            this.IsViewerConnected = false;
            LogWriteLine("App connection failed.");

            ViewerConnectionFailed?.Invoke(connection);
        }
Exemplo n.º 13
0
        private void OnSessionDisconnected(NetworkConnection connection)
        {
            this.IsServerConnected = false;
            LogWriteLine("Server connection disconnected.");

            SessionDisconnected?.Invoke(connection);
        }