*/
#endregion
using System;
-using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.Composition;
-using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
-using System.Net;
-using System.Net.NetworkInformation;
-using System.Security.Cryptography;
-using System.ServiceModel.Description;
-using System.Text;
+using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
-using Castle.ActiveRecord.Queries;
-using Microsoft.WindowsAPICodePack.Net;
using Pithos.Core.Agents;
using Pithos.Interfaces;
-using System.ServiceModel;
using Pithos.Network;
using log4net;
[Export(typeof(PithosMonitor))]
public class PithosMonitor:IDisposable
{
+ private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
private int _blockSize;
private string _blockHash;
}
private AccountInfo _accountInfo;
-
-
- private static readonly ILog Log = LogManager.GetLogger(typeof(PithosMonitor));
+
+
public bool Pause
return;
}
_cancellationSource = new CancellationTokenSource();
-
- CloudClient=new CloudFilesClient(UserName,ApiKey);
- CloudClient.UsePithos = true;
- CloudClient.AuthenticationUrl = this.AuthenticationUrl;
+
+ CloudClient = new CloudFilesClient(UserName, ApiKey)
+ {UsePithos = true, AuthenticationUrl = AuthenticationUrl};
+
_accountInfo = CloudClient.Authenticate();
_accountInfo.SiteUri = AuthenticationUrl;
var pithosContainers = new List<string>{ FolderConstants.TrashContainer,FolderConstants.PithosContainer};
foreach (var container in pithosContainers)
{
- var info=CloudClient.GetContainerInfo(this.UserName, container);
+ var info=CloudClient.GetContainerInfo(UserName, container);
if (info == ContainerInfo.Empty)
{
- CloudClient.CreateContainer(this.UserName, container);
- info = CloudClient.GetContainerInfo(this.UserName, container);
+ CloudClient.CreateContainer(UserName, container);
+ info = CloudClient.GetContainerInfo(UserName, container);
}
_blockSize = info.BlockSize;
_blockHash = info.BlockHash;
private void IndexLocalFiles()
{
- StatusNotification.NotifyChange("Indexing Local Files",TraceLevel.Info);
- using (log4net.ThreadContext.Stacks["Monitor"].Push("Indexing local files"))
+ StatusNotification.NotifyChange("Indexing Local Files");
+ using (ThreadContext.Stacks["Monitor"].Push("Indexing local files"))
{
Log.Info("START");
try
public override int GetHashCode(CloudAction obj)
{
+ if (obj == null)
+ return 0;
var hash1 = (obj.LocalFile == null) ? int.MaxValue : obj.LocalFile.FullName.GetHashCode();
var hash2 = (obj.CloudFile == null) ? int.MaxValue : (obj.CloudFile.Hash ?? obj.CloudFile.Name??"").GetHashCode();
var hash3 = obj.Action.GetHashCode();
}
}
- private Timer timer;
-
private void StartNetworkAgent()
{
- NetworkAgent.AddAccount(_accountInfo);
-
NetworkAgent.StatusNotification = StatusNotification;
NetworkAgent.Start();
}
//Make sure a hidden cache folder exists to store partial downloads
- private static string CreateHiddenFolder(string rootPath, string folderName)
+ private static void CreateHiddenFolder(string rootPath, string folderName)
{
if (String.IsNullOrWhiteSpace(rootPath))
throw new ArgumentNullException("rootPath");
Log.InfoFormat("Reset cache folder to hidden: {0}", folder);
}
}
- return folder;
}
if (FileAgent!=null)
FileAgent.Stop();
FileAgent = null;
- if (timer != null)
- timer.Dispose();
- timer = null;
}
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>
let relativePath = _accountInfo.StorageUri
.MakeRelativeUri(uri)
.RelativeUriToFilePath()
- select Path.Combine(RootPath, relativePath)).ToList();
+ //Trim the account name
+ 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))
- {
- Directory.Delete(removedPath,true);
- }
-
- //Ensure we remove any file state below the deleted folders
- FileState.RemovePaths(removed);
- }
public ObjectInfo GetObjectInfo(string filePath)
{
//Create the root URL for the target account
var oldName = UserName;
var absoluteUri = _accountInfo.StorageUri.AbsoluteUri;
- var nameIndex=absoluteUri.IndexOf(oldName);
+ var nameIndex=absoluteUri.IndexOf(oldName, StringComparison.Ordinal);
var root=absoluteUri.Substring(0, nameIndex);
accountInfo = new AccountInfo
}
else
{
- accountName = this.UserName;
+ accountName = UserName;
container = parts[0];
relativeUrl = String.Join("/", parts.Splice(1));
}
//Create the root URL for the target account
var oldName = UserName;
var absoluteUri = _accountInfo.StorageUri.AbsoluteUri;
- var nameIndex=absoluteUri.IndexOf(oldName);
+ var nameIndex=absoluteUri.IndexOf(oldName, StringComparison.Ordinal);
var root=absoluteUri.Substring(0, nameIndex);
accountInfo = new AccountInfo