Skip to content

ktairov/YellowDrawer

Repository files navigation

YellowDrawer.Storage.

Build status NuGet

What is YellowDrawer.Storage?

.Net library which implements providers for working with GridFS, Azure and Amazon Cloud Storages. Providers implement a general interface and have the same set of methods for working with Cloud Storages. Thus, we do the work with the Cloud Storage much easier avoiding confusion. In addition, using this providers it is easy to change the usage of one Cloud Storage for another without global project modifications. Also, in the YellowDrawer.Storage.Common library the provider for FileSystem data access is implemented.

Install

First, install NuGet. Then, install YellowDrawer Azure or YellowDrawer GridFS or YellowDrawer Amazon from the package manager console:

PM> YellowDrawer.Storage.Azure
PM> YellowDrawer.Storage.Amazon
PM> YellowDrawer.Storage.GridFS

The latest versions of the required frameworks are automatically installed

Initialize Azure StorageProvider

			var cloudStorageAccount = CloudStorageAccount.Parse(connectionStringAzure);
			azureProvider = new AzureBlobStorageProvider(cloudStorageAccount);

Initialize Amazon StorageProvider

			var awsAccessKey = "";
			var awsSecretKey = "";
			var awsBucketName = "";
			var amazonBaseUrl = "TestYellowDrawer";
			var amazonClient = new AmazonS3Client(awsAccessKey, awsSecretKey, Amazon.RegionEndpoint.USEast1);
			var amazonProvider = new AmazonStorageProvider(amazonClient, amazonBaseUrl, awsBucketName);

Initialize GridFS StorageProvider

			var mongoConnectionString = "mongodb://{ConnectionString}";
			var client = new MongoClient(mongoConnectionString);
			var server = client.GetDatabase(mongoDataBase);

Initialize FileSystem StorageProvider

			var fileSystemProvider = new FileSystemStorageProvider("C://");

Actions StorageProvider

			GetPublicUrl(string path);
			IStorageFile GetFile(string path);
			IEnumerable<IStorageFile> ListFiles(string path);
			IEnumerable<IStorageFolder> ListFolders(string path);
			void CreateFolder(string path);
			void DeleteFolder(string path);
			void RenameFolder(string path, string newPath);
			void DeleteFile(string path);
			void RenameFile(string path, string newPath);
			IStorageFile CreateFile(string path, byte[] arr = null);
			bool IsFileExists(string path);
			bool IsFolderExits(string path);
			bool TryCreateFolder(string path);