Ejemplo n.º 1
0
        /// <summary>
        /// Uploads a file
        /// </summary>
        /// <param name="dropboxFilePath">The target location for the upload</param>
        /// <param name="localFilePath">The local file to upload</param>
        /// <returns>The result of the asynchronous operation</returns>
        internal async Task UploadFileUI(string dropboxFilePath, string localFilePath, bool overwrite)
        {
            try
            {
                lblAction.Text      = "Uploading:";
                lblFileName.Text    = Path.GetFileName(localFilePath);
                lblSource.Text      = Path.GetDirectoryName(localFilePath);
                lblDestination.Text = Path.GetDirectoryName(dropboxFilePath);
                this.Show();
                this.BringToFront();
                _cancellationTokenSource = new CancellationTokenSource();

                using (var dropbox = new DropboxFiles())
                {
                    dropbox.FileTransferProgress += Dropbox_FileTransferProgress;
                    await dropbox.UploadFile(dropboxFilePath, localFilePath, overwrite, _cancellationTokenSource.Token);
                }

                _cancellationTokenSource = null;

                this.Refresh();
                Thread.Sleep(300);
            }
            catch (Exception ex)
            {
                ErrorPanel.ShowError(this, ex);
            }
        }
Ejemplo n.º 2
0
        private void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            if (!string.IsNullOrEmpty(DropboxAuthorization.AccessToken))
            {
                return;
            }

            timerTimeout.Stop();
            busyIcon1.Hide();
            browser.Show();

            if (!e.Url.ToString().StartsWith(Configuration.DropboxAuthorizationUrl, StringComparison.OrdinalIgnoreCase))
            {
                // we need to ignore all navigation that isn't to the redirect uri.
                browser.Focus();
                return;
            }

            try
            {
                if (_Authorization.Validate(e.Url))
                {
                    Authenticated(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                ErrorPanel.ShowError(this, ex);
            }
        }
Ejemplo n.º 3
0
        private async void listview_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            try
            {
                listview.LabelEdit = false;
                if (e.Label == null)
                {
                    listview.Items.RemoveAt(e.Item);
                }
                else
                {
                    string path = _CurrentPath;
                    if (!path.EndsWith("/"))
                    {
                        path += "/";
                    }
                    path += e.Label;

                    using (var dropbox = new DropboxFiles())
                    {
                        await dropbox.CreateFolder(path);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorPanel.ShowError(this, ex);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Navigates to the required folder
        /// </summary>
        /// <param name="path">The path to navigate to</param>
        /// <returns>The result of the asynchronous operation</returns>
        internal async Task NavigateToFolder(OpenDialogType dialogType, string path, string searchTerm)
        {
            _CurrentPath = DropboxFiles.FixPath(path);
            _DialogType  = dialogType;
            _SearchTerm  = searchTerm;

            busyIcon1.Show();
            busyIcon1.BringToFront();

            try
            {
                // Clear the list for for common code path to make UI look correct
                listview.Items.Clear();

                using (var dropbox = new DropboxFiles())
                {
                    FileSystemObjects items;

                    if (string.IsNullOrEmpty(_SearchTerm))
                    {
                        items = await dropbox.GetFolderContents(_CurrentPath, _DialogType);
                    }
                    else
                    {
                        items = await dropbox.Search(_CurrentPath, _DialogType, _SearchTerm);
                    }

                    // We might have ended up in the async method multiple times so lets clear again just in case
                    listview.Items.Clear();

                    foreach (var item in items)
                    {
                        switch (item.ItemType)
                        {
                        case FileSystemObjectType.Folder:
                            var folder = CreateItem(item.Name, "Folder", "", "File folder", "", "", item);
                            listview.Items.Add(folder);
                            break;

                        case FileSystemObjectType.File:
                            if (IncludeFile(item))
                            {
                                var task = AddFile(dropbox, item);
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorPanel.ShowError(this, ex);
            }

            busyIcon1.Hide();
        }
Ejemplo n.º 5
0
 private void workerTest_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
 {
     // If test was successful then navigate browser to dropbox login url
     if (e.Result == null)
     {
         timerTimeout.Start();
         browser.Navigate(_Authorization.URI);
     }
     else
     {
         ErrorPanel.ShowError(this, e.Result as Exception);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds the error panel to a control
        /// </summary>
        /// <param name="parent">The parent control to add the panel to</param>
        /// <param name="message">The message to display</param>
        /// <param name="ex">The initial exception</param>
        internal static void ShowError(Control parent, Exception ex)
        {
            foreach (Control ctl in parent.Controls)
            {
                ctl.Hide();
            }

            ErrorPanel err = new ErrorPanel();

            err.Exception       = ex;
            err.lblMessage.Text = ex.Message;
            err.Dock            = DockStyle.Fill;
            parent.Controls.Add(err);
        }