Exemple #1
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        public void OnStart(string[] args)
        {
            //obtain the configuration information for SAF.Service
            //loop through service nodes and start them one by one
            foreach (var item in Services)
            {
                try {
                    IService service = item.Value;
                    //initialize the service
                    service.Initialize();
                    instanceArray.Add(service);

                    //create SecuritySwitchThread object to process the service
                    ThreadStart          ts  = new ThreadStart(service.Start);
                    SecuritySwitchThread sst = new SecuritySwitchThread(ts, service.ServiceInfo.RunAs, crypto);

                    //start the SecuritySwitchThread's thread.
                    sst.Start();
                    threadArray.Add(sst.BaseThread);
                    Thread t = new Thread(ts);
                }
                catch (Exception /* ex */) {
                    //write to the event log
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            //obtain the configuration information for SAF.Service
            ConfigurationManager cm = (ConfigurationManager)ConfigurationSettings.GetConfig("Framework");

            SAF.Configuration.ServiceConfiguration serviceConfig = cm.ServiceConfig;
            XmlNode servicesXml = serviceConfig.ServicesXml;

            //loop through service nodes and start them one by one
            foreach (XmlNode node in servicesXml.ChildNodes)
            {
                try
                {
                    string typeInfo;
                    //obtain the type information from the xml data
                    typeInfo = node.Attributes["type"].Value;
                    Type     type     = Type.GetType(typeInfo);
                    IService instance = (IService)Activator.CreateInstance(type);
                    //initialize the service
                    instance.Initialize(node);
                    XmlNode runAs = node.SelectSingleNode("RunAs");
                    instanceArray.Add(instance);

                    //create SecuritySwitchThread object to process the
                    //the service
                    ThreadStart          ts  = new ThreadStart(instance.Start);
                    SecuritySwitchThread sst = new SecuritySwitchThread(ts, runAs);
                    //start the SecuritySwitchThread's thread.
                    sst.Start();
                    threadArray.Add(sst.BaseThread);
                }
                catch (Exception ex)
                {
                    //write to the event log
                }
            }
        }