/// <summary>
        /// Load settings from a dictionary.
        /// </summary>
        public static IDictionary <string, string> LoadSettings(FeedSettings settings)
        {
            var values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "catalogenabled", settings.CatalogEnabled.ToString().ToLowerInvariant() },
                { "catalogpagesize", settings.CatalogPageSize.ToString() },
                { "symbolsfeedenabled", settings.SymbolsEnabled.ToString().ToLowerInvariant() },
                { "badgesenabled", settings.BadgesEnabled.ToString().ToLowerInvariant() }
            };

            if (settings.RetentionMaxStableVersions > 0)
            {
                values.Add("retentionmaxstableversions", settings.RetentionMaxStableVersions.ToString());
            }

            if (settings.RetentionMaxPrereleaseVersions > 0)
            {
                values.Add("retentionmaxprereleaseversions", settings.RetentionMaxPrereleaseVersions.ToString());
            }

            if (settings.RetentionGroupByFirstPrereleaseLabelCount > 0)
            {
                values.Add("retentiongroupbyfirstprereleaselabelcount", settings.RetentionGroupByFirstPrereleaseLabelCount.ToString());
            }

            return(values);
        }
Beispiel #2
0
        /// <summary>
        /// Load settings from a dictionary.
        /// </summary>
        public static IDictionary <string, string> LoadSettings(FeedSettings settings)
        {
            var values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "catalogenabled", settings.CatalogEnabled.ToString().ToLowerInvariant() },
                { "catalogpagesize", settings.CatalogPageSize.ToString() },
                { "symbolsfeedenabled", settings.SymbolsEnabled.ToString().ToLowerInvariant() }
            };

            return(values);
        }
Beispiel #3
0
        /// <summary>
        /// Load settings from a dictionary.
        /// </summary>
        public static FeedSettings LoadSettings(IDictionary <string, string> values)
        {
            var settings = new FeedSettings();

            foreach (var pair in values)
            {
                switch (pair.Key.ToLowerInvariant())
                {
                case "catalogenabled":
                    settings.CatalogEnabled = GetBoolOrDefault(pair.Value, defaultValue: false);
                    break;

                case "catalogpagesize":
                    settings.CatalogPageSize = Math.Max(1, GetIntOrDefault(pair.Value, defaultValue: 1024));
                    break;

                case "symbolsfeedenabled":
                    settings.SymbolsEnabled = GetBoolOrDefault(pair.Value, defaultValue: false);
                    break;

                case "badgesenabled":
                    settings.BadgesEnabled = GetBoolOrDefault(pair.Value, defaultValue: true);
                    break;

                case "retentionmaxstableversions":
                    settings.RetentionMaxStableVersions = GetIntOrDefault(pair.Value, defaultValue: -1);
                    break;

                case "retentionmaxprereleaseversions":
                    settings.RetentionMaxPrereleaseVersions = GetIntOrDefault(pair.Value, defaultValue: -1);
                    break;

                case "retentiongroupbyfirstprereleaselabelcount":
                    settings.RetentionGroupByFirstPrereleaseLabelCount = GetIntOrDefault(pair.Value, defaultValue: -1);
                    break;

                case "externalsearch":
                    settings.ExternalSearch = GetStringOrDefault(pair.Value, null);
                    break;
                }
            }

            if (settings.RetentionMaxStableVersions < 1)
            {
                settings.RetentionMaxStableVersions = null;
            }

            if (settings.RetentionMaxPrereleaseVersions < 1)
            {
                settings.RetentionMaxPrereleaseVersions = null;
            }

            return(settings);
        }
Beispiel #4
0
        public static async Task SaveSettings(ISleetFileSystem fileSystem, FeedSettings settings, ILogger log, CancellationToken token)
        {
            // Get current file
            var file = GetSettingsFileFromFeed(fileSystem);

            // Update json
            var json = await file.GetJson(log, token);

            var values = LoadSettings(settings);

            Set(json, values);

            // Save
            await file.Write(json, log, token);
        }
Beispiel #5
0
        /// <summary>
        /// Load settings from a dictionary.
        /// </summary>
        public static FeedSettings LoadSettings(IDictionary <string, string> values)
        {
            var settings = new FeedSettings();

            foreach (var pair in values)
            {
                switch (pair.Key.ToLowerInvariant())
                {
                case "catalogenabled":
                    settings.CatalogEnabled = GetBoolOrDefault(pair.Value, defaultValue: false);
                    break;

                case "catalogpagesize":
                    settings.CatalogPageSize = Math.Max(1, GetIntOrDefault(pair.Value, defaultValue: 1024));
                    break;

                case "symbolsfeedenabled":
                    settings.SymbolsEnabled = GetBoolOrDefault(pair.Value, defaultValue: false);
                    break;

                case "retentionmaxstableversions":
                    settings.RetentionMaxStableVersions = GetIntOrDefault(pair.Value, defaultValue: -1);
                    break;

                case "retentionmaxprereleaseversions":
                    settings.RetentionMaxPrereleaseVersions = GetIntOrDefault(pair.Value, defaultValue: -1);
                    break;
                }
            }

            if (settings.RetentionMaxStableVersions < 1)
            {
                settings.RetentionMaxStableVersions = null;
            }

            if (settings.RetentionMaxPrereleaseVersions < 1)
            {
                settings.RetentionMaxPrereleaseVersions = null;
            }

            return(settings);
        }
