Пример #1
0
        private void sendClipboardDatas()
        {
            //MessageBox.Show("Sending clipboard to server:" + i.ToString() + " .\nYou will be advised when the transfer is completed.", "Starting Transfer", MessageBoxButtons.OK, MessageBoxIcon.Information);

            Socket s = _host.ds(i);

            if (s == null)
            {
                EnableCB();
                return;
            }

            IDataObject clipboardData = Clipboard.GetDataObject();

            string[] formats = clipboardData.GetFormats();

            try{
                foreach (string format in formats)
                {
                    //Console.WriteLine("Analizing clipboard. FORMAT FOUND: " + format);
                    if (format == DataFormats.FileDrop)
                    {
                        continue;
                    }
                    MsgStream.Send(new DataMsgCBP(format, clipboardData.GetData(format)), _host.ds(i));
                }

                /* SENDING FILE TYPE */

                if (Clipboard.ContainsFileDropList())
                {
                    long size = ClipboardFiles.GetCBFilesSize();
                    if (size > ClipboardFiles.MaxSize)
                    {
                        if (MessageBox.Show("The size of clipboard's content is greater than MaxSize: " + ClipboardFiles.MaxSize
                                            + " \nConfirm the transfer?", "Closing Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            EnableCB();
                            return;
                        }
                    }

                    MsgStream.Send(new InitFileCBP(), s);
                    ClipboardFiles.SendClipboardFiles(s);
                    MsgStream.Send(new StopFileCBP(), s);
                    ConfirmCBP m = (ConfirmCBP)MsgStream.Receive(s);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Ops...\nSomething goes wrong during Clipboard Transfer[on Sending].\nThe connection will be closed.\nTry again later.",
                                                     "Clipboard Transfer Error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                this.DisconnectionReq();
                Console.WriteLine("Clipboard file transfer error: " + e.Message);
            }


            EnableCB();
            return;
        }
Пример #2
0
 private void Quit()
 {
     if (MessageBox.Show("The program is going to quit, all the connections will be shutdown.\nConfirm?", "Closing Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         for (int k = 0; k < 4; k++)
         {
             _sp[k].DisconnectionReq();
         }
         eThread.Abort();
         dThread.Abort();
         ClipboardFiles.FreeTmpResources();
         Application.Exit();
     }
 }
Пример #3
0
            public override void Update()
            {
                base.Update();

                if (_obj is DataMsgCBP)
                {
                    DataMsgCBP dataMsgCBP = (DataMsgCBP)_obj;
                    Clipboard.SetData(dataMsgCBP.format, dataMsgCBP.content);
                }
                else if (_obj is InitFileCBP)
                {
                    ClipboardFiles.RecvClipboardFiles(Server.CommSocket);
                }
                else if (_obj is GetMsgCBP)
                {
                    IDataObject clipboardData = Clipboard.GetDataObject();
                    string[]    formats       = clipboardData.GetFormats();
                    foreach (string format in formats)
                    {
                        if (format == DataFormats.FileDrop)
                        {
                            continue;
                        }
                        Console.WriteLine("Format: " + format);
                        MsgStream.Send(new DataMsgCBP(format, clipboardData.GetData(format)),
                                       Server.CommSocket);
                    }

                    if (Clipboard.ContainsFileDropList())
                    {
                        if (ClipboardFiles.GetCBFilesSize() > ClipboardFiles.MaxSize)
                        {
                            MsgStream.Send(new MaxSizeCBP(), Server.CommSocket);
                            Object response = MsgStream.Receive(Server.CommSocket);
                            if (!(response is ConfirmCBP))
                            {
                                return;
                            }
                        }
                        MsgStream.Send(new InitFileCBP(), Server.CommSocket);
                        ClipboardFiles.SendClipboardFiles(Server.CommSocket);
                        MsgStream.Send(new StopFileCBP(), Server.CommSocket);
                        MsgStream.Receive(Server.CommSocket); // wait for an ack
                    }
                    else
                    {
                        MsgStream.Send(new StopFileCBP(), Server.CommSocket);
                    }
                }
            }
Пример #4
0
        /// <summary>
        /// Pulire le risorse in uso.
        /// </summary>
        /// <param name="disposing">ha valore true se le risorse gestite devono essere eliminate, false in caso contrario.</param>
        protected override void Dispose(bool disposing)
        {
            // Save settings
            if (ipListBox.SelectedItem != null)
            {
                Properties.Settings.Default["IpAddress"] = ipListBox.SelectedItem.ToString();
            }
            else
            {
                Properties.Settings.Default["IpAddress"] = "";
            }
            Properties.Settings.Default["EventsPort"]    = (ushort)eventsPortUpDown.Value;
            Properties.Settings.Default["ClipboardPort"] = (ushort)clipboardUpDown.Value;
            Properties.Settings.Default["Password"]      = psswBox.Text;
            Properties.Settings.Default["Autorun"]       = autorunCheckBox.Checked;
            Properties.Settings.Default.Save();
            RegistryKey key;

            key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\", true);
            if (autorunCheckBox.Checked)
            {
                key.SetValue(ProgramKeyName, "\"" + AppDomain.CurrentDomain.BaseDirectory +
                             AppDomain.CurrentDomain.FriendlyName + "\"");
            }
            else
            {
                if (key.GetValue(ProgramKeyName, null) != null)
                {
                    key.DeleteValue("PDS_Project_Server");
                }
            }
            key.Close();


            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
            if (_evtServer != null)
            {
                _evtServer.Terminate();
            }
            if (_clpbServer != null)
            {
                _clpbServer.Terminate();
            }
            _blinking.Terminate();
            ClipboardFiles.FreeTmpResources();
        }
Пример #5
0
        public void ReceiveCBMsg()
        {
            Message m;
            int     i = 0;

            while (true)
            {
                while (_de.WaitOne())
                {
                    lock (_dq) { m = _dq.Dequeue(); }
                    i = ((GetMsgCBP)m).i;

                    //Console.WriteLine("Processing Getting RQ to: " + i);

                    if ((i != 0) && (i != 1) && (i != 2) && (i != 3))
                    {
                        continue;
                    }

                    if (_ds[i] != null)
                    {
                        _sp[i].CBGetting();

                        try
                        {
                            MsgStream.Send(m, _ds[i]);
                            //Console.WriteLine("richiesta di ricezione inviata");

                            do
                            {
                                m = (Message)MsgStream.Receive(_ds[i]);

                                if (m is DataMsgCBP)
                                {
                                    DataMsgCBP dataMsgCBP = (DataMsgCBP)m;
                                    //Console.WriteLine("ricevuto pacchetto: " + dataMsgCBP.format);
                                    System.Windows.Forms.Clipboard.SetData(dataMsgCBP.format, dataMsgCBP.content);
                                }


                                if (m is InitFileCBP) //FILEMSG
                                {
                                    /*
                                     * System.Windows.Forms.MessageBox.Show("Receiving file/s from server: " + i.ToString()
                                     + " .\nYou will be advised when the transfer is completed.", "Starting File/s Transfer",
                                     +  System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                                     */

                                    ClipboardFiles.RecvClipboardFiles(_ds[i]);
                                    Console.WriteLine("CBP : Received Files.");

                                    /*
                                     *
                                     * System.Windows.Forms.MessageBox.Show("File/s received from server: " + i.ToString()
                                     + " .", "Transfer completed",
                                     +  System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                                     */
                                    _sp[i].EnableCB();
                                    break;
                                }

                                if (m is MaxSizeCBP)
                                {
                                    if (System.Windows.Forms.MessageBox.Show("The size of clipboard's content is greater than MaxSize: " + ClipboardFiles.MaxSize
                                                                             + " \nConfirm the transfer?", "File size exceeding", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
                                    {
                                        System.Windows.Forms.MessageBox.Show("Receiving file/s from server: " + i.ToString()
                                                                             + " .\nYou will be advised when the transfer is completed.", "Starting File/s Transfer",
                                                                             System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);

                                        MsgStream.Send(new ConfirmCBP(), _ds[i]);
                                        ClipboardFiles.RecvClipboardFiles(_ds[i]);

                                        System.Windows.Forms.MessageBox.Show("File/s received from server: " + i.ToString()
                                                                             + " .", "Transfer completed",
                                                                             System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);

                                        _sp[i].EnableCB();
                                        break;
                                    }
                                    else
                                    {
                                        MsgStream.Send(new StopFileCBP(), _ds[i]);
                                        _sp[i].EnableCB();
                                        break;
                                    }
                                }
                            }while(!(m is StopFileCBP));

                            _sp[i].EnableCB();
                        }
                        catch (Exception e)
                        {
                            //Console.WriteLine("Errore nella richiesta CB: chiusura sockets e disconnessione.");
                            System.Windows.Forms.MessageBox.Show("Ops...\nSomething goes wrong during Clipboard Transfer[on Receiving].\nThe connection will be closed.\nTry again later.",
                                                                 "Clipboard Transfer Error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                            _sp[i].DisconnectionReq();
                            Console.WriteLine("Clipboard file transfer error: " + e.Message);
                        }
                    } //end checking socket nullity
                }     //end wait condition
            }         //end infinite loop
        }             //end ReceiveCBMsg