Added special handling of IfModifiedSince if a new shared container is detected
[pithos-ms-client] / trunk / Pithos.Network / CloudFilesClient.cs
index a99d224..da412be 100644 (file)
@@ -312,9 +312,17 @@ namespace Pithos.Network
             }
         }
 
-        //Request listing of all objects in a container modified since a specific time.
-        //If the *since* value is missing, return all objects
-        public IList<ObjectInfo> ListSharedObjects(DateTime? since = null)
+
+        /// <summary>
+        /// Request listing of all objects in a container modified since a specific time.
+        /// If the *since* value is missing, return all objects
+        /// </summary>
+        /// <param name="knownContainers">Use the since variable only for the containers listed in knownContainers. Unknown containers are considered new
+        /// and should be polled anyway
+        /// </param>
+        /// <param name="since"></param>
+        /// <returns></returns>
+        public IList<ObjectInfo> ListSharedObjects(HashSet<string> knownContainers,DateTime? since = null )
         {
 
             using (ThreadContext.Stacks["Share"].Push("List Objects"))
@@ -322,19 +330,25 @@ namespace Pithos.Network
                 if (Log.IsDebugEnabled) Log.DebugFormat("START");
                 //'since' is not used here because we need to have ListObjects return a NoChange result
                 //for all shared accounts,containers
+
+                Func<ContainerInfo, string> GetKey = c => String.Format("{0}\\{1}", c.Account, c.Name);
+
                 var accounts = ListSharingAccounts();
-                var items = from account in accounts 
-                            let containers = ListContainers(account.name) 
-                            from container in containers 
-                            select ListObjects(account.name, container.Name,since);
+                var containers = (from account in accounts
+                                 let conts = ListContainers(account.name)
+                                 from container in conts
+                                 select container).ToList();                
+                var items = from container in containers 
+                            let actualSince=knownContainers.Contains(GetKey(container))?since:null
+                            select ListObjects(container.Account , container.Name,  actualSince);
                 var objects=items.SelectMany(r=> r).ToList();
-/*
-                var objects = new List<ObjectInfo>();
-                foreach (var containerObjects in items)
+                
+                //Store any new containers
+                foreach (var container in containers)
                 {
-                    objects.AddRange(containerObjects);
+                    knownContainers.Add(GetKey(container));
                 }
-*/
+
                 if (Log.IsDebugEnabled) Log.DebugFormat("END");
                 return objects;
             }