public static void SaveDefaultSettingsForAllClasses() { var logger = new TaskLogging(); try { CommonFunctions.LoadAllSolutionAssemblies(); } catch (Exception e) { logger.CreateLogRecord(e); } foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(t => t.FullName)) { var q = from t in assembly.GetTypes() where t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(SettingsRepresent)) select t; try { q.ToList().ForEach(t => Activator.CreateInstance(t, "")); } catch (Exception e) { logger.CreateLogRecord(e); } } }
public static void SendLog(TaskLogging taskLogging) { var taskRepresent = new { Settings.Project, TaskResult = taskLogging.ErrorAccured() ? "ERROR" : "SUCCESS", ObjectName = taskLogging.Source, CurrentDateTime = DateTime.Now.ToString(CultureInfo.CurrentCulture) }; var header = Settings.ReportHeaderPattern.FormatWith(taskRepresent); var messagesRepresent = GetLogMessageText(taskLogging); try { SendReportMail(header, messagesRepresent.ToString(), taskLogging.Source); } catch (Exception e) { taskLogging.CreateLogRecord(e); } }
public void AddLogRecord(TaskLogging logger) { if (CurrentBackUpState == BackupState.Error) { logger.CreateLogRecord(LogResult, EventLogEntryType.Error); } if (CurrentBackUpState == BackupState.NotApplicable) { logger.CreateLogRecord(LogResult, EventLogEntryType.Warning); } if (CurrentBackUpState == BackupState.Success) { logger.CreateLogRecord(LogResult); } }
private static StringBuilder GetLogMessageText(TaskLogging taskLogging) { var messageText = new StringBuilder(); var firstMessage = taskLogging.Min(t => t.DateTime); var taskRepresent = new { Settings.Project, TaskResult = taskLogging.ErrorAccured() ? "ERROR" : "SUCCESS", ObjectName = taskLogging.Source, CurrentDateTime = firstMessage.ToString(CultureInfo.CurrentCulture) ?? DateTime.Now.ToString(CultureInfo.CurrentCulture) }; var body = Settings.ReportPattern.FormatWith(taskRepresent); messageText.Append(body); messageText.Append("<ul>"); foreach (var message in taskLogging) { messageText.Append("<li>"); var messageRepresent = new { MessageType = message.EntryType.ToString(), MessageDateTime = message.DateTime.ToString(CultureInfo.CurrentCulture), Represent = message.Message }; messageText.Append(Settings.LogMessagePattern.FormatWith(messageRepresent)); messageText.Append("</li>"); } messageText.Append("</ul>"); return(messageText); }
/// <summary> /// Target task entry point /// </summary> /// <returns> /// true for success /// </returns> public override bool Execute() { Logging = new TaskLogging(this); var wrappedTaskPath = GetWrappedTaskPath(); // see if the task is just a stub, which is the case if we have a wrapped task // (this allows to build and debug) if (wrappedTaskPath == null) { return(Run(false)); } // run the application as a command-line application var process = new Process { StartInfo = { FileName = wrappedTaskPath, WorkingDirectory = Environment.CurrentDirectory, Arguments = string.Join(" ", GetPropertiesArguments()), UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardInput = true, } }; process.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data != null) { Logging.Write(e.Data); } }; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); return(process.ExitCode == 0); }
/// <summary> /// Target task entry point /// </summary> /// <returns> /// true for success /// </returns> public override bool Execute() { var wrappedTaskPath = GetWrappedTaskPath(); Logging = new TaskLogging(this); // see if the task is just a stub, which is the case if we have a wrapped task // (this allows to build and debug) if (wrappedTaskPath == null) { Run(); } else { // run the application as a command-line application var process = new Process { StartInfo = { FileName = wrappedTaskPath, Arguments = CreateArguments(), UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardInput = true, } }; process.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data != null) { Logging.Write(e.Data); } }; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); } return(true); }