Exemplo n.º 1
0
        public void LocalizationSettings_IfTheFileResourcesDirectoryIsChangedToADirectoryThatDoesNotExist_ShouldThrowADirectoryNotFoundException()
        {
            IFileSystem           fileSystem = null;
            ILocalizationSettings settings   = null;

            try
            {
                var serviceProvider = this.BuildServiceProvider("Configuration-With-File-Resources-Directory-Path-Only.json", true);
                fileSystem = serviceProvider.GetRequiredService <IFileSystem>();
                settings   = serviceProvider.GetRequiredService <ILocalizationSettings>();
                var stringLocalizer = (StringLocalizer)((StringLocalizer)serviceProvider.GetService <IStringLocalizer>()).Clone(CultureInfo.GetCultureInfo("en-US"));

                Assert.AreEqual(0, stringLocalizer.GetAllStrings(false).Count(), this.PossibleReasonForFailure);
            }
            catch
            {
                Assert.Fail("Unexpected failure.");
            }

            var fileResourcesDirectoryPath = "Z:\\" + Guid.NewGuid();

            try
            {
                settings.FileResourcesDirectory = fileSystem.DirectoryInfo.FromDirectoryName(fileResourcesDirectoryPath);
            }
            catch (DirectoryNotFoundException directoryNotFoundException)
            {
                var message = $"File-resources-directory-exception: The directory \"{fileResourcesDirectoryPath}\" does not exist.";

                if (directoryNotFoundException.Message.Equals(message, StringComparison.OrdinalIgnoreCase))
                {
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        public ResourceProvider(IFileSystem fileSystem, IHostEnvironment hostEnvironment, ILoggerFactory loggerFactory, IResourceLocator resourceLocator, ILocalizationSettings settings)
        {
            this.FileSystem      = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
            this.HostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
            this.Logger          = (loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory))).CreateLogger(this.GetType());
            this.ResourceLocator = resourceLocator ?? throw new ArgumentNullException(nameof(resourceLocator));
            this.Settings        = settings ?? throw new ArgumentNullException(nameof(settings));

            this.FileResourcesDirectoryWatcher = this.CreateFileResourcesDirectoryWatcher(fileSystem, hostEnvironment, settings);

            settings.EmbeddedResourceAssembliesChanged += this.OnEmbeddedResourceAssembliesChanged;
            settings.FileResourcesDirectoryChanged     += this.OnFileResourcesDirectoryChanged;
        }
Exemplo n.º 3
0
        protected internal IFileSystemWatcher CreateFileResourcesDirectoryWatcher(IFileSystem fileSystem, IHostEnvironment hostEnvironment, ILocalizationSettings settings)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            if (hostEnvironment == null)
            {
                throw new ArgumentNullException(nameof(hostEnvironment));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var fileSystemWatcher = fileSystem.FileSystemWatcher.CreateNew();

            this.SetFileSystemWatcher(settings.FileResourcesDirectory, fileSystemWatcher, hostEnvironment);

            fileSystemWatcher.IncludeSubdirectories = true;

            fileSystemWatcher.Changed += this.OnFileResourcesDirectoryEntryChanged;
            fileSystemWatcher.Created += this.OnFileResourcesDirectoryEntryCreated;
            fileSystemWatcher.Deleted += this.OnFileResourcesDirectoryEntryDeleted;
            fileSystemWatcher.Error   += this.OnFileResourcesDirectoryEntryError;
            fileSystemWatcher.Renamed += this.OnFileResourcesDirectoryEntryRenamed;

            return(fileSystemWatcher);
        }
 public UserTimeCookiedOffsetResolver(ILocalizationSettings localizationSettings)
 {
     _localizationSettings = localizationSettings;
 }
        public LocalizationProvider(ILocalizationPathResolver localizationPathResolver, ILocalizedStringFactory localizedStringFactory, ILoggerFactory loggerFactory, IResourceProvider resourceProvider, ILocalizationSettings settings)
        {
            this.LocalizationPathResolver = localizationPathResolver ?? throw new ArgumentNullException(nameof(localizationPathResolver));
            this.LocalizedStringFactory   = localizedStringFactory ?? throw new ArgumentNullException(nameof(localizedStringFactory));
            this.Logger           = (loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory))).CreateLogger(this.GetType());
            this.ResourceProvider = resourceProvider ?? throw new ArgumentNullException(nameof(resourceProvider));
            this.Settings         = settings ?? throw new ArgumentNullException(nameof(settings));

            resourceProvider.EmbeddedResourcesChanged   += this.OnEmbeddedResourcesChanged;
            resourceProvider.FileResourceContentChanged += this.OnFileResourceContentChanged;
            resourceProvider.FileResourcesChanged       += this.OnFileResourcesChanged;
            settings.AlphabeticalSortingChanged         += this.OnAlphabeticalSortingChanged;
            settings.IncludeParentCulturesChanged       += this.OnIncludeParentCulturesChanged;
        }