Get a real-time log of SHARPSVN performing SVN operations

Source: Internet
Author: User

1 How to get the SHARPSVN operation log

A previous essay (using SHARPSVN to perform an SVN operation) speaks of a Svnclientreport object that can be bound to a Svnclient object by claiming one. In order to illustrate the convenience, the corresponding program fragments are written again below,

using New svnclient ()) {    new  StringBuilder ();     New svnclientreporter (client, strbuilder);}

The program fragment uses a StringBuilder object to claim the Svnclientreport object. In this way, we can only wait until the SVN operation is performed to get all the operation logs from the StringBuilder object. If the SVN operation is time-consuming (for example, thousands of files on a commit), we are not able to get a log of sharpsvn executing the SVN operation in real time, we will assume the program is stuck. So, how do I get a log of SHARPSVN operations in real time?

2 Get SHARPSVN operation log in real time

First, get SHARPSVN execute the SVN operation log only by declaring the Svnclientreport object. This is our point of occurrence, so how do you declare a Svnclientreport object that gets the operation log in real time? First look at the constructor of the Svnclientreport class (refer to http://docs.sharpsvn.net/current/),

Svnclientreporter (Svnclient, TextWriter);

Svnclientreporter (Svnclient, StringBuilder);

Svnclientreporter (Svnclientargs, TextWriter);

Svnclientreporter (Svnclientargs, StringBuilder);

Svnclientreporter (Svnclient, StringBuilder, IFormatProvider);

Svnclientreporter (Svnclientargs, StringBuilder, IFormatProvider);

With the constructor of the Svnclientreport class, we can see that we could only declare a Svnclientreport object using a StringBuilder or TextWriter object. The previous section we have seen through the StringBuilder object is unable to get the SHARPSVN operation log in real time, then we can only start from TextWriter.

Through http://msdn.microsoft.com/zh-cn/library/ywxh2328%28VS.80%29.aspx, we see that TextWriter is an abstract class, So can we just define a TextWriter derived class to achieve our real-time access to the SHARPSVN operation log?!

The following implementation of the Myrealtimetextwriter class inherits the abstract class TextWriter, implements the property Encoding (must be implemented), and overrides the implementation of void Write (string) and void WriteLine (string Value) Two methods, both of which inform the outside world of the data received by triggering the DataReceived event.

classmyrealtimetextwriter:textwriter{//TextWriter derived classes must implement the     PublicEncoding Encoding {Get{returnEncoding.UTF8;} }        //when the data is received, the event is triggered     Public Eventaction<string>datareceived; Private voidOndatareceived (stringvalue) {        if(DataReceived! =NULL) {datareceived (value); }    }      Public Override voidWrite (stringvalue)    {ondatareceived (value); }     Public Override voidWriteLine (stringvalue)    {ondatareceived (value); }}

With the Myrealtimetextwriter class, we can implement the following program to get the log of the SHARPSVN operation in real time.

using(Svnclient client =Newsvnclient ()) {Myrealtimetextwriter Realtimetextwriter=NewMyrealtimetextwriter (); Realtimetextwriter.datareceived+=Newaction<string>(        Delegate(stringvalue) {            /*Do on the sharpsvn operation logs*/        }); Svnclientreporter reporter=Newsvnclientreporter (client, realtimetextwriter); /*Do SVN operations*/}

The above program generates Svnclientreport objects through a Myrealtimetextwriter object. Each time the SHARPSVN operation produces a log message, the Write (string) or WriteLine (string) method of the Myrealtimetextwriter object is called, and the two methods immediately trigger the DataReceived Event tells the outside of the log generated, so it reached the real-time access to the SHARPSVN operation log.

(done)

Get a real-time log of SHARPSVN performing SVN operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.