public EmailNotificationMethod( ILocalizedTextService textService, IHostingEnvironment hostingEnvironment, IEmailSender emailSender, IOptions <HealthChecksSettings> healthChecksSettings, IOptions <ContentSettings> contentSettings, IMarkdownToHtmlConverter markdownToHtmlConverter) : base(healthChecksSettings) { var recipientEmail = Settings?["RecipientEmail"]; if (string.IsNullOrWhiteSpace(recipientEmail)) { Enabled = false; return; } RecipientEmail = recipientEmail; _textService = textService ?? throw new ArgumentNullException(nameof(textService)); _hostingEnvironment = hostingEnvironment; _emailSender = emailSender; _markdownToHtmlConverter = markdownToHtmlConverter; _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); }
public UploadFileTypeValidator(ILocalizedTextService localizedTextService, IOptionsMonitor <ContentSettings> contentSettings) { _localizedTextService = localizedTextService; _contentSettings = contentSettings.CurrentValue; contentSettings.OnChange(x => _contentSettings = x); }
/// <summary> /// Function to create a content object interface. /// </summary> /// <param name="settings">The initial settings for the content.</param> /// <returns> /// A new content object interface. /// </returns> protected override ContentObject OnCreateContentObject(ContentSettings settings) { // Retrieve our codecs. GetCodecs(); return(new GorgonImageContent(this, (GorgonImageContentSettings)settings)); }
public HtmlUrlParser(IOptions <ContentSettings> contentSettings, ILogger <HtmlUrlParser> logger, IProfilingLogger profilingLogger, IIOHelper ioHelper) { _contentSettings = contentSettings.Value; _logger = logger; _ioHelper = ioHelper; _profilingLogger = profilingLogger; }
public CurrentUserController( MediaFileManager mediaFileManager, IOptionsSnapshot <ContentSettings> contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IUserService userService, IUmbracoMapper umbracoMapper, IBackOfficeUserManager backOfficeUserManager, ILocalizedTextService localizedTextService, AppCaches appCaches, IShortStringHelper shortStringHelper, IPasswordChanger <BackOfficeIdentityUser> passwordChanger, IUserDataService userDataService) { _mediaFileManager = mediaFileManager; _contentSettings = contentSettings.Value; _hostingEnvironment = hostingEnvironment; _imageUrlGenerator = imageUrlGenerator; _backofficeSecurityAccessor = backofficeSecurityAccessor; _userService = userService; _umbracoMapper = umbracoMapper; _backOfficeUserManager = backOfficeUserManager; _localizedTextService = localizedTextService; _appCaches = appCaches; _shortStringHelper = shortStringHelper; _passwordChanger = passwordChanger; _userDataService = userDataService; }
public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger <DataTypeMapDefinition> logger, IOptions <ContentSettings> contentSettings, IConfigurationEditorJsonSerializer serializer) { _propertyEditors = propertyEditors; _logger = logger; _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _serializer = serializer; }
public virtual async Task <IActionResult> Delete(string id) { _cache.Remove(typeof(ContentSettings).ToString()); ContentSettings model = Engine.Settings.Content; if (model == null) { model = new ContentSettings(); } var types = model.Types.ToList(); if (!types.Any(t => t.Type.ToLower() == id)) { MessageType = AlertType.Info; SaveMessage = "Deleted successfully."; return(RedirectToAction(nameof(Index))); } types.RemoveAll(t => t.Type.ToLower() == id); model.Types = types.ToArray(); model.CheckBaseFields(); Engine.Settings.Set(model); // refresh all content metas and things await RefreshAllMetasAsync(); MessageType = AlertType.Info; SaveMessage = "Deleted successfully."; return(RedirectToAction(nameof(Index))); }
public DataTypeController( PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IOptionsSnapshot <ContentSettings> contentSettings, IUmbracoMapper umbracoMapper, PropertyEditorCollection propertyEditorCollection, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, ILocalizedTextService localizedTextService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, IConfigurationEditorJsonSerializer serializer) { _propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors)); _dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService)); _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); _propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection)); _contentTypeService = contentTypeService ?? throw new ArgumentNullException(nameof(contentTypeService)); _mediaTypeService = mediaTypeService ?? throw new ArgumentNullException(nameof(mediaTypeService)); _memberTypeService = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService)); _localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); _backOfficeSecurityAccessor = backOfficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backOfficeSecurityAccessor)); _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
public ContentTypeMapDefinition( CommonMapper commonMapper, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IFileService fileService, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, ILoggerFactory loggerFactory, IShortStringHelper shortStringHelper, IOptions <GlobalSettings> globalSettings, IHostingEnvironment hostingEnvironment, IOptionsMonitor <ContentSettings> contentSettings) { _commonMapper = commonMapper; _propertyEditors = propertyEditors; _dataTypeService = dataTypeService; _fileService = fileService; _contentTypeService = contentTypeService; _mediaTypeService = mediaTypeService; _memberTypeService = memberTypeService; _loggerFactory = loggerFactory; _logger = _loggerFactory.CreateLogger <ContentTypeMapDefinition>(); _shortStringHelper = shortStringHelper; _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _contentSettings = contentSettings.CurrentValue; contentSettings.OnChange(x => _contentSettings = x); }
public MacroRenderer( IProfilingLogger profilingLogger, ILogger <MacroRenderer> logger, IUmbracoContextAccessor umbracoContextAccessor, IOptions <ContentSettings> contentSettings, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IHostingEnvironment hostingEnvironment, ICookieManager cookieManager, ISessionManager sessionManager, IRequestAccessor requestAccessor, PartialViewMacroEngine partialViewMacroEngine, IHttpContextAccessor httpContextAccessor) { _profilingLogger = profilingLogger ?? throw new ArgumentNullException(nameof(profilingLogger)); _logger = logger; _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _textService = textService; _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _cookieManager = cookieManager; _sessionManager = sessionManager; _requestAccessor = requestAccessor; _partialViewMacroEngine = partialViewMacroEngine; _httpContextAccessor = httpContextAccessor; }
public void Returns_Success_ForValid_Configuration() { var validator = new ContentSettingsValidator(); ContentSettings options = BuildContentSettings(); ValidateOptionsResult result = validator.Validate("settings", options); Assert.True(result.Succeeded); }
public void Returns_Fail_For_Configuration_With_Invalid_Error404Collection_Due_To_Duplicate_Id() { var validator = new ContentSettingsValidator(); ContentSettings options = BuildContentSettings(contentXPath: "/aaa/bbb"); ValidateOptionsResult result = validator.Validate("settings", options); Assert.False(result.Succeeded); }
protected override void ComposeSettings() { var contentSettings = new ContentSettings(); var userPasswordConfigurationSettings = new UserPasswordConfigurationSettings(); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); }
public void Returns_Fail_For_Configuration_With_Invalid_Error404Collection_Due_To_Empty_Culture() { var validator = new ContentSettingsValidator(); ContentSettings options = BuildContentSettings(culture: string.Empty); ValidateOptionsResult result = validator.Validate("settings", options); Assert.False(result.Succeeded); }
public void Returns_Fail_For_Configuration_With_Invalid_AutoFillImageProperties_Collection() { var validator = new ContentSettingsValidator(); ContentSettings options = BuildContentSettings(culture: string.Empty); ValidateOptionsResult result = validator.Validate("settings", options); Assert.False(result.Succeeded); }
public void Can_Generate_Xml_Representation_Of_Media() { // Arrange var mediaType = MockedContentTypes.CreateImageMediaType("image2"); ServiceContext.MediaTypeService.Save(mediaType); // reference, so static ctor runs, so event handlers register // and then, this will reset the width, height... because the file does not exist, of course ;-( var loggerFactory = NullLoggerFactory.Instance; var scheme = Mock.Of <IMediaPathScheme>(); var contentSettings = new ContentSettings(); var mediaFileManager = new MediaFileManager(Mock.Of <IFileSystem>(), scheme, loggerFactory.CreateLogger <MediaFileManager>(), ShortStringHelper); var ignored = new FileUploadPropertyEditor(DataValueEditorFactory, mediaFileManager, Microsoft.Extensions.Options.Options.Create(contentSettings), DataTypeService, LocalizationService, LocalizedTextService, UploadAutoFillProperties, ContentService); var media = MockedMedia.CreateMediaImage(mediaType, -1); media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests ServiceContext.MediaService.Save(media, Constants.Security.SuperUserId); // so we have to force-reset these values because the property editor has cleared them media.SetValue(Constants.Conventions.Media.Width, "200"); media.SetValue(Constants.Conventions.Media.Height, "200"); media.SetValue(Constants.Conventions.Media.Bytes, "100"); media.SetValue(Constants.Conventions.Media.Extension, "png"); var nodeName = media.ContentType.Alias.ToSafeAlias(ShortStringHelper); var urlName = media.GetUrlSegment(ShortStringHelper, new[] { new DefaultUrlSegmentProvider(ShortStringHelper) }); // Act XElement element = media.ToXml(Factory.GetRequiredService <IEntityXmlSerializer>()); // Assert Assert.That(element, Is.Not.Null); Assert.That(element.Name.LocalName, Is.EqualTo(nodeName)); Assert.AreEqual(media.Id.ToString(), (string)element.Attribute("id")); Assert.AreEqual(media.ParentId.ToString(), (string)element.Attribute("parentID")); Assert.AreEqual(media.Level.ToString(), (string)element.Attribute("level")); Assert.AreEqual(media.SortOrder.ToString(), (string)element.Attribute("sortOrder")); Assert.AreEqual(media.CreateDate.ToString("s"), (string)element.Attribute("createDate")); Assert.AreEqual(media.UpdateDate.ToString("s"), (string)element.Attribute("updateDate")); Assert.AreEqual(media.Name, (string)element.Attribute("nodeName")); Assert.AreEqual(urlName, (string)element.Attribute("urlName")); Assert.AreEqual(media.Path, (string)element.Attribute("path")); Assert.AreEqual("", (string)element.Attribute("isDoc")); Assert.AreEqual(media.ContentType.Id.ToString(), (string)element.Attribute("nodeType")); Assert.AreEqual(media.GetCreatorProfile(ServiceContext.UserService).Name, (string)element.Attribute("writerName")); Assert.AreEqual(media.CreatorId.ToString(), (string)element.Attribute("writerID")); Assert.IsNull(element.Attribute("template")); Assert.AreEqual(media.Properties[Constants.Conventions.Media.File].GetValue().ToString(), element.Elements(Constants.Conventions.Media.File).Single().Value); Assert.AreEqual(media.Properties[Constants.Conventions.Media.Width].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Width).Single().Value); Assert.AreEqual(media.Properties[Constants.Conventions.Media.Height].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Height).Single().Value); Assert.AreEqual(media.Properties[Constants.Conventions.Media.Bytes].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Bytes).Single().Value); Assert.AreEqual(media.Properties[Constants.Conventions.Media.Extension].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Extension).Single().Value); }
public HtmlUrlParser(IOptionsMonitor <ContentSettings> contentSettings, ILogger <HtmlUrlParser> logger, IProfilingLogger profilingLogger, IIOHelper ioHelper) { _contentSettings = contentSettings.CurrentValue; _logger = logger; _ioHelper = ioHelper; _profilingLogger = profilingLogger; contentSettings.OnChange(x => _contentSettings = x); }
public void ResetCache() { if (!Engine.Services.Installed) { return; } var options = new DbContextOptionsBuilder <HoodDbContext>(); options.UseSqlServer(_config["ConnectionStrings:DefaultConnection"]); var db = new HoodDbContext(options.Options); byKey = new Lazy <Dictionary <int, ContentCategory> >(() => { var q = from d in db.ContentCategories select new ContentCategory { Id = d.Id, DisplayName = d.DisplayName, Slug = d.Slug, ContentType = d.ContentType, ParentCategoryId = d.ParentCategoryId, ParentCategory = d.ParentCategory, Children = d.Children, Count = d.Content.Where(c => c.Content.Status == ContentStatus.Published).Count(), }; return(q.ToDictionary(c => c.Id)); }); ContentSettings contentSettings = Engine.Settings.Content; bySlug = new Dictionary <string, Lazy <Dictionary <string, ContentCategory> > >(); foreach (var type in contentSettings.Types.Where(t => t.Enabled)) { bySlug.Add( type.Type, new Lazy <Dictionary <string, ContentCategory> >(() => { var q = from d in db.ContentCategories where d.ContentType == type.Type select new ContentCategory { Id = d.Id, DisplayName = d.DisplayName, Slug = d.Slug, ContentType = d.ContentType, ParentCategoryId = d.ParentCategoryId, ParentCategory = d.ParentCategory, Children = d.Children, Count = d.Content.Where(c => c.Content.Status == ContentStatus.Published).Count(), }; return(q.ToDictionary(c => c.Slug)); }) ); } topLevel = new Lazy <ContentCategory[]>(() => byKey.Value.Values.Where(c => c.ParentCategoryId == null).ToArray()); }
public virtual IActionResult Content() { _cache.Remove(typeof(ContentSettings).ToString()); ContentSettings model = Engine.Settings.Content; if (model == null) { model = new ContentSettings(); } return(View(model)); }
public MediaMapDefinition(ICultureDictionary cultureDictionary, CommonMapper commonMapper, CommonTreeNodeMapper commonTreeNodeMapper, IMediaService mediaService, IMediaTypeService mediaTypeService, ILocalizedTextService localizedTextService, MediaUrlGeneratorCollection mediaUrlGenerators, IOptions <ContentSettings> contentSettings, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { _commonMapper = commonMapper; _commonTreeNodeMapper = commonTreeNodeMapper; _mediaService = mediaService; _mediaTypeService = mediaTypeService; _mediaUrlGenerators = mediaUrlGenerators; _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _tabsAndPropertiesMapper = new TabsAndPropertiesMapper <IMedia>(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider); }
internal static IActionResult PostSetAvatarInternal(IList<IFormFile> files, IUserService userService, IAppCache cache, MediaFileManager mediaFileManager, IShortStringHelper shortStringHelper, ContentSettings contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, int id) { if (files is null) { return new UnsupportedMediaTypeResult(); } var root = hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempFileUploads); //ensure it exists Directory.CreateDirectory(root); //must have a file if (files.Count == 0) { return new NotFoundResult(); } IUser? user = userService.GetUserById(id); if (user == null) { return new NotFoundResult(); } if (files.Count > 1) { return new ValidationErrorResult( "The request was not formatted correctly, only one file can be attached to the request"); } //get the file info IFormFile file = files.First(); var fileName = file.FileName.Trim(new[] { '\"' }).TrimEnd(); var safeFileName = fileName.ToSafeFileName(shortStringHelper); var ext = safeFileName.Substring(safeFileName.LastIndexOf('.') + 1).ToLower(); if (contentSettings.DisallowedUploadFiles.Contains(ext) == false) { //generate a path of known data, we don't want this path to be guessable user.Avatar = "UserAvatars/" + (user.Id + safeFileName).GenerateHash<SHA1>() + "." + ext; using (Stream fs = file.OpenReadStream()) { mediaFileManager.FileSystem.AddFile(user.Avatar, fs, true); } userService.Save(user); } return new OkObjectResult(user.GetUserAvatarUrls(cache, mediaFileManager, imageUrlGenerator)); }
public AdminVisualEditorStateService( IHttpContextAccessor httpContextAccessor, IUserContextService userContextService, ContentSettings contentSettings, IVisualEditorStateCache visualEditorStateCache ) { _httpContextAccessor = httpContextAccessor; _userContextService = userContextService; _contentSettings = contentSettings; _visualEditorStateCache = visualEditorStateCache; }
public TinyMceController( IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper, IOptionsSnapshot <ContentSettings> contentSettings, IIOHelper ioHelper, IImageUrlGenerator imageUrlGenerator) { _hostingEnvironment = hostingEnvironment; _shortStringHelper = shortStringHelper; _contentSettings = contentSettings.Value; _ioHelper = ioHelper; _imageUrlGenerator = imageUrlGenerator; }
public FileUploadPropertyValueEditor( DataEditorAttribute attribute, MediaFileManager mediaFileManager, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IOptions <ContentSettings> contentSettings, IJsonSerializer jsonSerializer, IIOHelper ioHelper) : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) { _mediaFileManager = mediaFileManager ?? throw new ArgumentNullException(nameof(mediaFileManager)); _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); }
public virtual async Task <IActionResult> ResetContent() { var model = new ContentSettings(); Engine.Settings.Set(model); // refresh all content metas and things await RefreshAllMetasAsync(); SaveMessage = $"The settings have been reset to their default values."; MessageType = AlertType.Success; return(RedirectToAction(nameof(Index))); }
public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, ILogger <NotificationService> logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IOptions <GlobalSettings> globalSettings, IOptions <ContentSettings> contentSettings, IEmailSender emailSender) { _notificationsRepository = notificationsRepository; _globalSettings = globalSettings.Value; _contentSettings = contentSettings.Value; _emailSender = emailSender; _uowProvider = provider ?? throw new ArgumentNullException(nameof(provider)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _contentService = contentService ?? throw new ArgumentNullException(nameof(contentService)); _localizationService = localizationService; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _ioHelper = ioHelper; }
static void LoadSettings() { settingsLock.AcquireWriterLock(Timeout.Infinite); try { if (cache != null) { cache.Dispose(); } _settings = ConfigurationProvider.Settings; // bool validLicense = Alachisoft.NCache.ContentOptimization.Licensing.LicesnseManager.IsLicenseValid; /* if (!validLicense) * { * FileBasedTraceProvider.Current.WriteTrace(TraceSeverity.CriticalEvent, "License not verified"); * _settings.EnableViewstateCaching = false; * } */ if (_settings.Enabled) { if (_settings.CacheSettings == null) { throw new Exception("Cache settings not set"); } var cacheAdapter = new CacheAdapter(_settings.CacheSettings.CacheName); cacheAdapter.RetryInterval = _settings.CacheSettings.ConnectionRetryInterval.HasValue ? _settings.CacheSettings.ConnectionRetryInterval.Value : 300; cacheAdapter.Load(); if (_settings.CacheSettings.Expiration == null) { throw new Exception("Expiration settings not set"); } cacheAdapter.DefaultExpiration = _settings.CacheSettings.Expiration.Convert(); cache = cacheAdapter.GetSynchronized(settingsLock); } } finally { settingsLock.ReleaseWriterLock(); } }
/// <summary> /// Initializes a new instance of the <see cref="ContentFinderByConfigured404"/> class. /// </summary> public ContentFinderByConfigured404( ILogger <ContentFinderByConfigured404> logger, IEntityService entityService, IOptions <ContentSettings> contentConfigSettings, IExamineManager examineManager, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor) { _logger = logger; _entityService = entityService; _contentSettings = contentConfigSettings.Value; _examineManager = examineManager; _variationContextAccessor = variationContextAccessor; _umbracoContextAccessor = umbracoContextAccessor; }
public MediaFileManager( IFileSystem fileSystem, IMediaPathScheme mediaPathScheme, ILogger <MediaFileManager> logger, IShortStringHelper shortStringHelper, IServiceProvider serviceProvider, IOptions <ContentSettings> contentSettings) { _mediaPathScheme = mediaPathScheme; _logger = logger; _shortStringHelper = shortStringHelper; _serviceProvider = serviceProvider; _contentSettings = contentSettings.Value; FileSystem = fileSystem; }
public MediaValueSetBuilder( PropertyEditorCollection propertyEditors, UrlSegmentProviderCollection urlSegmentProviders, MediaUrlGeneratorCollection mediaUrlGenerators, IUserService userService, IShortStringHelper shortStringHelper, IOptions <ContentSettings> contentSettings) : base(propertyEditors, false) { _urlSegmentProviders = urlSegmentProviders; _mediaUrlGenerators = mediaUrlGenerators; _userService = userService; _shortStringHelper = shortStringHelper; _contentSettings = contentSettings.Value; }