public void SyncRemote(string canonical_name, string localPath, string remoteFolderPath,
string url, string user, string password, string repositoryId)
{
// Prepare checkout directory.
string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name);
CleanDirectory(localDirectory);
Console.WriteLine("Synced to clean state.");
// Mock.
IActivityListener activityListener = new Mock<IActivityListener>().Object;
// Sync.
RepoInfo repoInfo = new RepoInfo(
canonical_name,
CMISSYNCDIR,
remoteFolderPath,
url,
user,
password,
repositoryId,
5000,
false,
DateTime.MinValue,
true);
using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener))
{
using (CmisRepo.SynchronizedFolder synchronizedFolder =
new CmisRepo.SynchronizedFolder(repoInfo, cmis, activityListener))
using (Watcher watcher = new Watcher(localDirectory))
{
synchronizedFolder.Sync();
CleanAll(localDirectory);
WatcherTest.WaitWatcher();
synchronizedFolder.Sync();
Console.WriteLine("Synced to clean state.");
ISession session = CreateSession(repoInfo);
IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath);
string name1 = "SyncChangeLog.1";
string path1 = Path.Combine(localDirectory, name1);
string name2 = "SyncChangeLog.2";
string path2 = Path.Combine(localDirectory, name2);
// create document
Console.WriteLine(" Remote create file");
Assert.IsFalse(File.Exists(path1));
IDocument doc1 = CreateDocument(folder, name1, "SyncChangeLog");
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return File.Exists(path1);
}));
Assert.IsTrue(File.Exists(path1));
//TODO: AtomPub does not support copy
//// copy document
//Console.WriteLine(" Remote copy file");
//Assert.IsFalse(File.Exists(path2));
//IDocument doc2 = CopyDocument(folder, doc1, name2);
//synchronizedFolder.Sync();
//Assert.IsTrue(File.Exists(path2));
// rename document
Console.WriteLine(" Remote rename file");
Assert.IsTrue(File.Exists(path1));
Assert.IsFalse(File.Exists(path2));
IDocument doc2 = RenameDocument(doc1, name2);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return !File.Exists(path1) && File.Exists(path2);
}));
Assert.IsFalse(File.Exists(path1));
Assert.IsTrue(File.Exists(path2));
// create folder
Console.WriteLine(" Remote create folder");
Assert.IsFalse(Directory.Exists(path1));
IFolder folder1 = CreateFolder(folder, name1);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return Directory.Exists(path1);
}));
Assert.IsTrue(Directory.Exists(path1));
// move document
Console.WriteLine(" Remote move file");
string filename = Path.Combine(path1, name2);
Assert.IsFalse(File.Exists(filename));
doc2.Move(folder, folder1);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return File.Exists(filename);
}));
// delete document
Console.WriteLine(" Remote delete file");
Assert.IsTrue(File.Exists(filename));
doc2.DeleteAllVersions();
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return !File.Exists(filename);
}));
Assert.IsFalse(File.Exists(filename));
// rename folder
Console.WriteLine(" Remote rename folder");
Assert.IsTrue(Directory.Exists(path1));
Assert.IsFalse(Directory.Exists(path2));
IFolder folder2 = RenameFolder(folder1, name2);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return !Directory.Exists(path1) && Directory.Exists(path2);
}));
Assert.IsFalse(Directory.Exists(path1));
Assert.IsTrue(Directory.Exists(path2));
// move folder
Console.WriteLine(" Remote move folder");
Assert.IsFalse(Directory.Exists(path1));
folder1 = CreateFolder(folder, name1);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return Directory.Exists(path1) && !Directory.Exists(Path.Combine(path2, name1));
}));
Assert.IsTrue(Directory.Exists(path1));
Assert.IsFalse(Directory.Exists(Path.Combine(path2, name1)));
folder1.Move(folder, folder2);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return !Directory.Exists(path1) && Directory.Exists(Path.Combine(path2, name1));
}));
Assert.IsFalse(Directory.Exists(path1));
Assert.IsTrue(Directory.Exists(Path.Combine(path2, name1)));
// move folder with sub folder and sub file
Console.WriteLine(" Remote move folder with subfolder and subfile");
Assert.IsFalse(File.Exists(Path.Combine(path2, name1, name1)));
Assert.IsFalse(Directory.Exists(Path.Combine(path2, name1, name2)));
CreateDocument(folder1, name1, "SyncChangeLog");
CreateFolder(folder1, name2);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return File.Exists(Path.Combine(path2, name1, name1)) && Directory.Exists(Path.Combine(path2, name1, name2));
}));
Assert.IsTrue(File.Exists(Path.Combine(path2, name1, name1)));
Assert.IsTrue(Directory.Exists(Path.Combine(path2, name1, name2)));
folder1.Move(folder2, folder);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return File.Exists(Path.Combine(path1, name1)) && Directory.Exists(Path.Combine(path1, name2));
}));
Assert.IsTrue(File.Exists(Path.Combine(path1, name1)));
Assert.IsTrue(Directory.Exists(Path.Combine(path1, name2)));
// delete folder tree
Console.WriteLine(" Remote delete folder tree");
Assert.IsTrue(Directory.Exists(path1));
folder1.DeleteTree(true, null, true);
Assert.IsTrue(WaitUntilSyncIsDone(synchronizedFolder, delegate {
return !Directory.Exists(path1);
}, 20));
Assert.IsFalse(Directory.Exists(path1));
Assert.IsTrue(Directory.Exists(path2));
folder2.DeleteTree(true, null, true);
WaitUntilSyncIsDone(synchronizedFolder, delegate {
return !Directory.Exists(path2);
});
if(Directory.Exists(path2))
synchronizedFolder.ForceFullSync();
Assert.IsFalse(Directory.Exists(path2));
// Clean.
Console.WriteLine("Clean all.");
Clean(localDirectory, synchronizedFolder);
}
}
}