protected Application() { #if (NO_NATIVE_BOOTSTRAPPER) Assembly assembly = null; #else var assembly = Assembly.GetEntryAssembly() ?? GetType().GetTypeInfo().Assembly; #endif Log = new NullLogWriter(); CommandLine = new CommandLineKeyValueStore(Environment.GetCommandLineArgs().Skip(1).ToArray()); Metadata = new AssemblyMetadata(assembly); Context = new ApplicationExecutionContext(); mCommandLine = new CommandLineProcessor(GetType()); var productKey = Metadata.FileName.NormalizeNull().TryTransform(Path.GetFileNameWithoutExtension); #if (NO_NATIVE_BOOTSTRAPPER) var assemblyDir = Directory.GetCurrentDirectory(); #else var assemblyDir = (assembly.Location.TryTransform(Path.GetDirectoryName) ?? Directory.GetCurrentDirectory()).AsKey(); #endif var userDir = Context.GetUserDataDirectoryName("Local", Metadata.CompanyName.NormalizeNull() ?? "XW", productKey ?? ".Default"); var machineDir = Context.GetMachineDataDirectoryName(Metadata.CompanyName.NormalizeNull() ?? "XW", productKey ?? ".Default"); WorkingDirectory = new FileSystemStore(assemblyDir); UserDataDirectory = new FileSystemStore(userDir); MachineDataDirectory = new FileSystemStore(machineDir); mCurrent = this; mResult = Result.Success; mWaitHandler = new RuntimeWaitHandler(); }
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { var config = new AppConfig(); configuration.GetSection("Application").Bind(config); services.AddScoped <IDownloadService, DownloadService>(); //picture service var useAzureBlobStorage = !String.IsNullOrEmpty(config.AzureBlobStorageConnectionString); var useAmazonBlobStorage = (!String.IsNullOrEmpty(config.AmazonAwsAccessKeyId) && !String.IsNullOrEmpty(config.AmazonAwsSecretAccessKey) && !String.IsNullOrEmpty(config.AmazonBucketName) && !String.IsNullOrEmpty(config.AmazonRegion)); if (useAzureBlobStorage) { //Windows Azure BLOB services.AddScoped <IPictureService, AzurePictureService>(); } else if (useAmazonBlobStorage) { //Amazon S3 Simple Storage Service services.AddScoped <IPictureService, AmazonPictureService>(); } else { //standard file system services.AddScoped <IPictureService, PictureService>(); } services.AddSingleton <IMediaFileStore>(serviceProvider => { var fileStore = new FileSystemStore(CommonPath.WebRootPath); return(new DefaultMediaFileStore(fileStore)); }); }
public FileSystemFileReference( string filePath, string path, FileSystemStore store, bool withMetadata, FileExtendedProperties extendedProperties, IPublicUrlProvider publicUrlProvider, IExtendedPropertiesProvider extendedPropertiesProvider) { this.FileSystemPath = filePath; this.Path = path.Replace('\\', '/'); this.store = store; this.extendedPropertiesProvider = extendedPropertiesProvider; this.withMetadata = withMetadata; this.propertiesLazy = new Lazy <IFileProperties>(() => { if (withMetadata) { return(new FileSystemFileProperties(this.FileSystemPath, extendedProperties)); } throw new InvalidOperationException("Metadata are not loaded, please use withMetadata option"); }); this.publicUrlLazy = new Lazy <string>(() => { if (publicUrlProvider != null) { return(publicUrlProvider.GetPublicUrl(this.store.Name, this)); } throw new InvalidOperationException("There is not FileSystemServer enabled."); }); }
protected PluginStorage([NotNull] FileSystemStore storage) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } mStorage = storage; }
protected PluginStorage([NotNull] string directoryName) { if (directoryName == null) { throw new ArgumentNullException(nameof(directoryName)); } mStorage = new FileSystemStore(directoryName.AsKey(), isReadOnly: true); }
public Result <PluginInfo> FindPlugin <TInterface>(FileSystemStore directory) where TInterface : class, IPlugin { if (directory == null) { throw new ArgumentNullException(nameof(directory)); } return(FindPlugin(directory, typeof(TInterface))); }
public Window1() { MinusZero.Instance.Initialize(); InitializeComponent(); MinusZero m = MinusZero.Instance; IVertex r = m.Root.AddVertex(null, "0"); GeneralUtil.ParseAndExcute(r, null, "{\"meta1\"{test1{test11,test12}},meta2{test2},meta3{test3}}"); for (int zzz = 0; zzz < 50; zzz++) { for (int x = 1; x <= 200; x++) { IVertex rr = r.AddVertex(null, "node " + x); for (int xx = 1; xx <= 10; xx++) { IVertex rrr = rr.AddVertex(null, "2node " + xx); for (int xxx = 1; xxx <= 2; xxx++) { rrr.AddVertex(null, "3node " + zzz); } //rrr.AddVertex(GraphUtil.DeepFindOneByValue(r, "meta" + xxx), "a"); } } } FileSystemStore fss = new FileSystemStore("c:\\", m, new AccessLevelEnum[] { AccessLevelEnum.NoRestrictions }); m.Root.AddEdge(null, fss.Root); IVertex w = m.Root.GetAll("\"C:\"\\File:"); GraphUtil.ReplaceEdge(this.TreeVisualiser1.Vertex, "BaseVertex", m.Root); GraphUtil.ReplaceEdge(this.TreeVisualiser1.Vertex, "SelectedVertexes", w); }
public override void ConfigureServices(IServiceCollection services) { services.AddSingleton <IWorkflowsFileStore>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >().Value; var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var mediaPath = Path.Combine(shellOptions.ShellsApplicationDataPath, shellOptions.ShellsContainerName, shellSettings.Name, "elsa"); var fileStore = new FileSystemStore(mediaPath); return(new WorkflowsFileStore(fileStore)); }); services.AddScoped <IWorkflowStore, FileSystemWorkflowStore>(); }
public RoxyFilemanController( IWebHostEnvironment hostingEnvironment, IPermissionService permissionService) { _hostingEnvironment = hostingEnvironment; _permissionService = permissionService; var fullPathToUpload = Path.Combine(CommonPath.WebRootPath, Path.Combine("assets", "images", "uploaded")); if (!Directory.Exists(fullPathToUpload)) { Directory.CreateDirectory(fullPathToUpload); } var fullPath = Path.Combine(CommonPath.WebRootPath, Path.Combine("assets", "images")); var fileStore = new FileSystemStore(fullPath); _mediaFileStore = new DefaultMediaFileStore(fileStore); }
static ApplicationStore() { var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly(); // ReSharper disable once AssignNullToNotNullAttribute var versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); var productName = versionInfo.ProductName.NormalizeNull() ?? (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name.NormalizeNull() ?? "Common"; foreach (var c in Path.GetInvalidFileNameChars()) { productName = productName.Replace($"{c}", ""); } if (string.IsNullOrEmpty(productName)) { productName = "_"; } mProgramData = new FileSystemStore(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), mApplicationGroupKey, productName)); mLocalAppData = new FileSystemStore(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), mApplicationGroupKey, productName)); mRoamingAppData = new FileSystemStore(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), mApplicationGroupKey, productName)); }
public override void ConfigureServices(IServiceCollection services) { services.AddSingleton <IAnchorTag, MediaAnchorTag>(); services.Configure <TemplateOptions>(o => { o.MemberAccessStrategy.Register <DisplayMediaFieldViewModel>(); o.MemberAccessStrategy.Register <Anchor>(); o.Filters.AddFilter("img_tag", MediaFilters.ImgTag); }) .AddLiquidFilter <AssetUrlFilter>("asset_url") .AddLiquidFilter <ResizeUrlFilter>("resize_url"); services.AddTransient <IConfigureOptions <MediaOptions>, MediaOptionsConfiguration>(); services.AddSingleton <IMediaFileProvider>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >(); var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var options = serviceProvider.GetRequiredService <IOptions <MediaOptions> >().Value; var mediaPath = GetMediaPath(shellOptions.Value, shellSettings, options.AssetsPath); if (!Directory.Exists(mediaPath)) { Directory.CreateDirectory(mediaPath); } return(new MediaFileProvider(options.AssetsRequestPath, mediaPath)); }); services.AddSingleton <IStaticFileProvider, IMediaFileProvider>(serviceProvider => serviceProvider.GetRequiredService <IMediaFileProvider>() ); services.AddSingleton <IMediaFileStore>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >(); var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var mediaOptions = serviceProvider.GetRequiredService <IOptions <MediaOptions> >().Value; var mediaEventHandlers = serviceProvider.GetServices <IMediaEventHandler>(); var mediaCreatingEventHandlers = serviceProvider.GetServices <IMediaCreatingEventHandler>(); var logger = serviceProvider.GetRequiredService <ILogger <DefaultMediaFileStore> >(); var mediaPath = GetMediaPath(shellOptions.Value, shellSettings, mediaOptions.AssetsPath); var fileStore = new FileSystemStore(mediaPath); var mediaUrlBase = "/" + fileStore.Combine(shellSettings.RequestUrlPrefix, mediaOptions.AssetsRequestPath); var originalPathBase = serviceProvider.GetRequiredService <IHttpContextAccessor>() .HttpContext?.Features.Get <ShellContextFeature>()?.OriginalPathBase ?? null; if (originalPathBase.HasValue) { mediaUrlBase = fileStore.Combine(originalPathBase.Value, mediaUrlBase); } return(new DefaultMediaFileStore(fileStore, mediaUrlBase, mediaOptions.CdnBaseUrl, mediaEventHandlers, mediaCreatingEventHandlers, logger)); }); services.AddScoped <IPermissionProvider, Permissions>(); services.AddScoped <IAuthorizationHandler, ManageMediaFolderAuthorizationHandler>(); services.AddScoped <INavigationProvider, AdminMenu>(); // ImageSharp // Add ImageSharp Configuration first, to override ImageSharp defaults. services.AddTransient <IConfigureOptions <ImageSharpMiddlewareOptions>, MediaImageSharpConfiguration>(); services.AddImageSharp() .RemoveProvider <PhysicalFileSystemProvider>() .AddProvider <MediaResizingFileProvider>() .AddProcessor <ImageVersionProcessor>() .AddProcessor <TokenCommandProcessor>(); services.AddScoped <MediaTokenSettingsUpdater>(); services.AddScoped <IMediaTokenService, MediaTokenService>(); services.AddTransient <IConfigureOptions <MediaTokenOptions>, MediaTokenOptionsConfiguration>(); services.AddScoped <IFeatureEventHandler>(sp => sp.GetRequiredService <MediaTokenSettingsUpdater>()); services.AddScoped <IModularTenantEvents>(sp => sp.GetRequiredService <MediaTokenSettingsUpdater>()); // Media Field services.AddContentField <MediaField>() .UseDisplayDriver <MediaFieldDisplayDriver>(); services.AddScoped <IContentPartFieldDefinitionDisplayDriver, MediaFieldSettingsDriver>(); services.AddScoped <AttachedMediaFieldFileService, AttachedMediaFieldFileService>(); services.AddScoped <IContentHandler, AttachedMediaFieldContentHandler>(); services.AddScoped <IModularTenantEvents, TempDirCleanerService>(); services.AddScoped <IDataMigration, Migrations>(); services.AddRecipeExecutionStep <MediaStep>(); // MIME types services.TryAddSingleton <IContentTypeProvider, FileExtensionContentTypeProvider>(); services.AddTagHelpers <ImageTagHelper>(); services.AddTagHelpers <ImageResizeTagHelper>(); services.AddTagHelpers <AnchorTagHelper>(); // Media Profiles services.AddScoped <MediaProfilesManager>(); services.AddScoped <IMediaProfileService, MediaProfileService>(); services.AddRecipeExecutionStep <MediaProfileStep>(); // Media Name Normalizer services.AddScoped <IMediaNameNormalizerService, NullMediaNameNormalizerService>(); services.AddScoped <IUserAssetFolderNameProvider, DefaultUserAssetFolderNameProvider>(); }
public CompressedStore(FileSystemStore <T> store) { _fs = store; }
public void EnsureContentBaseDirectoryIsMadeIfAbsent() { string ns = "Test.Foo"; string p = @"\temp-wikitests-creation"; FileSystemStore store = new FileSystemStore(TheFederation, ns, p); Assert.IsTrue(Directory.Exists(p)); store.Delete(); }
public override void ConfigureServices(IServiceCollection services) { services.AddTransient <IConfigureOptions <MediaOptions>, MediaOptionsConfiguration>(); services.AddSingleton <IMediaFileProvider>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >(); var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var options = serviceProvider.GetRequiredService <IOptions <MediaOptions> >().Value; var mediaPath = GetMediaPath(shellOptions.Value, shellSettings, options.AssetsPath); if (!Directory.Exists(mediaPath)) { Directory.CreateDirectory(mediaPath); } return(new MediaFileProvider(options.AssetsRequestPath, mediaPath)); }); services.AddSingleton <IStaticFileProvider, IMediaFileProvider>(serviceProvider => serviceProvider.GetRequiredService <IMediaFileProvider>() ); services.AddSingleton <IMediaFileStore>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >(); var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var mediaOptions = serviceProvider.GetRequiredService <IOptions <MediaOptions> >().Value; var mediaPath = GetMediaPath(shellOptions.Value, shellSettings, mediaOptions.AssetsPath); var fileStore = new FileSystemStore(mediaPath); var mediaUrlBase = "/" + fileStore.Combine(shellSettings.RequestUrlPrefix, mediaOptions.AssetsRequestPath); var originalPathBase = serviceProvider.GetRequiredService <IHttpContextAccessor>() .HttpContext?.Features.Get <ShellContextFeature>()?.OriginalPathBase ?? null; if (originalPathBase.HasValue) { mediaUrlBase = fileStore.Combine(originalPathBase.Value, mediaUrlBase); } return(new DefaultMediaFileStore(fileStore, mediaUrlBase, mediaOptions.CdnBaseUrl)); }); services.AddScoped <IPermissionProvider, Permissions>(); services.AddScoped <IAuthorizationHandler, AttachedMediaFieldsFolderAuthorizationHandler>(); services.AddScoped <INavigationProvider, AdminMenu>(); services.AddContentPart <ImageMediaPart>(); services.AddMedia(); services.AddLiquidFilter <MediaUrlFilter>("asset_url"); services.AddLiquidFilter <ResizeUrlFilter>("resize_url"); services.AddLiquidFilter <ImageTagFilter>("img_tag"); // ImageSharp // Add ImageSharp Configuration first, to override ImageSharp defaults. services.AddTransient <IConfigureOptions <ImageSharpMiddlewareOptions>, MediaImageSharpConfiguration>(); services.AddImageSharpCore() .SetRequestParser <QueryCollectionRequestParser>() .SetMemoryAllocator <ArrayPoolMemoryAllocator>() .SetCache <PhysicalFileSystemCache>() .SetCacheHash <CacheHash>() .AddProvider <MediaResizingFileProvider>() .AddProcessor <ResizeWebProcessor>() .AddProcessor <FormatWebProcessor>() .AddProcessor <ImageVersionProcessor>() .AddProcessor <BackgroundColorWebProcessor>(); // Media Field services.AddContentField <MediaField>(); services.AddScoped <IContentFieldDisplayDriver, MediaFieldDisplayDriver>(); services.AddScoped <IContentPartFieldDefinitionDisplayDriver, MediaFieldSettingsDriver>(); services.AddScoped <AttachedMediaFieldFileService, AttachedMediaFieldFileService>(); services.AddScoped <IContentHandler, AttachedMediaFieldContentHandler>(); services.AddScoped <IModularTenantEvents, TempDirCleanerService>(); services.AddScoped <IDataMigration, Migrations>(); services.AddRecipeExecutionStep <MediaStep>(); // MIME types services.TryAddSingleton <IContentTypeProvider, FileExtensionContentTypeProvider>(); services.AddTagHelpers <ImageTagHelper>(); services.AddTagHelpers <ImageResizeTagHelper>(); }
private ReadWriteStore CreateFileSystemStore(string ns) { string currentDir = System.IO.Directory.GetCurrentDirectory(); string path = currentDir + "\\" + ns; FileSystemStore store = new FileSystemStore(TheFederation, ns, path); TheFederation.RegisterNamespace(store); return store; }
public void SetUp() { MockWikiApplication application = new MockWikiApplication(new FederationConfiguration(), new LinkMaker("test://FileSystemStoreTests/"), OutputFormat.HTML, new MockTimeProvider(TimeSpan.FromSeconds(1))); federation = new Federation(application); _fileSystem = new MockFileSystem( new MockDirectory(@"C:\", new MockDirectory("flexwiki", new MockDirectory("namespaces", new MockDirectory("namespaceone", new MockFile(@"TopicOne.wiki", new DateTime(2004, 10, 28), @"This is some content"), new MockFile(@"TopicTwo.wiki", new DateTime(2004, 10, 29), @"This is some other content"), new MockFile(@"MULTIcapsGoodTopic.wiki", new DateTime(2004, 11, 05), new DateTime(2007, 10, 22), @"", MockTopicStorePermissions.ReadOnly, true), new MockFile(@"HomePage.wiki", new DateTime(2004, 10, 30), @"Home page."), new MockFile(@"HomePage(2003-11-24-20-31-20-WINGROUP-davidorn).awiki", new DateTime(2004, 10, 31), @"Old home page."), new MockFile(@"CodeImprovementIdeas.wiki", new DateTime(2004, 11, 10), @"Latest"), new MockFile(@"CodeImprovementIdeas(2003-11-23-14-34-03-127.0.0.1).awiki", new DateTime(2004, 11, 09), @"Latest"), new MockFile(@"CodeImprovementIdeas(2003-11-23-14-34-04.8890-127.0.0.1).awiki", new DateTime(2004, 11, 08), @"Older"), new MockFile(@"CodeImprovementIdeas(2003-11-23-14-34-05.1000-127.0.0.1).awiki", new DateTime(2004, 11, 07), @"Still older"), new MockFile(@"CodeImprovementIdeas(2003-11-23-14-34-06.1-127.0.0.1).awiki", new DateTime(2004, 11, 06), @"Even older"), new MockFile(@"CodeImprovementIdeas(2003-11-23-14-34-07-Name).awiki", new DateTime(2004, 11, 05), @"Really old"), new MockFile(@"CodeImprovementIdeas(2003-11-23-14-34-08.123-Name).awiki", new DateTime(2004, 11, 04), @"Oldest"), new MockFile(@"TestDeleteHistory.wiki", new DateTime(2004, 11, 10), @"Latest"), new MockFile(@"TestDeleteHistory(2003-11-23-14-34-03-127.0.0.1).awiki", new DateTime(2004, 11, 09), @"Latest"), new MockFile(@"TestDeleteHistory(2003-11-23-14-34-04.8890-127.0.0.1).awiki", new DateTime(2004, 11, 08), @"Older"), new MockFile(@"TestDeleteHistory(2003-11-23-14-34-05.1000-127.0.0.1).awiki", new DateTime(2004, 11, 07), @"Still older"), new MockFile(@"TestDeleteHistory(2003-11-23-14-34-06.1-127.0.0.1).awiki", new DateTime(2004, 11, 06), @"Even older"), new MockFile(@"TestDeleteHistory(2003-11-23-14-34-07-Name).awiki", new DateTime(2004, 11, 05), @"Really old"), new MockFile(@"TestDeleteHistory(2003-11-23-14-34-08.123-Name).awiki", new DateTime(2004, 11, 04), @"Oldest"), new MockFile(@"ReadOnlyTopic.wiki", new DateTime(2004, 11, 05), @"", MockTopicStorePermissions.ReadOnly), new MockFile(@"ReadOnlyTopic(2004-11-05-00-00-00-Name).awiki", new DateTime(2004, 11, 05), @""), new MockFile(@"ReadOnlyTopic2.wiki", new DateTime(2004, 11, 05), new DateTime(2007, 10, 22), @"", MockTopicStorePermissions.ReadOnly, true), new MockFile(@"ReadWriteTopic.wiki", new DateTime(2004, 11, 05), new DateTime(2007, 10, 22), @"", MockTopicStorePermissions.ReadWrite, false), new MockFile(@"DeletedTopic(2004-11-11-00-00-00-Name).awiki", new DateTime(2004, 11, 11), @"This topic was deleted.") ) ) ) ) ); federation.RegisterNamespace(new FileSystemStore(_fileSystem), "NamespaceOne", new NamespaceProviderParameterCollection( new NamespaceProviderParameter("Root", Root))); // Necessary to bypass security because a non-existent manager can't be // retrieved directly from the federation manager = WikiTestUtilities.GetNamespaceManagerBypassingSecurity(federation, "NamespaceOne"); _provider = (FileSystemStore)manager.GetProvider(typeof(FileSystemStore)); IMockWikiApplication setApp = (IMockWikiApplication)Federation.Application; setApp.SetApplicationProperty("DisableNewParser", false); setApp.SetApplicationProperty("EnableNewParser", true); parser = new ParserEngine(federation); //Necessary to init WikiInputDocument for all WomDocument tests //inputDoc = parser.InitWikiDocument(Path.Combine(mockapp.WebPath, @"InputDocs/AstralisLux.wiki")); }
public override void ConfigureServices(IServiceCollection services) { services.AddSingleton <IMediaFileStore>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >(); var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var mediaPath = GetMediaPath(shellOptions.Value, shellSettings); var fileStore = new FileSystemStore(mediaPath); var mediaUrlBase = "/" + fileStore.Combine(shellSettings.RequestUrlPrefix, AssetsUrlPrefix); return(new MediaFileStore(fileStore, mediaUrlBase)); }); services.AddScoped <IPermissionProvider, Permissions>(); services.AddScoped <INavigationProvider, AdminMenu>(); services.AddSingleton <ContentPart, ImageMediaPart>(); services.AddMedia(); services.AddLiquidFilter <MediaUrlFilter>("asset_url"); services.AddLiquidFilter <ResizeUrlFilter>("resize_url"); services.AddLiquidFilter <ImageTagFilter>("img_tag"); // ImageSharp services.AddImageSharpCore( options => { options.Configuration = Configuration.Default; options.MaxBrowserCacheDays = 7; options.MaxCacheDays = 365; options.CachedNameLength = 12; options.OnValidate = validation => { // Force some parameters to prevent disk filling. // For more advanced resize parameters the usage of profiles will be necessary. // This can be done with a custom IImageWebProcessor implementation that would // accept profile names. validation.Commands.Remove(ResizeWebProcessor.Compand); validation.Commands.Remove(ResizeWebProcessor.Sampler); validation.Commands.Remove(ResizeWebProcessor.Xy); validation.Commands.Remove(ResizeWebProcessor.Anchor); validation.Commands.Remove(BackgroundColorWebProcessor.Color); if (validation.Commands.Count > 0) { if (!validation.Commands.ContainsKey(ResizeWebProcessor.Mode)) { validation.Commands[ResizeWebProcessor.Mode] = "max"; } if (validation.Commands.TryGetValue(ResizeWebProcessor.Width, out var width)) { if (Int32.TryParse(width, out var parsedWidth)) { if (Array.BinarySearch <int>(Sizes, parsedWidth) == -1) { validation.Commands.Clear(); } } else { validation.Commands.Remove(ResizeWebProcessor.Width); } } if (validation.Commands.TryGetValue(ResizeWebProcessor.Height, out var height)) { if (Int32.TryParse(height, out var parsedHeight)) { if (Array.BinarySearch <int>(Sizes, parsedHeight) == -1) { validation.Commands.Clear(); } } else { validation.Commands.Remove(ResizeWebProcessor.Height); } } } }; options.OnProcessed = _ => { }; options.OnPrepareResponse = _ => { }; }) .SetRequestParser <QueryCollectionRequestParser>() .SetBufferManager <PooledBufferManager>() .SetCacheHash <CacheHash>() .SetAsyncKeyLock <AsyncKeyLock>() .SetCache <PhysicalFileSystemCache>() .AddResolver <MediaFileSystemResolver>() .AddProcessor <ResizeWebProcessor>(); // Media Field services.AddSingleton <ContentField, MediaField>(); services.AddScoped <IContentFieldDisplayDriver, MediaFieldDisplayDriver>(); services.AddScoped <IContentPartFieldDefinitionDisplayDriver, MediaFieldSettingsDriver>(); services.AddRecipeExecutionStep <MediaStep>(); // MIME types services.TryAddSingleton <IContentTypeProvider, FileExtensionContentTypeProvider>(); services.AddTagHelpers <ImageTagHelper>(); services.AddTagHelpers <ImageResizeTagHelper>(); }
public Result <PluginInfo> FindPlugin(FileSystemStore directory, Type interfaceType) { if (directory == null) { throw new ArgumentNullException(nameof(directory)); } if (interfaceType == null) { throw new ArgumentNullException(nameof(interfaceType)); } var files = directory.Keys.Where(x => x.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)).ToArray(); var loadedTypes = new List <Type>(); var loadingProblems = new List <string>(); PluginInfo info = null; foreach (var file in files) { try { var fullName = directory.Identifier.Concat(new StringKey(file)).ToString(); var assembly = LoadAssembly(fullName); var implementation = GetPluginImplementationType(assembly, interfaceType); if (implementation != null) { var instance = (IPlugin)Activator.CreateInstance(implementation, new NullHostContext()); info = new PluginInfo { AssemblyLocation = fullName, DisplayName = instance.DisplayName, TypeName = instance.GetType().Name, TypeFullName = instance.GetType().FullName, Id = instance.Id, Version = instance.Version }; break; } } catch (ReflectionTypeLoadException rtle) { loadedTypes.AddRange(rtle.Types.Where(x => x != null)); loadingProblems.AddRange(rtle.LoaderExceptions.Select(x => $"Error loading \"{file}\": {x.Message}")); } catch (Exception exception) { loadingProblems.Add($"Loading {file}: {exception.Message}"); } } if (info == null) { if (!files.Any()) { return(Result.CreateError <Result <PluginInfo> >("The specified directory doesn't contain any assemblies.")); } var diagnosticsStringBuilder = new StringBuilder(); var counter = 0; diagnosticsStringBuilder.AppendLine("The specified directory didn't contain any valid plugin assembly or the plugin assembly failed to load."); diagnosticsStringBuilder.AppendLine("Processed assemblies:"); foreach (var file in files) { diagnosticsStringBuilder.AppendLine($" {++counter}: {Path.GetFileName(file)}"); } counter = 0; diagnosticsStringBuilder.AppendLine("Discovered types:"); foreach (var type in loadedTypes) { diagnosticsStringBuilder.AppendLine($" {++counter}: {type.FullName}"); } counter = 0; diagnosticsStringBuilder.AppendLine("Registered loading exceptions:"); foreach (var exception in loadingProblems) { diagnosticsStringBuilder.AppendLine($" {++counter}: {exception}"); } return(Result.CreateError <Result <PluginInfo> >(diagnosticsStringBuilder.ToString())); } return(new Result <PluginInfo> { Data = info }); }
public override void ConfigureServices(IServiceCollection services) { services.AddSingleton <IMediaFileProvider>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >(); var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var mediaPath = GetMediaPath(shellOptions.Value, shellSettings); if (!Directory.Exists(mediaPath)) { Directory.CreateDirectory(mediaPath); } return(new MediaFileProvider(AssetsRequestPath, mediaPath)); }); services.AddSingleton <IStaticFileProvider>(serviceProvider => { return(serviceProvider.GetRequiredService <IMediaFileProvider>()); }); services.AddSingleton <IMediaFileStore>(serviceProvider => { var shellOptions = serviceProvider.GetRequiredService <IOptions <ShellOptions> >(); var shellSettings = serviceProvider.GetRequiredService <ShellSettings>(); var mediaPath = GetMediaPath(shellOptions.Value, shellSettings); var fileStore = new FileSystemStore(mediaPath); var mediaUrlBase = "/" + fileStore.Combine(shellSettings.RequestUrlPrefix, AssetsRequestPath); var originalPathBase = serviceProvider.GetRequiredService <IHttpContextAccessor>() .HttpContext?.Features.Get <ShellContextFeature>()?.OriginalPathBase ?? null; if (originalPathBase.HasValue) { mediaUrlBase = fileStore.Combine(originalPathBase, mediaUrlBase); } return(new MediaFileStore(fileStore, mediaUrlBase)); }); services.AddScoped <IPermissionProvider, Permissions>(); services.AddScoped <IAuthorizationHandler, AttachedMediaFieldsFolderAuthorizationHandler>(); services.AddScoped <INavigationProvider, AdminMenu>(); services.AddSingleton <ContentPart, ImageMediaPart>(); services.AddMedia(); services.AddLiquidFilter <MediaUrlFilter>("asset_url"); services.AddLiquidFilter <ResizeUrlFilter>("resize_url"); services.AddLiquidFilter <ImageTagFilter>("img_tag"); // ImageSharp services.AddImageSharpCore(options => { options.Configuration = Configuration.Default; options.MaxBrowserCacheDays = _maxBrowserCacheDays; options.MaxCacheDays = _maxCacheDays; options.CachedNameLength = 12; options.OnParseCommands = validation => { // Force some parameters to prevent disk filling. // For more advanced resize parameters the usage of profiles will be necessary. // This can be done with a custom IImageWebProcessor implementation that would // accept profile names. validation.Commands.Remove(ResizeWebProcessor.Compand); validation.Commands.Remove(ResizeWebProcessor.Sampler); validation.Commands.Remove(ResizeWebProcessor.Xy); validation.Commands.Remove(ResizeWebProcessor.Anchor); validation.Commands.Remove(BackgroundColorWebProcessor.Color); if (validation.Commands.Count > 0) { if (!validation.Commands.ContainsKey(ResizeWebProcessor.Mode)) { validation.Commands[ResizeWebProcessor.Mode] = "max"; } } }; options.OnProcessed = _ => { }; options.OnPrepareResponse = _ => { }; }) .SetRequestParser <QueryCollectionRequestParser>() .SetMemoryAllocator <ArrayPoolMemoryAllocator>() .SetCache <PhysicalFileSystemCache>() .SetCacheHash <CacheHash>() .AddProvider <MediaResizingFileProvider>() .AddProcessor <ResizeWebProcessor>() .AddProcessor <FormatWebProcessor>() .AddProcessor <ImageVersionProcessor>() .AddProcessor <BackgroundColorWebProcessor>(); // Media Field services.AddSingleton <ContentField, MediaField>(); services.AddScoped <IContentFieldDisplayDriver, MediaFieldDisplayDriver>(); services.AddScoped <IContentPartFieldDefinitionDisplayDriver, MediaFieldSettingsDriver>(); services.AddScoped <AttachedMediaFieldFileService, AttachedMediaFieldFileService>(); services.AddScoped <IContentHandler, AttachedMediaFieldContentHandler>(); services.AddScoped <IModularTenantEvents, TempDirCleanerService>(); services.AddRecipeExecutionStep <MediaStep>(); // MIME types services.TryAddSingleton <IContentTypeProvider, FileExtensionContentTypeProvider>(); services.AddTagHelpers <ImageTagHelper>(); services.AddTagHelpers <ImageResizeTagHelper>(); }