/// <summary> /// Returns the IDependencyDownloader object according to the type provided. Used by clean only /// </summary> /// <param name="downloadername">Name of the downloader</param> /// <returns>Downloader object</returns> public IDependencyDownloader GetDownloader(string downloadername) { IDependencyDownloader downl; // Todo MRI: After migration: Remove old Downloader types switch (downloadername) { case "Downloader_FileShare": case "Downloader_FileShareCopy": downl = new DownloaderFileShareCopy(); break; case "Downloader_SourceControl": case "Downloader_SourceControlMapping": downl = new DownloaderSourceControlMapping(); break; case "Downloader_BinaryRepository": case "Downloader_SourceControlCopy": downl = new DownloaderSourceControlCopy(); break; case "Downloader_ZippedDependency": downl = new ZippedDependencyDownloader(); break; case "Downloader_Subversion": downl = new DownloaderSubversion(); break; default: throw new DependencyManagementFoundationPluginNotFoundException(); } return(downl); }
/// <summary> /// Returns the IDependencyDownloader object according to the name provided. /// If a provider with this name cannot be found a DependencyManagementFoundationPluginNotFoundException is thrown. /// </summary> /// <param name="component">The component to download</param> /// <returns>Downloader object</returns> public IDependencyDownloader GetDownloader(IComponent component) { IDependencyDownloader downloader; switch (component.Type) { case ComponentType.FileShare: case ComponentType.BuildResult: case ComponentType.VNextBuildResult: downloader = new DownloaderFileShareCopy(); break; case ComponentType.SourceControl: downloader = new DownloaderSourceControlMapping( component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceTeamProjectCollectionUrl), component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceName), component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceOwner)); break; case ComponentType.BinaryRepository: downloader = new DownloaderSourceControlCopy( component.GetFieldValue(DependencyProviderValidSettingName.BinaryTeamProjectCollectionUrl), component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceName), component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceOwner)); break; case ComponentType.SourceControlCopy: downloader = new DownloaderSourceControlCopy( component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceTeamProjectCollectionUrl), component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceName), component.GetFieldValue(DependencyProviderValidSettingName.WorkspaceOwner)); break; case ComponentType.Subversion: downloader = new DownloaderSubversion(); break; default: throw new DependencyManagementFoundationPluginNotFoundException(); } // Add zipper facade if component is a compressen component (and not a source control mapping). In addition get the value that determines if the downloaded archives should be deleted if (component.Type != ComponentType.SourceControl && component.GetFieldValue(DependencyProviderValidSettingName.CompressedDependency) == "True") { var originalDownloader = downloader; //Try to parse the value from the settings. if this failes show an error and bool deleteArchives = false; try { if (component.GetFieldValue(DependencyProviderValidSettingName.DeleteArchiveFiles) == "True") { deleteArchives = bool.Parse(component.GetFieldValue(DependencyProviderValidSettingName.DeleteArchiveFiles)); } } catch (Exception) { throw new Exception("The settings is missing that determines if the archive files should be deleted, please make sure it is set accordingly"); } downloader = new ZippedDependencyDownloader(originalDownloader, deleteArchives); } return(downloader); }
public void Download(string source, string destination, IDependencyDownloaderWatermark watermark, bool force, ISettings <DownloaderValidSettings> settings) { if (source == null) { throw new ArgumentNullException("source"); } if (destination == null) { throw new ArgumentNullException("destination"); } if (watermark == null) { throw new ArgumentNullException("watermark"); } if (settings == null) { throw new ArgumentNullException("settings"); } Logger.Instance().Log(TraceLevel.Info, "{0}: Downloading component {1} to {2} ...", DownloadType, source, destination); // Save compressed files to temp path and temporarily store watermarks. Turn of mappings as they only apply to the extracted folder structure var tempPath = Path.Combine(destination, "..\\", "DM_TEMP"); //Create the temp Path if (!Directory.Exists(tempPath)) { DirectoryInfo di = Directory.CreateDirectory(tempPath); } //save the folder mapping var tempFolderMapping = settings.GetSetting(DownloaderValidSettings.FolderMappings); var remainingArtefacts = new HashSet <string>(watermark.ArtifactsToClean); //Download the zip files and the rest of the contents ignore any mappings to get everything in the temppath settings.SettingsDictionary[DownloaderValidSettings.FolderMappings] = null; _downloader .Download(source, tempPath, watermark, force, settings); //var zipWatermarks = new Dictionary<string, object>(watermark.Watermarks); // The DownloaderFileShareCopy / DownloaderSourceControlCopy creates artifacts for cleanup, // which are deleted by the ZippedDependencyDownloader and must not be saved. watermark.ArtifactsToClean = remainingArtefacts; //Extract the zipped files in the temp path ExtractCompressedFiles(tempPath, tempPath, watermark, force); //Set the settings to a move operation settings.AddSetting(new KeyValuePair <DownloaderValidSettings, string>(DownloaderValidSettings.OperationType, "Move")); //Set the temporary saved mapping again settings.SettingsDictionary[DownloaderValidSettings.FolderMappings] = tempFolderMapping; //The SourceControlCopy-Provider needs the FileShareCopy-Provider to copy the extracted files from the temp folder to the //target folder, because the SourceControlCopy-Provider works not with local folders as source folder if (_downloader.DownloadType == "Downloader_SourceControlCopy") { IDependencyDownloader tmpDownloader = new DownloaderFileShareCopy(); tmpDownloader.Download(tempPath, destination, watermark, force, settings); } // Provider: FileShare, BuildResult else { //Copy the files from the temp path to the final destination _downloader.Download(tempPath, destination, watermark, force, settings); } //Cleanup: Delete the temp path try { DeleteTempDirectory(tempPath); } catch (Exception e) { Logger.Instance().Log(TraceLevel.Error, "Deleting temp folder {0} did not succeed: {1}", tempPath, e.Message); Logger.Instance().Log(TraceLevel.Error, "Stacktrace: {0}", e.StackTrace); } }