Ejemplo n.º 1
0
        /// <summary>
        /// Formats a RelationshipDescriptor into a user-readable string:
        /// Name, version: x, min: x, max: x
        /// </summary>
        private static string RelationshipToPrintableString(RelationshipDescriptor dep)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(dep.ToString());
            return(sb.ToString());
        }
Ejemplo n.º 2
0
Archivo: Main.cs Proyecto: pjf/CKAN
 /// <summary>
 /// Formats a RelationshipDescriptor into a user-readable string:
 /// Name, version: x, min: x, max: x
 /// </summary>
 private static string RelationshipToPrintableString(RelationshipDescriptor dep)
 {
     StringBuilder sb = new StringBuilder();
     sb.Append(dep.name);
     if (!string.IsNullOrEmpty(dep.version)) sb.Append(", version: " + dep.version);
     if (!string.IsNullOrEmpty(dep.min_version)) sb.Append(", min: " + dep.version);
     if (!string.IsNullOrEmpty(dep.max_version)) sb.Append(", max: " + dep.version);
     return sb.ToString();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Return the most recent release of a module with a optional ksp version to target and a RelationshipDescriptor to satisfy. 
        /// </summary>
        /// <param name="ksp_version">If not null only consider mods which match this ksp version.</param>
        /// <param name="relationship">If not null only consider mods which satisfy the RelationshipDescriptor.</param>
        /// <returns></returns>
        public CkanModule Latest(KSPVersion ksp_version = null, RelationshipDescriptor relationship=null)
        {
            var available_versions = new List<Version>(module_version.Keys);
            CkanModule module;
            log.DebugFormat("Our dictionary has {0} keys", module_version.Keys.Count);
            log.DebugFormat("Choosing between {0} available versions", available_versions.Count);
            // Uh oh, nothing available. Maybe this existed once, but not any longer.
            if (available_versions.Count == 0)
            {
                return null;
            }

            // Sort most recent versions first.
            available_versions.Reverse();

            if (ksp_version == null && relationship == null)
            {
                module = module_version[available_versions.First()];

                log.DebugFormat("No KSP version restriction, {0} is most recent", module);
                return module;
            }
            if (relationship == null)
            {
                // Time to check if there's anything that we can satisfy.
                var version =
                    available_versions.FirstOrDefault(v => module_version[v].IsCompatibleKSP(ksp_version));
                if (version != null)
                    return module_version[version];

                log.DebugFormat("No version of {0} is compatible with KSP {1}",
                    module_version[available_versions[0]].identifier, ksp_version);

                return null;
            }
            if (ksp_version == null)
            {
                var version = available_versions.FirstOrDefault(relationship.version_within_bounds);
                return version == null ? null : module_version[version];
            }
            else
            {
                var version = available_versions.FirstOrDefault(v =>
                    relationship.version_within_bounds(v) &&
                    module_version[v].IsCompatibleKSP(ksp_version));
                return version == null ? null : module_version[version];
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Formats a RelationshipDescriptor into a user-readable string:
        /// Name, version: x, min: x, max: x
        /// </summary>
        private static string RelationshipToPrintableString(RelationshipDescriptor dep)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(dep.name);
            if (dep.version != null)
            {
                sb.Append(", version: " + dep.version);
            }
            if (dep.min_version != null)
            {
                sb.Append(", min: " + dep.min_version);
            }
            if (dep.max_version != null)
            {
                sb.Append(", max: " + dep.max_version);
            }
            return(sb.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the latest version of a module that can be installed for
        /// the given KSP version. This is a *private* method that assumes
        /// the `available_for_current_version` list has been correctly
        /// calculated. Not for direct public consumption. ;)
        /// </summary>
        private List<CkanModule> LatestAvailableWithProvides(string module, KSPVersion ksp_version,
            IEnumerable<CkanModule> available_for_current_version, RelationshipDescriptor relationship_descriptor=null)
        {
            log.DebugFormat("Finding latest available with provides for {0}", module);

            // TODO: Check user's stability tolerance (stable, unstable, testing, etc)

            var modules = new List<CkanModule>();

            try
            {
                // If we can find the module requested for our KSP, use that.
                CkanModule mod = LatestAvailable(module, ksp_version, relationship_descriptor);
                if (mod != null)
                {
                    modules.Add(mod);
                }
            }
            catch (ModuleNotFoundKraken)
            {
                // It's cool if we can't find it, though.
            }

            // Walk through all our available modules, and see if anything
            // provides what we need.

            // Get our candidate module. We can assume this is non-null, as
            // if it *is* null then available_for_current_version is corrupted,
            // and something is terribly wrong.
            foreach (CkanModule candidate in available_for_current_version)
            {
                // Find everything this module provides (for our version of KSP)
                List<string> provides = candidate.provides;

                // If the module has provides, and any of them are what we're looking
                // for, the add it to our list.
                if (provides != null && provides.Any(provided => provided == module))
                {
                    modules.Add(candidate);
                }
            }
            return modules;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// <see cref = "IRegistryQuerier.LatestAvailableWithProvides" />
 /// </summary>
 public List<CkanModule> LatestAvailableWithProvides(string module, KSPVersion ksp_version, RelationshipDescriptor relationship_descriptor = null)
 {
     // This public interface calculates a cache of modules which
     // are compatible with the current version of KSP, and then
     // calls the private version below for heavy lifting.
     return LatestAvailableWithProvides(module, ksp_version,
         available_modules.Values.Select(pair => pair.Latest(ksp_version)).Where(mod => mod != null).ToArray(),
         relationship_descriptor);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// <see cref = "IRegistryQuerier.LatestAvailable" />
        /// </summary>
        // TODO: Consider making this internal, because practically everything should
        // be calling LatestAvailableWithProvides()
        public CkanModule LatestAvailable(
            string module,
            KSPVersion ksp_version,
            RelationshipDescriptor relationship_descriptor =null)
        {
            log.DebugFormat("Finding latest available for {0}", module);

            // TODO: Check user's stability tolerance (stable, unstable, testing, etc)

            try
            {
                return available_modules[module].Latest(ksp_version,relationship_descriptor);
            }
            catch (KeyNotFoundException)
            {
                throw new ModuleNotFoundKraken(module);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Formats a RelationshipDescriptor into a user-readable string:
 /// Name, version: x, min: x, max: x
 /// </summary>
 private static string RelationshipToPrintableString(RelationshipDescriptor dep)
 {
     StringBuilder sb = new StringBuilder();
     sb.Append(dep.name);
     if (dep.version != null) sb.Append(", version: " + dep.version);
     if (dep.min_version != null) sb.Append(", min: " + dep.min_version);
     if (dep.max_version != null) sb.Append(", max: " + dep.max_version);
     return sb.ToString();
 }