private void CrawlChangeLogSyncAndUpdateChangeLogToken(IList<IChangeEvent> changeLogs, IFolder remoteFolder, string remotePath, string localFolder)
{
SleepWhileSuspended();
var sw = new System.Diagnostics.Stopwatch();
activityListener.ActivityStarted();
try
{
sw.Start();
Logger.InfoFormat("Change log sync start : {0} logs", changeLogs.Count());
// TODO: Compact changelogs
foreach (var change in changeLogs)
{
var id = change.ObjectId;
try
{
Logger.InfoFormat("Change log : Type={0}, Name={1}, Id={2}", change.ChangeType, change.Properties["cmis:name"].First(), id);
}
catch
{
Logger.InfoFormat("Change log : Type={0}, Id={1} ", change.ChangeType, id);
}
try
{
var cmisObject = session.GetObject(id);
CrawlCmisObject(cmisObject);
}
catch (CmisObjectNotFoundException ex)
{
if (change.ChangeType == ChangeType.Deleted)
{
var local = database.GetSyncItem(id);
if (local != null)
{
var destFolderPath = Path.GetDirectoryName(local.LocalPath);
var destFolderItem = SyncItemFactory.CreateFromLocalPath(destFolderPath, true, repoInfo, database);
try
{
var destCmisFolder = session.GetObjectByPath(destFolderItem.RemotePath) as IFolder;
if (local.IsFolder)
{
CrawlSync(destCmisFolder, destFolderItem.RemotePath, destFolderItem.LocalPath);
}
else
{
CheckLocalFile(local.LocalPath, destCmisFolder, new List<string>());
}
}
catch (Exception e)
{
if (e is ArgumentNullException || e is CmisObjectNotFoundException)
{
// GetObjectByPath failure
Logger.InfoFormat("Remote parent object not found, ignore. {0}", destFolderItem.RemotePath);
}
else
{
throw;
}
}
}
else
{
Logger.InfoFormat("Remote deleted object not in local database, ignore. {0}", id);
}
}
else
{
Logger.InfoFormat("Remote object not found but delete event, ignore. {0}", id);
}
}
catch (Exception ex)
{
Logger.Debug(ex);
}
}
sw.Stop();
Logger.InfoFormat("Change log sync end : {1} min / {0} logs", changeLogs.Count(), sw.Elapsed);
}
finally
{
activityListener.ActivityStopped();
}
}