Пример #1
0
 private static string GetCorrelationId(string taskName)
 {
     try
     {
         var           factory  = new TaskServiceConvertorFactory();
         DateTime      time     = DateTime.Now;
         ITaskEventLog eventLog = factory.CreateTaskEventLog(taskName);
         ITaskEvent    events   = (from a in eventLog
                                   where a.TaskCategory == "Task Started" && time > StartTime
                                   orderby a.TimeCreated
                                   select a).LastOrDefault();
         if (null != events)
         {
             return(events.Correlation);
         }
         return("");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
         Log("Error",
             string.Format(
                 "Error creating task history. Exception: {0}" + Environment.NewLine + "StackTrace: {1}",
                 e.Message, e.StackTrace));
         Environment.Exit(1);
     }
     return("");
 }
Пример #2
0
        public IList <IResourceHistory> CreateHistory(IScheduledResource resource)
        {
            // group event log entries by correlation id
            ITaskEventLog evt       = _factory.CreateTaskEventLog(String.Format("\\{0}\\", _warewolfFolderPath) + resource.Name);
            var           groupings =
                from a in
                evt.Where(x => !String.IsNullOrEmpty(x.Correlation) && !String.IsNullOrEmpty(x.TaskCategory) && _taskStates.Values.Contains(x.TaskCategory))
                group a by a.Correlation
                into corrGroup
                select new

            {
                StartDate = corrGroup.Min(a => a.TimeCreated),
                EndDate   = corrGroup.Max(a => a.TimeCreated),
                EventId   = corrGroup.Max(a => a.EventId),
                corrGroup.Key
            };
            // for each grouping get the data and debug output
            IList <IResourceHistory> eventList = groupings.OrderBy(a => a.StartDate).Reverse().Take(resource.NumberOfHistoryToKeep == 0 ? int.MaxValue : resource.NumberOfHistoryToKeep).Select(
                a =>
                new ResourceHistory("", CreateDebugHistory(DebugHistoryPath, a.Key),
                                    new EventInfo(a.StartDate.Value, a.StartDate.HasValue && a.EndDate.HasValue ? a.EndDate.Value.Subtract(a.StartDate.Value) : TimeSpan.MaxValue, a.EndDate.Value, GetRunStatus(a.EventId, DebugHistoryPath, a.Key), a.Key, a.EventId < 103 ? "" : _taskStates[a.EventId]), GetUserName(DebugHistoryPath, a.Key))
                as IResourceHistory).ToList();

            return(eventList);
        }
Пример #3
0
        public IList <IResourceHistory> CreateHistory(IScheduledResource resource)
        {
            ITaskEventLog evt       = _factory.CreateTaskEventLog($"\\{_warewolfFolderPath}\\" + resource.Name);
            var           groupings = from a in evt.Where(x => !string.IsNullOrEmpty(x.Correlation) &&
                                                          !string.IsNullOrEmpty(x.TaskCategory) && _taskStates.Values.Contains(x.TaskCategory))
                                      group a by a.Correlation into corrGroup
                                      select new
            {
                StartDate = corrGroup.Min(a => a.TimeCreated),
                EndDate   = corrGroup.Max(a => a.TimeCreated),
                EventId   = corrGroup.Max(a => a.EventId),
                corrGroup.Key
            };
            // for each grouping get the data and debug output
            IList <IResourceHistory> eventList = groupings.OrderBy(a => a.StartDate).Reverse()
                                                 .Take(resource.NumberOfHistoryToKeep == 0 ? int.MaxValue : resource.NumberOfHistoryToKeep)
                                                 .Select(a =>
            {
                TimeSpan duration;
                DateTime start;
                DateTime end;
                var debugOutput = CreateDebugHistory(DebugHistoryPath, a.Key);
                var output      = debugOutput.FirstOrDefault();
                if (output != null)
                {
                    duration = new TimeSpan(output.Duration.Hours, output.Duration.Minutes, output.Duration.Seconds);
                    start    = output.StartTime;
                    end      = output.EndTime;
                }
                else
                {
                    start    = a.StartDate.Value; end = a.EndDate.Value;
                    duration = a.StartDate.HasValue && a.EndDate.HasValue ? a.EndDate.Value.Subtract(a.StartDate.Value) : TimeSpan.MaxValue;
                }
                return(new ResourceHistory("", debugOutput,
                                           new EventInfo(start, duration, end, GetRunStatus(a.EventId, DebugHistoryPath, a.Key), a.Key, a.EventId < 103 ? "" : _taskStates[a.EventId]), GetUserName(DebugHistoryPath, a.Key))
                       as IResourceHistory);
            }).ToList();
            var result = eventList.Where(history => history.TaskHistoryOutput.Success != ScheduleRunStatus.Unknown).ToList();

            return(result);
        }