c# - 提交时工作人员服务 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 将服务作为控制台应用程序运行。它是这样工作的!为什么该应用程序只能作为控制台应用程序而不是作为服务工作?
解决方案
推荐阅读
- javascript - DOM 元素数据集包含带有 (this) 参数的调用
- python - ProgrammingError:对象是在线程 id 14408 中创建的,这是线程 id 2776。我无法创建帐户
- tdd - 我想弄清楚:如果你做对了,是什么阻止你“玩”单元测试?
- http - 为什么我可以使用 DBeaver/JDBC 而不是 HTTP 连接到 Clickhouse?
- d - 如何在 BetterC 模式下进行字符串格式化?
- python - 如何将重复的列转置为行 Pandas
- ios - 自定义标签栏按钮操作未按预期工作
- mysql - 为 Django 项目 (macOS) 安装 mysqlclient 时出现问题
- java - Panoply情节错误!因为“clut”为空
- ruby - Ruby 查找 has_one 关系为真且在数组中的所有对象