Exemple #1
0
		public SimpleSharding()
		{
			var client1 = NewAsyncClient(0, fileSystemName: "shard1");
			var client2 = NewAsyncClient(1, fileSystemName: "shard2");
            shardedClient = new AsyncShardedFilesServerClient(new ShardStrategy(new Dictionary<string, IAsyncFilesCommands>
				{
					{"1", client1},
					{"2", client2},
				}));
		}
        public async Task ShouldWork()
        {
            var client1 = NewAsyncClient(0, fileSystemName: "shard1");
            var client2 = NewAsyncClient(1, fileSystemName: "shard2");

            var shards = new Dictionary<string, IAsyncFilesCommands>
            {
                {"Europe", client1},
                {"Asia", client2},
            };

            var strategy = new ShardStrategy(shards);

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

            var client = new AsyncShardedFilesServerClient(strategy);

            var fileName = await client.UploadAsync("test1", new RavenJObject()
            {
                {
                    "Region", "Europe"
                }
            }, new MemoryStream());

            Assert.Equal("/Europe/test1", fileName);

            fileName = await client.UploadAsync("test2", new RavenJObject()
            {
                {
                    "region", "asia"
                }
            }, new MemoryStream());

            Assert.Equal("/Asia/test2", fileName);
        }
        public string UploadFile(string filePath, string country)
        {
            var command = new AsyncShardedFilesServerClient(FileStore.ShardStrategy);

            string fileName = String.Empty;

            try
            {
                using (FileStream fileStream = File.Open(filePath, FileMode.Open))
                {
                    string file = Path.GetFileName(filePath);

                    fileName = command.UploadAsync(file, new RavenJObject()
                    {
                        {
                            "Country", country
                        }
                    }, fileStream).Result;
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return fileName;
        }