New Posts New Posts RSS Feed: Inherit or Customize BOS Window Service
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Inherit or Customize BOS Window Service

 Post Reply Post Reply
Author
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post Topic: Inherit or Customize BOS Window Service
    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?

Back to Top
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post 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();
            //}
        }
    }
}
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post 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)
 
Back to Top
yafei View Drop Down
Newbie
Newbie


Joined: 25-Aug-2010
Location: los Angeles
Posts: 21
Post Options Post Options   Quote yafei Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 03-Sep-2010 at 11:42am
We have investigated and confirmed that this is a bug.

We will have it fixed.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down