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

            streamWriter.Write(expected);
            streamWriter.Flush();
            ms.Position = 0;
            var newFileName = await shardedClient.UploadAsync("abc.txt", ms);

            var ms2 = await shardedClient.DownloadAsync(newFileName);

            var actual = new StreamReader(ms2).ReadToEnd();

            Assert.Equal(expected, actual);
        }
        private void SaveFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();

                saveFileDialog.ShowDialog();

                string locazioneFile = String.Empty;

                if (lstFiles.SelectedItem != null)
                {
                    locazioneFile = ((SearchResult)(lstFiles.SelectedItem)).Indirizzo;
                }
                if (filesList.SelectedItem != null)
                {
                    locazioneFile = ((FileHeader)(filesList.SelectedItem)).FullPath;
                }

                Stream file = null;

                var command = new AsyncShardedFilesServerClient(FileStore.ShardStrategy);

                file = command.DownloadAsync(locazioneFile).Result;


                if (String.IsNullOrEmpty(saveFileDialog.FileName) == false)
                {
                    string fileName = saveFileDialog.FileName;

                    using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                    {
                        file.CopyTo(stream);
                        stream.Close();
                        file.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }