CmisSync.Lib.Sync.CmisRepo.SynchronizedFolder.UpdateFile C# (CSharp) Метод

UpdateFile() приватный Метод

Upload new version of file.
private UpdateFile ( string localFilePath, IDocument remoteFile ) : bool
localFilePath string
remoteFile IDocument
Результат bool
            private bool UpdateFile(string localFilePath, IDocument remoteFile)
            {
                SleepWhileSuspended();
                try
                {
                    var syncItem = database.GetSyncItemFromLocalPath(localFilePath);
                    if (null == syncItem)
                    {
                        syncItem = SyncItemFactory.CreateFromLocalPath(localFilePath, false, repoInfo, database);
                    }

                    Logger.Info("Updating: " + syncItem.LocalPath);
                    using (Stream localfile = File.Open(localFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        // Ignore files with null or empty content stream.
                        if ((localfile == null) && (localfile.Length == 0))
                        {
                            Logger.Info("Skipping update of file with null or empty content stream: " + localFilePath);
                            return true;
                        }

                        // Check is write permission is allow

                        // Check if the file is Check out or not
                        //if (!(bool)remoteFile.IsVersionSeriesCheckedOut)
                        if ((remoteFile.IsVersionSeriesCheckedOut == null) || !(bool)remoteFile.IsVersionSeriesCheckedOut)
                        {

                            // Prepare content stream
                            ContentStream remoteStream = new ContentStream();
                            remoteStream.FileName = repoInfo.CmisProfile.localFilename(remoteFile);
                            remoteStream.Length = localfile.Length;
                            remoteStream.MimeType = remoteFile.GetContentStream().MimeType;
                            remoteStream.Stream = localfile;
                            remoteStream.Stream.Flush();
                            Logger.Debug("before SetContentStream");

                            // CMIS do not have a Method to upload block by block. So upload file must be full.
                            // We must waiting for support of CMIS 1.1 https://issues.apache.org/jira/browse/CMIS-628
                            // http://docs.oasis-open.org/cmis/CMIS/v1.1/cs01/CMIS-v1.1-cs01.html#x1-29700019
                            // DotCMIS.Client.IObjectId objID = remoteFile.SetContentStream(remoteStream, true, true);
                            remoteFile.SetContentStream(remoteStream, true, true);

                            Logger.Debug("after SetContentStream");

                            // Get updated file.
                            var allFileVersions = remoteFile.GetAllVersions();
                            // CMIS 1.1 specification for getAllVersions: "returns the list of all document objects in the specified version series, sorted by cmis:creationDate descending"
                            // So the latest version is at index 0
                            var updatedFile = allFileVersions[0];

                            // Update timestamp in database.
                            DateTime serverSideModificationDate = updatedFile.LastModificationDate.Value.ToUniversalTime();
                            database.SetFileServerSideModificationDate(syncItem, serverSideModificationDate);

                            // Update checksum
                            database.RecalculateChecksum(syncItem);

                            // TODO Update metadata?
                            Logger.Info("Updated: " + syncItem.LocalPath);
                            return true;
                        }
                        else
                        {
                            string message = String.Format("File {0} is CheckOut on the server by another user: {1}", syncItem.LocalPath, remoteFile.CheckinComment);

                            // throw new IOException("File is Check Out on the server");
                            Logger.Info(message);
                            Utils.NotifyUser(message);
                            return false;
                        }
                    }
                }
                catch (Exception e)
                {
                    ProcessRecoverableException("Could not update file: " + localFilePath, e);
                    return false;
                }
            }

Same methods

CmisRepo.SynchronizedFolder::UpdateFile ( string filePath, IFolder remoteFolder ) : bool