Ejemplo n.º 1
0
		public async Task Foo()
		{
			#region sharding_1
			var shards = new Dictionary<string, IAsyncFilesCommands>
			{
				{"europe", new AsyncFilesServerClient("http://localhost:8080", "NorthwindFS")},
				{"asia", new AsyncFilesServerClient("http://localhost:8081", "NorthwindFS")},
			};

			var shardStrategy = new ShardStrategy(shards)
			{
				/*
				ShardAccessStrategy = ...
				ShardResolutionStrategy = ...
				ModifyFileName = ...
				*/
			};

			var shardedCommands = new AsyncShardedFilesServerClient(shardStrategy);
			#endregion

			#region file_operations
			string fileName = await shardedCommands.UploadAsync("test.bin", new RavenJObject()
			{
				{
					"Owner", "Admin"
				}
			}, new MemoryStream()); // will return either /europe/test.bin or /asia/test.bin name

			// you need to pass the returned file name here to let the client know on which shard the file exists
			using (var content = await shardedCommands.DownloadAsync(fileName)) 
			{
				
			}

			string renamed = await shardedCommands.RenameAsync(fileName, "new.bin");

			await shardedCommands.DeleteAsync(renamed);

			#endregion

			#region search_browse_operations
			FileHeader[] fileHeaders = await shardedCommands.BrowseAsync();

			SearchResults searchResults = await shardedCommands.SearchAsync("__fileName:test*");
			#endregion

			#region custom_shard_res_strategy_2
			var strategy = new ShardStrategy(shards);

			strategy.ShardResolutionStrategy = new RegionMetadataBasedResolutionStrategy(shards.Keys.ToList(), strategy.ModifyFileName, strategy.Conventions);

			var client = new AsyncShardedFilesServerClient(strategy);
			#endregion
		}
Ejemplo n.º 2
0
        public async Task Foo()
        {
            #region sharding_1
            var shards = new Dictionary <string, IAsyncFilesCommands>
            {
                { "europe", new AsyncFilesServerClient("http://localhost:8080", "NorthwindFS") },
                { "asia", new AsyncFilesServerClient("http://localhost:8081", "NorthwindFS") },
            };

            var shardStrategy = new ShardStrategy(shards)
            {
                /*
                 * ShardAccessStrategy = ...
                 * ShardResolutionStrategy = ...
                 * ModifyFileName = ...
                 */
            };

            var shardedCommands = new AsyncShardedFilesServerClient(shardStrategy);
            #endregion

            #region file_operations
            string fileName = await shardedCommands.UploadAsync("test.bin", new RavenJObject()
            {
                {
                    "Owner", "Admin"
                }
            }, new MemoryStream());             // will return either /europe/test.bin or /asia/test.bin name

            // you need to pass the returned file name here to let the client know on which shard the file exists
            using (var content = await shardedCommands.DownloadAsync(fileName))
            {
            }

            string renamed = await shardedCommands.RenameAsync(fileName, "new.bin");

            await shardedCommands.DeleteAsync(renamed);

            #endregion

            #region search_browse_operations
            FileHeader[] fileHeaders = await shardedCommands.BrowseAsync();

            SearchResults searchResults = await shardedCommands.SearchAsync("__fileName:test*");

            #endregion

            #region custom_shard_res_strategy_2
            var strategy = new ShardStrategy(shards);

            strategy.ShardResolutionStrategy = new RegionMetadataBasedResolutionStrategy(shards.Keys.ToList(), strategy.ModifyFileName, strategy.Conventions);

            var client = new AsyncShardedFilesServerClient(strategy);
            #endregion
        }
Ejemplo n.º 3
0
        public async Task CanSearchForFilesBySizeWithSharding()
        {
            var name1 = await shardedClient.UploadAsync("1", StreamOfLength(1));

            var name2 = await shardedClient.UploadAsync("2", StreamOfLength(2));

            var name3 = await shardedClient.UploadAsync("3", StreamOfLength(3));

            var name4 = await shardedClient.UploadAsync("4", StreamOfLength(4));

            var name5 = await shardedClient.UploadAsync("5", StreamOfLength(5));

            var result = await shardedClient.SearchAsync("__size_numeric:[Lx2 TO Lx4]");

            var files     = result.Files;
            var fileNames = files.Select(f => f.FullPath).ToArray();

            Assert.Equal(3, result.FileCount);
            Assert.Contains(name2, fileNames);
            Assert.Contains(name3, fileNames);
            Assert.Contains(name4, fileNames);
        }