public override void Solve(
IFileSystemInfo localFileSystemInfo,
IObjectId remoteId,
ContentChangeType localContent = ContentChangeType.NONE,
ContentChangeType remoteContent = ContentChangeType.NONE)
{
Stopwatch completewatch = new Stopwatch();
completewatch.Start();
Logger.Debug("Starting LocalObjectAdded");
localFileSystemInfo.Refresh();
if (!localFileSystemInfo.Exists) {
throw new FileNotFoundException(string.Format("Local file/folder {0} has been renamed/moved/deleted", localFileSystemInfo.FullName));
}
string parentId = Storage.GetRemoteId(this.GetParent(localFileSystemInfo));
if (parentId == null) {
if (this.IsParentReadOnly(localFileSystemInfo)) {
return;
} else {
throw new ArgumentException("ParentId is null => invoke crawl sync to create parent first");
}
}
ICmisObject addedObject;
try {
addedObject = this.AddCmisObject(localFileSystemInfo, parentId, this.Session);
} catch (CmisConstraintException e) {
this.EnsureThatLocalFileNameContainsLegalCharacters(localFileSystemInfo, e);
throw;
} catch (CmisPermissionDeniedException e) {
OperationsLogger.Warn(string.Format("Permission denied while trying to Create the locally added object {0} on the server ({1}).", localFileSystemInfo.FullName, e.Message));
return;
}
Guid uuid = this.WriteOrUseUuidIfSupported(localFileSystemInfo);
OperationsLogger.Info(string.Format("Created remote {2} {0} for {1}", addedObject.Id, localFileSystemInfo.FullName, addedObject is IFolder ? "folder" : "document"));
MappedObject mapped = new MappedObject(
localFileSystemInfo.Name,
addedObject.Id,
localFileSystemInfo is IDirectoryInfo ? MappedObjectType.Folder : MappedObjectType.File,
parentId,
addedObject.ChangeToken)
{
Guid = uuid,
LastRemoteWriteTimeUtc = addedObject.LastModificationDate,
LastLocalWriteTimeUtc = localFileSystemInfo is IFileInfo && (localFileSystemInfo as IFileInfo).Length > 0 ? (DateTime?)null : (DateTime?)localFileSystemInfo.LastWriteTimeUtc,
LastChangeToken = addedObject.ChangeToken,
LastContentSize = localFileSystemInfo is IDirectoryInfo ? -1 : 0,
ChecksumAlgorithmName = localFileSystemInfo is IDirectoryInfo ? null : "SHA-1",
LastChecksum = localFileSystemInfo is IDirectoryInfo ? null : SHA1.Create().ComputeHash(new byte[0])
};
this.Storage.SaveMappedObject(mapped);
var localFile = localFileSystemInfo as IFileInfo;
if (localFile != null) {
var transmission = this.transmissionManager.CreateTransmission(TransmissionType.UPLOAD_NEW_FILE, localFile.FullName);
if (localFile.Length > 0) {
Stopwatch watch = new Stopwatch();
OperationsLogger.Debug(string.Format("Uploading file content of {0}", localFile.FullName));
watch.Start();
try {
mapped.LastChecksum = this.UploadFile(localFile, addedObject as IDocument, transmission);
mapped.ChecksumAlgorithmName = "SHA-1";
} catch (Exception ex) {
if (ex is UploadFailedException && (ex as UploadFailedException).InnerException is CmisStorageException) {
OperationsLogger.Warn(string.Format("Could not upload file content of {0}:", localFile.FullName), (ex as UploadFailedException).InnerException);
return;
}
throw;
}
watch.Stop();
if (this.ServerCanModifyDateTimes) {
(addedObject as IDocument).UpdateLastWriteTimeUtc(localFile.LastWriteTimeUtc);
}
mapped.LastContentSize = localFile.Length;
mapped.LastChangeToken = addedObject.ChangeToken;
mapped.LastRemoteWriteTimeUtc = addedObject.LastModificationDate;
mapped.LastLocalWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc;
this.Storage.SaveMappedObject(mapped);
OperationsLogger.Info(string.Format("Uploaded file content of {0} in [{1} msec]", localFile.FullName, watch.ElapsedMilliseconds));
} else {
transmission.Length = 0;
transmission.Position = 0;
transmission.Status = TransmissionStatus.FINISHED;
}
}
completewatch.Stop();
Logger.Debug(string.Format("Finished LocalObjectAdded after [{0} msec]", completewatch.ElapsedMilliseconds));
}