首页 > 解决方案 > 提交时工作人员服务 C#sharpsvn 错误

问题描述

我目前正在尝试创建一个在 SVN 存储库中自动添加和提交目录的服务。我已经成功创建了一个工作服务来检查是否有新文件并添加/提交它们。我目前面临的问题如下。

当我在 Visual Studio(控制台应用程序)中运行该服务时,它可以工作。它添加文件,然后将文件提交到 SVN 存储库。

我现在发布了该服务并将其注册到 Windows 服务,它正确启动并添加了文件,但它没有提交文件。我收到一个 SVNSharpException,我捕获了异常并记录了信息。我认为 SVNErrorCategory 34 意味着无法创建会话 => 没有互联网连接?

public bool CommitDirectory(string directory, string message)
        {
            if ( string.IsNullOrEmpty(directory) )
                return true; // if the directory is empty, the folder was already comited
            using ( SvnClient client = new SvnClient() )
            {
                SvnCommitArgs args = new SvnCommitArgs
                {
                    LogMessage = message,
                    ThrowOnError = true,
                    ThrowOnCancel = true,
                    Depth = SvnDepth.Infinity

                };

                try
                {
                    return client.Commit(directory, args);
                }
                catch ( Exception e )
                {
                    if ( e is SharpSvn.SvnException )
                    {
                        if ( depth > 0 )
                        {
                            switch ( (e as SharpSvn.SvnException).SvnErrorCategory )
                            {
                                case ((SvnErrorCategory) 40): // parent is not under version control
                                    depth--; // decrease depth
                                    return CommitDirectory(Directory.GetParent(directory).FullName, message); // try  to add parent folder
                                case ((SvnErrorCategory) 34): // could not create session => no internet connection 
                                    _logger.LogInformation("Currently unable to create a session to the repository.");
                                    return false;
                                default:
                                    _logger.LogError(e,"Could not commit the {directory}, error: {error}.", directory, e.Message);
                                    return false;
                            }
                        }
                        else
                        {
                            _logger.LogError("Unable to add the {directory}, the directory is not a working copy!", directory);
                            return false;
                        }
                    }
                    else
                    {
                        _logger.LogError(e, "An error occured during the commit proccess. {msg}", e.Message);
                        return false;
                    }
                }
            }
        }

因此,我尝试通过在发布后双击 Service.exe 将服务作为控制台应用程序运行。它是这样工作的!为什么该应用程序只能作为控制台应用程序而不是作为服务工作?

标签: c#svnservicebackgroundworkersharpsvn

解决方案


推荐阅读