_accountInfo = CloudClient.Authenticate();
_accountInfo.AccountPath = RootPath;
+
+ var pithosFolder = Path.Combine(RootPath, FolderConstants.PithosContainer);
+ if (!Directory.Exists(pithosFolder))
+ Directory.CreateDirectory(pithosFolder);
+ //Create the cache folder and ensure it is hidden
+ CreateHiddenFolder(RootPath, FolderConstants.CacheFolder);
+
var policy=CloudClient.GetAccountPolicies(_accountInfo);
StatusNotification.NotifyAccount(policy);
Log.Info("START");
try
{
- var fragmentsPath = Path.Combine(RootPath, FolderConstants.FragmentsFolder);
+ var cachePath = Path.Combine(RootPath, FolderConstants.CacheFolder);
var directory = new DirectoryInfo(RootPath);
var files =
from file in directory.EnumerateFiles("*", SearchOption.AllDirectories)
- where !file.FullName.StartsWith(fragmentsPath, StringComparison.InvariantCultureIgnoreCase) &&
+ where !file.FullName.StartsWith(cachePath, StringComparison.InvariantCultureIgnoreCase) &&
!file.Extension.Equals("ignore", StringComparison.InvariantCultureIgnoreCase)
select file;
StatusKeeper.ProcessExistingFiles(files);
NetworkAgent.ProcessRemoteFiles();
}
- //Make sure a hidden fragments folder exists to store partial downloads
+ //Make sure a hidden cache folder exists to store partial downloads
private static string CreateHiddenFolder(string rootPath, string folderName)
{
if (String.IsNullOrWhiteSpace(rootPath))
var info = Directory.CreateDirectory(folder);
info.Attributes |= FileAttributes.Hidden;
- Log.InfoFormat("Created Fragments Folder: {0}", folder);
+ Log.InfoFormat("Created cache Folder: {0}", folder);
+ }
+ else
+ {
+ var info = new DirectoryInfo(folder);
+ if ((info.Attributes & FileAttributes.Hidden) == 0)
+ {
+ info.Attributes |= FileAttributes.Hidden;
+ Log.InfoFormat("Reset cache folder to hidden: {0}", folder);
+ }
}
return folder;
}
FileAgent.StatusKeeper = StatusKeeper;
FileAgent.Workflow = Workflow;
- FileAgent.FragmentsPath = Path.Combine(RootPath, FolderConstants.FragmentsFolder);
+ FileAgent.CachePath = Path.Combine(RootPath, FolderConstants.CacheFolder);
FileAgent.Start(_accountInfo, RootPath);
}
public IEnumerable<string> GetRootFolders()
{
- var dirs=CloudClient.ListObjects(UserName, FolderConstants.PithosContainer, "");
- return from dir in dirs
- select dir.Name;
+ var dirs = from container in CloudClient.ListContainers(UserName)
+ from dir in CloudClient.ListObjects(UserName, container.Name, "")
+ select dir.Name;
+ return dirs;
+ }
+
+ public ObjectInfo GetObjectInfo(string filePath)
+ {
+ if (String.IsNullOrWhiteSpace(filePath))
+ throw new ArgumentNullException("filePath");
+ Contract.EndContractBlock();
+
+ var file=new FileInfo(filePath);
+ string relativeUrl;//=file.AsRelativeUrlTo(this.RootPath);
+ var relativePath = file.AsRelativeTo(RootPath);
+
+ string accountName,container;
+
+ var parts=relativePath.Split('\\');
+
+ var accountInfo = _accountInfo;
+ if (relativePath.StartsWith(FolderConstants.OthersFolder))
+ {
+ accountName = parts[1];
+ container = parts[2];
+ relativeUrl = String.Join("/", parts.Splice(3));
+ //Create the root URL for the target account
+ var oldName = UserName;
+ var absoluteUri = _accountInfo.StorageUri.AbsoluteUri;
+ var nameIndex=absoluteUri.IndexOf(oldName);
+ var root=absoluteUri.Substring(0, nameIndex);
+
+ accountInfo = new AccountInfo
+ {
+ UserName = accountName,
+ AccountPath = Path.Combine(accountInfo.AccountPath, parts[0], parts[1]),
+ StorageUri = new Uri(root + accountName),
+ BlockHash=accountInfo.BlockHash,
+ BlockSize=accountInfo.BlockSize,
+ Token=accountInfo.Token
+ };
+ }
+ else
+ {
+ accountName = this.UserName;
+ container = parts[0];
+ relativeUrl = String.Join("/", parts.Splice(1));
+ }
+
+ var client = new CloudFilesClient(accountInfo);
+ var objectInfo=client.GetObjectInfo(accountName, container, relativeUrl);
+ return objectInfo;
+ }
+
+ public ContainerInfo GetContainerInfo(string filePath)
+ {
+ if (String.IsNullOrWhiteSpace(filePath))
+ throw new ArgumentNullException("filePath");
+ Contract.EndContractBlock();
+
+ var file=new FileInfo(filePath);
+ var relativePath = file.AsRelativeTo(RootPath);
+
+ string accountName,container;
+
+ var parts=relativePath.Split('\\');
+
+ var accountInfo = _accountInfo;
+ if (relativePath.StartsWith(FolderConstants.OthersFolder))
+ {
+ accountName = parts[1];
+ container = parts[2];
+ //Create the root URL for the target account
+ var oldName = UserName;
+ var absoluteUri = _accountInfo.StorageUri.AbsoluteUri;
+ var nameIndex=absoluteUri.IndexOf(oldName);
+ var root=absoluteUri.Substring(0, nameIndex);
+
+ accountInfo = new AccountInfo
+ {
+ UserName = accountName,
+ AccountPath = Path.Combine(accountInfo.AccountPath, parts[0], parts[1]),
+ StorageUri = new Uri(root + accountName),
+ BlockHash=accountInfo.BlockHash,
+ BlockSize=accountInfo.BlockSize,
+ Token=accountInfo.Token
+ };
+ }
+ else
+ {
+ accountName = UserName;
+ container = parts[0];
+ }
+
+ var client = new CloudFilesClient(accountInfo);
+ var containerInfo=client.GetContainerInfo(accountName, container);
+ return containerInfo;
}
}