Click here to Skip to main content
15,881,588 members
Articles / Web Development / ASP.NET

Subversion Multiple Repository on a Single Server

Rate me:
Please Sign up or sign in to vote.
2.10/5 (4 votes)
29 Aug 2006CPOL3 min read 36.2K   9   5
This article shows how to run multiple Subversion instances inside a Windows Service, and within the same executable host a standard Windows Form application and provide an ASP.NET page to redirect your users to the specific repository.

Sample Image - subversioncodeprojectheader.gif

Introduction

After reviewing the service wrapper for Subversion that is available at http://svnservice.tigris.org/, I found that for the environment that I work in, we need to run multiple instances of the service, but I wanted to make it one service that is installed onto our server. Given that the Subversion server uses a very small (at least mine are) memory footprint, I came up with the idea of having the one service run multiple instances of the SVN server.

I also wanted the project to be able to be run purely as an Exe for the purposes of testing. We actually employ a strategy similar to this for another project so that our developers can run the program on their machine (without the requirement for the service installation), enabling the debugging of assemblies easier.... but that is another article :-)

Points of Interest

Given that it has been identified in the comments that this could be done easier using the Directory approach, hopefully someone will find it useful for the ability to host a Service and a regular WinForms application in one executable.

Setting up the Project

To create this project, you just use VS.NET to create a Windows Service application. This will create the necessary project files etc. You now will need to make some modifications to the sub Main to allow the application to run as a Service or as an application.

Setting the Service

To make the program be able to run in the correct mode, we will need to modify ServiceInstaller.vb so that when the service is installed, it will modify the command line parameters that are sent to the application.

We make our Main function in the service examine the command line to determine that these parameters have been supplied.

VB
If Environment.GetCommandLineArgs.GetUpperBound(0) > 0 Then
  theArgs = theArgs.Substring(theArgs.IndexOf("/"))
  Dim collectionArgs() As String
  collectionArgs = theArgs.Split("/"c)
  Dim i As Integer
  For i = 1 To collectionArgs.GetUpperBound(0)
    Dim strParameterValue() As String
    strParameterValue = collectionArgs(i).Split("="c)
    Select Case strParameterValue(0).ToLower
      Case "mode"
        If strParameterValue(1).ToLower = "service" Then
          blnService = True
        End If
      Case Else

    End Select
  Next i
Else
  blnService = False
End If

Now that we have run, we need to start the service, or run the application.

VB
If blnService Then
  Dim ServicesToRun() As System.ServiceProcess.ServiceBase
  ServicesToRun = New System.ServiceProcess.ServiceBase() _
                      {New ServiceController(configFile)}
  System.ServiceProcess.ServiceBase.Run(ServicesToRun) 
Else   
  ' Check for previous instance of the service or application
  If Diagnostics.Process.GetProcessesByName(_
       Diagnostics.Process.GetCurrentProcess.ProcessName).Length <= 1 Then
    Dim systemOperation As Start     
    systemOperation = New Start(configFile)
    systemOperation.Daemons.Start()
    System.Windows.Forms.Application.Run(New _
           ActiveRepositoriesForm(systemOperation.Daemons))
    systemOperation.Daemons.Stop()   
  End If 
End If

To see the intimate details of this, examine the source code in the "ServiceController.vb" and "Start.vb" files.

Setting up the Application

We use a ListView control presenting the information about the processes that we have created and the ports that we have running.

Setting up the ASP.NET page

The page is very simply a web based version of the application except that it enables you to click a link if you have TortiseSVN installed, and it will redirect you to that location.

Why am I looking at Subversion

I have been using SourceSafe for most of the development projects I have been involved with since I started working on the Windows platform around 10 years ago. After listening to Hanselminutes, I have been hearing and reading nothing but good things about Subversion. I also recently examined our SourceSafe to find that it had corrupted itself (fortunately, only a couple of files). Therefore, I have started showing our other developers the pros of Subversion with little to none of the cons associated with SourceSafe.

The speed at which check-in and out (Add, Update, Commit) are done is just outstanding.

Where to From Here

I will be revising the program to enable commands to be sent to the Service to perform a backup (and compress the backup), and also stop/start/restart a specific instance of the Subversion repository that is being run.

Bugs? What Bugs?

In the testing I have done, I haven't found any, but if you do, please let me know. I have tested this in Win2000, WinXP, and Win2003.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Member 463769721-Jul-13 20:10
Member 463769721-Jul-13 20:10 
GeneralEasier solution Pin
Jochen Jonckheere29-Aug-06 4:14
Jochen Jonckheere29-Aug-06 4:14 
GeneralRe: Easier solution Pin
Carsten Zeumer29-Aug-06 4:32
Carsten Zeumer29-Aug-06 4:32 
AnswerRe: Easier solution Pin
Jochen Jonckheere29-Aug-06 4:52
Jochen Jonckheere29-Aug-06 4:52 
GeneralRe: Easier solution Pin
Carsten Zeumer29-Aug-06 5:58
Carsten Zeumer29-Aug-06 5:58 
ok, you win Wink | ;)

(has this always been possible with svn or is this something new?)

/cadi

24 hours is not enough

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.