Example #1
0
 public static async Task<bool> ExecuteMonitor(MonitorView monitor, DateTime startTime)
 {
     var result = await monitor.Check(startTime);
     DashOpsCommands.ShowLastLog.RaiseCanExecuteChanged();
     CommandManager.InvalidateRequerySuggested();
     return result;
 }
Example #2
0
        private static string MonitorInfo(MonitorView monitor)
        {
            var sb = new StringBuilder();
            sb.AppendLine(monitor.Title);
            sb.AppendLine();
            sb.Append("ID: ");
            sb.AppendLine(monitor.CommandId);
            sb.Append("Interval: ");
            sb.AppendLine(monitor.Interval.Seconds.ToString());

            if (monitor is CommandMonitorView cmdMonitor)
            {
                sb.Append("Command: ");
                sb.AppendLine(cmdMonitor.Command);
                if (!string.IsNullOrWhiteSpace(cmdMonitor.Arguments))
                {
                    sb.Append("Arguments: ");
                    sb.AppendLine(cmdMonitor.Arguments);
                }
                sb.Append("Working Directory: ");
                sb.AppendLine(cmdMonitor.WorkingDirectory);
            }

            if (monitor is WebMonitorView webMonitor)
            {
                sb.Append("Url: ");
                sb.AppendLine(webMonitor.Url);
                sb.Append("Timeout: ");
                sb.AppendLine(webMonitor.Timeout.Seconds.ToString());
                sb.Append("Allowed Status Codes: ");
                sb.AppendLine(string.Join(", ", webMonitor.StatusCodes));
                if (webMonitor.Headers != null)
                {
                    sb.AppendLine("Headers:");
                    foreach (var key in webMonitor.Headers.Keys.OrderBy(k => k))
                    {
                        sb.AppendLine($"  - {key} = {webMonitor.Headers[key]}");
                    }
                }
                else
                {
                    sb.AppendLine("Headers: none");
                }
            }
            sb.Append("Required Patterns:");
            sb.AppendLine(monitor.RequiredPatterns?.Length.ToString() ?? "0");
            sb.Append("Forbidden Patterns:");
            sb.AppendLine(monitor.ForbiddenPatterns?.Length.ToString() ?? "0");
            return sb.ToString();
        }
Example #3
0
        private static void ProcessMonitor(MonitorView monitor, DateTime now)
        {
            if (monitor.IsRunning)
            {
                return;
            }
            if (monitor.HasLastExecutionResult)
            {
                var nextExecutionTime = monitor.LastExecutionTime + monitor.Interval;
                if (nextExecutionTime > now)
                {
                    return;
                }
            }
#pragma warning disable CS4014
            Core.ExecuteMonitor(monitor, now);
#pragma warning restore CS4014
        }
Example #4
0
 public static void ShowMonitorInfo(MonitorView monitor)
 {
     MessageBox.Show(MonitorInfo(monitor), "Monitor Info",
         MessageBoxButton.OK, MessageBoxImage.Information);
 }