Exemple #1
0
        private static void WriteLogRecord(Guid guid, int severity, string text, string stackTrace, params string[] textParameters)
        {
            List <BackgroundTask> tasks = TaskController.GetTasks(guid);

            if (tasks.Count > 0)
            {
                BackgroundTask rootTask = tasks[0];

                BackgroundTaskLogRecord log = new BackgroundTaskLogRecord(
                    rootTask.Id,
                    tasks.Count - 1,
                    false,
                    text,
                    stackTrace,
                    textParameters);

                TaskController.AddLog(log);

                if (severity > rootTask.Severity)
                {
                    rootTask.Severity = severity;

                    TaskController.UpdateTask(rootTask);
                }
            }
        }
Exemple #2
0
        public static void StartTask(string taskId, string source, string taskName, object itemName, int itemId,
                                     int scheduleId, int packageId, int maximumExecutionTime, List <BackgroundTaskParameter> parameters)
        {
            if (String.IsNullOrEmpty(taskId))
            {
                taskId = Guid.NewGuid().ToString("N");
            }

            var user = SecurityContext.User;

            int userId = user.OwnerId == 0
                             ? user.UserId
                             : user.OwnerId;

            int effectiveUserId = user.UserId;

            String itemNameStr = itemName != null
                ? itemName.ToString()
                : String.Empty; //: itemId > 0 ? "(Id = " + itemId + ")" : String.Empty;

            BackgroundTask task = new BackgroundTask(Guid, taskId, userId, effectiveUserId, source, taskName, itemNameStr,
                                                     itemId, scheduleId, packageId, maximumExecutionTime, parameters);


            List <BackgroundTask> tasks = TaskController.GetTasks(Guid);

            if (tasks.Count > 0)
            {
                BackgroundTask rootTask = tasks[0];

                BackgroundTaskLogRecord log = new BackgroundTaskLogRecord(
                    rootTask.Id,
                    tasks.Count - 1,
                    true,
                    String.Format("{0}_{1}", source, taskName),
                    new string[] { itemNameStr });


                TaskController.AddLog(log);
            }

            // call event handler
            CallTaskEventHandler(task, false);

            AddTaskThread(TaskController.AddTask(task), Thread.CurrentThread);
        }
Exemple #3
0
        private static void WriteLogRecord(int severity, string text, string stackTrace, params string[] textParameters)
        {
            BackgroundTaskLogRecord logRecord = new BackgroundTaskLogRecord();

            logRecord.Severity            = severity;
            logRecord.Text                = text;
            logRecord.TextParameters      = textParameters;
            logRecord.TextIdent           = TasksStack.Count - 1;
            logRecord.ExceptionStackTrace = stackTrace;
            RootTask.LogRecords.Add(logRecord);
            RootTask.LastLogRecord = logRecord;

            // change entire task severity
            if (severity > RootTask.Severity)
            {
                RootTask.Severity = severity;
            }
        }
Exemple #4
0
        public static void StartTask(string taskId, string source, string taskName, object itemName)
        {
            // create new task object
            BackgroundTask task = new BackgroundTask();

            task.TaskId          = String.IsNullOrEmpty(taskId) ? Guid.NewGuid().ToString("N") : taskId;
            task.UserId          = SecurityContext.User.UserId;
            task.EffectiveUserId = SecurityContext.User.IsPeer ? SecurityContext.User.OwnerId : task.UserId;
            task.StartDate       = DateTime.Now;
            task.Source          = source;
            task.TaskName        = taskName;
            task.ItemName        = itemName != null?itemName.ToString() : "";

            task.Severity   = 0; //info
            task.TaskThread = Thread.CurrentThread;

            // new "parent" task?
            if (TasksStack.Count == 0)
            {
                // register task globally
                tasks[task.TaskId] = task;
            }
            else
            {
                // child task
                // add log record to the root task
                BackgroundTaskLogRecord logRecord = new BackgroundTaskLogRecord();
                logRecord.InnerTaskStart = true;
                logRecord.Text           = source + "_" + taskName;
                logRecord.TextParameters = new string[] { itemName != null?itemName.ToString() : "" };
                logRecord.TextIdent      = TasksStack.Count - 1;
                RootTask.LogRecords.Add(logRecord);

                // change log records destination
                // for nested task
                task.LogRecords = RootTask.LogRecords;
            }

            // call event handler
            CallTaskEventHandler(task, false);

            // push task on the stack
            TasksStack.Add(task);
        }
 public static void AddLog(BackgroundTaskLogRecord log)
 {
     DataProvider.AddBackgroundTaskLog(log.TaskId, log.Date, log.ExceptionStackTrace, log.InnerTaskStart,
                                       log.Severity, log.Text, log.TextIdent, BuildParametersXml(log.TextParameters));
 }
Exemple #6
0
 public static void AddLog(BackgroundTaskLogRecord log)
 {
     DataProvider.AddBackgroundTaskLog(log.TaskId, log.Date, log.ExceptionStackTrace, log.InnerTaskStart,
                                       log.Severity, log.Text, log.TextIdent, BuildParametersXml(log.TextParameters));
 }