Changed Pithos storage URL to include the Pithos container at CloudFilesClient.cs
authorPanagiotis Kanavos <pkanavos@gmail.com>
Wed, 15 Jun 2011 18:35:41 +0000 (21:35 +0300)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Wed, 15 Jun 2011 18:36:06 +0000 (21:36 +0300)
Modified tests to run against both Pithos and Rackspace

trunk/Pithos.Core/PithosMonitor.cs
trunk/Pithos.Interfaces/ICloudClient.cs
trunk/Pithos.Network.Test/ChecksumTest.cs
trunk/Pithos.Network.Test/NetworkOpsTest.cs
trunk/Pithos.Network/CloudFilesClient.cs

index c58c264..cedab5c 100644 (file)
@@ -311,10 +311,9 @@ namespace Pithos.Core
             if ( hash != info.Hash)
             {
                 this.StatusKeeper.SetFileOverlayStatus(path, FileOverlayStatus.Synch);
-                using (var stream = File.OpenRead(path))
-                {
-                    CloudClient.PutObject("PITHOS", fileName, stream, fileSize);
-                }
+                
+                    CloudClient.PutObject("PITHOS", fileName, path, fileSize);
+                
             }
             this.StatusKeeper.SetFileStatus(path,FileStatus.Unchanged);
             this.StatusKeeper.SetFileOverlayStatus(path,FileOverlayStatus.Normal);
index 68d97cf..6db6591 100644 (file)
@@ -12,7 +12,7 @@ namespace Pithos.Interfaces
     {
         string ApiKey { get; set; }
         string UserName { get; set; }
-        string StorageUrl { get; set; }
+        Uri StorageUrl { get; set; }
         string Token { get; set; }
         bool UsePithos { get; set; }
         void Authenticate(string userName,string apiKey);
@@ -25,7 +25,7 @@ namespace Pithos.Interfaces
         void DeleteContainer(string container);
         
         Stream GetObject(string container, string objectName);
-        void PutObject(string container, string objectName, Stream file,long fileSize);
+        void PutObject(string container, string objectName, string fileName,long fileSize);
         void DeleteObject(string container, string objectName);
         void MoveObject(string container, string oldObjectName, string newObjectName);
         bool ObjectExists(string container,string objectName);
@@ -38,7 +38,7 @@ namespace Pithos.Interfaces
     {
         public string ApiKey { get; set; }
         public string UserName { get; set; }
-        public string StorageUrl { get; set; }
+        public Uri StorageUrl { get; set; }
         public string Token { get; set; }
 
         public bool UsePithos { get; set; }
@@ -51,7 +51,7 @@ namespace Pithos.Interfaces
 
             Contract.Ensures(apiKey==ApiKey);
             Contract.Ensures(userName==UserName);
-            Contract.Ensures(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Ensures(StorageUrl!=null);
             Contract.Ensures(!String.IsNullOrWhiteSpace(Token));
             
         }
@@ -59,7 +59,7 @@ namespace Pithos.Interfaces
         public IList<ContainerInfo> ListContainers()
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);            
 
             return default(IList<ContainerInfo>);
         }
@@ -67,7 +67,7 @@ namespace Pithos.Interfaces
         public IList<ObjectInfo> ListObjects(string container)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl != null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
 
             return default(IList<ObjectInfo>);
@@ -76,7 +76,7 @@ namespace Pithos.Interfaces
         public bool ContainerExists(string container)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
 
             return default(bool);
@@ -85,7 +85,7 @@ namespace Pithos.Interfaces
         public ContainerInfo GetContainerInfo(string container)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
 
             return default(ContainerInfo);
@@ -94,34 +94,33 @@ namespace Pithos.Interfaces
         public void CreateContainer(string container)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
         }
 
         public void DeleteContainer(string container)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
         }
 
         public Stream GetObject(string container, string objectName)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
             Contract.Requires(!String.IsNullOrWhiteSpace(objectName));
 
             return default(Stream);
         }
 
