Пример #1
0
        void controlConnectionWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            byte[] arg = (byte[])e.UserState;
            if (arg == TipoComandoBytes.ACTIVE_CLIPBOARD_ACK)
            {
                if (isCopy)
                {
                    clipboard = new MyClipboard();
                }
                clipboardConnectionWorker.RunWorkerAsync();
                return;
            }

            try
            {
                WriteMessage(server.TCPControlChannel.GetStream(), arg, 0, arg.Length);
            }
            catch (IOException ioe)
            {
                Trace.TraceError("IOException in controlConnectionWorker_ProgressChanged(). Stack trace:\n{0}\n", ioe.StackTrace);
                state = State.CLOSED_ERROR_SERVER;
                controlConnectionWorker.CancelAsync();
            }
            catch (NetworkException)
            {
                Trace.TraceError("NetworkException in controlConnectionWorker_ProgressChanged().");
                state = State.CLOSED_ERROR_NETWORK;
                controlConnectionWorker.CancelAsync();
            }
        }
Пример #2
0
        public ServerConnection(Server server, Connection connection)
        {
            this.server     = server;
            this.connection = connection;
            this.state      = State.CONNECTED;
            this.random     = new Random();

            server.TCPControlChannel.GetStream().ReadTimeout = random.Next(TIMEOUT_MIN, TIMEOUT_MAX);
            clipboard = new MyClipboard();

            //Thread Control Connection
            controlConnectionWorker = new BackgroundWorker();
            controlConnectionWorker.WorkerSupportsCancellation = true;
            controlConnectionWorker.DoWork               += controlConnectionWorker_DoWork;
            controlConnectionWorker.RunWorkerCompleted   += controlConnectionWorker_RunWorkerCompleted;
            controlConnectionWorker.WorkerReportsProgress = true;
            controlConnectionWorker.ProgressChanged      += controlConnectionWorker_ProgressChanged;
            controlConnectionWorker.RunWorkerAsync();
            //Thread Clipboard Move
            clipboardConnectionWorker = new BackgroundWorker();
            clipboardConnectionWorker.WorkerSupportsCancellation = true;
            clipboardConnectionWorker.WorkerReportsProgress      = true;
            clipboardConnectionWorker.DoWork             += clipboardConnectionWorker_DoWork;
            clipboardConnectionWorker.ProgressChanged    += clipboardConnectionWorker_ProgressChanged;
            clipboardConnectionWorker.RunWorkerCompleted += clipboardConnectionWorker_RunWorkerCompleted;
        }
        public ServerConnection(Server server, Connection connection)
        {
            this.server = server;
            this.connection = connection;
            this.state = State.CONNECTED;
            this.random = new Random();

            server.TCPControlChannel.GetStream().ReadTimeout = random.Next(TIMEOUT_MIN, TIMEOUT_MAX);
            clipboard = new MyClipboard();

            //Thread Control Connection
            controlConnectionWorker = new BackgroundWorker();
            controlConnectionWorker.WorkerSupportsCancellation = true;
            controlConnectionWorker.DoWork += controlConnectionWorker_DoWork;
            controlConnectionWorker.RunWorkerCompleted += controlConnectionWorker_RunWorkerCompleted;
            controlConnectionWorker.WorkerReportsProgress = true;
            controlConnectionWorker.ProgressChanged += controlConnectionWorker_ProgressChanged;
            controlConnectionWorker.RunWorkerAsync();
            //Thread Clipboard Move
            clipboardConnectionWorker = new BackgroundWorker();
            clipboardConnectionWorker.WorkerSupportsCancellation = true;
            clipboardConnectionWorker.WorkerReportsProgress = true;
            clipboardConnectionWorker.DoWork += clipboardConnectionWorker_DoWork;
            clipboardConnectionWorker.ProgressChanged += clipboardConnectionWorker_ProgressChanged;
            clipboardConnectionWorker.RunWorkerCompleted += clipboardConnectionWorker_RunWorkerCompleted;
        }
