Example #1
0
        // at this point should be on UI thread
        private void WorkerProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            NugetProgressItem nugetProgress = (NugetProgressItem)e.UserState;
            NugetProgressArgs args          = new NugetProgressArgs();

            args.nugetProgress = nugetProgress;
            ProgressChanged(this, args);
        }
Example #2
0
        private void HandleProgressChanged(object sender, NugetProgressArgs e)
        {
            NugetProgressItem progress = e.nugetProgress;
            Nuget             nuget    = progress.nuget;
            string            key      = nuget.GetFileName();
            GroupBox          infoBox;

            if (!progressDict.ContainsKey(key))
            {
                infoBox = CreateNewProgressBox(key);
                progressDict.Add(key, infoBox);
                tlpDownloads.Controls.Add(infoBox);
                panDownloads.ScrollControlIntoView(infoBox);
            }
            else
            {
                infoBox = progressDict[key];
            }
            ProgressBar bar = (ProgressBar)infoBox.Controls.Find(PROGRESS_BAR_NAME, false)[0];

            bar.Value = progress.downloadPercent;
        }
        private void ProcessUntilDone(object sender, DoWorkEventArgs args)
        {
            try
            {
                while (mManager.IsStillDoingWork())
                {
                    if (isAborting)
                    {
                        return;
                    }

                    Nuget nuget = null;
                    try
                    {
                        nuget = mManager.DequeueNuget();
                        if (nuget == null)
                        {
                            IsProcessing = false;
                            Thread.Sleep(100);
                            continue;
                        }
                        IsProcessing = true;
                        WriteConsole(String.Format("Processing {0}", nuget.GetFileName()));
                        currentNugetProgress = new NugetProgressItem(nuget);
                        ReportProgress();

                        if (isNugetAlreadyInLocal())
                        {
                            WriteConsole(String.Format("Found Existing '{0}'", currentNugetProgress.pathOnDisk));
                            currentNugetProgress.downloadPercent = 100;
                            ReportProgress();
                        }
                        else
                        {
                            IsDownloading = true;
                            mManager.AddNewNugetReportItem(nuget);

                            string Url = mManager.mParams.remoteNugetPath + nuget.GetNugetPath();

                            // have not figured out nuget folder structure yet.
                            // will go will nugets in root.
                            //string downloadPath = mManager.mParams.stagingNugetPath + nuget.GetNugetPath().Replace("/", "\\");
                            string downloadPath = mManager.mParams.stagingNugetPath + nuget.GetFileName();
                            string parentDir    = Path.GetDirectoryName(downloadPath);
                            if (!Directory.Exists(parentDir))
                            {
                                Directory.CreateDirectory(parentDir);
                            }
                            currentNugetProgress.pathOnDisk = downloadPath;

                            WriteConsole(String.Format("Downloading from '{0}' to '{1}'", Url, downloadPath));

                            webClient.DownloadFileAsync(new Uri(Url), downloadPath);

                            while (IsDownloading)
                            {
                                if (isAborting)
                                {
                                    return;
                                }
                                Thread.Sleep(200);
                            }
                        }

                        ProcessNugetDependencies();
                    }
                    catch (Exception ex)
                    {
                        WriteConsole("Error in worker thread: " + ex.ToString());
                        if (nuget != null)
                        {
                            nuget.failCount += 1;
                            if (nuget.failCount >= MAX_PACKAGE_FAILURE_COUNT)
                            {
                                WriteConsole(String.Format("Error: '{0}' failed too many times. Bye!", nuget.GetFileName()));
                                mManager.RaiseTheFlagOfError();
                            }
                            else
                            {
                                mManager.ForceAddNugetToQueue(nuget);
                            }
                        }
                        //workerFailureCount += 1;
                        //if (workerFailureCount > MAX_FAILURE_COUNT)
                        //{
                        //	return;
                        //}
                        continue;
                    }
                }
            }
            finally
            {
                IsFinished = true;
                WriteConsole("Thread Exited");
            }
        }