CmisSync.Lib.Consumer.SituationSolver.LocalObjectAdded.AddCmisObject C# (CSharp) Method

AddCmisObject() private method

private AddCmisObject ( IFileSystemInfo localFile, string parentId, ISession session ) : ICmisObject
localFile IFileSystemInfo
parentId string
session ISession
return ICmisObject
        private ICmisObject AddCmisObject(IFileSystemInfo localFile, string parentId, ISession session) {
            string name = localFile.Name;
            Dictionary<string, object> properties = new Dictionary<string, object>();
            properties.Add(PropertyIds.Name, name);
            if (this.ServerCanModifyDateTimes) {
                properties.Add(PropertyIds.CreationDate, localFile.CreationTimeUtc);
                properties.Add(PropertyIds.LastModificationDate, localFile.LastWriteTimeUtc);
            }

            Stopwatch watch = new Stopwatch();
            ICmisObject result;
            if (localFile is IDirectoryInfo) {
                properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisFolder.GetCmisValue());
                watch.Start();
                var objId = session.CreateFolder(properties, new ObjectId(parentId));
                watch.Stop();
                Logger.Debug(string.Format("CreatedFolder in [{0} msec]", watch.ElapsedMilliseconds));
                watch.Restart();
                var operationContext = OperationContextFactory.CreateContext(session, true, false, PropertyIds.Name, PropertyIds.LastModificationDate, PropertyIds.ChangeToken);
                result = session.GetObject(objId, operationContext);
                watch.Stop();
                Logger.Debug(string.Format("GetFolder in [{0} msec]", watch.ElapsedMilliseconds));
            } else {
                bool emptyFile = (localFile as IFileInfo).Length == 0;
                properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
                watch.Start();
                using (var emptyStream = new MemoryStream(new byte[0])) {
                    var objId = session.CreateDocument(
                        properties,
                        new ObjectId(parentId),
                        emptyFile ? this.CreateEmptyStream(name, emptyStream) : null,
                        null,
                        null,
                        null,
                        null);
                    watch.Stop();
                    Logger.Debug(string.Format("CreatedDocument in [{0} msec]", watch.ElapsedMilliseconds));
                    watch.Restart();
                    var operationContext = OperationContextFactory.CreateContext(session, true, false, PropertyIds.Name, PropertyIds.LastModificationDate, PropertyIds.ChangeToken, PropertyIds.ContentStreamLength);
                    result = session.GetObject(objId, operationContext);
                    watch.Stop();
                    Logger.Debug(string.Format("GetDocument in [{0} msec]", watch.ElapsedMilliseconds));
                }
            }

            return result;
        }