コード例 #1
0
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string finalMessage = String.Empty;

            if (e.Error != null)
            {
                finalMessage = e.Error.GetType().ToString() + ": " + e.Error.Message;
                ClipboardTrasfer.ShowErrorMessage(e.Error);
            }
            else if (e.Cancelled)
            {
                finalMessage = "Timeout expired. File will be deleted";
                Thread.Sleep(300);
                File.Delete(fileName);
            }
            else
            {
                Console.WriteLine(fileName + " download COMPLETED!!!");
            }

            ClipboardNetworkChannel.downloadCompleted(this);

            if (view != null)
            {
                view.progressLabel.Content = finalMessage;
                Thread.Sleep(500);
                view.Close();
            }
        }
コード例 #2
0
        public static void connectToServer()
        {
            try
            {
                socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socket.Connect(new IPEndPoint(MainWindow.serverIP, MainWindow.connectRemotePort));

                byte[] bufferToSend = Encoding.Unicode.GetBytes(passwdDigest);
                Utility.SendBytes(socket, bufferToSend, bufferToSend.Length, SocketFlags.None);

                byte[] response = new byte[4];
                if (!Utility.ReceiveBytes(socket, response, response.Length, SocketFlags.None))
                {
                    throw new Exception();
                }

                if (Encoding.Unicode.GetString(response).Equals("OK"))
                {
                    MessageBox.Show("Connected");
                    InputEventTransfer.Target = new IPEndPoint(MainWindow.serverIP, MainWindow.inputRemotePort);
                    ClipboardNetworkChannel.StartService(MainWindow.clipboardLocalPort);
                    ClipboardTrasfer.Target = new IPEndPoint(MainWindow.serverIP, MainWindow.clipboardRemotePort);

                    OnClientConnected();
                }
                else
                {
                    MessageBox.Show("Wrong password");
                    ConnectWindow.worker.ReportProgress(70);
                    Utility.ShutdownSocket(socket);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    e.Message);
                ConnectWindow.worker.ReportProgress(50);
                Utility.ShutdownSocket(socket);
                ClipboardTrasfer.StopService();
                ClipboardNetworkChannel.StopService();
                InputEventTransfer.StopService();
            }
        }
コード例 #3
0
 public static void disconnectFromServer()
 {
     try
     {
         byte[] bufferBye = Encoding.Unicode.GetBytes("BYE");
         Utility.SendBytes(socket, bufferBye, bufferBye.Length, SocketFlags.None);
     }
     catch (Exception)
     {
         Utility.ShutdownSocket(socket);
     }
     finally
     {
         MainWindow.keep.DeadClient = null;
         OnClientDisconnected();
         InputEventTransfer.StopService();
         ClipboardNetworkChannel.StopService();
         ClipboardTrasfer.StopService();
         Utility.ShutdownSocket(socket);
         MessageBox.Show("Disconnected");
     }
 }
コード例 #4
0
        public static void SendClipboardNotice(IDataObject obj)
        {
            if (obj.GetDataPresent(DataFormats.Text))
            {
                string text = (string)obj.GetData(DataFormats.Text);
                ClipboardTrasfer.SendText(text);
            }
            else if (obj.GetDataPresent(DataFormats.FileDrop))
            {
                /* get the list of absolute file paths actually inside Windows Clipboard */
                var dropList = (string[])obj.GetData(DataFormats.FileDrop, false);

                if (!ConfirmSend(dropList))
                {
                    return;
                }

                /* get parent folder, i.e. the folder in which Windows Clipboard was changed */
                int    lastDirSeparatorIndex = (dropList[0].LastIndexOf('\\') + 1);
                string parentDir             = dropList[0].Remove(lastDirSeparatorIndex);

                string path = "";
                foreach (string s in dropList)
                {
                    path += s.Substring(parentDir.Length);
                    path += "|";
                }
                path = path.Remove(path.Length - 1);

                foreach (string absoluteFilePath in dropList)
                {
                    /*
                     * Check if current absolute file path inside the Clipboard represents
                     * a Directory and (if greater than MAX_SIZE) user confirmed its transfer
                     */
                    if (Directory.Exists(absoluteFilePath))
                    {
                        /* First, send to client the current folder... */
                        ClipboardTrasfer.SendNewFolder(absoluteFilePath, ref parentDir);

                        /* ...and all its subfolders */
                        string[] subDirs = Directory.GetDirectories(absoluteFilePath, "*.*", SearchOption.AllDirectories);
                        foreach (string dir in subDirs)
                        {
                            ClipboardTrasfer.SendNewFolder(dir, ref parentDir);
                        }
                        /* finally, send to client all subfiles in order to 'fill' all previously sent folders */
                        string[] subFiles = Directory.GetFiles(absoluteFilePath, "*.*", System.IO.SearchOption.AllDirectories);
                        foreach (string file in subFiles)
                        {
                            ClipboardTrasfer.SendFile(file, ref parentDir);
                        }
                    }

                    /*
                     * Check if current absolute file path inside the Clipboard represents
                     * a File and (if greater than MAX_SIZE) user confirmed its transfer
                     */
                    else if (File.Exists(absoluteFilePath))
                    {
                        ClipboardTrasfer.SendFile(absoluteFilePath, ref parentDir);
                    }
                }

                /*
                 * Finally, send the path drop list, so that Clipboard could change for the counterpart
                 */
                ClipboardTrasfer.SendPathDropList(path);
            }
            else if (obj.GetDataPresent(DataFormats.Bitmap))
            {
                BitmapSource bitmap = (BitmapSource)obj.GetData(DataFormats.Bitmap);
                ClipboardTrasfer.SendBitmap(bitmap);
            }
        }