public async Task TestAmazonCDN() { string strDesertPath = TestContent.GetContentFilePhysicalPath("/Images/Desert.jpg"); AmazonS3Client objAWSClient = new AmazonS3Client(Amazon.RegionEndpoint.USEast1); //Test 1: Delete a file if it exists, then store an image, check it's existance, get it's properties, and compare file versions IFileServer server1 = new FileServerAmazonS3("LocalFolder", "http://web.com", objAWSClient, AmazonS3Bucket); IFileQuery file1 = new FileQuery("Desert.jpg", "uploads/images"); if (server1.FileExistsInCDN(file1) || server1.FileExistsLocal(file1)) server1.Delete(file1); Assert.IsFalse(server1.FileExistsInCDN(file1)); Assert.IsFalse(server1.FileExistsLocal(file1)); file1.MetaData.Add("test", "Value"); server1.StoreImage(strDesertPath, file1); var props = server1.GetFilePropertiesFromCDN(file1); props.MetaData.Remove("nothing"); Assert.IsTrue(server1.FileExistsLocal(file1)); Assert.IsTrue(server1.FileExistsInCDN(file1)); var props1CDN = server1.GetFilePropertiesFromCDN(file1); var props1Local = server1.GetFilePropertiesLocal(file1); Assert.IsNotNull(props1CDN); Assert.IsNotNull(props1Local); Assert.IsTrue(props1Local.IsCurrentVersionOf(props1CDN)); //Run Test1 with async modifiers IFileServer server2 = new FileServerAmazonS3("LocalFolder2", "http://web.com", objAWSClient, AmazonS3Bucket); IFileQuery file21 = new FileQuery("Desert.jpg", "SiteImageFile"); if (server1.FileExistsInCDN(file21) || server1.FileExistsLocal(file21)) server1.Delete(file21); Assert.IsFalse(server1.FileExistsInCDN(file21)); Assert.IsFalse(server1.FileExistsLocal(file21)); await server2.StoreImageAsync(strDesertPath, file21); Assert.IsTrue(server2.FileExistsLocal(file21)); Assert.IsTrue(server2.FileExistsInCDN(file21)); var props2CDN = server2.GetFilePropertiesFromCDN(file21); var props2Local = server2.GetFilePropertiesLocal(file21); Assert.IsNotNull(props2CDN); Assert.IsNotNull(props2Local); Assert.IsTrue(props2Local.IsCurrentVersionOf(props2CDN)); //Test 2: Store a file from a Unicode text string, then retreive it and compare the strings IFileQuery file2 = new FileQuery("Test.txt", "Scripts"); server1.StoreFileFromString("this is some text § how was that", file2); string strFile2Text = server1.LoadFileText(file2); Assert.AreEqual(strFile2Text, "this is some text § how was that"); server1.DeleteFileLocal(file2); Assert.IsFalse(server1.FileExistsLocal(file2)); string test = server1.LoadFileText(file2); Assert.AreEqual(test, "this is some text § how was that"); //Test 3: Make sure that this file, which was never uploaded, reflects that reality IFileQuery file3 = new FileQuery("Redfish.jpg", "uploads/images"); Assert.IsFalse(server1.FileExistsLocal(file3)); Assert.IsFalse(server1.FileExistsInCDN(file3)); var strURL3 = server1.GetCDNURL(file3); Assert.IsTrue(Model.URL.IsValid(strURL3)); var props2 = server1.GetFilePropertiesFromCDN(file3); Assert.IsNull(props2); //Test 4: Test each upload method string strKoalaPath = TestContent.GetContentFilePhysicalPath("/Images/Koala.jpg"); System.Drawing.Image imgKoala = System.Drawing.Image.FromFile(strKoalaPath); IFileQuery file4 = new FileQuery("Upload.jpg", "Images"); string strURL; file4.FileName = "UploadFromFile.jpg"; strURL = server1.GetCDNURL(file4); server1.StoreImage(strKoalaPath, file4); Assert.IsTrue(server1.FileExistsLocal(file4)); Assert.IsTrue(server1.FileExistsInCDN(file4)); Assert.IsFalse(server1.FileExpiredLocal(file4)); file4.FileName = "UploadFromImage.jpg"; strURL = server1.GetCDNURL(file4); server1.StoreImage(imgKoala, file4); Assert.IsTrue(server1.FileExistsLocal(file4)); Assert.IsTrue(server1.FileExistsInCDN(file4)); Assert.IsFalse(server1.FileExpiredLocal(file4)); file4.FileName = "UploadFromImage.png"; strURL = server1.GetCDNURL(file4); server1.StoreImage(imgKoala, file4, System.Drawing.Imaging.ImageFormat.Png); Assert.IsTrue(server1.FileExistsLocal(file4)); Assert.IsTrue(server1.FileExistsInCDN(file4)); Assert.IsFalse(server1.FileExpiredLocal(file4)); file4.FileName = "UploadFromStream.png"; strURL = server1.GetCDNURL(file4); var stream = new System.IO.MemoryStream(); imgKoala.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Position = 0; server1.StoreImage(stream, file4); Assert.IsTrue(server1.FileExistsLocal(file4)); Assert.IsTrue(server1.FileExistsInCDN(file4)); Assert.IsFalse(server1.FileExpiredLocal(file4)); file4.FileName = "UploadFromFileAsFile.jpg"; strURL = server1.GetCDNURL(file4); server1.StoreFile(strKoalaPath, file4); Assert.IsTrue(server1.FileExistsLocal(file4)); Assert.IsTrue(server1.FileExistsInCDN(file4)); Assert.IsFalse(server1.FileExpiredLocal(file4)); file4.FileName = "UploadFromStreamAsFile.jpg"; strURL = server1.GetCDNURL(file4); var stream2 = new System.IO.MemoryStream(); imgKoala.Save(stream2, System.Drawing.Imaging.ImageFormat.Jpeg); stream2.Position = 0; server1.StoreFile(stream2, file4); Assert.IsTrue(server1.FileExistsLocal(file4)); Assert.IsTrue(server1.FileExistsInCDN(file4)); Assert.IsFalse(server1.FileExpiredLocal(file4)); }
private void Example() { //Simple example for S3... AmazonS3Client objAWSClient = new AmazonS3Client(Amazon.RegionEndpoint.USEast1); IFileServer server1 = new FileServerAmazonS3("/LocalFolder/" , "http://localhostedurl.com", objAWSClient, "S3BucketName"); IFileQuery file1 = new FileQuery("Desert.jpg", "uploads/images"); server1.StoreImage("C:\\SomeFile.jpg", file1); //Cleanup if (server1.FileExistsInCDN(file1) || server1.FileExistsLocal(file1)) server1.Delete(file1); //Simple example for Azure Microsoft.WindowsAzure.Storage.CloudStorageAccount objCDNClient = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse( ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString); IFileServer server2 = new FileServerAzure("/LocalFolder/" , "http://localhostedurl.com", objCDNClient, "AzureBucketName"); IFileQuery file2 = new FileQuery("Jellyfish.jpg", "Images"); server2.StoreImage("C:\\SomeFile.jpg", file2); //Cleanup if (server2.FileExistsInCDN(file2) || server2.FileExistsLocal(file2)) server2.Delete(file2); //Look at all the ways an IFileQuery can be turned into useful paths, the file server setup //is designed so that every node can store it's files in different disk paths, but a given //FileQuery will find the correct file at any node, regardless of their specific configurations. //The "Base" path is the portion that is common to all nodes, local and remote. IFileServer server3 = new FileServerAzure("/Uploads/", "http://www.testdomain.com", null, "AzureBucketName"); IFileQuery file3 = new FileQuery("Awesome.jpg", "Images"); string strURL, strLocalRelativePath, strPhysicalPath, strBasePath, strCDNPath; strURL = server3.GetLocalURL(file3); //http://www.testdomain.com/Uploads/Images/Awesome.jpg strPhysicalPath = server3.GetLocalDiskPath(file3); //C:\\Users\\MyUser\\Documents\\General.CDN\\General.CDN.Tests\\bin\\Debug\\Uploads\\Images\\Awesome.jpg strLocalRelativePath = server3.GetLocalRelativePath(file3); //Uploads/Images/Awesome.jpg strBasePath = server3.GetBasePath(file3); //Images/Awesome.jpg strCDNPath = server3.GetCDNPath(file3, true); //unittest/Images/Awesome.jpg var blnExistsLocal = server3.FileExistsLocal(file3); var enuExistsHTTP = server3.FileExistsLocal_HTTPCheck(file3); var blnExistsRemote = server3.FileExistsInCDN(file3); //Would you like to know if a file on your local node is up to date... try this... //IsCurrentVersionOf uses MD5 hash matching for files less than 10MB //if the file is larger or MD5 is not available in remote server... file byte size will be used for comparison var props1CDN = server3.GetFilePropertiesFromCDN(file3); var props1Local = server3.GetFilePropertiesLocal(file3); bool blnUpToDate = props1Local.IsCurrentVersionOf(props1CDN); }
private void Example() { //Simple example for S3... AmazonS3Client objAWSClient = new AmazonS3Client(Amazon.RegionEndpoint.USEast1); IFileServer server1 = new FileServerAmazonS3("/LocalFolder/" , "http://localhostedurl.com", objAWSClient, "S3BucketName"); IFileQuery file1 = new FileQuery("Desert.jpg", "uploads/images"); server1.StoreImage("C:\\SomeFile.jpg", file1); //Cleanup if (server1.FileExistsInCDN(file1) || server1.FileExistsLocal(file1)) { server1.Delete(file1); } //Simple example for Azure Microsoft.WindowsAzure.Storage.CloudStorageAccount objCDNClient = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse( ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString); IFileServer server2 = new FileServerAzure("/LocalFolder/" , "http://localhostedurl.com", objCDNClient, "AzureBucketName"); IFileQuery file2 = new FileQuery("Jellyfish.jpg", "Images"); server2.StoreImage("C:\\SomeFile.jpg", file2); //Cleanup if (server2.FileExistsInCDN(file2) || server2.FileExistsLocal(file2)) { server2.Delete(file2); } //Look at all the ways an IFileQuery can be turned into useful paths, the file server setup //is designed so that every node can store it's files in different disk paths, but a given //FileQuery will find the correct file at any node, regardless of their specific configurations. //The "Base" path is the portion that is common to all nodes, local and remote. IFileServer server3 = new FileServerAzure("/Uploads/", "http://www.testdomain.com", null, "AzureBucketName"); IFileQuery file3 = new FileQuery("Awesome.jpg", "Images"); string strURL, strLocalRelativePath, strPhysicalPath, strBasePath, strCDNPath; strURL = server3.GetLocalURL(file3); //http://www.testdomain.com/Uploads/Images/Awesome.jpg strPhysicalPath = server3.GetLocalDiskPath(file3); //C:\\Users\\MyUser\\Documents\\General.CDN\\General.CDN.Tests\\bin\\Debug\\Uploads\\Images\\Awesome.jpg strLocalRelativePath = server3.GetLocalRelativePath(file3); //Uploads/Images/Awesome.jpg strBasePath = server3.GetBasePath(file3); //Images/Awesome.jpg strCDNPath = server3.GetCDNPath(file3, true); //unittest/Images/Awesome.jpg var blnExistsLocal = server3.FileExistsLocal(file3); var enuExistsHTTP = server3.FileExistsLocal_HTTPCheck(file3); var blnExistsRemote = server3.FileExistsInCDN(file3); //Would you like to know if a file on your local node is up to date... try this... //IsCurrentVersionOf uses MD5 hash matching for files less than 10MB //if the file is larger or MD5 is not available in remote server... file byte size will be used for comparison var props1CDN = server3.GetFilePropertiesFromCDN(file3); var props1Local = server3.GetFilePropertiesLocal(file3); bool blnUpToDate = props1Local.IsCurrentVersionOf(props1CDN); }