Esempio n. 1
0
        /// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The name of the build result component.</param>
        /// <param name="version">The component version.</param>
        /// <returns>The loaded dependency definition xml file or null if dependency definition file was not found</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            var buildNumberSpec = _buildServer.CreateBuildDetailSpec(name.TeamProject, name.BuildDefinition);

            buildNumberSpec.BuildNumber      = version.BuildNumber;
            buildNumberSpec.InformationTypes = new string[] { };
            var result = _buildServer.QueryBuilds(buildNumberSpec);

            foreach (var dependencyDefinitionFile in _dependencyDefinitionFileNameList)
            {
                var dependencyDefinitionFileLocation = Path.Combine(result.Builds.First().DropLocation, dependencyDefinitionFile);

                // DesignDecision MRI: Dependency definition files are optional!
                if (!File.Exists(dependencyDefinitionFileLocation))
                {
                    continue;
                }

                var xdoc = XDocument.Load(dependencyDefinitionFileLocation);

                Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, dependencyDefinitionFileLocation, name, version);

                return(xdoc);
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Loading a dependency definition file was skipped for component {1}#{2}.", ResolverType, name, version);
            return(null);
        }
        /// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The subversion folder path for the component.</param>
        /// <param name="version">The component version.</param>
        /// <returns>The loaded dependency definition xml file</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
            {
                var dependencyDefinitionFileLocation = string.Format("{0}/{1}", name, dependencyDefinitionFileName);

                try
                {
                    if (!ProviderSubversion.Instance.ItemExists(dependencyDefinitionFileLocation, version.ToString()))
                    {
                        Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found", ResolverType, dependencyDefinitionFileLocation, name, version);
                        continue;
                    }
                }
                catch (SvnAuthenticationException)
                {
                    Logger.Instance().Log(TraceLevel.Error, "{0}: Unable to connect to repository {1}, because authentication failed. Please login once at your your Subversion client to store the credentials locally.", ResolverType, name);
                    throw new InvalidProviderConfigurationException(string.Format("Could not connect to Subversion {0}, because Authentication failed.", name));
                }

                var xdoc = ProviderSubversion.Instance.GetComponentTargetsContent(dependencyDefinitionFileLocation, version.ToString());

                Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, dependencyDefinitionFileLocation, name, version);
                return(xdoc);
            }

            return(null);
        }
        /// <summary>
        /// Determines whether a component exists having a specific version
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <param name="version">The specific version of the component</param>
        /// <returns>True if the component exists at the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            var componentVersionPath = Path.Combine(ResolverSettings.GetSetting(ResolverValidSettings.FileShareUrl), name.ToString(), version.ToString());

            if (Directory.Exists(componentVersionPath))
            {
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach (var dependencyDefinitionFileName in _validDependencyDefinitionFileNames)
                // ReSharper restore LoopCanBeConvertedToQuery
                {
                    var dependencyDefinitionFile = Path.Combine(componentVersionPath, dependencyDefinitionFileName);
                    if (File.Exists(dependencyDefinitionFile))
                    {
                        Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found on file share", ResolverType, name, version);
                        return(true);
                    }
                }
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found on file share", ResolverType, name, version);
            return(false);
        }
        /// <summary>
        /// Determines whether a folder exists having a specific version
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <param name="version">The name of the component (branch folder)</param>
        /// <returns>true if the branch folder exists at the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            try
            {
                if (ProviderSubversion.Instance.ItemExists(name.ToString(), version.ToString()))
                {
                    foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
                    {
                        var dependencyDefinitionFile = string.Format("{0}/{1}", name.ToString(), dependencyDefinitionFileName);
                        if (ProviderSubversion.Instance.ItemExists(dependencyDefinitionFile, version.ToString()))
                        {
                            Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found on Subversion", ResolverType, name, version);
                            return(true);
                        }
                    }
                }
            }
            catch (SvnAuthenticationException)
            {
                Logger.Instance().Log(TraceLevel.Error, "{0}: Unable to connect to repository {1}, because authentication failed. Please login once at your your Subversion client to store the credentials locally.", ResolverType, name);
                throw new InvalidProviderConfigurationException(string.Format("Could not connect to Subversion {0}, because Authentication failed.", name));
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found on Subversion", ResolverType, name, version);
            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// Determines whether a build result exists based on a build definition in a specific team project.
        /// The build number or build quality/build status determines the version.
        /// </summary>
        /// <param name="name">The component name (Team project with build definition)</param>
        /// <param name="version">The component version (Build number or build quality/build status)</param>
        /// <returns>True if a build result exists with this the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            try
            {
                var buildDef = _buildServer.GetBuildDefinition(name.TeamProject, name.BuildDefinition);

                if (buildDef != null && !string.IsNullOrEmpty(version.BuildNumber))
                {
                    var buildNumberSpec = _buildServer.CreateBuildDetailSpec(name.TeamProject, name.BuildDefinition);
                    buildNumberSpec.BuildNumber      = version.BuildNumber;
                    buildNumberSpec.InformationTypes = new string[] { };
                    var result = _buildServer.QueryBuilds(buildNumberSpec);

                    if (result.Builds.Any())
                    {
                        Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found on build server", ResolverType, name, version);
                        return(true);
                    }
                }

                Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found on build server", ResolverType, name, version);
                return(false);
            }
            catch (BuildDefinitionNotFoundException)
            {
                Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found on build server", ResolverType, name, version);
                return(false);
            }
        }
        /// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The source control folder path for the component.</param>
        /// <param name="version">The component version.</param>
        /// <returns>The loaded dependency definition xml file</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
            {
                var dependencyDefinitionFileLocation = VersionControlPath.Combine(name.ToString(), dependencyDefinitionFileName);
                if (!VersionControlServer.ServerItemExists(dependencyDefinitionFileLocation, version.TfsVersionSpec, DeletedState.Any, ItemType.File))
                {
                    Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found", ResolverType, dependencyDefinitionFileLocation, name, version);
                    continue;
                }

                var item = VersionControlServer.GetItem(dependencyDefinitionFileLocation, version.TfsVersionSpec, DeletedState.Any, true);
                using (var content = item.DownloadFile())
                {
                    var xdoc = XDocument.Load(content);
                    Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, dependencyDefinitionFileLocation, name, version);
                    return(xdoc);
                }
            }

            return(null);
        }
        /// <summary>
        /// Determines whether a build result exists based on a build definition in a specific team project.
        /// The build number or build build status determines the version.
        /// </summary>
        /// <param name="name">The component name (Team project with build definition)</param>
        /// <param name="version">The component version (Build number or build build status)</param>
        /// <returns>True if a build result exists with this the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            try
            {
                var buildDef = _client.GetDefinitionsAsync(project: name.TeamProject, type: TFSWebApi.DefinitionType.Build).Result;

                if (buildDef != null && !string.IsNullOrEmpty(version.BuildNumber))
                {
                    var builds = _client.GetBuildsAsync(project: name.TeamProject, buildNumber: version.BuildNumber, type: TFSWebApi.DefinitionType.Build).Result;

                    if (builds.Any())
                    {
                        Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found on build server", ResolverType, name, version);
                        return(true);
                    }
                }

                Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found on build server", ResolverType, name, version);
                return(false);
            }
            catch (BuildDefinitionNotFoundException)
            {
                Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found on build server", ResolverType, name, version);
                return(false);
            }
        }
        /// <summary>
        /// Determines whether a version control folder exists having a specific version
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <param name="version">The name of the component (branch folder)</param>
        /// <returns>true if the branch folder exists at the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            // Check if folder exists in source control
            if (!VersionControlServer.ServerItemExists(name.ToString(), version.TfsVersionSpec, DeletedState.NonDeleted, ItemType.Folder))
            {
                Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found in source control", ResolverType, name, version);
                return(false);
            }

            // Check if component.targets exists inside folder
            var folderItems = VersionControlServer.GetItems(VersionControlPath.Combine(name.ToString(), "*"), version.TfsVersionSpec, RecursionType.OneLevel);

            foreach (Item item in folderItems.Items)
            {
                var itemName = VersionControlPath.GetFileName(item.ServerItem);

                foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
                {
                    if (string.Equals(itemName, dependencyDefinitionFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found in source control", ResolverType, name, version);
                        return(true);
                    }
                }
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found in source control", ResolverType, name, version);
            return(false);
        }
        /// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The name of the binary repository component.</param>
        /// <param name="version">The component version.</param>
        /// <returns>The loaded dependency definition xml file</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
            {
                var dependencyDefinitionFileLocation = VersionControlPath.Combine(VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), version.ToString()), dependencyDefinitionFileName);

                if (!VersionControlServer.ServerItemExists(dependencyDefinitionFileLocation, ItemType.File))
                {
                    Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found", ResolverType, dependencyDefinitionFileLocation, name, version);
                    continue;
                }

                var dependencyDefinitionFileStream = VersionControlServer.GetItem(dependencyDefinitionFileLocation, VersionSpec.Latest).DownloadFile();
                var xdoc = XDocument.Load(dependencyDefinitionFileStream);

                // Close the previously opened filestream to ensure a cleanup
                dependencyDefinitionFileStream.Close();

                Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, dependencyDefinitionFileLocation, name, version);
                return(xdoc);
            }

            return(null);
        }
        /// <summary>
        /// Determines whether a version control folder exists having a specific version
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <param name="version">The version for the component</param>
        /// <returns>True if a version folder exists at the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            if (VersionControlServer.ServerItemExists(VersionControlPath.Combine(PathPrefix, name.ToString()), VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder))
            {
                var path = VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), version.ToString());

                if (VersionControlServer.ServerItemExists(path, VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder))
                {
                    // Check if component.targets exists inside folder
                    var folderItems = VersionControlServer.GetItems(VersionControlPath.Combine(path, "*"));
                    foreach (var item in folderItems.Items)
                    {
                        var itemName = VersionControlPath.GetFileName(item.ServerItem);

                        foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
                        {
                            if (string.Equals(itemName, dependencyDefinitionFileName, StringComparison.OrdinalIgnoreCase))
                            {
                                Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found in binary repository", ResolverType, name, version);
                                return(true);
                            }

                            Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found in binary repository", ResolverType, dependencyDefinitionFileName, name, version);
                        }
                    }
                }
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found in binary repository", ResolverType, name, version);
            return(false);
        }
        /// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The name of the build result component.</param>
        /// <param name="version">The component version.</param>
        /// <returns>The loaded dependency definition xml file or null if dependency definition file was not found</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            var build     = _client.GetBuildsAsync(project: name.TeamProject, buildNumber: version.BuildNumber, type: TFSWebApi.DefinitionType.Build).Result.First();
            var artifacts = _client.GetArtifactsAsync(name.TeamProject, build.Id).Result;

            foreach (var dependencyDefinitionFile in _dependencyDefinitionFileNameList)
            {
                if (!artifacts.Any())
                {
                    break;
                }
                else
                {
                    foreach (var artifact in artifacts)
                    {
                        if (artifact.Resource.Type == "FilePath")
                        {
                            var path = $"{artifact.Resource.Data}/{artifact.Name}/{dependencyDefinitionFile}";
                            if (File.Exists(path))
                            {
                                var xdoc = XDocument.Load(path);
                                Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, path, name, version);
                                return(xdoc);
                            }
                            Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found", ResolverType, path, name, version);
                        }
                        else
                        {
                            var content = _client.GetArtifactContentZipAsync(name.TeamProject, build.Id, artifact.Name);
                            using (ZipArchive archive = new ZipArchive(content.Result))
                            {
                                foreach (ZipArchiveEntry entry in archive.Entries)
                                {
                                    if (entry.Name.Equals(dependencyDefinitionFile, StringComparison.OrdinalIgnoreCase))
                                    {
                                        var xdoc = XDocument.Load(entry.Open());
                                        Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, entry.FullName, name, version);

                                        return(xdoc);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Loading a dependency definition file was skipped for component {1}#{2}.", ResolverType, name, version);
            return(null);
        }
        /// <summary>
        /// Returns all versions for a component found in the repository.
        /// </summary>
        /// <param name="name">The component name.</param>
        /// <returns>The list of versions</returns>
        public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName name)
        {
            ValidateComponentName(name);

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available component versions...", ResolverType);

            var availableVersions = new List <IComponentVersion>();

            if (VersionControlServer.ServerItemExists(VersionControlPath.Combine(PathPrefix, name.ToString()), VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder))
            {
                var versionItems = VersionControlServer.GetItems(VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), "*"));

                foreach (var version in versionItems.Items)
                {
                    if (version.ItemType.Equals(ItemType.Folder))
                    {
                        // Check if component.targets exists inside folder
                        var folderItems = VersionControlServer.GetItems(VersionControlPath.Combine(VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), VersionControlPath.GetFileName(version.ServerItem)), "*"));
                        var dependencyDefinitionFileFound = false;

                        foreach (var item in folderItems.Items)
                        {
                            var itemName = VersionControlPath.GetFileName(item.ServerItem);

                            foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
                            {
                                if (string.Equals(itemName, dependencyDefinitionFileName, StringComparison.OrdinalIgnoreCase))
                                {
                                    Logger.Instance().Log(TraceLevel.Info, "{0}: Found version {1}", ResolverType, VersionControlPath.GetFileName(version.ServerItem));
                                    availableVersions.Add(new ComponentVersion(VersionControlPath.GetFileName(version.ServerItem)));
                                    dependencyDefinitionFileFound = true;
                                }
                            }
                        }

                        if (!dependencyDefinitionFileFound)
                        {
                            Logger.Instance().Log(TraceLevel.Warning, "{0}: Skipping version {1} (Dependency definition file is not present)", ResolverType, VersionControlPath.GetFileName(version.ServerItem));
                        }
                    }
                }
            }
            else
            {
                Logger.Instance().Log(TraceLevel.Error, "{0}: Directory {1} for component {2} does not exist", ResolverType, VersionControlPath.Combine(PathPrefix, name.ToString()), name);
                throw new InvalidComponentException(string.Format("Could not find component {0} in binary repository", name));
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying component versions finished successfully", ResolverType);

            return(availableVersions);
        }
        /// <summary>
        /// Determines whether a component exists
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <returns>true if the component exists; false if not</returns>
        public bool ComponentExists(IComponentName name)
        {
            ValidateComponentName(name);

            if (Directory.Exists(Path.Combine(ResolverSettings.GetSetting(ResolverValidSettings.FileShareUrl), name.ToString())))
            {
                Logger.Instance().Log(TraceLevel.Info, "{0}: Component folder for component {1} was found on file share", ResolverType, name);
                return(true);
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component folder for component {1} was not found on file share", ResolverType, name);
            return(false);
        }
        /// <summary>
        /// Validates the component name.
        /// </summary>
        /// <param name="name">The component name.</param>
        private static void ValidateComponentName(IComponentName name)
        {
            if (name == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Source control component was null");
                throw new ArgumentNullException("name", "Source control component was null");
            }

            if (string.IsNullOrEmpty(name.ToString()))
            {
                Logger.Instance().Log(TraceLevel.Error, "Source control path for binary repository component {0} was empty", name);
                throw new ArgumentException(string.Format("Source control path for binary repository component {0} was empty", name), "name");
            }
        }
        /// <summary>
        /// Validates the component name and check path for wildcards.
        /// </summary>
        /// <param name="name">The component name.</param>
        private static void ValidateComponentName(IComponentName name)
        {
            if (name == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Build result component name was null");
                throw new ArgumentNullException("name", "Build result component name was null");
            }

            if (string.IsNullOrEmpty(name.ToString()))
            {
                Logger.Instance().Log(TraceLevel.Error, "Team project and/or build definition for component {0} was empty", name);
                throw new ArgumentException(string.Format("Team project and/or build definition for component {0} was empty", name), "name");
            }
        }
        /// <summary>
        /// Validates the component name and check path for wildcards.
        /// </summary>
        /// <param name="name">The component name.</param>
        private static void ValidateComponentName(IComponentName name)
        {
            if (name == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Source control component was null");
                throw new ArgumentNullException("name", "Source control component was null");
            }

            if (string.IsNullOrEmpty(name.Path) || VersionControlPath.IsWildcard(name.Path))
            {
                Logger.Instance().Log(TraceLevel.Error, "Source control path for component {0} was empty or contained wildcards", name);
                throw new ArgumentException(string.Format("Source control path for component {0} was empty or contained wildcards", name), "name");
            }
        }
        /// <summary>
        /// Discover all available versions for a specific component.
        /// </summary>
        /// <param name="componentName">The name of the component</param>
        /// <returns>A list with all versions</returns>
        public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName componentName)
        {
            var componentVersions = new List <IComponentVersion>();
            var componentPath     = Path.Combine(ResolverSettings.GetSetting(ResolverValidSettings.FileShareUrl), componentName.Path);

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available component versions...", ResolverType);

            try
            {
                if (Directory.Exists(componentPath))
                {
                    foreach (var versionPath in Directory.GetDirectories(componentPath))
                    {
                        var componentVersion = versionPath.Split(Path.DirectorySeparatorChar).Last();

                        foreach (var dependencyDefinitionFileName in _validDependencyDefinitionFileNames)
                        {
                            var dependencyDefinitionFile = Path.Combine(versionPath, dependencyDefinitionFileName);

                            if (File.Exists(dependencyDefinitionFile))
                            {
                                Logger.Instance().Log(TraceLevel.Info, "{0}: Found version {1}", ResolverType, componentVersion);
                                componentVersions.Add(new ComponentVersion(componentVersion));
                            }
                        }

                        Logger.Instance().Log(TraceLevel.Warning, "{0}: Skipping version {1} (Dependency definition file is not present)", ResolverType, componentVersion);
                    }
                }
                else
                {
                    Logger.Instance().Log(TraceLevel.Error, "{0}: Directory {1} for component {2} does not exist", ResolverType, componentPath, componentName);
                    throw new InvalidComponentException(string.Format("Could not find component {0} on file share", componentName));
                }
            }
            catch (UnauthorizedAccessException uae)
            {
                Logger.Instance().Log(
                    TraceLevel.Error,
                    "{0}: Could not access file share {1} (Unauthorized access exception {2})",
                    ResolverType,
                    ResolverSettings.GetSetting(ResolverValidSettings.FileShareUrl),
                    uae.Message);
                throw new InvalidAccessRightsException(string.Format("Could not access file share ({0})", ResolverSettings.GetSetting(ResolverValidSettings.FileShareUrl)));
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying component versions finished successfully", ResolverType);

            return(componentVersions);
        }
        /// <summary>
        /// Determines whether a component folder exists
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <returns>True if the branch folder exists; false if not</returns>
        public bool ComponentExists(IComponentName name)
        {
            ValidateComponentName(name);

            // Check if folder exists in source control
            if (VersionControlServer.ServerItemExists(VersionControlPath.Combine(PathPrefix, name.Path), VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder))
            {
                Logger.Instance().Log(TraceLevel.Info, "{0}: Component folder for {1} was found in binary repository", ResolverType, name);
                return(true);
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component folder for {1} was not found in binary repository", ResolverType, name);
            return(false);
        }
        /// <summary>
        /// Validates the component name and check path for wildcards.
        /// </summary>
        /// <param name="name">The component name.</param>
        private static void ValidateComponentName(IComponentName name)
        {
            if (name == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "File share component name was null");
                throw new ArgumentNullException("name", "File share component name was null");
            }

            if (string.IsNullOrEmpty(name.ToString()))
            {
                Logger.Instance().Log(TraceLevel.Error, "File share path for component {0} was empty", name);
                throw new ArgumentException(string.Format("File share path for component {0} was empty", name), "name");
            }
        }
        /// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <param name="version">The exact version of the component</param>
        /// <returns>The loaded dependency definition xml file</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);

            foreach (var dependencyDefinitionFileName in _validDependencyDefinitionFileNames)
            {
                var dependencyDefinitionFileLocation = Path.Combine(ResolverSettings.GetSetting(ResolverValidSettings.FileShareUrl), name.ToString(), version.ToString(), dependencyDefinitionFileName);
                if (!File.Exists(dependencyDefinitionFileLocation))
                {
                    Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found", ResolverType, dependencyDefinitionFileLocation, name, version);
                    continue;
                }

                var xdoc = XDocument.Load(dependencyDefinitionFileLocation);

                Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, dependencyDefinitionFileLocation, name, version);
                return(xdoc);
            }

            return(null);
        }
        /// <summary>
        /// Determines whether a build definition exists with this build definition name in a specific team project.
        /// </summary>
        /// <param name="name">The component name (Build definition and team project)</param>
        /// <returns>True if a build definition exists; False if not</returns>
        public bool ComponentExists(IComponentName name)
        {
            ValidateComponentName(name);

            try
            {
                var buildDef = _client.GetDefinitionsAsync(project: name.TeamProject, type: TFSWebApi.DefinitionType.Build).Result;
                if (buildDef != null)
                {
                    Logger.Instance().Log(TraceLevel.Info, "{0}: Build Definition for component {1} was found on build server", ResolverType, name);
                    return(true);
                }

                Logger.Instance().Log(TraceLevel.Info, "{0}: Build Definition for component {1} was not found on build server", ResolverType, name);
                return(false);
            }
            catch (BuildDefinitionNotFoundException)
            {
                Logger.Instance().Log(TraceLevel.Info, "{0}: Build Definition for component {1} was not found on build server", ResolverType, name);
                return(false);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Determines whether a build definition exists with this build definition name in a specific team project.
        /// </summary>
        /// <param name="name">The component name (Build definition and team project)</param>
        /// <returns>True if a build definition exists; False if not</returns>
        public bool ComponentExists(IComponentName name)
        {
            ValidateComponentName(name);

            try
            {
                var buildDef = _buildServer.GetBuildDefinition(name.TeamProject, name.BuildDefinition);
                if (buildDef != null)
                {
                    Logger.Instance().Log(TraceLevel.Info, "{0}: Build Definition for component {1} was found on build server", ResolverType, name);
                    return(true);
                }

                Logger.Instance().Log(TraceLevel.Info, "{0}: Build Definition for component {1} was not found on build server", ResolverType, name);
                return(false);
            }
            catch (BuildDefinitionNotFoundException)
            {
                Logger.Instance().Log(TraceLevel.Info, "{0}: Build Definition for component {1} was not found on build server", ResolverType, name);
                return(false);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Discover all available versions.
        /// </summary>
        /// <param name="name">The component name</param>
        /// <returns>A list with all versions</returns>
        public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName name)
        {
            var versList = new List <IComponentVersion>();

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available component versions...", ResolverType);

            var teamProject = _versionControlServer.TryGetTeamProject(name.TeamProject);

            if (teamProject == null)
            {
                Logger.Instance().Log(
                    TraceLevel.Info,
                    "{0}: Could not find team project {1} on version control server for team project collection {2}",
                    ResolverType,
                    name.TeamProject,
                    ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl));
                throw new InvalidComponentException(
                          string.Format(
                              "Could not find team project {0} on version control server for team project collection {1}",
                              name.TeamProject,
                              ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)));
            }

            var buildDef = _buildServer.GetBuildDefinition(teamProject.Name, name.BuildDefinition);

            if (buildDef == null)
            {
                Logger.Instance().Log(
                    TraceLevel.Info,
                    "{0}: Could not find build definition {1} for team project {2} on version control server for tfs {3}",
                    ResolverType,
                    name.BuildDefinition,
                    name.TeamProject,
                    ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl));
                throw new InvalidComponentException(
                          string.Format(
                              "Could not find build definition {0} for team project {1} on version control server for tfs {2}",
                              name.BuildDefinition,
                              name.TeamProject,
                              ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)));
            }

            // Query all builds with this teamProject and build definition name
            // BuildNumber xor (BuildQuality or BuildStatus) = version
            var spec = _buildServer.CreateBuildDetailSpec(buildDef);

            spec.InformationTypes = new string[] { };
            var details = _buildServer.QueryBuilds(spec);

            foreach (var buildResult in details.Builds)
            {
                List <string> availableBuildQuality = null;
                if (buildResult.Quality != null)
                {
                    availableBuildQuality = new List <string> {
                        buildResult.Quality
                    };
                }

                var availableBuildStatus = new List <string> {
                    buildResult.Status.ToString()
                };
                var vers = new ComponentVersion(buildResult.BuildNumber, availableBuildStatus, availableBuildQuality, null);
                versList.Add(vers);
                Logger.Instance().Log(TraceLevel.Info, "{0}: Found build {1}", ResolverType, vers.ToString());
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying component versions finished successfully", ResolverType);
            return(versList);
        }
 /// <summary>
 /// The source control resolver does not support querying component versions.
 /// </summary>
 /// <param name="name">The name of the component</param>
 /// <returns>An InvalidComponentException exception is thrown</returns>
 public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName name)
 {
     Logger.Instance().Log(TraceLevel.Error, "{0}: Querying available component versions is not supported", ResolverType);
     throw new NotImplementedException(string.Format("Querying available component versions is not supported by the {0}", ResolverType));
 }
        /// <summary>
        /// Discover all available versions.
        /// </summary>
        /// <param name="name">The component name</param>
        /// <returns>A list with all versions</returns>
        public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName name)
        {
            var versList = new List <IComponentVersion>();

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available component versions...", ResolverType);

            var teamProject = _versionControlServer.TryGetTeamProject(name.TeamProject);

            if (teamProject == null)
            {
                Logger.Instance().Log(
                    TraceLevel.Info,
                    "{0}: Could not find team project {1} on version control server for team project collection {2}",
                    ResolverType,
                    name.TeamProject,
                    ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl));
                throw new InvalidComponentException(
                          string.Format(
                              "Could not find team project {0} on version control server for team project collection {1}",
                              name.TeamProject,
                              ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)));
            }

            var buildDef = (_client.GetDefinitionsAsync(project: teamProject.Name, name: name.BuildDefinition)).Result;

            if (buildDef == null)
            {
                Logger.Instance().Log(
                    TraceLevel.Info,
                    "{0}: Could not find build definition {1} for team project {2} on version control server for tfs {3}",
                    ResolverType,
                    name.BuildDefinition,
                    name.TeamProject,
                    ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl));
                throw new InvalidComponentException(
                          string.Format(
                              "Could not find build definition {0} for team project {1} on version control server for tfs {2}",
                              name.BuildDefinition,
                              name.TeamProject,
                              ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)));
            }

            // Query all builds with this teamProject and build definition name
            var build = _client.GetBuildsAsync(teamProject.Name, definitions: new List <int> {
                buildDef.First().Id
            }, type: TFSWebApi.DefinitionType.Build).Result;

            foreach (var buildResult in build)
            {
                List <string> availableBuildTags = null;
                if (buildResult.Tags != null && buildResult.Tags.Count() > 0)
                {
                    availableBuildTags = buildResult.Tags;
                }
                var availableBuildStatus = new List <string> {
                    buildResult.Status.ToString()
                };
                var vers = new ComponentVersion(buildResult.BuildNumber, availableBuildStatus, acceptedBuildQuality: null, acceptedBuildTags: availableBuildTags);
                versList.Add(vers);
                Logger.Instance().Log(TraceLevel.Info, "{0}: Found build {1}", ResolverType, vers.ToString());
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying component versions finished successfully", ResolverType);
            return(versList);
        }