Exemplo n.º 1
0
        void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                string msg = string.Format("System error while loading directory: {0}", e.Error.Message);
                Log.Error(msg, e.Error);
                this.ViewModel.Status = msg;
            }
            else
            {
                ListDirectoryResult result = (ListDirectoryResult)e.Result;
                switch (result.StatusCode)
                {
                case ResultStatusCode.RetryAuthentication:
                    // Request login- first login will be initiated from here after failing 1st call to pscp which attemps key based auth
                    AuthEventArgs authEvent = new AuthEventArgs
                    {
                        UserName = this.Session.Username,
                        Password = this.Session.Password
                    };
                    this.OnAuthRequest(authEvent);
                    if (authEvent.Handled)
                    {
                        // retry listing
                        this.Session.Username = authEvent.UserName;
                        this.Session.Password = authEvent.Password;
                        this.LoadDirectory(result.Path);
                    }
                    break;

                case ResultStatusCode.Success:
                    // list files
                    string msg = result.MountCount > 0
                            ? string.Format("{0} items", result.MountCount)
                            : string.Format("{0} files {1} directories", result.FileCount, result.DirCount);
                    this.ViewModel.Status      = string.Format("{0} @ {1}", msg, DateTime.Now);
                    this.CurrentPath           = result.Path;
                    this.ViewModel.CurrentPath = result.Path.Path;
                    BrowserViewModel.UpdateList(this.ViewModel.Files, result.Files);
                    break;

                case ResultStatusCode.Error:
                    string errMsg = result.ErrorMsg != null
                            ? result.ErrorMsg
                            : result.Error != null
                                ? string.Format("Error listing directory, {0}", result.Error.Message)
                                : "Unknown Error listing directory";

                    Log.Error(errMsg, result.Error);
                    this.ViewModel.Status = errMsg;
                    break;

                default:
                    Log.InfoFormat("Unknown result '{0}'", result.StatusCode);
                    break;
                }
            }
            this.ViewModel.BrowserState = BrowserState.Ready;
        }
Exemplo n.º 2
0
        public void LocalViewModel()
        {
            BrowserViewModel viewModel = new BrowserViewModel();

            // test notify
            string updatedProp = null;
            viewModel.PropertyChanged += (s, e) =>  
            {
                Log.InfoFormat("PropertyChanged: {0}", e.PropertyName);
                updatedProp = e.PropertyName;
            };
            viewModel.Status = "foobar";
            Assert.AreEqual("Status", updatedProp);

            Assert.IsNotNull(viewModel.Files);
        }
Exemplo n.º 3
0
        /// <summary>Construct a new instance of the BrowserPresenter class with parameters</summary>
        /// <param name="name">A string that identifies the name of the associated <seealso cref="ViewModel"/> e.g. "Local" or "Remote"</param>
        /// <param name="model">The BrowserModel object used to get the data from a file system</param>
        /// <param name="session">The session information containing host, ip, and other data specific to the BrowserModel</param>
        /// <param name="fileTransferPresenter">Methods and tools for working with file transfers</param>
        public BrowserPresenter(string name, IBrowserModel model, SessionData session, IFileTransferPresenter fileTransferPresenter)
        {
            Model   = model;
            Session = session;

            FileTransferPresenter = fileTransferPresenter;
            FileTransferPresenter.ViewModel.FileTransfers.ListChanged += FileTransfers_ListChanged;

            BackgroundWorker = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };
            BackgroundWorker.DoWork             += BackgroundWorker_DoWork;
            BackgroundWorker.ProgressChanged    += BackgroundWorker_ProgressChanged;
            BackgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;

            ViewModel = new BrowserViewModel
            {
                Name         = name,
                BrowserState = BrowserState.Ready
            };
        }