[研究] CKSource.CKFinder.Connector.Sample 3.3.0-rc5 試用 (NuGet)
2020-09-15
CKSource.CKFinder 目前最新到 3.5.1.1,CKSource.CKFinder.Connector.Sample 最新只到 3.3.0-rc5。
參考
CKSource.CKFinder.Connector.Sample 3.3.0-rc5
https://packages.nuget.org/packages/CKSource.CKFinder.Connector.Sample/3.3.0-rc5
使用下面指令安裝
Install-Package CKSource.CKFinder.Connector.Sample -Version 3.3.0-rc5
CKSource.CKFinder.Connector.Core.Exceptions.InvalidConfigException: 'Configuration error: 'type' 屬性未宣告。'
CKSource.CKFinder.Connector.Core.Exceptions.InvalidConfigException
HResult=0x80131500
Message=Configuration error: 'type' 屬性未宣告。
Source=<無法評估例外狀況來源>
StackTrace:
<無法評估例外狀況堆疊追蹤>
內部例外狀況 1:
XmlSchemaValidationException: 'type' 屬性未宣告。
********************************************************************************
參考這裡
https://ckeditor.com/docs/ckfinder/ckfinder3-net/configuration_by_code.html
修改 Startup.cs 檔案內容如下:
[assembly: Microsoft.Owin.OwinStartup(typeof(WebApplication2.Startup))] namespace WebApplication2 { using System.Configuration; using CKSource.CKFinder.Connector.Config; using CKSource.CKFinder.Connector.Core.Builders; using CKSource.CKFinder.Connector.Core.Logs; using CKSource.CKFinder.Connector.Host.Owin; using CKSource.CKFinder.Connector.Logs.NLog; using CKSource.CKFinder.Connector.KeyValue.EntityFramework; using CKSource.FileSystem.Dropbox; using CKSource.FileSystem.Local; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Cookies; using Owin; using CKSource.CKFinder.Connector.Core.Acl; using CKSource.CKFinder.Connector.Core; using System.Collections.Generic; using CKSource.CKFinder.Connector.Core.Authentication; using System.Threading.Tasks; using System.Threading; public class Startup { //public void Configuration(IAppBuilder builder) //{ // LoggerManager.LoggerAdapterFactory = new NLogLoggerAdapterFactory(); // RegisterFileSystems(); // builder.UseCookieAuthentication(new CookieAuthenticationOptions // { // AuthenticationType = "ApplicationCookie", // AuthenticationMode = AuthenticationMode.Active // }); // var route = ConfigurationManager.AppSettings["ckfinderRoute"]; // builder.Map(route, SetupConnector); //} //private static void RegisterFileSystems() //{ // FileSystemFactory.RegisterFileSystem<LocalStorage>(); // FileSystemFactory.RegisterFileSystem<DropboxStorage>(); //} //private static void SetupConnector(IAppBuilder builder) //{ // var keyValueStoreProvider = new EntityFrameworkKeyValueStoreProvider("CacheConnectionString"); // var allowedRoleMatcherTemplate = ConfigurationManager.AppSettings["ckfinderAllowedRole"]; // var authenticator = new RoleBasedAuthenticator(allowedRoleMatcherTemplate); // var connectorFactory = new OwinConnectorFactory(); // var connectorBuilder = new ConnectorBuilder(); // var connector = connectorBuilder // .LoadConfig() // .SetAuthenticator(authenticator) // .SetRequestConfiguration( // (request, config) => // { // config.LoadConfig(); // config.SetKeyValueStoreProvider(keyValueStoreProvider); // }) // .Build(connectorFactory); // builder.UseConnector(connector); //} public ConnectorBuilder ConfigureConnector() { var connectorBuilder = new ConnectorBuilder(); connectorBuilder .SetRequestConfiguration( (request, config) => { config.AddProxyBackend("local", new LocalStorage(@"MyFiles")); config.AddResourceType("Files", resourceBuilder => resourceBuilder.SetBackend("local", "files")); config.AddAclRule(new AclRule( new StringMatcher("*"), new StringMatcher("/"), new StringMatcher("*"), new Dictionary<Permission, PermissionType> { { Permission.FolderView, PermissionType.Allow }, { Permission.FolderCreate, PermissionType.Allow }, { Permission.FolderRename, PermissionType.Allow }, { Permission.FolderDelete, PermissionType.Allow }, { Permission.FileView, PermissionType.Allow }, { Permission.FileCreate, PermissionType.Allow }, { Permission.FileRename, PermissionType.Allow }, { Permission.FileDelete, PermissionType.Allow }, { Permission.ImageResize, PermissionType.Allow }, { Permission.ImageResizeCustom, PermissionType.Allow } })); }) .SetAuthenticator(new MyAuthenticator()); return connectorBuilder; } public class MyAuthenticator : IAuthenticator { public Task<IUser> AuthenticateAsync(ICommandRequest commandRequest, CancellationToken cancellationToken) { var user = new User(true, null); return Task.FromResult((IUser)user); } } public void Configuration(IAppBuilder appBuilder) { var connectorBuilder = ConfigureConnector(); var connector = connectorBuilder.Build(new OwinConnectorFactory()); appBuilder.Map("/CKFinder/connector", builder => builder.UseConnector(connector)); } } } |
執行結果如下
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="Autofac" version="5.2.0" targetFramework="net472" /> <package id="CKSource.CKFinder" version="3.5.1.1" targetFramework="net472" /> <package id="CKSource.CKFinder.Connector.Config" version="3.5.1.1" targetFramework="net472" /> <package id="CKSource.CKFinder.Connector.Core" version="3.5.1.1" targetFramework="net472" /> <package id="CKSource.CKFinder.Connector.Host.Owin" version="3.5.1.1" targetFramework="net472" /> <package id="CKSource.CKFinder.Connector.KeyValue.EntityFramework" version="3.5.1.1" targetFramework="net472" /> <package id="CKSource.CKFinder.Connector.Logs.NLog" version="3.5.1.1" targetFramework="net472" /> <package id="CKSource.CKFinder.Connector.Sample" version="3.3.0-rc5" targetFramework="net472" developmentDependency="true" /> <package id="CKSource.FileSystem" version="1.1.2" targetFramework="net472" /> <package id="CKSource.FileSystem.Dropbox" version="1.1.2" targetFramework="net472" /> <package id="CKSource.FileSystem.Local" version="1.1.2" targetFramework="net472" /> <package id="Dropbox.Api" version="3.1.1" targetFramework="net472" /> <package id="EntityFramework" version="6.1.3" targetFramework="net472" /> <package id="EntityFramework.SqlServerCompact" version="6.1.3" targetFramework="net472" /> <package id="ImageProcessor" version="2.8.0" targetFramework="net472" /> <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net472" /> <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net472" /> <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net472" /> <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net472" /> <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" /> <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net472" /> <package id="Microsoft.Owin" version="3.0.1" targetFramework="net472" /> <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net472" /> <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net472" /> <package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net472" /> <package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net472" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net472" /> <package id="NLog" version="4.3.2" targetFramework="net472" /> <package id="Owin" version="1.0" targetFramework="net472" /> <package id="Pri.LongPath" version="2.0.40" targetFramework="net472" /> <package id="RestSharp" version="105.2.3" targetFramework="net472" /> <package id="System.Net.Http" version="4.0.0" targetFramework="net472" /> <package id="System.Net.Http.Formatting.Extension" version="5.2.3.0" targetFramework="net472" /> <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" /> <package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net472" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net472" /> </packages> |
沒有留言:
張貼留言