Esempio n. 1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref = "T:System.Exception" /> class with a specified error message and a reference to the inner exception that is the cause of this exception.
 /// </summary>
 /// <param name = "message">The error message that explains the reason for the exception. 
 /// </param>
 /// <param name = "task"></param>
 /// <param name = "innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. 
 /// </param>
 public TaskException(string message, TaskBase task, Exception innerException = null)
     : base(message, innerException)
 {
     Task = task;
     this.Critical = false;
 }
 private object[] GetMessagePrameters(TaskBase task)
 {
     return GetMessagePrameters(task, null);
 }
Esempio n. 3
0
 void task_Error(TaskBase sender, VendScreen.Common.UsefulTypes.EventArgs<TaskException> eventArgs)
 {
     var commands = sender.Config.Task.Commands;
     var descr = VSSyncExportTask.GetCommandsDescr(commands, true);
     MessageBox.Show(this, @"The command for sending ({0}) failed. ".F(descr)+ Environment.NewLine + eventArgs.Value.Message, @"Sending error",
         MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
 protected void SendReport(TaskBase task, EventArgs<TaskException> args, string body, List<string> files,
                           string taskStatus)
 {
     var keyLine = args != null && !args.Value.Key.IsNullOrEmpty() ? " Key " + args.Value.Key : null;
     subject = "{0}:{1}.{2}".F(taskStatus, task.Description, keyLine);
     var attachment = args.IfNotNull(item => item.Value.Serialize());
     SendReport(body, attachment, args.IfNotNull(item => item.Value.Files));
 }
        /// <summary>
        ///     create array of parameters for message template
        ///     0 - DateTime.Now
        ///     1 task.Description
        ///     2 Status Message
        ///     3 Error Message
        ///     4 Inner Exception (with stack)
        ///     5 User
        /// </summary>
        /// <param name = "task"></param>
        /// <param name = "args"></param>
        /// <returns></returns>
        protected override object[] GetMessagePrameters(TaskBase task, EventArgs<TaskException> args)
        {
            var error = (args == null)
                            ? string.Empty
                            : (args.Value == null)
                                  ? string.Empty
                                  : args.Value.Message +
                                    (args.Value.InnerException == null
                                         ? string.Empty
                                         : args.Value.InnerException.Message);
            var result = new object[]
            {
                DateTime.Now, task.Description, task.Status.StatusMessage, error,
                args.IfNotNull(val => val.Value).IfNotNull(val => val.InnerException),
                Config.Instance.WebService.Login
            };

            return result;
        }
        public override void TaskError(TaskBase sender, EventArgs<TaskException> eventArgs)
        {
            const string defaultTemplate = "User: {5}\r\n{0} {1} task failed. Error: {3}";
            Log = sender.Logger;
            var template = ErrorMessageTemplate.IsNullOrEmpty() ? defaultTemplate : ErrorMessageTemplate;

            if (eventArgs.Value.InnerException != null)
            {
                template = "User: {5}\r\n{0} {1} task failed. {4}";
            }

            var body = template.F(GetMessagePrameters(sender, eventArgs));
            if (eventArgs.Value.Critical)
            {
                body = "Service was stopped.\r\n" + body;
            }

            string dir = Config.Instance.GetOutputFolder() + "\\tmp\\error_" + DateTime.Now.ToString("yyyyMMdd") + "\\";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            FileInfo fi = new FileInfo(dir + "Errors.log");
            if (!fi.Exists)
            {
                fi.Create().Close();
            }
            using (StreamWriter sw = fi.AppendText())
            {
                sw.WriteLine(body);
                sw.WriteLine();
            }

            //copying not sended files
            foreach (CommandType type in sender.Config.Task.Commands)
            {
                try
                {
                    string filename = type.OutputFileName;
                    File.Copy(Config.Instance.GetOutputFolder() + "\\" + filename, dir + Path.GetFileNameWithoutExtension(filename) + "_" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + Path.GetExtension(filename));
                }
                catch (Exception e) { }
            }

            /*this.error = true;
            const string defaultTemplate = "User: {5}\r\n{0} {1} task failed. Error: {3}";
            Log = sender.Logger;
            var template = ErrorMessageTemplate.IsNullOrEmpty() ? defaultTemplate : ErrorMessageTemplate;

            if (eventArgs.Value.InnerException != null)
            {
                template = "User: {5}\r\n{0} {1} task failed. {4}";
            }

            var body = template.F(GetMessagePrameters(sender, eventArgs));
            if (eventArgs.Value.Critical)
            {
                body = "Service was stopped.\r\n" + body;
            }
            SendReport(sender, eventArgs, body, eventArgs.Value.Files, "Error");*/
        }
Esempio n. 7
0
 protected virtual object[] GetMessagePrameters(TaskBase task, EventArgs<TaskException> eventArgs)
 {
     return null;
 }
Esempio n. 8
0
 public virtual void TaskError(TaskBase sender, EventArgs<TaskException> eventArgs)
 {
 }