Exemplo n.º 1
0
            public FileTransferUiProxy(IFileTransfer ft)
            {
                View = new FileTransferViewItem(Path.GetFileName(ft.Name), ft.BytesTotal, ft.Direction);
                Desc = ft;
                switch (ft.Direction)
                {
                case FileTransferDirection.In:
                    // waiting
                    View.Accept  += ViewAccept;
                    View.Decline += ViewDecline;
                    whBound       = true;
                    // receiving
                    View.Cancel += ViewCancel;
                    // received
                    View.Open         += ViewOpen;
                    View.ShowInFolder += ViewShowInFolder;
                    View.Conceal      += ViewConceal;
                    break;

                case FileTransferDirection.Out:
                    View.Cancel  += ViewCancel;
                    View.Conceal += ViewConceal;
                    break;
                }
                lastUpdate = DateTime.Now;
            }
Exemplo n.º 2
0
        public void RunMockView()
        {
            Form form = new Form();

            MockFileTransferPresenter presenter = new MockFileTransferPresenter();

            presenter.ViewModel.FileTransfers.Add(
                new FileTransferViewItem("Running", "Source", "Target")
            {
                Progress = 50,
                Start    = DateTime.Now,
                Message  = "Chugging...",
                Status   = FileTransfer.Status.Running
            });
            presenter.ViewModel.FileTransfers.Add(
                new FileTransferViewItem("Done", "Source", "Target")
            {
                Progress = 100,
                Start    = DateTime.Now,
                Message  = "Completed in 23.3s",
                Status   = FileTransfer.Status.Complete
            });
            presenter.ViewModel.FileTransfers.Add(
                new FileTransferViewItem("Done", "Source", "Target")
            {
                Progress = 10,
                Start    = DateTime.Now,
                Message  = "Canceled",
                Status   = FileTransfer.Status.Canceled
            });

            FileTransferView view = new FileTransferView(presenter)
            {
                Dock = DockStyle.Fill
            };

            form.Controls.Add(view);
            form.Size = new Size(1024, 250);
            form.Show();

            Thread thread = new Thread(() =>
            {
                Thread.Sleep(1000);
                // simulate updates
                int increment = 1;
                while (true)
                {
                    Thread.Sleep(100);
                    FileTransferViewItem item = presenter.ViewModel.FileTransfers[0];
                    if (item.Progress == 99 || item.Progress == 1)
                    {
                        increment *= -1;
                    }
                    item.Progress += increment;

                    if (view.IsDisposed)
                    {
                        break;
                    }

                    view.BeginInvoke(new Action(() => presenter.ViewModel.FileTransfers.ResetItem(0)), null);
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }