commit 4147814ee9f22d90fd9eb31378226c83b436d035
Author: Panagiotis Kanavos <pkanavos@gmail.com>
Date:   Wed Feb 29 16:14:02 2012 +0200

    Modified Selective Sync behavior to mark the files in the unselected paths as Unversioned, instead of removing them.
    Resolves #2112

diff --git a/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs b/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
index a801923..70da404 100644
--- a/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
+++ b/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
@@ -42,24 +42,19 @@
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.IO;
 using System.Linq;
-using System.Text;
 using System.Threading.Tasks;
 using Caliburn.Micro;
 using Pithos.Client.WPF.Properties;
 using Pithos.Core;
-using Pithos.Core.Agents;
 using Pithos.Interfaces;
-using Pithos.Network;
 
 namespace Pithos.Client.WPF.SelectiveSynch
 {
     class SelectiveSynchViewModel:Screen
     {
         private const string DirectoryType = "application/directory";
-        private IEventAggregator _events ;
+        private readonly IEventAggregator _events ;
 
         private string _title;
         public string Title
@@ -81,7 +76,7 @@ namespace Pithos.Client.WPF.SelectiveSynch
         }
 
         private ObservableCollection<ObjectInfo> _checks;
-        private PithosMonitor _monitor;
+        private readonly PithosMonitor _monitor;
         private bool _isBusy=true;
 
         public ObservableCollection<ObjectInfo> Checks
@@ -124,8 +119,6 @@ namespace Pithos.Client.WPF.SelectiveSynch
                                   };
             var ownFolders = dirs.ToList();
 
-            var accounts = client.ListSharingAccounts();
-
             var accountNodes=from account in client.ListSharingAccounts()
                              select new DirectoryRecord
                              {
@@ -155,8 +148,8 @@ namespace Pithos.Client.WPF.SelectiveSynch
 
             Execute.OnUIThread(() =>
                                    {
-                                       this.RootNodes.Add(rootItem);
-                                       this.RootNodes.Add(othersNode);
+                                       RootNodes.Add(rootItem);
+                                       RootNodes.Add(othersNode);
                                    });
 
             SetInitialSelections(Account);
diff --git a/trunk/Pithos.Core/FileState.cs b/trunk/Pithos.Core/FileState.cs
index 559d584..58f91be 100644
--- a/trunk/Pithos.Core/FileState.cs
+++ b/trunk/Pithos.Core/FileState.cs
@@ -420,11 +420,11 @@ namespace Pithos.Core
         }
 
         /// <summary>
-        /// Remove all FileState rows from the database whose path
+        /// Mark Unversioned all FileState rows from the database whose path
         /// starts with one of the removed paths
         /// </summary>
         /// <param name="removed"></param>
-        public static void RemovePaths(List<string> removed)
+        public static void UnversionPaths(List<string> removed)
         {
             if (removed == null)
                 return;
@@ -442,15 +442,24 @@ namespace Pithos.Core
 
             //Generate a query from the disjunction
             var query=QueryOver.Of<FileState>().Where(disjunction);
-            //Adn retrieveonly the IDs
-            var idQuery = new ProjectionQuery<FileState,Guid>(query.DetachedCriteria,
-                Projections.ProjectionList()
-                .Add(Projections.Id()));
-            
-            var ids=idQuery.Execute();
-            DeleteAll(ids);
-                
+                        
+            ExecuteWithRetry((session,instance)=>
+                                 {
+                                     using (var t=session.BeginTransaction())
+                                     {
+                                         var states = query.GetExecutableQueryOver(session).List();
+                                         foreach (var state in states)
+                                         {
+                                             state.FileStatus = FileStatus.Unversioned;
+                                             state.OverlayStatus = FileOverlayStatus.Unversioned;
+                                             state.Update();
+                                         }
+                                         t.Commit();
+                                     }
+                                     return null;
+                                 },null);
         }
+
     }
 
     [ActiveRecord("Tags")]
diff --git a/trunk/Pithos.Core/IPithosWorkflow.cs b/trunk/Pithos.Core/IPithosWorkflow.cs
index cb8b902..18cc984 100644
--- a/trunk/Pithos.Core/IPithosWorkflow.cs
+++ b/trunk/Pithos.Core/IPithosWorkflow.cs
@@ -62,6 +62,7 @@ namespace Pithos.Core
         Modified,
         Renamed,
         Deleted,
-        Conflict
+        Conflict,
+        Unversioned
     }
 }
\ No newline at end of file
diff --git a/trunk/Pithos.Core/PithosMonitor.cs b/trunk/Pithos.Core/PithosMonitor.cs
index f1f7486..a3fc17c 100644
--- a/trunk/Pithos.Core/PithosMonitor.cs
+++ b/trunk/Pithos.Core/PithosMonitor.cs
@@ -483,12 +483,26 @@ namespace Pithos.Core
             
             FileAgent.SelectivePaths=selectivePaths;
             PollAgent.SetSyncUris(uris);
-
+            
             var removedPaths = UrisToFilePaths(removed);
-            RemoveSelectivePaths(removedPaths);
+            UnversionSelectivePaths(removedPaths);
+
+        }
+
+        /// <summary>
+        /// Mark all unselected paths as Unversioned
+        /// </summary>
+        /// <param name="removed"></param>
+        private void UnversionSelectivePaths(List<string> removed)
+        {
+            if (removed == null)
+                return;
 
+            //Ensure we remove any file state below the deleted folders
+            FileState.UnversionPaths(removed);
         }
 
+
         /// <summary>
         /// Return a list of absolute filepaths from a list of Uris
         /// </summary>
@@ -507,27 +521,6 @@ namespace Pithos.Core
                     select Path.Combine(RootPath, relativePath.After(_accountInfo.UserName + '\\'))).ToList();            
         }
 
-        /// <summary>
-        /// Delete the folders that were removed from synchronization
-        /// </summary>
-        /// <param name="removed"></param>
-        private void RemoveSelectivePaths(List<string> removed)
-        {
-            if (removed == null)
-                return;
-
-            foreach (var removedPath in removed.Where(Directory.Exists))
-            {
-                try
-                {
-                    Directory.Delete(removedPath, true);
-                }
-                catch { }
-            }
-
-            //Ensure we remove any file state below the deleted folders
-            FileState.RemovePaths(removed);
-        }
 
         public ObjectInfo GetObjectInfo(string filePath)
         {
