首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SharpSvn GetFileVersions和GetContentStream抛出InvalidOperationException

SharpSvn GetFileVersions和GetContentStream抛出InvalidOperationException
EN

Stack Overflow用户
提问于 2012-07-26 05:55:49
回答 2查看 914关注 0票数 1

我正在尝试使用SharpSvn来获取特定修订版的文件内容。我有以下代码:

代码语言:javascript
复制
var svnClient = new SvnClient();
var revisionInfo = new SvnFileVersionsArgs
    {
        Start = 80088,
        End = 80093
    };

Collection<SvnFileVersionEventArgs> fileVersions;
svnClient.GetFileVersions(
    new SvnUriTarget("https://DbDiff.svn.codeplex.com/svn/DbDiffCommon/DataAccess/SqlCommand11.xml"), 
    revisionInfo,
    out fileVersions);

var stream =  fileVersions[0].GetContentStream();

然而,在最后一行,我得到了以下异常:

代码语言:javascript
复制
System.InvalidOperationException was unhandled
  Message=This method can only be invoked from the eventhandler handling this eventargs instance
  Source=SharpSvn
  StackTrace:
       at SharpSvn.SvnFileVersionEventArgs.GetContentStream(SvnFileVersionWriteArgs args) in g:\dist\src\sharpsvn\commands\fileversions.cpp:line 545
       at SharpSvn.SvnFileVersionEventArgs.GetContentStream() in g:\dist\src\sharpsvn\commands\fileversions.cpp:line 534
       at SharpSvnFileVersions.Program.Main(String[] args) in c:\temp\SharpSvnFileVersions\Program.cs:line 29
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

我应该如何着手获取每次修订时的文件内容?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-26 23:01:33

看起来我可以使用SvnClient.Write()来抓取文件内容:

代码语言:javascript
复制
SvnClient svnClient = new SvnClient();
SvnUriTarget target = new SvnUriTarget("https://DbDiff.svn.codeplex.com/svn/DbDiffCommon/DataAccess/SqlCommand11.xml", 80088);

Stream stream = new MemoryStream();
svnClient.Write(target, stream);
票数 3
EN

Stack Overflow用户

发布于 2015-03-26 17:28:54

GetFileVersions仅适用于特定场景。Subversion本身使用它来实现指责。我碰巧为一个不同的场景创建了这个测试程序:将一个文件的所有修订版迁移到一个新的存储库。在这里张贴它供其他人使用。

代码语言:javascript
复制
using System;
using System.IO;
using SharpSvn;
using SharpSvn.UI;

class SvnDumpFileToRepository
{
    static void Main(string[] args)
    {
        Uri uri = null;
        if (args.Length < 2
            || !Uri.TryCreate(args[0], UriKind.Absolute, out uri))
        {
            Console.Error.WriteLine("Usage: SvnDumpFileToRepository URL PATH");
        }

        using (SvnRepositoryClient repos = new SvnRepositoryClient())
        {
            repos.CreateRepository(args[1]);
        }

        Uri reposUri = SvnTools.LocalPathToUri(args[1], true);

        using (SvnClient client = new SvnClient())
        using (SvnClient client2 = new SvnClient())
        {
            SvnUI.Bind(client, new SvnUIBindArgs());

            string fileName = SvnTools.GetFileName(uri);
            bool create = true;
            client.FileVersions(uri,
                delegate(object sender, SvnFileVersionEventArgs e)
                {
                    Console.Write("Copying {0} in r{1}", fileName, e.Revision);

                    using (MemoryStream ms = new MemoryStream())
                    {
                        e.WriteTo(ms); // Write full text to memory stream
                        ms.Position = 0;

                        // And now use 'svnmucc' to update repository
                        client2.RepositoryOperation(reposUri,
                            new SvnRepositoryOperationArgs { LogMessage = e.LogMessage },
                            delegate(SvnMultiCommandClient mucc)
                            {
                                if (create)
                                {
                                    mucc.CreateFile(fileName, ms);
                                    create = false;
                                }
                                else
                                    mucc.UpdateFile(fileName, ms);
                            });
                    }
                });
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11659239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档