Пример #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
		}
Пример #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
        }
Пример #3
0
        public async Task CanBrowseWithSharding()
        {
            var ms           = new MemoryStream();
            var streamWriter = new StreamWriter(ms);
            var expected     = new string('a', 1024);

            streamWriter.Write(expected);
            streamWriter.Flush();
            ms.Position = 0;

            await shardedClient.UploadAsync("a.txt", ms);

            ms.Position = 0;
            await shardedClient.UploadAsync("b.txt", ms);

            ms.Position = 0;
            await shardedClient.UploadAsync("c.txt", ms);

            ms.Position = 0;
            await shardedClient.UploadAsync("d.txt", ms);

            ms.Position = 0;
            await shardedClient.UploadAsync("e.txt", ms);

            var pagingInfo = new ShardPagingInfo(shardedClient.NumberOfShards);
            var result     = await shardedClient.BrowseAsync(2, pagingInfo);

            Assert.Equal(2, result.Length);

            pagingInfo.CurrentPage++;
            result = await shardedClient.BrowseAsync(2, pagingInfo);

            Assert.Equal(2, result.Length);

            pagingInfo.CurrentPage++;
            result = await shardedClient.BrowseAsync(2, pagingInfo);

            Assert.Equal(1, result.Length);

            pagingInfo.CurrentPage++;
            result = await shardedClient.BrowseAsync(2, pagingInfo);

            Assert.Equal(0, result.Length);
        }