示例#1
0
        protected override void OnStop()
        {
            var serviceStopTime = new ServiceStopTime {
                ScheduleEndTime = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
            };

            try
            {
                var schedulerExportPath = GlobalAppSettings.GetSchedulerExportPath();
                if (Directory.Exists(schedulerExportPath) == false)
                {
                    Directory.CreateDirectory(schedulerExportPath);
                }

                new SchedulerJob().SerializeTime(serviceStopTime,
                                                 GlobalAppSettings.GetSchedulerExportPath() + "config.xml");
                LogExtension.LogInfo("Service stopped", MethodBase.GetCurrentMethod());
            }
            catch (Exception e)
            {
                LogExtension.LogError("Exception is thrown while stopping service", e, MethodBase.GetCurrentMethod());
            }
            finally
            {
                base.OnStop();
            }
        }
示例#2
0
 public void SerializeTime(ServiceStopTime serviceStopTime, string path)
 {
     try
     {
         var xmlserializer = new XmlSerializer(typeof(ServiceStopTime));
         using (var writer = new StreamWriter(path))
         {
             xmlserializer.Serialize(writer, serviceStopTime);
             writer.Close();
         }
     }
     catch (Exception ex)
     {
         LogExtension.LogError("Exception while serializing service stop time", ex, MethodBase.GetCurrentMethod());
     }
 }