Example #1
0
        public void TestImagePathVariants()
        {
            IFileServer server1 = new FileServerAzure("/Uploads/", "http://www.testdomain.com", null, AzureBucket);
            IFileQuery  file1   = new FileQuery("Awesome.jpg", "Images");

            IFileServer server2 = new FileServerAzure("/Uploads/", "http://www.anotherdomain.com", null, AzureBucket);
            IFileQuery  file2   = new FileQuery("Coolness.png", "ExPhotoImageFile", "/");

            string strURL, strLocalRelativePath, strPhysicalPath, strBasePath, strCDNPath;
            bool   blnExistsLocal = false;

            Model.URL.URLCheckExistsResult enuExistsRemote = Model.URL.URLCheckExistsResult.Unknown;
            // Assert
            strURL               = server1.GetLocalURL(file1);
            strPhysicalPath      = server1.GetLocalDiskPath(file1);
            strLocalRelativePath = server1.GetLocalRelativePath(file1);
            strBasePath          = server1.GetBasePath(file1);
            strCDNPath           = server1.GetCDNPath(file1, true);
            blnExistsLocal       = server1.FileExistsLocal(file1);
            enuExistsRemote      = server1.FileExistsLocal_HTTPCheck(file1);

            Assert.IsNotNull(strURL);
            Assert.AreEqual(strURL, "http://www.testdomain.com/Uploads/Images/Awesome.jpg");
            Assert.IsNotNull(strPhysicalPath);
            Assert.IsNotNull(strLocalRelativePath);
            Assert.IsNotNull(strBasePath);
            Assert.IsNotNull(strCDNPath);
            Assert.IsTrue(Uri.IsWellFormedUriString(strURL, UriKind.Absolute));
            Assert.IsTrue(strPhysicalPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1);
            Assert.IsTrue(Uri.IsWellFormedUriString(strLocalRelativePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strBasePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strCDNPath, UriKind.Relative));
            Assert.IsTrue(Model.URL.IsValid(strURL));
            //Assert.IsTrue(enuExistsRemote == General.Model.URL.URLCheckExistsResult.Exists);

            strURL               = server2.GetLocalURL(file2);
            strPhysicalPath      = server2.GetLocalDiskPath(file2);
            strLocalRelativePath = server2.GetLocalRelativePath(file2);
            strBasePath          = server2.GetBasePath(file2);
            strCDNPath           = server1.GetCDNPath(file1, true);
            blnExistsLocal       = server2.FileExistsLocal(file2);
            enuExistsRemote      = server2.FileExistsLocal_HTTPCheck(file2);

            Assert.IsNotNull(strURL);
            Assert.AreEqual(strURL, "http://www.anotherdomain.com/Uploads/ExPhotoImageFile/Coolness.png");
            Assert.IsNotNull(strPhysicalPath);
            Assert.IsNotNull(strLocalRelativePath);
            Assert.IsNotNull(strBasePath);
            Assert.IsNotNull(strCDNPath);
            Assert.IsTrue(Uri.IsWellFormedUriString(strURL, UriKind.Absolute));
            Assert.IsTrue(strPhysicalPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1);
            Assert.IsTrue(Uri.IsWellFormedUriString(strLocalRelativePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strBasePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strCDNPath, UriKind.Relative));
            Assert.IsTrue(Model.URL.IsValid(strURL));
            //Assert.IsTrue(enuExistsRemote == General.Model.URL.URLCheckExistsResult.Exists);

            //This should not exist because it's the wrong server for the file.
            //Assert.IsTrue(server2.FileExistsLocal_HTTPCheck(file1) == General.Model.URL.URLCheckExistsResult.DoesNotExist);
        }
