コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
 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);
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
ファイル: Tasker.cs プロジェクト: picrap/BuildTasker
        /// <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);
        }