コード例 #1
0
        /// <summary>
        /// Start the transfer
        /// </summary>
        public void StartTransfer()
        {
            //------------------------------------
            //  Wake up the transfer thread
            //------------------------------------

            lock (this)
            {
                Status = Reply.ACCEPTED;
                Monitor.Pulse(this);
            }

            //------------------------------------
            //  Re-activate the Transfers Window
            //------------------------------------

            //  NOTE: Apparently, t.Show() or/with t.Activate() do not re-activate it.
            TransfersWindow t = (TransfersWindow)Application.Current.Properties["TransfersWindow"];

            t.WindowState = WindowState.Normal;
            t.Topmost     = true;
            t.Show();
            t.Activate();
            t.Topmost = false;

            //  Now you can actually close this window
            TheWindow.Close();
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="w">The window</param>
        /// <param name="Client">The client</param>
        public IncomingTransferViewModel(ConnectionWindow w, TcpClient Client)
        {
            //------------------------------------
            //  Init
            //------------------------------------

            PrivateSender = false;
            TheWindow     = w;
            SelectFolder  = new ChooseFolder(this);

            //------------------------------------
            //  Add the transfer but don't start it yet
            //------------------------------------

            List <Task> Transfers = (List <Task>)Application.Current.Properties["Transfers"];

            Transfers.Add(Task.Run(() =>
            {
                Receive Receiver = new Receive(Client);
                if (!Receiver.ParseHello())
                {
                    //  Not a valid request? then just close the window (NOTE: it is still hidden at this point)
                    TheWindow.Dispatcher.InvokeAsync(() =>
                    {
                        TheWindow.Close();
                    });
                    return;
                }
                else
                {
                    //  Open the window to ask user to accept or reject
                    TheWindow.Dispatcher.InvokeAsync(() =>
                    {
                        TheWindow.InitializeComponent();
                        TheWindow.DataContext = this;
                        TheWindow.Topmost     = true;
                        TheWindow.Show();
                        TheWindow.Activate();
                        TheWindow.Topmost = false;
                    });
                }

                //------------------------------------
                //  Render data
                //------------------------------------

                if (Receiver.SenderUser != null)
                {
                    UserRequestText    = Receiver.SenderUser.Name + " wants to send you";
                    UserProfilePicture = Receiver.SenderUser.PicBytes;
                }
                else
                {
                    UserRequestText = "A private user wants to send you";
                    PrivateSender   = true;
                }

                if (!Receiver.IsFolder)
                {
                    FileName         = Receiver.FileName + "." + Receiver.FileExtension;
                    UserRequestText += " a file:";
                    _Size            = Receiver.FileSize;
                    Extension        = Receiver.FileExtension;
                }
                else
                {
                    string[] _name   = Receiver.FileName.Split('/');
                    FileName         = _name[0];
                    UserRequestText += " a folder:";
                }

                //------------------------------------
                //  Wait for user's confirmation
                //------------------------------------

                lock (this)
                {
                    if (Status == Reply.UNANSWERED)
                    {
                        Monitor.Wait(this);
                    }
                }

                //------------------------------------
                //  Deal with user's decision
                //------------------------------------

                if (!SelectedPath.Equals(String.Empty))
                {
                    Receiver.FolderLocation = SelectedPath;
                }

                if (Status == Reply.ACCEPTED)
                {
                    Receiver.Start();
                }
                else
                {
                    Receiver.Reject(true);
                }
            }));

            Accept = new AcceptTransfer(this);
            Reject = new RejectTransfer(this);
        }