Added BlockUpdater.cs to perform block updates in a separate class. Will include...
[pithos-ms-client] / trunk / Pithos.Network / RestClient.cs
index edd59ee..fd4a5f3 100644 (file)
@@ -32,6 +32,8 @@ namespace Pithos.Network
 
         public string StatusDescription { get; set; }
 
+        public long? RangeFrom { get; set; }
+        public long? RangeTo { get; set; }
 
         public int Retries { get; set; }
 
@@ -73,6 +75,14 @@ namespace Pithos.Network
             request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
             if(Timeout>0)
                 request.Timeout = Timeout;
+
+            if (RangeFrom.HasValue)
+            {
+                if (RangeTo.HasValue)
+                    request.AddRange(RangeFrom.Value, RangeTo.Value);
+                else
+                    request.AddRange(RangeFrom.Value);
+            }
             return request; 
         }
 
@@ -94,20 +104,29 @@ namespace Pithos.Network
             {                
                 var response = (HttpWebResponse)base.GetWebResponse(request);
                 StatusCode = response.StatusCode;
-                StatusDescription = response.StatusDescription;
+                LastModified=response.LastModified;                
+                StatusDescription = response.StatusDescription;                
                 return response;
             }
             catch (WebException exc)
-            {
-                if (exc.Response!=null && exc.Response.ContentLength > 0)
+            {                
+                if (exc.Response!=null)
                 {
-                    string content = GetContent(exc.Response);
-                    Trace.TraceError(content);
+                    var response = (exc.Response as HttpWebResponse);
+                    if (response.StatusCode == HttpStatusCode.NotModified)
+                        return response;
+                    if (exc.Response.ContentLength > 0)
+                    {
+                        string content = GetContent(exc.Response);
+                        Trace.TraceError(content);
+                    }
                 }
                 throw;
             }
         }
 
+        public DateTime LastModified { get; private set; }
+
         private static string GetContent(WebResponse webResponse)
         {
             string content;
@@ -198,7 +217,29 @@ namespace Pithos.Network
                 return 0;
             }, actualRetries);
 
-            task.Wait();
+            try
+            {
+                task.Wait();
+            }
+            catch (AggregateException ex)
+            {
+                var exc = ex.InnerException;
+                if (exc is RetryException)
+                {
+                    Trace.TraceError("[{0}] RETRY FAILED for {1} after {2} retries",method,address,retries);
+                }
+                else
+                {
+                    Trace.TraceError("[{0}] FAILED for {1} with \n{2}", method, address, exc);
+                }
+                throw;
+
+            }
+            catch(Exception ex)
+            {
+                Trace.TraceError("[{0}] FAILED for {1} with \n{2}", method, address, ex);
+                throw;
+            }
         }
         
         /*private string RetryWithContent(string address, int retries, string method)
@@ -366,8 +407,8 @@ namespace Pithos.Network
                             {
                                 TimedOut = true;
                                 if (retryCount == 0)
-                                {
-                                    Trace.TraceError("[ERROR] Timed out too many times. {0}\n", e);
+                                {                                    
+                                    Trace.TraceError("[ERROR] Timed out too many times. \n{0}\n",e);
                                     tcs.SetException(new RetryException("Timed out too many times.", e));                                    
                                 }
                                 else