Пример #1
0
        public string Download(string directory, string fileName, bool overwrite)
        {
            var destination = Path.Combine(directory, fileName);

            // create directories that doesnt exist
            var directoryName = Path.GetDirectoryName(destination);

            if (directoryName != null && !Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            var result = Path.GetFullPath(destination);

            // if the file already exists delete it or move to next artifact
            if (File.Exists(destination))
            {
                if (!overwrite)
                {
                    return(result);
                }
                else
                {
                    File.Delete(destination);
                }
            }

            var index = Array.IndexOf(FileNames, fileName);

            _caller.GetDownloadFormat(tempfile => File.Move(tempfile, destination), _urls[index]);
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Takes a list of artifact urls and downloads them, see ArtifactsBy* methods.
        /// </summary>
        /// <param name="directory">
        /// Destination directory for downloaded artifacts, default is current working directory.
        /// </param>
        /// <param name="flatten">
        /// If <see langword="true"/> all files will be downloaded to destination directory, no subfolders will be created.
        /// </param>
        /// <param name="overwrite">
        /// If <see langword="true"/> files that already exist where a downloaded file is to be placed will be deleted prior to download.
        /// </param>
        /// <returns>
        /// A list of full paths to all downloaded artifacts.
        /// </returns>
        public List <string> Download(string directory = null, bool flatten = false, bool overwrite = true)
        {
            if (directory == null)
            {
                directory = Directory.GetCurrentDirectory();
            }
            var downloaded = new List <string>();

            foreach (var url in _urls)
            {
                // user probably didnt use to artifact url generating functions
                Debug.Assert(url.StartsWith("/repository/download/"));

                // figure out local filename
                var parts       = url.Split('/').Skip(5).ToArray();
                var destination = flatten
                    ? parts.Last()
                    : string.Join(Path.DirectorySeparatorChar.ToString(), parts);
                destination = Path.Combine(directory, destination);

                // create directories that doesnt exist
                var directoryName = Path.GetDirectoryName(destination);
                if (directoryName != null && !Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }

                // add artifact to list regardless if it was downloaded or skipped
                downloaded.Add(Path.GetFullPath(destination));

                // if the file already exists delete it or move to next artifact
                if (File.Exists(destination))
                {
                    if (overwrite)
                    {
                        File.Delete(destination);
                    }
                    else
                    {
                        continue;
                    }
                }
                _caller.GetDownloadFormat(tempfile => File.Move(tempfile, destination), url);
            }
            return(downloaded);
        }
Пример #3
0
 public void DownloadArtifactsByBuildId(string buildId, Action <string> downloadHandler)
 {
     _caller.GetDownloadFormat(downloadHandler, "/downloadArtifacts.html?buildId={0}", buildId);
 }
Пример #4
0
 public void DownloadConfiguration(BuildTypeLocator locator, Action <string> downloadHandler)
 {
     _caller.GetDownloadFormat(downloadHandler, "/app/rest/buildTypes/{0}", locator);
 }