在SharpSvn .NET库中设置提交作者会抛出SvnRepisitoryIOException异常

时间:2012-10-01 06:24:06

标签: authentication tortoisesvn commit sharpsvn author

如果您有使用SharpSvn .NET库的经验,我可以使用您在SVN提交期间设置提交作者的专业知识。我尝试过一些东西,但除非用户保存在TortoiseSVN中,否则它们都会抛出一个SvnRepisitoryIOException。但是,我想根据具体情况使用不同的用户凭据。如果我保存了用户的默认凭据,TortoiseSVN会在设置>中记住它们。保存的数据>经过身份验证的数据,并且能够使用该经过身份验证的用户作为提交作者提交文件。如果您在此处单击“清除”,则SharpSVN将无法知道在提交期间进行身份验证的人员。

假设你的班级有这些指令:使用SharpSvn; 使用SharpSvn.Security;我正在使用Windows的免费版VisualSVN服务器。我有两个用户,一个名为“user1”,密码为“pass1”,以便在下面的示例中保持简单。

如何防止抛出此异常并使用作者的不同用户进行提交(在我的提交日志中)?

尝试#1:

    using (SvnClient client = new SvnClient())
    { 
        client.Authentication.Clear();  // Clear a previous authentication 
        client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user1", "pass1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }

尝试#2:

    using (SvnClient client = new SvnClient())
    {
        client.SetProperty(("", "svn:author", "user1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }

尝试#3:

    using (SvnClient client = new SvnClient())
    {
        client.Authentication.Clear(); // Clear predefined handlers
        client.Authentication.UserNamePasswordHandlers
            += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
        {
            args.UserName = "user1";
            args.Password = "pass1";
        }; 

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }

1 个答案:

答案 0 :(得分:2)

在以管理员身份运行应用程序时获取堆栈跟踪后,我能够使用框架捕获异常并接受不受信任的证书颁发者。

*未处理的异常:SharpSvn.SvnRepositoryIOException:提交失败(详情如下):===> SharpSvn.SvnRepositoryIOException:无法连接到URL'https://mycomputer/svn/demo_repo/demo_project/trunk/file.txt'的存储库 - > SharpSvn.SvnRepositoryIOException:''的选项:服务器证书验证失败:颁发者不受信任(https:// mycomputer)   ---内部异常堆栈跟踪结束---   ---内部异常堆栈跟踪结束---     在SharpSvn.SvnClientArgs.HandleResult(SvnClientContext客户端,SvnException错误,对象目标)     在SharpSvn.SvnClientArgs.HandleResult(SvnClientContext客户端,svn_error_t *错误,对象目标)     ..... *

新代码:

            client.Authentication.Clear(); // Clear predefined handlers
            client.Authentication.UserNamePasswordHandlers
                += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
            {
                args.UserName = "user1";
                args.Password = "pass1";
            }; 

            client.Authentication.SslServerTrustHandlers​ +=
            delegate(object sender, SvnSslServerTrustEventArgs e)
            {
              e.AcceptedFailures = e.Failures;
              e.Save = true; // Save acceptance to authentication store
            };

            SvnCommitArgs ca = new SvnCommitArgs();
            ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
            bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);