Пример #4
0
 public MyClipboard(MyClipboard clipboardToCopy)
 {
     DirectoryFileDir = clipboardToCopy.DirectoryFileDir;
     BytesImage = clipboardToCopy.BytesImage;
     BytesAudio = clipboardToCopy.BytesAudio;
     TextClipboard = clipboardToCopy.TextClipboard;
     NumFiles = clipboardToCopy.NumFiles;
     Dimension = clipboardToCopy.Dimension;
 }
Пример #5
0
 public MyClipboard(MyClipboard clipboardToCopy)
 {
     DirectoryFileDir = clipboardToCopy.DirectoryFileDir;
     BytesImage       = clipboardToCopy.BytesImage;
     BytesAudio       = clipboardToCopy.BytesAudio;
     TextClipboard    = clipboardToCopy.TextClipboard;
     NumFiles         = clipboardToCopy.NumFiles;
     Dimension        = clipboardToCopy.Dimension;
 }
Пример #6
0
        internal void TransferCompleted(ServerConnection serverConnection, MyClipboard clipboardServer, bool isCopy)
        {
            if (isCopy)
            {
                clipboardClient = new MyClipboard(clipboardServer);
            }
            ServerTranferEventArgs args = new ServerTranferEventArgs
            {
                Server     = serverConnection.Server,
                Position   = serverConnessi.IndexOf(serverConnection),
                Copy       = isCopy,
                Completed  = true,
                Percentage = 100
            };
            EventHandler <ServerTranferEventArgs> handler = this.ServerTransferCompleted;

            if (handler != null)
            {
                handler(this, args);
            }
        }
Пример #7
0
 public Connection()
 {
     started             = false;
     clipboardClient     = new MyClipboard();
     serverInConnessione = new BlockingCollection <Server>(10);
     serverToConnect     = new ConcurrentQueue <Server>();
     serverConnessi      = new List <ServerConnection>();
     sendBroadcastWorker = new BackgroundWorker();
     sendBroadcastWorker.WorkerSupportsCancellation = true;
     sendBroadcastWorker.DoWork += sendBroadcastWorker_DoWork;
     connectServerWorker         = new BackgroundWorker();
     connectServerWorker.WorkerSupportsCancellation = true;
     connectServerWorker.WorkerReportsProgress      = true;
     connectServerWorker.DoWork          += connectServerWorker_DoWork;
     connectServerWorker.ProgressChanged += connectServerWorker_ProgressChanged;
     riceviInfoServerWorker = new BackgroundWorker();
     riceviInfoServerWorker.WorkerSupportsCancellation = true;
     riceviInfoServerWorker.WorkerReportsProgress      = true;
     riceviInfoServerWorker.DoWork          += riceviInfoServerWorker_DoWork;
     riceviInfoServerWorker.ProgressChanged += riceviInfoServerWorker_ProgressChanged;
 }
Пример #8
0
 public Connection()
 {
     started = false;
     clipboardClient = new MyClipboard();
     serverInConnessione = new BlockingCollection<Server>(10);
     serverToConnect = new ConcurrentQueue<Server>();
     serverConnessi = new List<ServerConnection>();
     sendBroadcastWorker = new BackgroundWorker();
     sendBroadcastWorker.WorkerSupportsCancellation = true;
     sendBroadcastWorker.DoWork += sendBroadcastWorker_DoWork;
     connectServerWorker = new BackgroundWorker();
     connectServerWorker.WorkerSupportsCancellation = true;
     connectServerWorker.WorkerReportsProgress = true;
     connectServerWorker.DoWork += connectServerWorker_DoWork;
     connectServerWorker.ProgressChanged += connectServerWorker_ProgressChanged;
     riceviInfoServerWorker = new BackgroundWorker();
     riceviInfoServerWorker.WorkerSupportsCancellation = true;
     riceviInfoServerWorker.WorkerReportsProgress = true;
     riceviInfoServerWorker.DoWork += riceviInfoServerWorker_DoWork;
     riceviInfoServerWorker.ProgressChanged += riceviInfoServerWorker_ProgressChanged;
 }