Example #2
0
        public void TestImagePathVariants()
        {
            IFileServer server1 = new FileServerAzure("/Uploads/", "http://www.testdomain.com", null, AzureBucket);
            IFileQuery file1 = new FileQuery("Awesome.jpg", "Images");

            IFileServer server2 = new FileServerAzure("/Uploads/", "http://www.anotherdomain.com", null, AzureBucket);
            IFileQuery file2 = new FileQuery("Coolness.png", "ExPhotoImageFile", "/");

            string strURL, strLocalRelativePath, strPhysicalPath, strBasePath, strCDNPath;
            bool blnExistsLocal = false;
            Model.URL.URLCheckExistsResult enuExistsRemote = Model.URL.URLCheckExistsResult.Unknown;
            // Assert
            strURL = server1.GetLocalURL(file1);
            strPhysicalPath = server1.GetLocalDiskPath(file1);
            strLocalRelativePath = server1.GetLocalRelativePath(file1);
            strBasePath = server1.GetBasePath(file1);
            strCDNPath = server1.GetCDNPath(file1, true);
            blnExistsLocal = server1.FileExistsLocal(file1);
            enuExistsRemote = server1.FileExistsLocal_HTTPCheck(file1);

            Assert.IsNotNull(strURL);
            Assert.AreEqual(strURL, "http://www.testdomain.com/Uploads/Images/Awesome.jpg");
            Assert.IsNotNull(strPhysicalPath);
            Assert.IsNotNull(strLocalRelativePath);
            Assert.IsNotNull(strBasePath);
            Assert.IsNotNull(strCDNPath);
            Assert.IsTrue(Uri.IsWellFormedUriString(strURL, UriKind.Absolute));
            Assert.IsTrue(strPhysicalPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1);
            Assert.IsTrue(Uri.IsWellFormedUriString(strLocalRelativePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strBasePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strCDNPath, UriKind.Relative));
            Assert.IsTrue(Model.URL.IsValid(strURL));
            //Assert.IsTrue(enuExistsRemote == General.Model.URL.URLCheckExistsResult.Exists);

            strURL = server2.GetLocalURL(file2);
            strPhysicalPath = server2.GetLocalDiskPath(file2);
            strLocalRelativePath = server2.GetLocalRelativePath(file2);
            strBasePath = server2.GetBasePath(file2);
            strCDNPath = server1.GetCDNPath(file1, true);
            blnExistsLocal = server2.FileExistsLocal(file2);
            enuExistsRemote = server2.FileExistsLocal_HTTPCheck(file2);

            Assert.IsNotNull(strURL);
            Assert.AreEqual(strURL, "http://www.anotherdomain.com/Uploads/ExPhotoImageFile/Coolness.png");
            Assert.IsNotNull(strPhysicalPath);
            Assert.IsNotNull(strLocalRelativePath);
            Assert.IsNotNull(strBasePath);
            Assert.IsNotNull(strCDNPath);
            Assert.IsTrue(Uri.IsWellFormedUriString(strURL, UriKind.Absolute));
            Assert.IsTrue(strPhysicalPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1);
            Assert.IsTrue(Uri.IsWellFormedUriString(strLocalRelativePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strBasePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strCDNPath, UriKind.Relative));
            Assert.IsTrue(Model.URL.IsValid(strURL));
            //Assert.IsTrue(enuExistsRemote == General.Model.URL.URLCheckExistsResult.Exists);

            //This should not exist because it's the wrong server for the file.
            //Assert.IsTrue(server2.FileExistsLocal_HTTPCheck(file1) == General.Model.URL.URLCheckExistsResult.DoesNotExist);

        }
Example #3
0
        public async Task TestAzureCDN()
        {
            string strFishPath = TestContent.GetContentFilePhysicalPath("/Images/Jellyfish.jpg");

            Microsoft.WindowsAzure.Storage.CloudStorageAccount objCDNClient
                = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString);
            IFileServer server1 = new FileServerAzure("LocalFolder", "", objCDNClient, AzureBucket);

            //Test 1: Delete a file if it exists, then store an image, check it's existance, get it's properties, and compare file versions
            IFileQuery file1 = new FileQuery("Jellyfish.jpg", "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(strFishPath, 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));

            //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);
            //server2.StoreFileFromString("some text", 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));
        }
Example #4
0
        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); 
        }
        public async Task TestAzureCDN()
        {
            string strFishPath = TestContent.GetContentFilePhysicalPath("/Images/Jellyfish.jpg");
            Microsoft.WindowsAzure.Storage.CloudStorageAccount objCDNClient 
                = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString);
            IFileServer server1 = new FileServerAzure("LocalFolder", "", objCDNClient, AzureBucket);
            
            //Test 1: Delete a file if it exists, then store an image, check it's existance, get it's properties, and compare file versions
            IFileQuery file1 = new FileQuery("Jellyfish.jpg", "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(strFishPath, 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));

            //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);
            //server2.StoreFileFromString("some text", 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));
        }