Exemplo n.º 1
0
        /// <summary>
        /// Gets a specific Octo.exe version from the Octopus Tools Folder
        /// </summary>
        /// <param name="version"></param>
        /// <exception cref="OctoposhExceptions.ToolVersionNotfound"></exception>
        public OctopusToolVersion GetToolByVersion(string version)
        {
            var toolVersion = GetAllToolVersions().FirstOrDefault(v => v.Version == Version.Parse(version));

            if (toolVersion == null)
            {
                throw OctoposhExceptions.ToolVersionNotfound(version);
            }
            else
            {
                return(toolVersion);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all the versions of Octo.exe available in the Octopus Tools Folder.
        /// </summary>
        public List <OctopusToolVersion> GetAllToolVersions()
        {
            var versions = new List <OctopusToolVersion>();

            var toolsFolder = GetToolsFolder();

            var toolsFolderChilds = Directory.GetDirectories(toolsFolder, "*", SearchOption.TopDirectoryOnly);

            if (toolsFolderChilds.Length == 0)
            {
                throw OctoposhExceptions.NoOctoExeVersionFoundInToolsFolder();
            }

            foreach (var child in toolsFolderChilds)
            {
                var files = Directory.GetFiles(child, "Octo.exe*");

                foreach (var file in files)
                {
                    var info = FileVersionInfo.GetVersionInfo(file);

                    versions.Add(new OctopusToolVersion()
                    {
                        Version = Version.Parse(info.ProductVersion),
                        Path    = file.Replace(@"\\", @"\")
                    });
                }
            }

            if (versions.Count == 0)
            {
                throw OctoposhExceptions.NoOctoExeVersionFoundInToolsFolder();
            }
            else
            {
                return(new List <OctopusToolVersion>(versions.OrderByDescending(v => v.Version)));
            }
        }