当前位置: 首页>>代码示例>>C#>>正文


C# IDocument.SetContentStream方法代码示例

本文整理汇总了C#中IDocument.SetContentStream方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.SetContentStream方法的具体用法?C# IDocument.SetContentStream怎么用?C# IDocument.SetContentStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocument的用法示例。


在下文中一共展示了IDocument.SetContentStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

        private static void Update(IDocument doc)
        {
            Stream data = File.OpenRead("../../local.txt");

            ContentStream contentStream = new ContentStream();
            contentStream.FileName = doc.ContentStreamFileName;
            contentStream.Length = data.Length;
            contentStream.MimeType = "application/octet-stream";
            contentStream.Stream = data;
            contentStream.Stream.Flush();

            Console.WriteLine("before");
            doc.SetContentStream(contentStream, true, true);
            Console.WriteLine("after"); // Not reached the second time the method is called.

            data.Close();
            data.Dispose();
            contentStream.Stream.Close();
        }
开发者ID:nicolas-raoul,项目名称:dotcmis-issue632,代码行数:19,代码来源:Program.cs

示例2: UpdateFile

            /// <summary>
            /// Upload new version of file.
            /// </summary>
            private bool UpdateFile(string filePath, IDocument remoteFile)
            {
                SleepWhileSuspended();
                try
                {
                    var syncItem = database.GetSyncItemFromLocalPath(filePath);
                    if (null == syncItem)
                    {
                        syncItem = SyncItemFactory.CreateFromLocalPath(filePath, repoinfo);
                    }

                    Logger.Info("Updating: " + syncItem.LocalPath);
                    using (Stream localfile = File.Open(filePath, 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: " + filePath);
                            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 = remoteFile.ContentStreamFileName;
                            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");

                            // Update timestamp in database.
                            database.SetFileServerSideModificationDate(syncItem, ((DateTime)remoteFile.LastModificationDate).ToUniversalTime());

                            // 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: " + filePath, e);
                    return false;
                }
            }
开发者ID:jelacote,项目名称:CmisSync,代码行数:75,代码来源:SynchronizedFolder.cs

示例3: UpdateFile

            /// <summary>
            /// Upload new version of file.
            /// </summary>
            private bool UpdateFile(string filePath, IDocument remoteFile)
            {
                sleepWhileSuspended();
                try
                {
                    Logger.Info("Updating: " + filePath);
                    using (Stream localfile = File.Open(filePath, 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: " + filePath);
                            return true;
                        }

                        // Prepare content stream
                        ContentStream remoteStream = new ContentStream();
                        remoteStream.FileName = remoteFile.ContentStreamFileName;
                        remoteStream.Length = localfile.Length;
                        remoteStream.MimeType = MimeType.GetMIMEType(Path.GetFileName(filePath));
                        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");

                        // Update timestamp in database.
                        database.SetFileServerSideModificationDate(filePath, ((DateTime)remoteFile.LastModificationDate).ToUniversalTime());

                        // Update checksum
                        database.RecalculateChecksum(filePath);

                        // TODO Update metadata?

                        Logger.Info("Updated: " + filePath);
                        return true;
                    }
                }
                catch (Exception e)
                {
                    ProcessRecoverableException("Could not update file: " + filePath, e);
                    return false;
                }
            }
开发者ID:keithwharrison,项目名称:Oris4Sync,代码行数:53,代码来源:SynchronizedFolder.cs

示例4: UploadFile

        /// <summary>
        ///  Uploads the localFileStream to remoteDocument.
        /// </summary>
        /// <returns>
        ///  The new CMIS document.
        /// </returns>
        /// <param name='remoteDocument'>
        ///  Remote document where the local content should be uploaded to.
        /// </param>
        /// <param name='localFileStream'>
        ///  Local file stream.
        /// </param>
        /// <param name='transmission'>
        ///  Transmission status where the uploader should report its uploading status.
        /// </param>
        /// <param name='hashAlg'>
        ///  Hash alg which should be used to calculate a checksum over the uploaded content.
        /// </param>
        /// <param name='overwrite'>
        ///  If true, the local content will overwrite the existing content.
        /// </param>
        /// <exception cref="CmisSync.Lib.Tasks.UploadFailedException">If upload fails</exception>
        public virtual IDocument UploadFile(
            IDocument remoteDocument,
            Stream localFileStream,
            Transmission transmission,
            HashAlgorithm hashAlg,
            bool overwrite = true,
            UpdateChecksum update = null)
        {
            if (remoteDocument == null) {
                throw new ArgumentException("remoteDocument can not be null");
            }

            if (localFileStream == null) {
                throw new ArgumentException("localFileStream can not be null");
            }

            if (transmission == null) {
                throw new ArgumentException("status can not be null");
            }

            if (hashAlg == null) {
                throw new ArgumentException("hashAlg can not be null");
            }

            using(NonClosingHashStream hashstream = new NonClosingHashStream(localFileStream, hashAlg, CryptoStreamMode.Read))
            using(var transmissionStream = transmission.CreateStream(hashstream))
            {
                ContentStream contentStream = new ContentStream();
                contentStream.FileName = remoteDocument.Name;
                contentStream.MimeType = Cmis.MimeType.GetMIMEType(contentStream.FileName);
                contentStream.Stream = transmissionStream;
                try {
                    remoteDocument.SetContentStream(contentStream, overwrite, true);
                } catch(Exception e) {
                    throw new UploadFailedException(e, remoteDocument);
                }
            }

            hashAlg.TransformFinalBlock(new byte[0], 0, 0);
            return remoteDocument;
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:63,代码来源:SimpleFileUploader.cs

示例5: UpdateFile

        /// <summary>
        /// Upload new version of file.
        /// </summary>
        private bool UpdateFile(string filePath, ref IDocument remoteFile)
        {
            CheckPendingCancelation();
            try
            {
                SyncItem syncItem = getSyncItemFromLocalPath(filePath);

                Logger.Info("Updating: " + syncItem.LocalPath);
                using (Stream localfile = File.Open(filePath, 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: " + filePath);
                        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 = remoteFile.ContentStreamFileName;
                        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");

                        // Update timestamp in database.
                        //remoteFile still refer to the old version of the file, and the LastModificationDate is not the right one:
                        //load the new version data
                        remoteFile = getSession().GetLatestDocumentVersion(remoteFile.Id);
                        database.SetFileServerSideModificationDate(syncItem, ((DateTime)remoteFile.LastModificationDate).ToUniversalTime());

                        // Update checksum
                        database.RecalculateChecksum(syncItem);

                        // TODO Update metadata?
                        Logger.Info("Updated: " + syncItem.LocalPath);
                        return true;
                    }
                    else
                    {
                        HandleException(new CheckOutFileException(syncItem.LocalPath, remoteFile.CheckinComment));
                        return false;
                    }
                }
            }
            catch (Exception e)
            {
                HandleException(new UploadFileException(filePath, e));
                return false;
            }
        }
开发者ID:lelmarir,项目名称:CmisSync,代码行数:70,代码来源:SyncFolderSyncronizer.cs

示例6: UpdateFile

            /// <summary>
            /// Upload new version of file.
            /// </summary>
            private void UpdateFile(string filePath, IDocument remoteFile)
            {
                try
                {
                    Logger.Info("## Updating " + filePath);
                    using (Stream localfile = File.OpenRead(filePath))
                    {
                        // 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: " + filePath);
                            return;
                        }

                        // Prepare content stream
                        ContentStream remoteStream = new ContentStream();
                        remoteStream.FileName = remoteFile.ContentStreamFileName;
                        remoteStream.Length = localfile.Length;
                        remoteStream.MimeType = MimeType.GetMIMEType(Path.GetFileName(filePath));
                        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");
                        Logger.Info("## Updated " + filePath);
                    }
                }
                catch (Exception e)
                {
                    Logger.Warn(String.Format("Exception while update file {0}: {1}", filePath, e));
                }
            }
开发者ID:jmanuelnavarro,项目名称:CmisSync,代码行数:40,代码来源:SynchronizedFolder.cs


注:本文中的IDocument.SetContentStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。