示例#1
0
        static void Main()
        {
            try
            {
                //Begin - Section 1: Enable Logging
                EnableLogging();
                //End - Section 1

                //Begin Section 2: - Get SSDP object
                var syncServDp   = new SynchronizationServiceDataProvider(_logger);
                var syncServices = syncServDp.GetServiceConfigurations();
                //End - Section 2

                //Begin Section 3: - Start The Service
                if (Debugger.IsAttached)
                {
                    var debugConfig = syncServDp.GetServiceConfiguration(DebugConfigID);
                    //Launch the Service
                    LDAPSyncService.Sync(debugConfig.DataItems[0].ConfigID);
                }
                else
                {
                    var servicesToRun = new List <ServiceBase>();

                    foreach (var serviceConfigurationModel in syncServices.DataItems)
                    {
                        switch (serviceConfigurationModel.ConfigTypeID)
                        {
                        //This determines all the service configuration for the LDAP that needs to be run
                        case ((int)ConfigType.LDAP):
                        {
                            if (debugMode)
                            {
                                EventLog.WriteEntry("SynchronizationService", "Adding service for ConfigXML " + serviceConfigurationModel.ConfigXML, EventLogEntryType.Information);
                            }

                            if (debugLogFileMode)
                            {
                                using (StreamWriter sw = File.AppendText("Log.txt"))
                                {
                                    sw.WriteLine("Adding service for ConfigXML " + serviceConfigurationModel.ConfigXML);
                                }
                            }

                            servicesToRun.Add(new LDAPSynchronizationService(serviceConfigurationModel.ConfigID));
                            break;
                        }
                        }
                    }
                    ;

                    ServiceBase.Run(servicesToRun.ToArray());
                }
                //End Section 3
            }
            catch (Exception e)
            {
                EventLog.WriteEntry("SynchronizationService", "Error launching services: " + e.Message, EventLogEntryType.Error);
            }
        }
示例#2
0
        protected override void OnStart(string[] args)
        {
            var syncServ = new SynchronizationServiceDataProvider(_logger);
            var config   = syncServ.GetServiceConfiguration(_configID).DataItems[0];

            using (XmlReader reader = XmlReader.Create(new StringReader(config.ConfigXML)))
            {
                // get the services that need to be started, and their intervals, from the db
                reader.ReadToFollowing("Timer");
                reader.ReadToDescendant("Interval");
                reader.MoveToFirstAttribute();
                var interval = Convert.ToDouble(reader.Value);

                _timerClock.Elapsed += delegate { LDAPSyncService.Sync(_configID); };
                _timerClock.Interval = interval * 60 * 1000; // interval (in minutes) to execute process
                _timerClock.Enabled  = true;
            }
        }