-        public void PutObject(string container, string objectName, Stream file,long fileSize)
+        public void PutObject(string container, string objectName, string fileName,long fileSize)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
-            Contract.Requires(file!=null);
-            Contract.Requires(file.CanRead);
+            Contract.Requires(!String.IsNullOrWhiteSpace(fileName));            
             Contract.Requires(fileSize>=0);            
             Contract.Requires(!String.IsNullOrWhiteSpace(objectName));
         }
@@ -129,7 +128,7 @@ namespace Pithos.Interfaces
         public void DeleteObject(string container, string objectName)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
             Contract.Requires(!String.IsNullOrWhiteSpace(objectName));
         }
@@ -137,7 +136,7 @@ namespace Pithos.Interfaces
         public void MoveObject(string container, string oldObjectName, string newObjectName)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
             Contract.Requires(!String.IsNullOrWhiteSpace(oldObjectName));
             Contract.Requires(!String.IsNullOrWhiteSpace(newObjectName));
@@ -146,7 +145,7 @@ namespace Pithos.Interfaces
         public bool ObjectExists(string container,string objectName)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
             Contract.Requires(!String.IsNullOrWhiteSpace(objectName));
 
@@ -156,7 +155,7 @@ namespace Pithos.Interfaces
         public ObjectInfo GetObjectInfo(string container,string objectName)
         {
             Contract.Requires(!String.IsNullOrWhiteSpace(Token));
-            Contract.Requires(!String.IsNullOrWhiteSpace(StorageUrl));
+            Contract.Requires(StorageUrl!=null);
             Contract.Requires(!String.IsNullOrWhiteSpace(container));
             Contract.Requires(!String.IsNullOrWhiteSpace(objectName));
 
index 2e5ecbd..c58aae5 100644 (file)
@@ -16,7 +16,7 @@ namespace Pithos.Network.Test
 
         private string _apiKey = "9d3cb7b231e96f72ebe96af1c6cd5112";
         private string _userName = "pkanavos";
-        private bool _usePithos = false;
+        private bool _usePithos = true;
 
         private ICloudClient client;
         [SetUp]
@@ -36,11 +36,10 @@ namespace Pithos.Network.Test
                 var filePath = "devguide.pdf";
                 var info=new FileInfo(filePath);
 
-                using (var file = File.OpenRead(filePath))
-                {
-                    var hash = CalculateHash(file);
-                    file.Seek(0, 0);
-                    client.PutObject("Shares", info.Name, file, info.Length);
+               
+                    var hash = CalculateHash(filePath);
+                    
+                    client.PutObject("Shares", info.Name, filePath, info.Length);
 
 
                     var meta = client.GetObjectInfo("Shares", "DeveloperGuide.pdf");
@@ -48,20 +47,21 @@ namespace Pithos.Network.Test
                     
 
                     Assert.AreEqual(hash,meta.Hash,String.Format("The hashes don't match, expected {0} but got {1}",hash,meta.Hash));
-                }
+                
 
             });
 
         
         }
 
