Exemple #1
0
        public string GetFilenameFromWebServer(DownloadLinkEnum downloadEnum)
        {
            try
            {
                var          request                = WebRequest.Create(GetEnumDescription(downloadEnum));
                var          response               = request.GetResponse();
                var          contentDisposition     = response.Headers["Content-Disposition"];
                const string contentFileNamePortion = "filename=";
                var          fileNameStartIndex     = contentDisposition.IndexOf(contentFileNamePortion, StringComparison.InvariantCulture) + contentFileNamePortion.Length;

                var originalFileNameLength = contentDisposition.Length - fileNameStartIndex;
                var originalFileName       = contentDisposition.Substring(fileNameStartIndex, originalFileNameLength);

                char[] trims   = { '"' };
                var    insert_ = originalFileName.Replace(" ", "_");

                var removefront = insert_.TrimStart(trims);

                originalFileName = removefront.TrimEnd(trims);

                return(originalFileName);
            }
            catch (NullReferenceException)
            {
                return(downloadEnum.ToString() + ".exe");
            }
            catch (WebException)
            {
                return(downloadEnum.ToString());
            }
        }
Exemple #2
0
        private void FileDownloadComplete(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                DownloadUpdate.Text = "The download has been canceled";
            }
            else if (e.Error != null) // We have an error! Retry a few times, then abort.
            {
                DownloadUpdate.Text = "An error occurred while trying to download file";
            }
            else
            {
                DownloadUpdate.Text = currentDownload.ToString() + " Download Complete";
            }

            Thread.Sleep(500);

            if (downloadApps.Count == 0)
            {
                DownloadUpdate.Text = "All Download Completed";
                Active = false;
                return;
            }
            else
            {
                DownloadFile(downloadApps.Pop());
            }
        }
Exemple #3
0
        string GetEnumDescription(DownloadLinkEnum enumValue)
        {
            var type       = typeof(DownloadLinkEnum);
            var memInfo    = type.GetMember(enumValue.ToString());
            var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(((DescriptionAttribute)attributes[0]).Description);
        }