using System;\r
using System.Collections.Concurrent;\r
-using System.Collections.Generic;
-using System.ComponentModel.Composition;
-using System.IO;
-using System.Linq;
-using System.Text;
-using Pithos.Interfaces;
-using Pithos.Network;
-
-namespace Pithos.Core.Agents
-{
- [Export(typeof(Selectives))]
- public class Selectives
- {
-
- public ConcurrentDictionary<Uri, List<Uri>> SelectiveUris { get; private set; }
-
- private ConcurrentDictionary<Uri, List<string>> SelectivePaths { get; set; }
-
- public Selectives()
+using System.Collections.Generic;\r
+using System.ComponentModel.Composition;\r
+using System.IO;\r
+using System.Linq;\r
+using System.Text;\r
+using Pithos.Interfaces;\r
+using Pithos.Network;\r
+\r
+namespace Pithos.Core.Agents\r
+{\r
+ [Export(typeof(Selectives))]\r
+ public class Selectives\r
+ {\r
+\r
+ public ConcurrentDictionary<Uri, List<Uri>> SelectiveUris { get; private set; }\r
+\r
+ private ConcurrentDictionary<Uri, List<string>> SelectivePaths { get; set; }\r
+\r
+ public Selectives()\r
{\r
SelectiveUris = new ConcurrentDictionary<Uri, List<Uri>>();\r
- SelectivePaths = new ConcurrentDictionary<Uri, List<string>>();
- }
-
- public void SetSelectedUris(AccountInfo account,List<Uri> uris)
- {
- SelectiveUris[account.AccountKey] = uris;
- SelectivePaths[account.AccountKey] = UrisToFilePaths(account,uris);
- }
-
- public bool IsSelected(ObjectInfo info)
- {
- List<Uri> filterUris;
- return !SelectiveUris.TryGetValue(info.AccountKey, out filterUris)
- || filterUris.Count ==0
- || filterUris.Any(f => info.Uri.IsAtOrDirectlyBelow(f));
- }
-
- public bool IsSelected(AccountInfo account,FileSystemInfo info)
- {
- return IsSelected(account,info.FullName);
- }
-
- public bool IsSelected(AccountInfo account, string fullPath)
- {
- List<string> paths;
- return !SelectivePaths.TryGetValue(account.AccountKey, out paths)
- || paths.Count == 0
- || paths.Any(fullPath.IsAtOrDirectlyBelow);
- }
-
- /// <summary>
- /// Return a list of absolute filepaths from a list of Uris
- /// </summary>
- /// <param name="uris"></param>
- /// <returns></returns>
- private List<string> UrisToFilePaths(AccountInfo account,IEnumerable<Uri> uris)
- {
- if (uris == null)
- return new List<string>();
-
- var accountPath = account.AccountPath;
- var storageUrl = account.StorageUri.ToString();
- var own = (from uri in uris
- where uri.ToString().StartsWith(storageUrl)
- let relativePath = account.StorageUri.MakeRelativeUri(uri).RelativeUriToFilePath()
- //Trim the account name
- select Path.Combine(accountPath, relativePath.After(account.UserName + '\\'))).ToList();
- var others = (from uri in uris
- where !uri.ToString().StartsWith(storageUrl)
- let relativePath = account.StorageUri.MakeRelativeUri(uri).RelativeUriToFilePath()
- //Trim the account name
- select Path.Combine(accountPath, "others-shared", relativePath)).ToList();
- return own.Union(others).ToList();
- }
-
- }
-}
+ SelectivePaths = new ConcurrentDictionary<Uri, List<string>>();\r
+ }\r
+\r
+ public void SetSelectedUris(AccountInfo account,List<Uri> uris)\r
+ {\r
+ SelectiveUris[account.AccountKey] = uris;\r
+ SelectivePaths[account.AccountKey] = UrisToFilePaths(account,uris);\r
+ }\r
+\r
+ public bool IsSelected(ObjectInfo info)\r
+ {\r
+ List<Uri> filterUris;\r
+ return !SelectiveUris.TryGetValue(info.AccountKey, out filterUris) \r
+ || filterUris.Count ==0\r
+ || filterUris.Any(f => info.Uri.IsAtOrDirectlyBelow(f));\r
+ }\r
+\r
+ public bool IsSelected(AccountInfo account,FileSystemInfo info)\r
+ {\r
+ return IsSelected(account,info.FullName);\r
+ }\r
+\r
+ public bool IsSelected(AccountInfo account, string fullPath)\r
+ {\r
+ List<string> paths;\r
+ return !SelectivePaths.TryGetValue(account.AccountKey, out paths)\r
+ || paths.Count == 0\r
+ || paths.Any(fullPath.IsAtOrDirectlyBelow);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Return a list of absolute filepaths from a list of Uris\r
+ /// </summary>\r
+ /// <param name="uris"></param>\r
+ /// <returns></returns>\r
+ private List<string> UrisToFilePaths(AccountInfo account,IEnumerable<Uri> uris)\r
+ {\r
+ if (uris == null)\r
+ return new List<string>();\r
+\r
+ var accountPath = account.AccountPath;\r
+ var storageUrl = account.StorageUri.ToString();\r
+ var own = (from uri in uris\r
+ where uri.ToString().StartsWith(storageUrl)\r
+ let relativePath = account.StorageUri.MakeRelativeUri(uri).RelativeUriToFilePath()\r
+ //Trim the account name\r
+ select Path.Combine(accountPath, relativePath.After(account.UserName + '\\'))).ToList();\r
+ var others = (from uri in uris\r
+ where !uri.ToString().StartsWith(storageUrl)\r
+ let relativePath = account.StorageUri.MakeRelativeUri(uri).RelativeUriToFilePath()\r
+ //Trim the account name\r
+ select Path.Combine(accountPath, "others-shared", relativePath)).ToList();\r
+ return own.Union(others).ToList();\r
+ }\r
+\r
+ }\r
+}\r