Esempio n. 1
0
        public IEnumerable <IndexSettingsModel> GetIndexSettings()
        {
            var settings = _cacheManager.Get <string, IEnumerable <IndexSettingsModel> >("Digic.Sitemap.IndexSettings",
                                                                                         ctx =>
            {
                var contentTypes = _contentManager.GetContentTypeDefinitions()
                                   .Where(ctd => ctd.Parts.FirstOrDefault(p => p.PartDefinition.Name == "AutoroutePart") != null)
                                   .ToList();

                var typeNames = contentTypes.Select(t => t.Name).ToArray();

                // Delete everything that no longer corresponds to these allowed content types
                var toDelete = _settingsRepository.Fetch(q => !typeNames.Contains(q.ContentType)).ToList();
                foreach (var record in toDelete)
                {
                    _settingsRepository.Delete(record);
                }
                _settingsRepository.Flush();



                var contentSettings = new List <IndexSettingsModel>();
                foreach (var type in contentTypes)
                {
                    var _type = type;
                    // Get the record, generate a new one if it doesn't exist.
                    SitemapSettingsRecord record = _settingsRepository.Fetch(q => q.ContentType == _type.Name).FirstOrDefault();
                    if (record == null)
                    {
                        record                 = new SitemapSettingsRecord();
                        record.ContentType     = type.Name;
                        record.IndexForDisplay = false;
                        record.IndexForXml     = false;
                        record.Priority        = 3;
                        record.UpdateFrequency = "weekly";
                        _settingsRepository.Create(record);
                    }

                    var model = new IndexSettingsModel()
                    {
                        DisplayName     = type.DisplayName,
                        Name            = type.Name,
                        IndexForDisplay = record.IndexForDisplay,
                        IndexForXml     = record.IndexForXml,
                        Priority        = record.Priority,
                        UpdateFrequency = record.UpdateFrequency
                    };
                    contentSettings.Add(model);
                }


                ctx.Monitor(_signals.When("ContentDefinitionManager"));
                ctx.Monitor(_signals.When("Digic.Sitemap.IndexSettings"));

                return(contentSettings);
            });

            return(settings);
        }
Esempio n. 2
0
        public async Task UpdateAsync([FromBody] IndexSettingsModel model)
        {
            try
            {
                IndexSettings indexSettings = Mapper.Map <IndexSettings>(model);

                await _indexSettingsService.UpdateAsync(indexSettings);
            }
            catch (EntityNotFoundException)
            {
                throw new ValidationApiException(HttpStatusCode.NotFound, "The index settings does not exist");
            }
            catch (InvalidOperationException exception)
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, exception.Message);
            }
        }
Esempio n. 3
0
        public async Task AddAsync([FromBody] IndexSettingsModel model)
        {
            try
            {
                IndexSettings indexSettings = Mapper.Map <IndexSettings>(model);

                await _indexSettingsService.AddAsync(indexSettings);
            }
            catch (EntityAlreadyExistsException)
            {
                throw new ValidationApiException(HttpStatusCode.Conflict, "The index settings already exists");
            }
            catch (InvalidOperationException exception)
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, exception.Message);
            }
        }