コード例 #1
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);
                    }
                }
            }
コード例 #2
0
ファイル: Host.cs プロジェクト: wj-wong/PDS_Project
        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