private void btnDownload_Click(object sender, EventArgs e) { if (!ValidateAll()) { return; } if (!ValidatePathExists(txtLocalNugetPath.Text)) { if (!PromptCreatePath(txtLocalNugetPath.Text)) { return; } } if (!ValidatePathExists(txtStagingNugetPath.Text)) { if (!PromptCreatePath(txtStagingNugetPath.Text)) { return; } } if (!ValidatePathExists(txtOutputReportPath.Text)) { if (!PromptCreatePath(txtOutputReportPath.Text)) { return; } } NugetManagerParams p = new NugetManagerParams(); p.localNugetPath = ensureEndsWithSlash(txtLocalNugetPath.Text); p.stagingNugetPath = ensureEndsWithSlash(txtStagingNugetPath.Text); p.remoteNugetPath = ensureEndsWithSlash(txtRemoteNugetPath.Text); p.outputReportPath = ensureEndsWithSlash(txtOutputReportPath.Text); p.framework = txtFramework.Text; p.frameworkVersion = txtFrameworkVersion.Text; char[] split = { '\n' }; Nuget nuget; foreach (string sNuget in txtNugets.Text.Split(split, StringSplitOptions.RemoveEmptyEntries)) { if (Nuget.TryParse(sNuget, out nuget)) { p.nugetsToDownload.Add(nuget); } } if (p.nugetsToDownload.Count <= 0) { MessageBox.Show("No nugets detected."); return; } DownloadDashboard form = new DownloadDashboard(p); form.Show(); }
public void AddNugetToQueue(Nuget nuget) { if (CriticalIsNugetRepeatCheck(nuget)) { return; } ForceAddNugetToQueue(nuget); }
public static bool TryParse(string psPath, out Nuget pNuget) { Nuget result = new Nuget(psPath); if (result.IsValid()) { pNuget = result; return(true); } pNuget = null; return(false); }
// only add if it is newly downloaded public void AddNewNugetReportItem(Nuget nuget) { string key = nuget.GetFileName(); if (newNugetHash.ContainsKey(key)) { return; } NewNugetReportItem item = new NewNugetReportItem(nuget); newNugetHash[key] = item; newNugets.Add(item); }
private bool CriticalIsNugetRepeatCheck(Nuget nuget) { string sNuget = nuget.GetFileName(); lock (mNugetLock) { if (mNugetsFileNamesAlreadyAdded.Contains(sNuget)) { return(true); } mNugetsFileNamesAlreadyAdded.Add(sNuget); return(false); } }
// only update if was added to dict with above function public void UpdateNewNugetReportItem(Nuget nuget, XmlElement xMetadata) { string key = nuget.GetFileName(); if (!newNugetHash.ContainsKey(key)) { return; } NewNugetReportItem item = newNugetHash[key]; item.authors = GetElementValue(xMetadata, "authors"); item.owners = GetElementValue(xMetadata, "owners"); item.projectUrl = GetElementValue(xMetadata, "projectUrl"); }
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; }
public NugetProgressItem(Nuget pNuget) { nuget = pNuget; }
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"); } }
private void ProcessNugetDependencies() { string sourcePath = currentNugetProgress.pathOnDisk; string tempFolder = Path.GetTempPath() + "NugetDownloader\\" + currentNugetProgress.nuget.GetFolderName(); try { if (!File.Exists(sourcePath)) { throw new Exception(String.Format("File '{0}' not found.", sourcePath)); } if (new FileInfo(sourcePath).Length <= 0) { throw new Exception(String.Format("File '{0}' has zero size. Maybe this version does not exist?", sourcePath)); } if (Directory.Exists(tempFolder)) { Directory.Delete(tempFolder, true); } try { // separate try catch for extracting nuget, because if failure, then we should delete and redownload. using (ZipArchive za = ZipFile.Open(sourcePath, ZipArchiveMode.Read)) { za.ExtractToDirectory(tempFolder); za.Dispose(); } } catch { // problem specifically with extracting. // going to delete the source path on disk // because it is probably corrupt. File.Delete(currentNugetProgress.pathOnDisk); // and throw to try to redownload. throw; } string nuspecPath = tempFolder + currentNugetProgress.nuget.id + ".nuspec"; XmlDocument nuspecDoc = new XmlDocument(); using (XmlTextReader xtr = new XmlTextReader(nuspecPath)) { xtr.Namespaces = false; nuspecDoc.Load(xtr); } mManager.UpdateNewNugetReportItem(currentNugetProgress.nuget, (XmlElement)nuspecDoc.SelectSingleNode("package/metadata")); XmlElement xDependencies = (XmlElement)nuspecDoc.SelectSingleNode("package/metadata/dependencies"); if (xDependencies == null) { // cool, no dependencies? // we are done. return; } // BIG TODO // was planning for some framework version number string comparison, // but for now going by exact match only. XmlElement xMatchGroup = null; foreach (XmlElement xGroup in xDependencies.SelectNodes("group")) { string targetFramework = xGroup.GetAttribute("targetFramework"); //if (targetFramework.StartsWith(mManager.mParams.framework)) //{ // string frameworkVersion = targetFramework.Substring(mManager.mParams.framework.Length); // if (mManager.mParams.frameworkVersion.CompareTo(frameworkVersion) > 0) // { // xMatchGroup = xGroup; // } //} if (targetFramework == (mManager.mParams.framework + mManager.mParams.frameworkVersion)) { xMatchGroup = xGroup; } } if (xMatchGroup == null) { //we have an inferior framework version, probably not supported. WriteConsole(String.Format( "Warning: no matching dependencies for '{0}'", currentNugetProgress.nuget.GetFileName() )); mManager.RaiseTheFlagOfWarning(); return; } foreach (XmlElement xDependency in xMatchGroup.SelectNodes("dependency")) { string name = xDependency.GetAttribute("id"); string version = xDependency.GetAttribute("version"); Nuget nuget = new Nuget(name, version); mManager.AddNugetToQueue(nuget); } } finally { if (Directory.Exists(tempFolder)) { Directory.Delete(tempFolder, true); } } }
// only use when there is an error and we might want to try it again. public void ForceAddNugetToQueue(Nuget nuget) { WriteConsole(String.Format("Queuing {0}", nuget.GetFileName())); mNugetsToProcess.Enqueue(nuget); }
public NewNugetReportItem(Nuget nuget) { id = nuget.id; version = nuget.version; }