private void timerMain_Elapsed(object p_Sender, System.Timers.ElapsedEventArgs p_E) { try { ucConfigurations = UserConfigurations.DeserializeFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configurations.xml")); } catch (Exception p_Exception) { logger.Error("Loading service configurations failed! \n" + Utils.GetExceptionMessage(p_Exception)); return; } try { using (FileTarget target = (FileTarget)LogManager.Configuration.FindTargetByName("file")) { target.MaxArchiveFiles = ucConfigurations.MaxArchiveFiles; } } catch (Exception p_Exception) { logger.Error(Utils.GetExceptionMessage(p_Exception)); return; } int hour = DateTime.Now.Hour; int minute = DateTime.Now.Minute; if (minute == ucConfigurations.StartTime.Minute && hour == ucConfigurations.StartTime.Hour) { Run(0); } }
public static UserConfigurations DeserializeFromFile(string p_FileName) { using (FileStream fileStream = new FileStream(p_FileName, FileMode.Open)) { try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(UserConfigurations)); UserConfigurations userConfiguration = (UserConfigurations)xmlSerializer.Deserialize(fileStream); return(userConfiguration); } finally { fileStream.Close(); } } }