Added option to disable selective Synchronization
authorpkanavos <pkanavos@gmail.com>
Mon, 7 May 2012 19:52:02 +0000 (22:52 +0300)
committerpkanavos <pkanavos@gmail.com>
Mon, 7 May 2012 19:52:02 +0000 (22:52 +0300)
When selective sync is disabled only owned files are synchronized. Shared files are not synchronized.
Folders (not their contents) are synchronized even when selective sync is disabled

13 files changed:
trunk/Pithos.Client.WPF/Preferences/PreferencesView.xaml
trunk/Pithos.Client.WPF/Preferences/PreferencesViewModel.cs
trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs
trunk/Pithos.Client.WPF/Properties/Settings.settings
trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchChanges.cs
trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchView.xaml
trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
trunk/Pithos.Core/Agents/CollectionExtensions.cs
trunk/Pithos.Core/Agents/SelectiveUris.cs
trunk/Pithos.Core/Agents/Uploader.cs
trunk/Pithos.Interfaces/AccountSettings.cs
trunk/Pithos.Interfaces/ObjectInfo.cs

index 687b17e..60cd8c1 100644 (file)
                                 <RowDefinition Height="Auto"/>
                                 <RowDefinition Height="Auto"/>
                                 <RowDefinition Height="Auto"/>
+                                <RowDefinition Height="Auto"/>
+                                <RowDefinition Height="Auto"/>
                                 <RowDefinition />
                             </Grid.RowDefinitions>
                             <Label Content="Server" Grid.Column="0" Grid.Row="0" Margin="0,5" HorizontalAlignment="Left"/>
                                     <ColumnDefinition Width="*"/>
                                     <ColumnDefinition Width="Auto"/>
                                 </Grid.ColumnDefinitions>
-                                <TextBox  Name="CurrentAccount_RootPath" Margin="1,5,5,-30" HorizontalAlignment="Stretch" IsReadOnly="True" ToolTip="{Binding CurrentAccount.RootPath}" Height="61" TextWrapping="WrapWithOverflow" />
+                                <TextBox  Name="CurrentAccount_RootPath" Margin="5" HorizontalAlignment="Stretch" IsReadOnly="True" ToolTip="{Binding CurrentAccount.RootPath}" Height="61" TextWrapping="WrapWithOverflow" />
                             </Grid>
-                            <CheckBox Name="CurrentAccount_IsActive" Content="Account is Active" Grid.Row="6" Margin="6,66,230,6" Grid.ColumnSpan="2"  />
-                            <Button Name="SelectiveSyncFolders" Content="Selective Sync" Width="100" Style="{StaticResource ButtonStyle}" Grid.Row="6" Margin="12,40,0,24" Grid.Column="1" />
-                            <Button Name="MoveAccountFolder" Content="Move ..." Margin="20,40,234,24" Grid.Row="6" Grid.Column="1" Width="100"/>
-                            <Button Name="ClearAccountCache" Content="Clear Cache" Margin="245,40,9,24" Grid.Row="6" Grid.Column="1" Width="100" />
-                            <CheckBox Name="Selective_IsActive" Content="Enable Selective Sync" Grid.Row="6" Margin="132,66,80,6" Grid.Column="2" Grid.ColumnSpan="2" IsChecked="False" />
+                            <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="1">
+                                <Button Name="SelectiveSyncFolders" Content="Selective Sync" Width="100" Style="{StaticResource ButtonStyle}" />
+                                <Button Name="MoveAccountFolder" Content="Move ..." Width="100" Style="{StaticResource ButtonStyle}"/>
+                                <Button Name="ClearAccountCache" Content="Clear Cache" Width="100" Style="{StaticResource ButtonStyle}"/>
+                            </StackPanel>
+                            <CheckBox  Name="CurrentAccount_IsActive" Content="Account is Active" Grid.Row="7"  Grid.Column="1"  />
                         </Grid>
                         
                     </GroupBox>
