I am currently trying to create a service that automatically adds and commits directories in a SVN repo. I have successfully created a worker service that checks if there are new files and add/commits them. The problem I am currently facing is the following.
When I run the service in Visual Studio ( console app) it works. It adds the files and then commits the files to the SVN repo.
I published the service now and registered it to the windows services and it starts correctly and also adds the files, BUT it does not commit the files. I am getting an SVNSharpException and I catch the exception and log the information. I thought the SVNErrorCategory 34 means the session could not be created => no internet connection??
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;
}
}
}
}
So I tried to run the service as console app, by double clicking on the Service.exe after publishing it. It works this way!
Why is the app only able to work as a console app and not as a service?
question from:
https://stackoverflow.com/questions/65920324/worker-service-c-sharp-sharpsvn-error-when-commiting 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…