Print Page | Close Window

Inherit or Customize BOS Window Service

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2107
Printed Date: 13-May-2026 at 12:56am


Topic: Inherit or Customize BOS Window Service
Posted By: yafei
Subject: Inherit or Customize BOS Window Service
Date Posted: 30-Aug-2010 at 12:29pm

I host BOS as a window service in the middle-tier. However, I want to add some business logics when the BOS Window Service is OnStart, OnStop, OnPause, OnShutDown, OnContinue, etc.  Is there any solutions?




Replies:
Posted By: yafei
Date Posted: 30-Aug-2010 at 5:28pm
It looks that I can use public virtual void OnServiceStartup(object sender, ServiceStartupEventArgs e) to implement one of them. I have made a prototype, but it is not working.  I have created a assembly which contain a class below and put this assembly with other BOS assemblies the same place. Do I miss anything ?
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IdeaBlade.EntityModel;
using System.IO;
namespace DomainModel
{
    public class ServiceApp : EntityServiceApplication
    {
        public void OnServiceStartUp(object sender, ServiceStartupEventArgs e)
        {
            string LogFile = "logFile.txt";
            LogMessage("Service Starting up ...", LogFile);
           base.OnServiceStartup(sender, e);
        }
        public void OnServceShutdown(object sender, EventArgs e)
        {
            string LogFile = "logFile.txt";
            LogMessage("Service Shuting Down ...", LogFile);
            base.OnServiceShutdown(sender, e);
        }
        public static void LogMessage(String strLogMe, string logfile)
        {
            // if (IsLogOn)
            // {
            FileStream fs = new FileStream(logfile, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter m_streamWriter = new StreamWriter(fs);
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            m_streamWriter.WriteLine(DateTime.UtcNow.ToString() + " : " + strLogMe);
            m_streamWriter.Flush();
            m_streamWriter.Close();
            //}
        }
    }
}


Posted By: ting
Date Posted: 30-Aug-2010 at 7:40pm
Heh, fix the spelling and capitalization of the methods and Visual Studio should tell you that you needed to declare them as 'override'.  ;)
 
These should be your method declarations:
 
public override void OnServiceStartup(object sender, ServiceStartupEventArgs e)
public override void OnServiceShutdown(object sender, EventArgs e)
 


Posted By: yafei
Date Posted: 31-Aug-2010 at 11:57am
Thank Ting for your help.
 
Now OnServiceStartup is working when I create the instance of the EntityManager from client side. But I could not find where and when I can trigger the OnServiceShutdown event ? I shutdown the BOS window service, but it didn't trigger the OnServiceShutdown event.
 


Posted By: ting
Date Posted: 31-Aug-2010 at 7:22pm
We're taking a look at the OnServiceShutdown event for the Window Service BOS and will let you know.


Posted By: sbelini
Date Posted: 03-Sep-2010 at 11:42am
We have investigated and confirmed that this is a bug.

We will have it fixed.



Print Page | Close Window