index 2b5f249..01c99c3 100644 (file)
@@ -225,7 +225,7 @@ namespace Pithos.Client.WPF.Preferences
             //var monitor = Shell.Monitors[CurrentAccount.AccountKey];\r
             \r
 \r
-            var model = new SelectiveSynchViewModel(/*monitor,*/_events,CurrentAccount.Account,CurrentAccount.ApiKey);\r
+            var model = new SelectiveSynchViewModel(_events,CurrentAccount.Account,CurrentAccount.ApiKey);            \r
             if (_windowManager.ShowDialog(model) == true)\r
             {\r
                 \r
index 220d9ff..1718b04 100644 (file)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.431
+//     Runtime Version:4.0.30319.530
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -389,20 +389,21 @@ namespace Pithos.Client.WPF.Properties {
         
         [global::System.Configuration.ApplicationScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute(@"
-                                       <ArrayOfServerSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
-                                               <ServerSettings>
-                                                       <ServerUri>https://pithos.okeanos.grnet.gr</ServerUri>
-                                                       <LoginUri>https://pithos.okeanos.grnet.gr/login</LoginUri>
-                                                       <LogoutUri>https://accounts.okeanos.grnet.gr/im/logout</LogoutUri>
-                                               </ServerSettings>
-                                               <ServerSettings>
-                                                       <ServerUri>https://pithos.dev.grnet.gr</ServerUri>
-                                                       <LoginUri>https://pithos.dev.grnet.gr/login</LoginUri>
-                                                       <LogoutUri>https://pithos.dev.grnet.gr/im/logout</LogoutUri>
-                                               </ServerSettings>
-                                       </ArrayOfServerSettings>
-                               ")]
+        [global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
+<ArrayOfServerSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
+  <ServerSettings>
+<ServerName>Pithos Production</ServerName>
+    <ServerUri>https://pithos.okeanos.grnet.gr</ServerUri>
+    <LoginUri>https://pithos.okeanos.grnet.gr/login</LoginUri>
+    <LogoutUri>https://accounts.okeanos.grnet.gr/im/logout</LogoutUri>
+  </ServerSettings>
+  <ServerSettings>
+<ServerName>Pithos Development</ServerName>
+    <ServerUri>https://pithos.dev.grnet.gr</ServerUri>
+    <LoginUri>https://pithos.dev.grnet.gr/login</LoginUri>
+    <LogoutUri>https://pithos.dev.grnet.gr/im/logout</LogoutUri>
+  </ServerSettings>
+</ArrayOfServerSettings>")]
         public global::Pithos.Interfaces.ServersCollection Servers {
             get {
                 return ((global::Pithos.Interfaces.ServersCollection)(this["Servers"]));
index d4af2ad..dca5124 100644 (file)
       <Value Profile="(Default)">False</Value>
     </Setting>
     <Setting Name="Servers" Type="Pithos.Interfaces.ServersCollection" Scope="Application">
-      <Value Profile="(Default)">
-                                       &lt;ArrayOfServerSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
-                                               &lt;ServerSettings&gt;
-                                                       &lt;ServerUri&gt;https://pithos.okeanos.grnet.gr&lt;/ServerUri&gt;
-                                                       &lt;LoginUri&gt;https://pithos.okeanos.grnet.gr/login&lt;/LoginUri&gt;
-                                                       &lt;LogoutUri&gt;https://accounts.okeanos.grnet.gr/im/logout&lt;/LogoutUri&gt;
-                                               &lt;/ServerSettings&gt;
-                                               &lt;ServerSettings&gt;
-                                                       &lt;ServerUri&gt;https://pithos.dev.grnet.gr&lt;/ServerUri&gt;
-                                                       &lt;LoginUri&gt;https://pithos.dev.grnet.gr/login&lt;/LoginUri&gt;
-                                                       &lt;LogoutUri&gt;https://pithos.dev.grnet.gr/im/logout&lt;/LogoutUri&gt;
-                                               &lt;/ServerSettings&gt;
-                                       &lt;/ArrayOfServerSettings&gt;
-                               </Value>
+      <Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
+&lt;ArrayOfServerSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
+  &lt;ServerSettings&gt;
+&lt;ServerName&gt;Pithos Production&lt;/ServerName&gt;
+    &lt;ServerUri&gt;https://pithos.okeanos.grnet.gr&lt;/ServerUri&gt;
+    &lt;LoginUri&gt;https://pithos.okeanos.grnet.gr/login&lt;/LoginUri&gt;
+    &lt;LogoutUri&gt;https://accounts.okeanos.grnet.gr/im/logout&lt;/LogoutUri&gt;
+  &lt;/ServerSettings&gt;
+  &lt;ServerSettings&gt;
+&lt;ServerName&gt;Pithos Development&lt;/ServerName&gt;
+    &lt;ServerUri&gt;https://pithos.dev.grnet.gr&lt;/ServerUri&gt;
+    &lt;LoginUri&gt;https://pithos.dev.grnet.gr/login&lt;/LoginUri&gt;
+    &lt;LogoutUri&gt;https://pithos.dev.grnet.gr/im/logout&lt;/LogoutUri&gt;
+  &lt;/ServerSettings&gt;
+&lt;/ArrayOfServerSettings&gt;</Value>
     </Setting>
   </Settings>
 </SettingsFile>
\ No newline at end of file
index 4801079..0d686a5 100644 (file)
@@ -49,6 +49,7 @@ namespace Pithos.Client.WPF.SelectiveSynch
 {
     public class SelectiveSynchChanges
     {
+        public bool Enabled { get; set; }
         public Uri[] Uris { get; set; }
         public AccountSettings Account { get; set; }
         public Uri[] Added { get; set; }
index f6a6b2b..d43a83a 100644 (file)
 
 
     </Window.Resources>
-    <Grid>
+    <extToolkit:BusyIndicator Name="IsBusy" BusyContent="Retrieving folders ..." DisplayAfter="0">
+        <Grid>
         <Grid.RowDefinitions>
+            <RowDefinition Height="Auto"/>
             <RowDefinition Height="*"/>
             <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
-        <extToolkit:BusyIndicator Name="IsBusy" Grid.Row="0" BusyContent="Retrieving folders ..." DisplayAfter="0">
-            <TreeView  Name="RootNodes" Margin="5"
-                  ItemContainerStyle="{StaticResource TreeItemStyle}" 
-                  ItemTemplate="{StaticResource CheckboxStyle}">
-            </TreeView>
-        </extToolkit:BusyIndicator>
-        <StackPanel Grid.Row="1">
+        <CheckBox x:Name="IsEnabled" Content="Enable Selective Syncing" Margin="5" Grid.Row="0"/>
+        <TreeView  Name="RootNodes" Margin="5" Grid.Row="1"
+                ItemContainerStyle="{StaticResource TreeItemStyle}" 
+                ItemTemplate="{StaticResource CheckboxStyle}"
+                    IsEnabled="{Binding IsEnabled}" >
+        </TreeView>
+        <StackPanel Grid.Row="2">
             <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
                 <Button Name="SaveChanges" Content="OK" Margin="5,5,10,5"  Style="{StaticResource ButtonStyle}"/>
                 <Button Name="RejectChanges" Content="Cancel" Margin="5,5,10,5"  Style="{StaticResource ButtonStyle}"/>                
             </StackPanel>
         </StackPanel>
     </Grid>
+    </extToolkit:BusyIndicator>
 </Window>
index abfe6d9..e680d88 100644 (file)
@@ -94,6 +94,7 @@ namespace Pithos.Client.WPF.SelectiveSynch
             //_monitor = monitor;\r
             _events = events;\r
             _apiKey = apiKey;\r
+            IsEnabled = account.SelectiveSyncEnabled;\r
             TaskEx.Run(LoadRootNode);\r
         }\r
 \r
@@ -267,7 +268,7 @@ namespace Pithos.Client.WPF.SelectiveSynch
                           where record.Removed && record.Uri != null\r
                          select record.Uri).ToArray();\r
             //TODO: Include Uris for the containers as well\r
-            _events.Publish(new SelectiveSynchChanges{Account=Account,Uris=uris,Added=added,Removed=removed});\r
+            _events.Publish(new SelectiveSynchChanges{Enabled=IsEnabled, Account=Account,Uris=uris,Added=added,Removed=removed});\r
             \r
 \r
             \r
@@ -275,11 +276,21 @@ namespace Pithos.Client.WPF.SelectiveSynch
             TryClose(true);\r
         }\r
 \r
-        \r
+        private bool _isEnabled;\r
+        public bool IsEnabled\r
+        {\r
+            get { return _isEnabled; }\r
+            set\r
+            {\r
+                _isEnabled = value;\r
+                NotifyOfPropertyChange(()=>IsEnabled);\r
+            }\r
+        }\r
+\r
         private void SaveSettings(IEnumerable<Uri> uris)\r
         {\r
             var selections = uris.Select(uri => uri.ToString()).ToArray();\r
-\r
+            Account.SelectiveSyncEnabled = IsEnabled;\r
             Account.SelectiveFolders.Clear();\r
             Account.SelectiveFolders.AddRange(selections);\r
             Settings.Default.Save();            \r
index 5dbb37e..dd3999d 100644 (file)
@@ -997,6 +997,7 @@ namespace Pithos.Client.WPF {
                        PithosMonitor monitor;
                        if (Monitors.TryGetValue(message.Account.AccountKey, out monitor))
                        {
+                    monitor.Selectives.SetIsSelectiveEnabled(message.Account.AccountKey, message.Enabled);
                            monitor.SetSelectivePaths(message.Uris, message.Added, message.Removed);
                        }
 
index b4ecd38..7282511 100644 (file)
 #endregion\r
 using System.Collections.Concurrent;\r
 using System.Diagnostics.Contracts;\r
+using System.IO;\r
 using Pithos.Interfaces;\r
 using System;\r
 using System.Collections.Generic;\r
 using System.Linq;\r
+using Pithos.Network;\r
 \r
 namespace Pithos.Core.Agents\r
 {\r
@@ -198,6 +200,14 @@ namespace Pithos.Core.Agents
                 && target.IsAtOrBelow(root);\r
         }\r
 \r
+        public static bool IsSharedTo(this string targetPath,AccountInfo account)\r
+        {\r
+            var othersFolder = Path.Combine(account.AccountPath, FolderConstants.OthersFolder);\r
+            var isShared = targetPath.IsAtOrBelow(othersFolder);\r
+            return isShared;\r
+\r
+        }\r
+\r
         /// <summary>\r
         /// Checkes whether a file path is below a root path\r
         /// </summary>\r
index ee2fa49..225e791 100644 (file)
@@ -24,6 +24,37 @@ namespace Pithos.Core.Agents
             SelectivePaths = new ConcurrentDictionary<Uri, List<string>>();\r
         }\r
 \r
+        readonly Dictionary<Uri, bool> _selectiveEnabled = new Dictionary<Uri, bool>();\r
+\r
+/*\r
+        public void SetIsSelectiveEnabled(AccountInfo account,bool value)\r
+        {\r
+            _selectiveEnabled[account.AccountKey]=value;\r
+        }\r
+*/\r
+\r
+        public void SetIsSelectiveEnabled(Uri accountKey,bool value)\r
+        {\r
+            _selectiveEnabled[accountKey]=value;\r
+        }\r
+/*\r
+\r
+        public bool IsSelectiveEnabled(AccountInfo account)\r
+        {\r
+            bool isEnabled;\r
+            _selectiveEnabled.TryGetValue(account.AccountKey, out isEnabled);\r
+            return isEnabled;\r
+        }\r
+*/\r
+\r
+        public bool IsSelectiveEnabled(Uri accountKey)\r
+        {\r
+            bool isEnabled;\r
+            _selectiveEnabled.TryGetValue(accountKey, out isEnabled);\r
+            return isEnabled;\r
+        }\r
+\r
+\r
         public void SetSelectedUris(AccountInfo account,List<Uri> uris)\r
         {\r
             SelectiveUris[account.AccountKey] = uris;\r
@@ -32,6 +63,12 @@ namespace Pithos.Core.Agents
 \r
         public bool IsSelected(ObjectInfo info)\r
         {\r
+            //Shared folders should NOT be synced if selective syncing is disabled\r
+            var isShared = info.IsShared;\r
+            var selectiveEnabled = IsSelectiveEnabled(info.AccountKey);\r
+            if (!selectiveEnabled)\r
+                return !isShared;\r
+\r
             List<Uri> filterUris;\r
             return !SelectiveUris.TryGetValue(info.AccountKey, out filterUris) \r
                 || filterUris.Count ==0\r
@@ -40,11 +77,22 @@ namespace Pithos.Core.Agents
 \r
         public bool IsSelected(AccountInfo account,FileSystemInfo info)\r
         {\r
+            if (info is DirectoryInfo)\r
+                return true;\r
             return IsSelected(account,info.FullName);\r
         }\r
 \r
         public bool IsSelected(AccountInfo account, string fullPath)\r
         {\r
+            if (Directory.Exists(fullPath))\r
+                return true;\r
+\r
+            //Shared folders should NOT be synced if selective syncing is disabled\r
+            var isShared = fullPath.IsSharedTo(account);\r
+            var selectiveEnabled = IsSelectiveEnabled(account.AccountKey);\r
+            if (!selectiveEnabled)\r
+                return !isShared;\r
+\r
             List<string> paths;\r
             return !SelectivePaths.TryGetValue(account.AccountKey, out paths)\r
                 || paths.Count == 0\r
index 168ada6..094d2f9 100644 (file)
@@ -50,7 +50,7 @@ namespace Pithos.Core.Agents
                     if (fileInfo.Extension.Equals("ignore", StringComparison.InvariantCultureIgnoreCase))\r
                         return;\r
 \r
-                    if (Selectives.IsSelected(action.AccountInfo, fileInfo))\r
+                    if (!Selectives.IsSelected(action.AccountInfo, fileInfo))\r
                         return;\r
 \r
                     //Try to load the action's local state, if it is empty\r
index 69bff8f..7ebfcd5 100644 (file)
@@ -67,10 +67,12 @@ namespace Pithos.Interfaces
 
         public string ServerUrl { get; set; }
 
-        private StringCollection _selectiveFolders = new StringCollection();
-
         public bool IsExpired { get; set; }
 
+        public bool SelectiveSyncEnabled { get; set; }
+
+        private StringCollection _selectiveFolders = new StringCollection();
+
         public StringCollection SelectiveFolders
         {
             get { return _selectiveFolders; }
@@ -81,6 +83,7 @@ namespace Pithos.Interfaces
 
     public class ServerSettings
     {
+        public string ServerName { get; set; }
         public string ServerUri { get; set; }
         public string LoginUri { get; set; }
         public string LogoutUri { get; set; }
index 484a39a..e0bd7b6 100644 (file)
@@ -375,5 +375,14 @@ namespace Pithos.Interfaces
             PreviousHash = previous.Hash;
             return this;
         }
+
+        public bool IsShared
+        {
+            get
+            {
+                var isShared = !Uri.ToString().StartsWith(StorageUri.ToString());
+                return isShared;
+            }
+        }
     }
 }
\ No newline at end of file