public async Task WhenStartedThenSubscribesForConsumers() { using var broker = new MiniMqttServer(PORT); var consumers = new[] { new ConsumerStub() { Subscriptions = new[] { "foo", "boo" } }, new ConsumerStub() { Subscriptions = new[] { "moo", "shoo" } } }; using var sut = new ConnectorBuilder() .WithConsumers(consumers) .Build(); await sut.ConnectAsync(HOST, PORT); var expected = consumers.SelectMany(c => c.Subscriptions).OrderBy(s => s); Assert.Equal(expected, broker.Subscriptions.OrderBy(s => s)); broker.Dispose(); }
private static void SetupConnector(IAppBuilder app) { /* * Create connector instance using ConnectorBuilder. The call to LoadConfig() method * will configure the connector using CKFinder configuration options defined in Web.config. */ var connectorFactory = new OwinConnectorFactory(); var connectorBuilder = new ConnectorBuilder(); var customAuthenticator = new CustomCKFinderAuthenticator(); var connector = connectorBuilder .LoadConfig() .SetRequestConfiguration( (request, config) => { config.LoadConfig(); var privateBackend = config.GetBackend("CKFinderPrivate"); /* * Create a key-value store provider to be used for saving CKFinder cache data. */ var keyValueStoreProvider = new FileSystemKeyValueStoreProvider(privateBackend); config.SetKeyValueStoreProvider(keyValueStoreProvider); }) .SetAuthenticator(customAuthenticator) .Build(connectorFactory); /* * Add the CKFinder connector middleware to web application pipeline. */ app.UseConnector(connector); }
public async Task WhenMessageHandledThenForwardingLoopBreaks() { using var broker = new MiniMqttServer(); var milestone = new SemaphoreSlim(0, 2); var callCounter = 0; var consumers = new[] { new ConsumerStub { ShouldHandle = true, Handler = _ => milestone.Release() }, new ConsumerStub { ShouldHandle = true, Handler = _ => Interlocked.Increment(ref callCounter) } }; using var sut = new ConnectorBuilder() .WithConsumers(consumers) .Build(); await sut.ConnectAsync(HOST, broker.Port); await broker.PublishAsync("boo", Encoding.ASCII.GetBytes("hoo")); Assert.True(await milestone.WaitAsync(TimeSpan.FromSeconds(5))); // publish again, so if the first message was going to sent to the second subscriber // it would not be missed await broker.PublishAsync("boo", Encoding.ASCII.GetBytes("hoo")); Assert.True(await milestone.WaitAsync(TimeSpan.FromSeconds(5))); Assert.Equal(2, consumers[0].PacketsToHandle.Count()); Assert.Equal(0, Volatile.Read(ref callCounter)); }
public ConnectorBuilder ConfigureConnector() { var connectorBuilder = new ConnectorBuilder(); connectorBuilder .SetRequestConfiguration( (request, config) => { config.AddProxyBackend("local", new LocalStorage(@"~/Upload/Ckfinder")); config.AddResourceType("Files", resourceBuilder => resourceBuilder.SetBackend("local", "files")); config.AddResourceType("Images", resourceBuilder => resourceBuilder.SetBackend("local", "images")); 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 CkIdentityModels()); return(connectorBuilder); }
public async Task WhenMessageReceivedThenForwardsToConsumers() { using var broker = new MiniMqttServer(); var milestone = new SemaphoreSlim(0, 2); var consumers = new[] { new ConsumerStub { ShouldHandle = false, Handler = _ => milestone.Release() }, new ConsumerStub { ShouldHandle = false, Handler = _ => milestone.Release() } }; using var sut = new ConnectorBuilder() .WithConsumers(consumers) .Build(); await sut.ConnectAsync(HOST, broker.Port); await broker.PublishAsync("boo", Encoding.ASCII.GetBytes("hoo")); Assert.True(await milestone.WaitAsync(TimeSpan.FromSeconds(5))); Assert.True(await milestone.WaitAsync(TimeSpan.FromSeconds(5))); Assert.All(consumers, c => Assert.Single(c.PacketsToHandle)); Assert.All(consumers, c => Assert.Equal("boo", c.PacketsToHandle.First().Topic)); Assert.All(consumers, c => Assert.Equal("hoo", Encoding.ASCII.GetString(c.PacketsToHandle.First().Payload))); }
public void WhenStartedThenHooksUpToProducers() { var producers = new[] { new ProducerStub(), new ProducerStub() }; var sut = new ConnectorBuilder() .WithProducers(producers) .Build(); Assert.All(producers, p => Assert.Equal(sut, p.Connector)); }
public async Task WhenStartedThenConnectsToServer() { using var broker = new MiniMqttServer(); using var sut = new ConnectorBuilder().Build(); await sut.ConnectAsync(HOST, broker.Port); Assert.Equal(1, broker.ConnectionCounter); }
public static IDependencyContainer Register(PublishConfiguration configuration) { var builder = DependencyBuilderFactory.Create(DependencyLibrary.Microsoft); builder.RegisterInstance(ConnectorBuilder.Build(configuration)); builder.RegisterInstance <ILoggingService>(new ConsoleLoggingService()); builder.Register <IScriptBuilder, ScriptBuilder>(); builder.Register <IScriptRunner, ScriptRunner>(); return(builder.Build()); }
private static void SetupConnector(IAppBuilder app) { /* * Create a connector instance using ConnectorBuilder. The call to the LoadConfig() method * will configure the connector using CKFinder configuration options defined in Web.config. */ var connectorFactory = new OwinConnectorFactory(); var connectorBuilder = new ConnectorBuilder(); /* * Create an instance of authenticator implemented in the previous step. */ var customAuthenticator = new CustomCKFinderAuthenticator(); connectorBuilder /* * Provide the global configuration. * * If you installed CKSource.CKFinder.Connector.Config you should load the static configuration * from XML: * connectorBuilder.LoadConfig(); */ .LoadConfig() .SetAuthenticator(customAuthenticator) .SetRequestConfiguration( (request, config) => { // TODO: Do we need EntityFrameworkKeyValueStoreProvider? /* * * If you installed CKSource.CKFinder.Connector.KeyValue.EntityFramework, you may enable caching: * config.SetKeyValueStoreProvider( * new EntityFrameworkKeyValueStoreProvider("CKFinderCacheConnection")); */ config.LoadConfig(); } ); /* * Build the connector middleware. */ var connector = connectorBuilder .Build(connectorFactory); /* * Add the CKFinder connector middleware to the web application pipeline. */ //app.Use(typeof(MyMiddleWare)); app.UseConnector(connector); }
public async Task WhenStartedTwiceThenSecondFails() { using var broker = new MiniMqttServer(); using var sut = new ConnectorBuilder().Build(); await sut.ConnectAsync(HOST, broker.Port); Assert.Equal(1, broker.ConnectionCounter); await Assert.ThrowsAsync <InvalidOperationException>(() => sut.ConnectAsync(HOST, broker.Port)); Assert.Equal(1, broker.ConnectionCounter); }
private static void SetupConnector(IAppBuilder app) { var connectorFactory = new OwinConnectorFactory(); var connectorBuilder = new ConnectorBuilder(); var customAuthenticator = new CKFinderAuthenticator(); connectorBuilder .LoadConfig() .SetAuthenticator(customAuthenticator) .SetRequestConfiguration((request, config) => { config.LoadConfig(); }); var connector = connectorBuilder.Build(connectorFactory); app.UseConnector(connector); }
private static void SetupConnector(IAppBuilder builder) { var keyValueStoreProvider = new EntityFrameworkKeyValueStoreProvider("CacheConnectionString"); var authenticator = new ShaggysAuthenticator(); 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); }
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); }
private static void SetupConnector(IAppBuilder builder) { 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(); var defaultBackend = config.GetBackend("default"); var keyValueStoreProvider = new FileSystemKeyValueStoreProvider(defaultBackend); config.SetKeyValueStoreProvider(keyValueStoreProvider); }) .Build(connectorFactory); builder.UseConnector(connector); }
private static void SetupConnector(IAppBuilder app) { /* * Create a connector instance using ConnectorBuilder. The call to the LoadConfig() method * will configure the connector using CKFinder configuration options defined in Web.config. */ var connectorFactory = new OwinConnectorFactory(); var connectorBuilder = new ConnectorBuilder(); /* * Create an instance of authenticator implemented in the previous step. */ var customAuthenticator = new CustomCKFinderAuthenticator(); connectorBuilder /* * Provide the global configuration. * * If you installed CKSource.CKFinder.Connector.Config you may load static configuration * from XML: * connectorBuilder.LoadConfig(); */ .LoadConfig() .SetAuthenticator(customAuthenticator) .SetRequestConfiguration( (request, config) => { /* Add a local backend. */ //config.AddProxyBackend("local", new LocalStorage(@"public/upload")); config.AddBackend("local", new LocalStorage(@"public/upload", "http://www.stampecreative.it/public/upload/")); /* Add a resource type that uses the local backend. */ config.AddResourceType("Files", resourceBuilder => resourceBuilder.SetBackend("local", "files")); config.AddResourceType("Images", resourceBuilder => resourceBuilder.SetBackend("local", "images")); /* Give full access to all resource types at any path for all users. */ 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 } })); }); /* * Configure settings per request. * * The minimal configuration has to include at least one backend, one resource type * and one ACL rule. * * For example: * config.AddBackend("default", new LocalStorage(@"C:\files")); * config.AddResourceType("images", builder => builder.SetBackend("default", "images")); * config.AddAclRule(new AclRule( * new StringMatcher("*"), * new StringMatcher("*"), * new StringMatcher("*"), * new Dictionary<Permission, PermissionType> { { Permission.All, PermissionType.Allow } })); * * If you installed CKSource.CKFinder.Connector.Config, you may load the static configuration * from XML: * config.LoadConfig(); * * If you installed CKSource.CKFinder.Connector.KeyValue.EntityFramework, you may enable caching: * config.SetKeyValueStoreProvider( * new EntityFrameworkKeyValueStoreProvider("CKFinderCacheConnection")); */ /* * Build the connector middleware. */ var connector = connectorBuilder .Build(connectorFactory); /* * Add the CKFinder connector middleware to the web application pipeline. */ app.UseConnector(connector); }
private static OwinConnector ConfigureConnector(string rootPath, string key, string value, string host) { var connectorBuilder = new ConnectorBuilder(); connectorBuilder.SetRequestConfiguration((request, config) => { config.AddBackend("CKFinderPrivate", new LocalStorage(rootPath + "/uploads"), null, true); config.AddBackend("default", new LocalStorage(rootPath + "/uploads", host + "/uploads"), null, false); config.SetCheckDoubleExtension(true); config.SetThumbnailBackend("CKFinderPrivate", "thumbs"); 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 } })); //public SizeAndQuality(int width, int height, ImageQuality quality); ImageQuality(int qualityValue); var thumbSize = new SizeAndQuality[] { new SizeAndQuality(120, 120, new ImageQuality(80)), new SizeAndQuality(250, 250, new ImageQuality(80)), new SizeAndQuality(300, 300, new ImageQuality(80)), new SizeAndQuality(500, 500, new ImageQuality(80)), }; config.SetThumbnailSizes(thumbSize); config.SetMaxImageSize(new Size(1600, 1600)); config.SetImageResizeThreshold(10, 80); config.SetCheckSizeAfterScaling(true); var imagesize = new SizeDefinition[] { new SizeDefinition("small", 480, 320, new ImageQuality(80)), new SizeDefinition("medium", 600, 480, new ImageQuality(80)), new SizeDefinition("large", 800, 600, new ImageQuality(80)), }; config.SetSizeDefinitions(imagesize); config.SetSecureImageUploads(true); config.SetDisallowUnsafeCharacters(false); //config.AddProxyBackend("local", new LocalStorage(@"MyFiles")); config.AddResourceType("Files", resourceBuilder => resourceBuilder.SetBackend("default", "files") .SetHideFoldersMatchers(new StringMatcher[] { new StringMatcher("_thumbs"), new StringMatcher("__thumbs"), new StringMatcher("CVS"), new StringMatcher(".*") }) ); config.AddResourceType("Documents", resourceBuilder => resourceBuilder.SetBackend("default", "documents") .SetAllowedExtensions("7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip".Split(',')) //.SetHideFilesMatchers(new StringMatcher[] { new StringMatcher(".*") }) .SetHideFoldersMatchers(new StringMatcher[] { new StringMatcher("_thumbs"), new StringMatcher("__thumbs"), new StringMatcher("CVS") })); config.AddResourceType("Images", resourceBuilder => resourceBuilder.SetBackend("default", "images") .SetAllowedExtensions("bmp,gif,jpeg,jpg,png".Split(',')) .SetHideFoldersMatchers(new StringMatcher[] { new StringMatcher("_thumbs"), new StringMatcher("__thumbs") }) ); }); connectorBuilder.SetAuthenticator(new AuthenticatorCustomer("*")).SetLicense(key, value); var connect = connectorBuilder.Build(new OwinConnectorFactory()); // connectorBuilder.licenseProvider.SetLicense("engcoo.vn", "W3N3FU2L7E11G871SYL1ARS4162D9"); return(connect); }
private static void SetupConnector(IAppBuilder app) { /* * Create a connector instance using ConnectorBuilder. The call to the LoadConfig() method * will configure the connector using CKFinder configuration options defined in Web.config. */ var connectorFactory = new OwinConnectorFactory(); var connectorBuilder = new ConnectorBuilder(); /* * Create an instance of authenticator implemented in the previous step. */ var customAuthenticator = new CKFinderAuthenticator(); connectorBuilder /* * Provide the global configuration. * * If you installed CKSource.CKFinder.Connector.Config you may load static configuration * from XML: * connectorBuilder.LoadConfig(); */ .SetAuthenticator(customAuthenticator) .SetRequestConfiguration( (request, config) => { var instanceId = request.QueryParameters["id"].FirstOrDefault() ?? string.Empty; //var baseUrl = GetBaseUrlByInstanceId(instanceId); //config.AddProxyBackend("default", new LocalStorage(root)); //config.AddProxyBackend("baseUrl", new LocalStorage(@"\ckfinder\userfiles\")); //config.AddResourceType("images", builder => builder.SetBackend("default", "images" )); config.LoadConfig(); /* * Configure settings per request. * * The minimal configuration has to include at least one backend, one resource type * and one ACL rule. * * For example: * config.AddBackend("default", new LocalStorage(@"C:\files")); * * config.AddAclRule(new AclRule( * new StringMatcher("*"), * new StringMatcher("*"), * new StringMatcher("*"), * new Dictionary<Permission, PermissionType> { { Permission.All, PermissionType.Allow } })); * * If you installed CKSource.CKFinder.Connector.Config, you may load the static configuration * from XML: * config.LoadConfig(); * * If you installed CKSource.CKFinder.Connector.KeyValue.EntityFramework, you may enable caching: * config.SetKeyValueStoreProvider( * new EntityFrameworkKeyValueStoreProvider("CKFinderCacheConnection")); */ } ); /* * Build the connector middleware. */ var connector = connectorBuilder .Build(connectorFactory); /* * Add the CKFinder connector middleware to the web application pipeline. */ app.UseConnector(connector); }
private static void SetupConnector(IAppBuilder app) { /* * Create a connector instance using ConnectorBuilder. The call to the LoadConfig() method * will configure the connector using CKFinder configuration options defined in Web.config. */ var connectorFactory = new OwinConnectorFactory(); var connectorBuilder = new ConnectorBuilder(); /* * Create an instance of authenticator implemented in the previous step. */ var customAuthenticator = new MyAuthenticator(); connectorBuilder /* * Provide the global configuration. * * If you installed CKSource.CKFinder.Connector.Config, you should load the static configuration * from XML: * connectorBuilder.LoadConfig(); */ .SetAuthenticator(customAuthenticator) .LoadConfig() .SetRequestConfiguration( (request, config) => { /* * If you installed CKSource.CKFinder.Connector.Config, you might want to load the static * configuration from XML as a base configuration to modify: */ config.LoadConfig(); /* * Configure settings per request. * * The minimal configuration has to include at least one backend, one resource type * and one ACL rule. * * For example: */ config.AddBackend("default1", new LocalStorage(@"C:\files")); config.AddResourceType("images", builder => builder.SetBackend("default1", "images")); config.AddAclRule(new AclRule( new StringMatcher("*"), new StringMatcher("*"), new StringMatcher("*"), new Dictionary <Permission, PermissionType> { { Permission.All, PermissionType.Allow } })); /* * If you installed CKSource.CKFinder.Connector.KeyValue.FileSystem, you may enable caching: */ var defaultBackend = config.GetBackend("default1"); } ); /* * Build the connector middleware. */ var connector = connectorBuilder .Build(connectorFactory); /* * Add the CKFinder connector middleware to the web application pipeline. */ app.UseConnector(connector); }