Пример #9
0
 public void RemotePaste(MyClipboard clipboardToSend)
 {
     if (state != State.ACTIVE)
     {
         return;
     }
     try
     {
         //mando il mex per attivare la CLIPBOARD per effettuare il Remote Copy
         if (!clipboardConnectionWorker.IsBusy && !clipboardToSend.isEmpty())
         {
             clipboard = new MyClipboard(clipboardToSend);
             isCopy    = false;
             WriteMessage(server.TCPControlChannel.GetStream(), TipoComandoBytes.ACTIVE_CLIPBOARD_RP, 0, TipoComandoBytes.ACTIVE_CLIPBOARD_RC.Length);
         }
     }
     catch (NetworkException)
     {
         Trace.TraceError("NetworkException in RemotePaste().");
         state = State.CLOSED_ERROR_NETWORK;
         controlConnectionWorker.CancelAsync();
     }
     catch (Exception se)
     {
         Trace.TraceError("Exception in RemotePaste(). Stack trace:\n{0}\n", se.StackTrace);
         if (se is IOException || se is SocketException)
         {
             state = State.CLOSED_ERROR_SERVER;
             controlConnectionWorker.CancelAsync();
         }
         else
         {
             state = State.CLOSED_ERROR_SERVER;
             controlConnectionWorker.CancelAsync();
         }
     }
 }
Пример #10
0
 internal void TransferCompleted(ServerConnection serverConnection, MyClipboard clipboardServer, bool isCopy)
 {
     if (isCopy)
     {
         clipboardClient = new MyClipboard(clipboardServer);
     }
     ServerTranferEventArgs args = new ServerTranferEventArgs
     {
         Server = serverConnection.Server,
         Position = serverConnessi.IndexOf(serverConnection),
         Copy = isCopy,
         Completed = true,
         Percentage = 100
     };
     EventHandler<ServerTranferEventArgs> handler = this.ServerTransferCompleted;
     if (handler != null)
     {
         handler(this, args);
     }
 }
        void controlConnectionWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            byte[] arg = (byte[])e.UserState;
            if (arg == TipoComandoBytes.ACTIVE_CLIPBOARD_ACK)
            {
                if (isCopy) { clipboard = new MyClipboard(); }
                clipboardConnectionWorker.RunWorkerAsync();
                return;
            }

            try
            {
                WriteMessage(server.TCPControlChannel.GetStream(), arg, 0, arg.Length);
            }
            catch (IOException ioe)
            {
                Trace.TraceError("IOException in controlConnectionWorker_ProgressChanged(). Stack trace:\n{0}\n", ioe.StackTrace);
                state = State.CLOSED_ERROR_SERVER;
                controlConnectionWorker.CancelAsync();
            }
            catch (NetworkException)
            {
                Trace.TraceError("NetworkException in controlConnectionWorker_ProgressChanged().");
                state = State.CLOSED_ERROR_NETWORK;
                controlConnectionWorker.CancelAsync();
            }
        }
        public void RemotePaste(MyClipboard clipboardToSend)
        {
            if (state != State.ACTIVE) return;
            try
            {
                //mando il mex per attivare la CLIPBOARD per effettuare il Remote Copy
                if (!clipboardConnectionWorker.IsBusy && !clipboardToSend.isEmpty())
                {
                    clipboard = new MyClipboard(clipboardToSend);
                    isCopy = false;
                    WriteMessage(server.TCPControlChannel.GetStream(), TipoComandoBytes.ACTIVE_CLIPBOARD_RP, 0, TipoComandoBytes.ACTIVE_CLIPBOARD_RC.Length);

                }
            }
            catch (NetworkException )
            {
                Trace.TraceError("NetworkException in RemotePaste().");
                state = State.CLOSED_ERROR_NETWORK;
                controlConnectionWorker.CancelAsync();
            }
            catch (Exception se)
            {
                Trace.TraceError("Exception in RemotePaste(). Stack trace:\n{0}\n", se.StackTrace);
                if (se is IOException || se is SocketException)
                {
                    state = State.CLOSED_ERROR_SERVER;
                    controlConnectionWorker.CancelAsync();
                }
                else
                {
                    state = State.CLOSED_ERROR_SERVER;
                    controlConnectionWorker.CancelAsync();
                }
            }
        }