/// <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 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>
        /// 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 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);
            }
        }
Exemplo 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>
        /// 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 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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Checks if the version represented by this version object equals the version represented by otherVersion object.
        /// </summary>
        /// <param name="otherVersion">Version representing IVersion object</param>
        /// <returns>True if equal. False otherwise</returns>
        public bool Equals(IComponentVersion otherVersion)
        {
            if (!string.IsNullOrEmpty(Version) && !string.IsNullOrEmpty(otherVersion.Version) && Version.Equals(otherVersion.Version))
            {
                return(true);
            }

            if (TfsVersionSpec != null && otherVersion.TfsVersionSpec != null && TfsVersionSpec.Equals(otherVersion.TfsVersionSpec))
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(BuildNumber) && !string.IsNullOrEmpty(otherVersion.BuildNumber) && BuildNumber.Equals(otherVersion.BuildNumber))
            {
                return(true);
            }

            if (ContainSameValues(BuildStatus, otherVersion.BuildStatus) && ContainSameValues(BuildQuality, otherVersion.BuildQuality))
            {
                return(true);
            }

            if (ContainSameValues(BuildStatus, otherVersion.BuildStatus) && ContainSameValues(BuildTags, otherVersion.BuildTags))
            {
                return(true);
            }

            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 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);
        }
Exemplo n.º 11
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 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>
        /// Validates the component version and check if version number is invalid.
        /// </summary>
        /// <param name="version">The component version.</param>
        private static void ValidateComponentVersion(IComponentVersion version)
        {
            if (version == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Version for build result component was null");
                throw new ArgumentNullException("version", "Version for build result component was null");
            }

            if (string.IsNullOrEmpty(version.BuildNumber) && (version.BuildStatus == null || !version.BuildStatus.Any()))
            {
                Logger.Instance().Log(TraceLevel.Error, "Version number for build result component was invalid");
                throw new ArgumentException("Version number for build result component was invalid", "version");
            }
        }
        /// <summary>
        /// Validates the component version and check if version number is invalid.
        /// </summary>
        /// <param name="version">The component version.</param>
        private static void ValidateComponentVersion(IComponentVersion version)
        {
            if (version == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Version for file share component was null");
                throw new ArgumentNullException("version", "Version for file share component was null");
            }

            if (version.Version == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Version number for file share component was invalid");
                throw new ArgumentException("Version number for file share component was invalid", "version");
            }
        }
        /// <summary>
        /// Validates the component version and check if version spec is invalid.
        /// </summary>
        /// <param name="version">The component version.</param>
        private static void ValidateComponentVersion(IComponentVersion version)
        {
            if (version == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Version for source control component was null");
                throw new ArgumentNullException("version", "Version for source control component was null");
            }

            if (version.TfsVersionSpec == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Version spec for source control component was invalid");
                throw new ArgumentException("Version spec for source control component was invalid", "version");
            }
        }
        /// <summary>
        /// Validates the component version and check if version number is invalid.
        /// </summary>
        /// <param name="version">The component version.</param>
        private static void ValidateComponentVersion(IComponentVersion version)
        {
            if (version == null)
            {
                Logger.Instance().Log(TraceLevel.Error, "Version for binary repository component was null");
                throw new ArgumentNullException("version", "Version for binary repository component was null");
            }

            if (string.IsNullOrEmpty(version.ToString()))
            {
                Logger.Instance().Log(TraceLevel.Error, "Version number for binary repository component was invalid");
                throw new ArgumentException("Version number for binary repository component was invalid", "version");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="version"></param>
        public Dependency(IComponent source, IComponent target, IComponentVersion version)
        {
            _source = source;
            if (_source == null)
            {
                throw new InvalidComponentException("Dependency for dependency graph was initialized with an invalid dependency description (Source component was null)");
            }

            _target = target;
            if (_target == null)
            {
                throw new InvalidComponentException("Dependency for dependency graph was initialized with an invalid dependency description (Target component was null)");
            }

            _version = version;
            if (_version == null)
            {
                throw new InvalidComponentException("Dependency for dependency graph was initialized with an invalid dependency description (Version was null)");
            }
        }
        /// <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>
 /// Constructor which creates a new Component object with a name, version type and a list with predecessor and successor components.
 /// </summary>
 /// <param name="effectiveVersion">Effective version to override</param>
 /// <param name="config">The deserialized config</param>
 /// <param name="predecessors">List of predecessor components</param>
 /// <param name="successors">List of successor components</param>
 public Component(IComponentVersion effectiveVersion, IDependencyProviderConfig config, List <IDependency> predecessors, List <IDependency> successors)
     : this(config, predecessors, successors)
 {
     // Override version here
     Version = effectiveVersion;
 }