コード例 #1
0
ファイル: UpgradeUtility.cs プロジェクト: zdarovka/Sleet
 /// <summary>
 /// Add default capabilities if none are provided.
 /// </summary>
 public static void AddDefaultCapabilities(FeedRequirements requirements)
 {
     // Infer default schema from Sleet 2.2.x if none is provided.
     if (requirements.RequiredCapabilities.Count < 1)
     {
         if (requirements.CreatorSleetVersion < new SemanticVersion(2, 2, 0))
         {
             requirements.RequiredCapabilities.Add(FeedCapability.Parse("schema:0.1.0"));
         }
         else
         {
             requirements.RequiredCapabilities.Add(FeedCapability.Parse("schema:1.0.0"));
         }
     }
 }
コード例 #2
0
ファイル: UpgradeUtility.cs プロジェクト: zdarovka/Sleet
        /// <summary>
        /// Read the assembly version.
        /// </summary>
        public static async Task <FeedRequirements> GetFeedRequirementsAsync(ISleetFileSystem fileSystem, ILogger log, CancellationToken token)
        {
            var requirements = new FeedRequirements();

            // Read feed index.json data
            var indexPath = fileSystem.Get("index.json");
            var json      = await indexPath.GetJson(log, token);

            var sleetVersion = json.GetValue("sleet:version")?.ToString();

            if (!string.IsNullOrEmpty(sleetVersion))
            {
                if (!SemanticVersion.TryParse(sleetVersion, out var version))
                {
                    throw new InvalidOperationException("Invalid sleet:version in index.json");
                }

                requirements.CreatorSleetVersion = version;
            }

            var requiredVersion = json.GetValue("sleet:requiredVersion")?.ToString();

            if (!string.IsNullOrEmpty(requiredVersion))
            {
                if (!VersionRange.TryParse(requiredVersion, out var range))
                {
                    throw new InvalidOperationException("Invalid sleet:requiredVersion in index.json");
                }

                requirements.RequiredVersion = range;
            }

            var requiredCaps = json.GetValue("sleet:capabilities")?.ToString();

            if (!string.IsNullOrEmpty(requiredCaps))
            {
                // Space delimited list of caps
                foreach (var s in requiredCaps.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    requirements.RequiredCapabilities.Add(FeedCapability.Parse(s));
                }
            }

            return(requirements);
        }