Exemplo n.º 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;
        }
Exemplo n.º 2
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);
                    }
                }
            }