Beispiel #6
0
        /// <summary>
        /// Load settings from a dictionary.
        /// </summary>
        public static FeedSettings LoadSettings(IDictionary <string, string> values)
        {
            var settings = new FeedSettings();

            foreach (var pair in values)
            {
                switch (pair.Key.ToLowerInvariant())
                {
                case "catalogenabled":
                    settings.CatalogEnabled = GetBoolOrDefault(pair.Value, defaultValue: false);
                    break;

                case "catalogpagesize":
                    settings.CatalogPageSize = Math.Max(1, GetIntOrDefault(pair.Value, defaultValue: 1024));
                    break;

                case "symbolsfeedenabled":
                    settings.SymbolsEnabled = GetBoolOrDefault(pair.Value, defaultValue: false);
                    break;
                }
            }

            return(settings);
        }
Beispiel #7
0
        public static async Task <bool> InitAsync(LocalSettings settings, ISleetFileSystem source, FeedSettings feedSettings, ILogger log, CancellationToken token)
        {
            SourceUtility.ValidateFileSystem(source);

            var exitCode  = true;
            var noChanges = true;
            var now       = DateTimeOffset.UtcNow;

            var context = new SleetContext()
            {
                LocalSettings  = settings,
                Source         = source,
                SourceSettings = feedSettings,
                Log            = log,
                Token          = token,
                OperationStart = now
            };

            log.LogMinimal($"Initializing {source.BaseURI.AbsoluteUri}");

            // Validate source
            var exists = await source.Validate(log, token);

            if (!exists)
            {
                return(false);
            }

            // Create service index.json
            noChanges &= !await CreateServiceIndexAsync(source, log, token, now);

            var serviceIndexFile = source.Get("index.json");
            var serviceIndexJson = await serviceIndexFile.GetJson(log, token);

            var serviceIndexJsonBefore = serviceIndexJson.DeepClone();

            serviceIndexJson["resources"] = new JArray();

            // Create sleet.settings.json
            noChanges &= !await CreateSettingsAsync(source, feedSettings, log, token, now, serviceIndexJson);

            // Create catalog/index.json
            if (feedSettings.CatalogEnabled)
            {
                noChanges &= !await CreateCatalogAsync(source, log, token, now, serviceIndexJson);
            }

            // Create autocomplete
            noChanges &= !await CreateAutoCompleteAsync(source, log, token, now, serviceIndexJson);

            // Create search
            noChanges &= !await CreateSearchAsync(source, log, token, now, serviceIndexJson);

            // Create package index
            noChanges &= !await CreatePackageIndexAsync(context, serviceIndexJson);

            // Additional entries
            AddServiceIndexEntry(source.BaseURI, "registration/", "RegistrationsBaseUrl/3.4.0", "Package registrations used for search and packages.config.", serviceIndexJson);
            AddServiceIndexEntry(source.BaseURI, "", "ReportAbuseUriTemplate/3.0.0", "Report abuse template.", serviceIndexJson);
            AddServiceIndexEntry(source.BaseURI, "flatcontainer/", "PackageBaseAddress/3.0.0", "Packages used by project.json", serviceIndexJson);

            // Add symbols feed if enabled
            if (feedSettings.SymbolsEnabled)
            {
                await AddSymbolsFeedAsync(source, serviceIndexJson, context);
            }

            // Check if services changed
            noChanges &= serviceIndexJsonBefore.Equals(serviceIndexJson);

            if (noChanges)
            {
                throw new InvalidOperationException("Source is already initialized. No actions taken.");
            }

            // Write the service index out
            await serviceIndexFile.Write(serviceIndexJson, log, token);

            // Save all
            exitCode &= await source.Commit(log, token);

            if (exitCode)
            {
                log.LogMinimal($"Successfully initialized {source.BaseURI.AbsoluteUri}");
            }
            else
            {
                log.LogError($"Failed to initialize {source.BaseURI.AbsoluteUri}");
            }

            return(exitCode);
        }
Beispiel #8
0
        private static async Task <bool> CreateSettingsAsync(ISleetFileSystem source, FeedSettings feedSettings, ILogger log, CancellationToken token, DateTimeOffset now, JObject serviceIndexJson)
        {
            AddServiceIndexEntry(source.BaseURI, "sleet.settings.json", "http://schema.emgarten.com/sleet#SettingsFile/1.0.0", "Sleet feed settings.", serviceIndexJson);

            // Create new file.
            var result = await CreateFromTemplateAsync(source, log, now, "Settings", "sleet.settings.json", token);

            // Write out the current settings.
            await FeedSettingsUtility.SaveSettings(source, feedSettings, log, token);

            return(result);
        }
Beispiel #9
0
 public static Task <bool> InitAsync(LocalSettings settings, ISleetFileSystem source, FeedSettings feedSettings, ILogger log, CancellationToken token)
 {
     return(InitAsync(settings, source, feedSettings, autoCreateBucket: true, log: log, token: token));
 }
Beispiel #10
0
        /// <summary>
        /// Apply setting handlers
        /// </summary>
        private static async Task ApplySettingHandlers(LocalSettings settings, ISleetFileSystem source, ILogger log, FeedSettings feedSettings, CancellationToken token)
        {
            if (feedSettings.ExternalSearch != null)
            {
                log.LogMinimal($"Setting external search url: {feedSettings.ExternalSearch}");

                var context = new SleetContext()
                {
                    LocalSettings  = settings,
                    SourceSettings = feedSettings,
                    Log            = log,
                    Source         = source,
                    Token          = token
                };

                var searchHandler = new ExternalSearchHandler(context);
                await searchHandler.Set(feedSettings.ExternalSearch);

                await source.Commit(log, token);
            }
        }