public async Task ItThrowsIfDestinationPathIsNull()
        {
            ProductRelease release = GetProductRelease("2.1", "2.1.8");
            ReleaseFile    file    = release.Files.FirstOrDefault();
            Func <Task>    f       = async() => await file.DownloadAsync(null);

            ArgumentNullException exception = await Assert.ThrowsAsync <ArgumentNullException>(f);
        }
        public async Task ItThrowsIfDestinationPathIsEmpty()
        {
            ProductRelease release = GetProductRelease("2.1", "2.1.8");
            ReleaseFile    file    = release.Files.FirstOrDefault();
            Func <Task>    f       = async() => await file.DownloadAsync("");

            ArgumentException exception = await Assert.ThrowsAsync <ArgumentException>(f);

            Assert.Equal($"Value cannot be empty.{Environment.NewLine}Parameter name: destinationPath", exception.Message);
        }
Exemplo n.º 3
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                UpdateProgress(1);
                int total = 10;
                int index = 0;

                AsposeComponentsManager comManager = new AsposeComponentsManager(this);
                foreach (AsposeComponent component in AsposeComponents.list.Values)
                {
                    if (component.is_selected())
                    {
                        GlobalData.SelectedComponent = component.get_name();

                        ProductRelease productRelease = getProductReleaseInfo(component.get_name());
                        component.set_downloadUrl(productRelease.DownloadLink);
                        component.set_downloadFileName(productRelease.FileName);
                        component.set_changeLog(productRelease.ChangeLog);
                        component.set_latestVersion(productRelease.VersionNumber);
                        if (AsposeComponentsManager.libraryAlreadyExists(component.get_downloadFileName()))
                        {
                            component.set_currentVersion(AsposeComponentsManager.readVersion(component));
                            if (AsposeComponentsManager.readVersion(component).CompareTo(component.get_latestVersion()) == 0)
                            {
                                component.set_downloaded(true);
                            }
                            else
                            {
                                AsposeComponentsManager.addToDownloadList(component, component.get_downloadUrl(), component.get_downloadFileName());
                            }
                        }
                        else
                        {
                            AsposeComponentsManager.addToDownloadList(component, component.get_downloadUrl(), component.get_downloadFileName());
                        }
                    }

                    decimal percentage = ((decimal)(index + 1) / (decimal)total) * 100;
                    UpdateProgress(Convert.ToInt32(percentage));

                    index++;
                }

                UpdateProgress(100);
                UpdateText("All operations completed");
            }
            catch (Exception) { }
        }
        /**
         *
         * @return
         */
        public bool downloadComponents()
        {
            if (!isIneternetConnected())
            {
                _pageOne.showMessage(Constants.INTERNET_CONNECTION_REQUIRED_MESSAGE_TITLE, Constants.INTERNET_CONNECTION_REQUIRED_MESSAGE, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                return(false);
            }

            foreach (AsposeComponent component in AsposeComponents.list.Values)
            {
                if (component.is_selected())
                {
                    GlobalData.SelectedComponent = component.get_name();

                    ProductRelease productRelease = getProductReleaseInfo(component.get_name());
                    component.set_downloadUrl(productRelease.DownloadLink);
                    component.set_downloadFileName(productRelease.FileName);
                    component.set_changeLog(productRelease.ChangeLog);
                    component.set_latestVersion(productRelease.VersionNumber);
                    if (libraryAlreadyExists(component.get_downloadFileName()))
                    {
                        component.set_currentVersion(readVersion(component));
                        if (readVersion(component).CompareTo(component.get_latestVersion()) == 0)
                        {
                            component.set_downloaded(true);
                            //storeVersion(component);
                        }
                        else
                        {
                            addToDownloadList(component, component.get_downloadUrl(), component.get_downloadFileName());
                        }
                    }
                    else
                    {
                        addToDownloadList(component, component.get_downloadUrl(), component.get_downloadFileName());
                    }
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        private void DownloadFileFromWeb(string productName)
        {
            try
            {
                ProductRelease productRelease = AsposeManager.GetProductReleaseInformation(productName);
                if (productRelease == null)
                {
                    return;
                }

                string downloadURL        = productRelease.DownloadLink;
                string downloadFolderRoot = AsposeManager.GetAsposeDownloadFolder(productName);
                GlobalData.backgroundWorker.ReportProgress(1);

                if (AsposeManager.IsReleaseExists(productName, downloadFolderRoot, productRelease.VersionNumber))
                {
                    GlobalData.backgroundWorker.ReportProgress(100);
                    return;
                }

                string downloadedReleasePath = downloadFolderRoot + "\\" + productName.ToLower() + ".zip";
                GlobalData.backgroundWorker.ReportProgress(1);

                Uri    url       = new Uri(downloadURL);
                string sFileName = Path.GetFileName(url.LocalPath);

                System.Net.HttpWebRequest  request  = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
                System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

                response.Close();
                // gets the size of the file in bytes
                long iSize = response.ContentLength;

                // keeps track of the total bytes downloaded so we can update the progress bar
                long       iRunningByteTotal = 0;
                WebClient  client            = new WebClient();
                Stream     strRemote         = client.OpenRead(url);
                FileStream strLocal          = new FileStream(downloadedReleasePath, FileMode.Create, FileAccess.Write, FileShare.None);

                int    iByteSize  = 0;
                byte[] byteBuffer = new byte[1024];
                while ((iByteSize = strRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
                {
                    // write the bytes to the file system at the file path specified
                    strLocal.Write(byteBuffer, 0, iByteSize);
                    iRunningByteTotal += iByteSize;

                    // calculate the progress out of a base "100"
                    double dIndex = (double)(iRunningByteTotal);
                    double dTotal = (double)iSize;
                    double dProgressPercentage = (dIndex / dTotal);
                    int    iProgressPercentage = (int)(dProgressPercentage * 98);

                    GlobalData.backgroundWorker.ReportProgress(iProgressPercentage);
                }
                strLocal.Close();
                strRemote.Close();

                AsposeManager.ExtractZipFile(downloadedReleasePath, downloadFolderRoot);
                AsposeManager.SaveReleaseInfo(productName, downloadFolderRoot, productRelease.VersionNumber);
                GlobalData.backgroundWorker.ReportProgress(100);
            }
            catch (Exception)
            {
                MessageBox.Show("An error occurred while downloading Aspose components. Your module will be created but may not contain all the components you have selected. Please make sure you have an active internet connection and then try creating the project again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (Form != null)
                {
                    Form.Dispose();
                }
            }

            GlobalData.backgroundWorker.ReportProgress(100);
        }