LEADTOOLS Medical (Leadtools.Dicom.Server.Admin assembly)
LEAD Technologies, Inc

InstallService Method

Example 





The settings that describe the DICOM service.
Installs the DICOM service.
Syntax
public DicomService InstallService( 
   ServerSettings settings
)
'Declaration
 
Public Function InstallService( _
   ByVal settings As ServerSettings _
) As DicomService
'Usage
 
Dim instance As ServiceAdministrator
Dim settings As ServerSettings
Dim value As DicomService
 
value = instance.InstallService(settings)
public DicomService InstallService( 
   ServerSettings settings
)
 function Leadtools.Dicom.Server.Admin.ServiceAdministrator.InstallService( 
   settings 
)
public:
DicomService^ InstallService( 
   ServerSettings^ settings
) 

Parameters

settings
The settings that describe the DICOM service.

Return Value

A DicomService class that represents the installed service.
Example
 
Private statusEvent As AutoResetEvent = New AutoResetEvent(False)


Public Sub InstallServiceTest()
   Dim admin As ServiceAdministrator = New ServiceAdministrator("C:\LEADTOOLS 17.5\Bin\Dotnet\Win32")
   Dim settings As ServerSettings = New ServerSettings()
   Dim service As DicomService

   settings.AETitle = "DICOM_SERVER"
   settings.Port = 104
   settings.DisplayName = "Sample Dicom Server"
   settings.IpAddress = Dns.GetHostEntry(Environment.MachineName).AddressList(0).ToString()
   service = admin.InstallService(settings)
   If Not service Is Nothing AndAlso service.Settings.AETitle = "DICOM_SERVER" Then

      AddHandler service.Message, AddressOf service_Message
      AddHandler service.StatusChange, AddressOf service_StatusChange

      Console.WriteLine("Base Directory: {0}", admin.BaseDirectory)
      Console.WriteLine("Server Directory: {0}", service.ServiceDirectory)

      Try
         Dim ae As AeInfo = New AeInfo()

         '
         ' Start the service
         '
         service.Start()
         service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(30))

         ProcessMessages()


         If service.IsAdminAvailable Then
            '
            ' Add AE Title
            '
            ae.AETitle = "CLIENT"
            ae.Port = 1000
            ae.Address = String.Empty
            service.SendMessage(MessageNames.AddAeTitle, ae)
         End If

         ProcessMessages()

         '
         ' Pause the service
         '
         service.Pause()
         service.WaitForStatus(ServiceControllerStatus.Paused, TimeSpan.FromSeconds(30))

         ProcessMessages()

      Finally
         If service.Status <> ServiceControllerStatus.Stopped Then
            '
            ' Stop the service
            '
            service.Stop()
            service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(30))
         End If

         '
         ' UnInstall the service
         '
         admin.UnInstallService(service)
      End Try
   End If
End Sub

'
' Need to process messages so events get called in time.  In a normal windows applications there is no need
'  to do this extra processing.
'
Private Sub ProcessMessages()
   Do While Not statusEvent.WaitOne(0)
      Application.DoEvents()
   Loop
End Sub

Private Sub service_StatusChange(ByVal sender As Object, ByVal e As EventArgs)
   Dim service As DicomService = TryCast(sender, DicomService)

   Console.WriteLine(service.Status)
   If service.Status = ServiceControllerStatus.Running OrElse service.Status = ServiceControllerStatus.Stopped OrElse service.Status = ServiceControllerStatus.Paused Then
      statusEvent.Set()
   End If
End Sub

Private Sub service_Message(ByVal sender As Object, ByVal e As MessageEventArgs)
   If e.Message.Message = MessageNames.AddAeTitle Then
      If e.Message.Success Then
         Dim ae As AeInfo = TryCast(e.Message.Data(0), AeInfo)

         Console.WriteLine("AE Title: {0}", ae.AETitle)
         Console.WriteLine("IP Address: {0}", ae.Address)
         Console.WriteLine("Port: {0}", ae.Port)
      Else
         Console.WriteLine("Error Adding AETITLE: {0}", e.Message.Error)
      End If
   End If
   statusEvent.Set()
End Sub
AutoResetEvent statusEvent = new AutoResetEvent(false);


public void InstallServiceTest()
{
   ServiceAdministrator admin = new ServiceAdministrator(@"C:\LEADTOOLS 17.5\Bin\Dotnet\Win32");
   ServerSettings settings = new ServerSettings();
   DicomService service;

   settings.AETitle = "DICOM_SERVER";
   settings.Port = 104;
   settings.DisplayName = "Sample Dicom Server";
   settings.IpAddress = Dns.GetHostEntry(Environment.MachineName).AddressList[0].ToString();
   service = admin.InstallService(settings);
   if(service!=null && service.Settings.AETitle == "DICOM_SERVER")
   {           
      service.Message += new EventHandler<MessageEventArgs>(service_Message);
      service.StatusChange += new EventHandler(service_StatusChange);

      Console.WriteLine("Base Directory: {0}", admin.BaseDirectory);
      Console.WriteLine("Server Directory: {0}", service.ServiceDirectory);

      try
      {
         AeInfo ae = new AeInfo();

         //
         // Start the service
         //

         service.Start();
         service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(30));

         ProcessMessages();


         if (service.IsAdminAvailable)
         {
            //
            // Add AE Title
            //

            ae.AETitle = "CLIENT";
            ae.Port = 1000;
            ae.Address = string.Empty;
            service.SendMessage(MessageNames.AddAeTitle, ae);
         }

         ProcessMessages();

         //
         // Pause the service
         //

         service.Pause();
         service.WaitForStatus(ServiceControllerStatus.Paused, TimeSpan.FromSeconds(30)); 

         ProcessMessages();

      }           
      finally
      {
         if(service.Status!= ServiceControllerStatus.Stopped)
         {
            //
            // Stop the service
            //

            service.Stop();
            service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(30)); 
         }

         //
         // UnInstall the service
         //

         admin.UnInstallService(service);
      }
   }
}

//
// Need to process messages so events get called in time.  In a normal windows applications there is no need
//  to do this extra processing.
//

private void ProcessMessages()
{
   while(!statusEvent.WaitOne(0))
   {
      Application.DoEvents();
   }
}

void service_StatusChange(object sender, EventArgs e)
{
   DicomService service = sender as DicomService;

   Console.WriteLine(service.Status);
   if(service.Status==ServiceControllerStatus.Running || service.Status == ServiceControllerStatus.Stopped ||
      service.Status == ServiceControllerStatus.Paused)
   {
      statusEvent.Set();
   }
}

void service_Message(object sender, MessageEventArgs e)
{ 
   if(e.Message.Message == MessageNames.AddAeTitle)
   {
      if (e.Message.Success)
      {
         AeInfo ae = e.Message.Data[0] as AeInfo;

         Console.WriteLine("AE Title: {0}", ae.AETitle);
         Console.WriteLine("IP Address: {0}", ae.Address);
         Console.WriteLine("Port: {0}", ae.Port);
      }
      else
      {
         Console.WriteLine("Error Adding AETITLE: {0}", e.Message.Error);
      }
   }
   statusEvent.Set();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ServiceAdministrator Class
ServiceAdministrator Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Dicom.Server.Admin requires a Medical toolkit server license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features