-        private static string CalculateHash(FileStream file)
+        private static string CalculateHash(string fileName)
         {
             string hash;
             using (var hasher = MD5.Create())
+            using(var stream=File.OpenRead(fileName))
             {
                 var hashBuilder = new StringBuilder();
-                foreach (byte b in hasher.ComputeHash(file))
+                foreach (byte b in hasher.ComputeHash(stream))
                     hashBuilder.Append(b.ToString("x2").ToLower());
                 hash = hashBuilder.ToString();
             }
index 18f9797..d5e9852 100644 (file)
@@ -15,25 +15,25 @@ namespace Pithos.Network.Test
     {
         private string _apiKey = "9d3cb7b231e96f72ebe96af1c6cd5112";
         private string _userName = "pkanavos";
-        private bool _usePithos = false;
+        
             
 
         [Test]
-        public void TestAuthenticate()
+        public void TestAuthenticate([Values(true,false)]bool usePithos)
         {
-            ICloudClient client = new CloudFilesClient{UsePithos=_usePithos};
+            ICloudClient client = new CloudFilesClient{UsePithos=usePithos};
             client.Authenticate(_userName, _apiKey);
-            string storageUrl=client.StorageUrl;
+            Uri storageUrl=client.StorageUrl;
             string token = client.Token;
 
-            Assert.IsNotEmpty(storageUrl, "Storage Url was empty");
+            Assert.IsNotNull(storageUrl, "Storage Url was empty");
             Assert.IsNotEmpty(token, "Token was empty");
         }
 
         [Test]
-        public void TestListContainers()
+        public void TestListContainers([Values(true, false)]bool usePithos)
         {
-            ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
             client.Authenticate(_userName, _apiKey);
 
             IList<ContainerInfo> containers=client.ListContainers();
@@ -41,9 +41,9 @@ namespace Pithos.Network.Test
         }
 
         [Test]
-        public void TestListObjects()
+        public void TestListObjects([Values(true, false)]bool usePithos)
         {
-            ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
             client.Authenticate(_userName, _apiKey);
 
             IList<ObjectInfo> objects=client.ListObjects("PITHOS");
@@ -51,23 +51,23 @@ namespace Pithos.Network.Test
         }
 
         [Test]
-        public void TestContainerExists()
+        public void TestContainerExists([Values(true, false)]bool usePithos)
         {
-            ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
             client.Authenticate(_userName, _apiKey);
-
-            bool dnzExists=client.ContainerExists("DotNetZone");
-            bool pithosExists = client.ContainerExists("PITHOS");
+            client.CreateContainer("TestContainer");
+            bool dnzExists=client.ContainerExists("TestContainer");
+            
             bool mooExists = client.ContainerExists("Moo");
             Assert.IsTrue(dnzExists);
-            Assert.IsTrue(pithosExists);
+            
             Assert.IsFalse(mooExists);
         }
 
         [Test]
-        public void TestGetContainerInfo()
+        public void TestGetContainerInfo([Values(true, false)]bool usePithos)
         {
-            ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
             client.Authenticate(_userName, _apiKey);
 
             var dnzInfo =client.GetContainerInfo("DotNetZone");
@@ -81,11 +81,11 @@ namespace Pithos.Network.Test
         }
 
         [Test]
-        public void TestCreateContainer()
+        public void TestCreateContainer([Values(true, false)]bool usePithos)
         {
             Assert.DoesNotThrow(() =>
                                     {
-                                        ICloudClient client = new CloudFilesClient{UsePithos=_usePithos};
+                                        ICloudClient client = new CloudFilesClient{UsePithos=usePithos};
                                         client.Authenticate(_userName, _apiKey);
 
                                         client.CreateContainer("Shares2");
@@ -100,11 +100,11 @@ namespace Pithos.Network.Test
         }
 
         [Test]
-        public void TestGetObject()
+        public void TestGetObject([Values(true, false)]bool usePithos)
         {
             Assert.DoesNotThrow(() =>
             {
-                ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+                ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
                 client.Authenticate(_userName, _apiKey);
 
                 client.CreateContainer("Shares");
@@ -121,34 +121,33 @@ namespace Pithos.Network.Test
         }
 
         [Test]
-        public void TestPutObject()
+        public void TestPutObject([Values(true, false)]bool usePithos)
         {
             Assert.DoesNotThrow(() =>
-            {
-                ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
-                client.Authenticate(_userName, _apiKey);
+                                    {
+                                        ICloudClient client = new CloudFilesClient {UsePithos = usePithos};
+                                        client.Authenticate(_userName, _apiKey);
 
-                client.CreateContainer("Shares");
-                Assert.IsTrue(client.ContainerExists("Shares"));                
+                                        client.CreateContainer("Shares");
+                                        Assert.IsTrue(client.ContainerExists("Shares"));
 
-                var filePath = "devguide.pdf";
-                FileInfo info=new FileInfo(filePath);
-                
-                using (var file = File.OpenRead(filePath))
-                {
-                    client.PutObject("Shares",info.Name, file,info.Length );
-                }
+                                        var filePath = "devguide.pdf";
+                                        FileInfo info = new FileInfo(filePath);
 
-            });
+
+                                        client.PutObject("Shares", info.Name, filePath, info.Length);
+
+
+                                    });
 
         }
 
         [Test]
-        public void TestGetObjectMetadata()
+        public void TestGetObjectMetadata([Values(true, false)]bool usePithos)
         {
             Assert.DoesNotThrow(() =>
             {
-                ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+                ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
                 client.Authenticate(_userName, _apiKey);
 
                 client.CreateContainer("Shares");
@@ -157,10 +156,9 @@ namespace Pithos.Network.Test
                 var filePath = "devguide.pdf";
                 FileInfo info = new FileInfo(filePath);
 
-                using (var file = File.OpenRead(filePath))
-                {
-                    client.PutObject("Shares", info.Name, file, info.Length);
-                }
+               
+                    client.PutObject("Shares", info.Name, filePath, info.Length);
+                
 
 
                 
@@ -173,11 +171,11 @@ namespace Pithos.Network.Test
         }
 
         [Test]
-        public void TestDeleteObject()
+        public void TestDeleteObject([Values(true, false)]bool usePithos)
         {
             Assert.DoesNotThrow(() =>
             {
-                ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+                ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
                 client.Authenticate(_userName, _apiKey);
 
                 client.CreateContainer("Shares");
@@ -186,33 +184,58 @@ namespace Pithos.Network.Test
                 var filePath = "devguide.pdf";
                 FileInfo info=new FileInfo(filePath);
                 
-                using (var file = File.OpenRead(filePath))
-                {
-                    client.PutObject("Shares",info.Name, file,info.Length );
-                }
+               
+                    client.PutObject("Shares",info.Name, filePath,info.Length );
+                
 
                 Assert.IsTrue(client.ObjectExists("Shares",info.Name),"File Created");
 
-                client.DeleteObject("Shares",info.Name);
-                Assert.IsFalse(client.ObjectExists("Shares", info.Name),"File Deleted");
+                client.DeleteObject("Shares/devguide.pdf",info.Name);
                 
+            });
 
+        }
+        
+        [Test]
+        public void TestDeleteContainer([Values(true, false)]bool usePithos)
+        {
+            Assert.DoesNotThrow(() =>
+            {
+                ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
+                client.Authenticate(_userName, _apiKey);
 
+                client.CreateContainer("Shares");
+                Assert.IsTrue(client.ContainerExists("Shares"),"Container Exists");                
 
+                var filePath = "devguide.pdf";
+                FileInfo info=new FileInfo(filePath);
+                
+               
+                    client.PutObject("Shares",info.Name, filePath,info.Length );
+                
+
+                Assert.IsTrue(client.ObjectExists("Shares",info.Name),"File Created");
+
+                client.DeleteObject("Shares",info.Name);
+                Assert.IsFalse(client.ObjectExists("Shares", info.Name),"Container Deleted");
+                
+                client.DeleteObject("Moo",info.Name);
+                Assert.IsFalse(client.ObjectExists("Moo", info.Name),"Container Deleted");
+                
             });
 
         }
 
-        [Test]
-        public void TestFilesWithSpaces()
+       /* [Test]
+        public void TestFilesWithSpaces([Values(true, false)]bool usePithos)
         {
-            ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
             client.Authenticate(_userName, _apiKey);
             
             var testName = "Name with spaces.txt";
             
             using(var stream=new MemoryStream())
-            using (var writer = new StreamWriter(stream))
+            using (var writer = new File.(stream))
             {
                 
                 writer.WriteLine("This is a test line");
@@ -230,14 +253,14 @@ namespace Pithos.Network.Test
                                     {
                                         client.DeleteObject("PITHOS", testName);                                        
                                     });
-        }
+        }*/
 
         [Test]
-        public void TestMoveObject()
+        public void TestMoveObject([Values(true, false)]bool usePithos)
         {
             Assert.DoesNotThrow(() =>
             {
-                ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+                ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
                 client.Authenticate(_userName, _apiKey);
 
                 client.CreateContainer("Shares");
@@ -246,10 +269,9 @@ namespace Pithos.Network.Test
                 var filePath = "devguide.pdf";
                 FileInfo info=new FileInfo(filePath);
                 
-                using (var file = File.OpenRead(filePath))
-                {
-                    client.PutObject("Shares",info.Name, file,info.Length );
-                }
+               
+                    client.PutObject("Shares",info.Name, filePath,info.Length );
+                
 
                 Assert.IsTrue(client.ObjectExists("Shares",info.Name),"File Created");
 
@@ -269,17 +291,17 @@ namespace Pithos.Network.Test
 
 
         [Test]
-        public void TestAuthenticateMissingArguments()
+        public void TestAuthenticateMissingArguments([Values(true, false)]bool usePithos)
         {
             Assert.Catch<ArgumentNullException>(() =>
             {
-                ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };                
+                ICloudClient client = new CloudFilesClient { UsePithos = usePithos };                
                 client.Authenticate("someUser",null);
             });
 
             Assert.Catch<ArgumentNullException>(() =>
             {
-                ICloudClient client = new CloudFilesClient { UsePithos = _usePithos };
+                ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
                 client.Authenticate(null,"someKey");
             });
 
index c0efdb9..b93be83 100644 (file)
@@ -21,14 +21,14 @@ namespace Pithos.Network
     public class CloudFilesClient:ICloudClient
     {
         string _rackSpaceAuthUrl = "https://auth.api.rackspacecloud.com/v1.0";
-        private string _pithosAuthUrl = "http://pithos.dev.grnet.gr/v1/";
+        private string _pithosAuthUrl = "http://pithos.dev.grnet.gr/v1/Pithos";
 
         private RestClient _client;
         private readonly TimeSpan _timeout = TimeSpan.FromSeconds(10);
         private readonly int _retries = 5;
         public string ApiKey { get; set; }
         public string UserName { get; set; }
-        public string StorageUrl { get; set; }
+        public Uri StorageUrl { get; set; }
         public string Token { get; set; }
         
         public string AuthUrl
@@ -64,15 +64,19 @@ namespace Pithos.Network
             
             if (String.IsNullOrWhiteSpace(storageUrl))
                 throw new InvalidOperationException("Failed to obtain storage url");
-            StorageUrl = storageUrl;
+            StorageUrl = new Uri(storageUrl);
 
-            
-            var token = GetHeaderValue("X-Auth-Token",response,keys);
-            if (String.IsNullOrWhiteSpace(token))
-                throw new InvalidOperationException("Failed to obtain token url");
-            Token = token;
+            if (!UsePithos)
+            {
+                var token = GetHeaderValue("X-Auth-Token", response, keys);
+                if (String.IsNullOrWhiteSpace(token))
+                    throw new InvalidOperationException("Failed to obtain token url");
+                Token = token;
+            }
+            else
+                Token = "0000";
 
-            _client = new RestClient { Authority = StorageUrl, RetryPolicy = new RetryPolicy { RetryCount = _retries }, Timeout = _timeout };
+            _client = new RestClient { Authority = StorageUrl.AbsoluteUri, RetryPolicy = new RetryPolicy { RetryCount = _retries }, Timeout = _timeout };
             _client.RetryPolicy.RetryConditions.Add(new TimeoutRetryCondition());
             _client.AddHeader("X-Auth-Token", Token);
             if (UsePithos)
@@ -230,9 +234,17 @@ namespace Pithos.Network
                 throw new ArgumentNullException("container", "The container property can't be empty");
 
             var request = new RestRequest { Path = container, Method = WebMethod.Put };
-            var response = _client.Request(request);
             
+            //var request=(HttpWebRequest)WebRequest.Create(new Uri(StorageUrl, container));
+            //request.Method = "PUT";
+            //request.ContentLength = 0;
+           /* foreach(var header in _client.GetAllHeaders())
+                request.Headers.Add(header.Name,header.Value);*/
+           
+            //var response = (HttpWebResponse) request.GetResponse();
             
+            var response = _client.Request(request);
+                        
             if (response.StatusCode!=HttpStatusCode.Created && response.StatusCode!=HttpStatusCode.Accepted )
                     throw new WebException(String.Format("ContainerExists failed with unexpected status code {0}", response.StatusCode));
         }
@@ -273,52 +285,71 @@ namespace Pithos.Network
                 throw new WebException(String.Format("GetObject failed with unexpected status code {0}", response.StatusCode));
         }
 
-        public void PutObject(string container, string objectName, Stream file,long fileSize)
+        public void PutObject(string container, string objectName, string fileName,long fileSize)
         {
             if (String.IsNullOrWhiteSpace(container))
                 throw new ArgumentNullException("container", "The container property can't be empty");
             if (String.IsNullOrWhiteSpace(objectName))
                 throw new ArgumentNullException("objectName", "The objectName property can't be empty");
-            if (file==null)
-                throw new ArgumentNullException("file", "The file property can't be empty");
+            if (String.IsNullOrWhiteSpace(fileName))
+                throw new ArgumentNullException("fileName", "The fileName property can't be empty");
 
 
-            string url = StorageUrl + "/" + container + "/" + objectName;                        
+            string url = StorageUrl + "/" + container + "/" + objectName;
 
-            WebRequest request = WebRequest.Create(url);
-            request.Headers["X-Auth-Token"]=Token;
+            //var request = new RestRequest {Path=container + "/" + objectName,Method=WebMethod.Put};
+            
+/*
+            var request = (HttpWebRequest)WebRequest.Create(url);
+            //request.Headers["X-Auth-Token"]=Token;
             request.Method = "PUT";
-            //request.Headers.Add("Content-Length",fileSize.ToString());
-            //request.Headers.Add("Content-Type","application/octet-stream");            
+            request.ContentLength = fileSize;
+            request.ContentType="application/octet-stream";      */      
 
+            
+            string hash = CalculateHash(fileName);
 
-            string hash = CalculateHash(file);
+            //request.Headers["ETag"] = hash;
+            /*request.AddHeader("ETag", hash);
+            request.AddFile(objectName,objectName,file,"application/octet-stream");
+            */
+           /* foreach(var header in _client.GetAllHeaders())
+                request.Headers.Add(header.Name,header.Value);
 
-            request.Headers["ETag"] = hash;
             using (var stream = request.GetRequestStream())
             {
                 file.Seek(0, SeekOrigin.Begin);
                 file.CopyTo(stream);
             }
+            request.ContentType = "application/octet-stream";
+*/
+            WebClient c = new WebClient();
+            foreach (var header in _client.GetAllHeaders())
+                c.Headers.Add(header.Name, header.Value);
+            c.Headers["ETag"] = hash;
+            
+            
+            c.UploadFile(new Uri(url), "PUT",fileName);
 
+            //var response=_client.Request(request); 
+            //var response=request.GetResponse() as HttpWebResponse;
 
-            var response=request.GetResponse() as HttpWebResponse;
-
-            if (response.StatusCode == HttpStatusCode.Created)
+           /* if (response.StatusCode == HttpStatusCode.Created)
                 return;
             if (response.StatusCode == HttpStatusCode.LengthRequired)
                 throw new InvalidOperationException();
             else
-                throw new WebException(String.Format("GetObject failed with unexpected status code {0}", response.StatusCode));
+                throw new WebException(String.Format("GetObject failed with unexpected status code {0}", response.StatusCode));*/
         }
 
-        private static string CalculateHash(Stream file)
+        private static string CalculateHash(string fileName)
         {
             string hash;
             using (var hasher = MD5.Create())
+            using(var stream=File.OpenRead(fileName))
             {
                 var hashBuilder=new StringBuilder();
-                foreach (byte b in hasher.ComputeHash(file))
+                foreach (byte b in hasher.ComputeHash(stream))
                     hashBuilder.Append(b.ToString("x2").ToLower());
                 hash = hashBuilder.ToString();                
             }