Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

svn - Worker Service C# sharpsvn error when commiting

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

1.4m articles

1.4m replys

5 comments

57.0k users

...