Beispiel #1
0
        } // Reset()

        #endregion // PUBLIC METHODS

        //// ---------------------------------------------------------------------

        #region PRIVATE METHODS
        /// <summary>
        /// Downloads the item.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns><c>true</c>if the item has been successfully downloaded;
        /// otherwise <c>false</c>.</returns>
        private async Task <bool> DownloadItem(TreeNode node)
        {
            var id = node?.Tag as string;

            if (id == null)
            {
                return(false);
            } // if

            var metadata = await this.Service.BrowseMetaData(id, "*");

            if (metadata == null)
            {
                return(false);
            } // if

            var address = metadata.Resource;

            var filename = metadata.Title;
            var ext      = GetFileExtensionFromProtocolInfo(metadata.ProtocolInfo);

            if (string.IsNullOrEmpty(ext))
            {
                ext = ".dat";
            } // if

            if (!filename.EndsWith(ext))
            {
                filename = filename + ext;
            } // if

            if (!string.IsNullOrEmpty(address))
            {
                var dlg = new SaveFileDialog();
                dlg.CheckPathExists = true;
                dlg.FileName        = filename;
                dlg.DefaultExt      = ext;
                if (dlg.ShowDialog(this) != DialogResult.OK)
                {
                    return(true);
                } // if

                if (metadata.Size < 1000000)
                {
                    return(await GetRemoteFileAsync(address, dlg.FileName));
                } // if

                this.progressForm          = new DownloadProgressForm();
                this.progressForm.FileText = filename;
                this.progressForm.SynchronizationContext = SynchronizationContext.Current;
                this.progressForm.Show(this);
                this.GetRemoteFile(address, dlg.FileName, metadata.Size);
                return(true);
            } // if

            Log.Warn("No resource address found!");

            return(false);
        } // DownloadItem()
Beispiel #2
0
        }     // GetRemoteFile()

        /// <summary>
        /// Handles the DownloadFileCompleted event of the Client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.AsyncCompletedEventArgs"/>
        /// instance containing the event data.</param>
        private void OnDownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (this.progressForm != null)
            {
                Log.Info($"Download finished.");
                this.progressForm.Close();
                this.progressForm = null;
            } // if
        }     // OnDownloadFileCompleted()