示例#1
0
        public ProjectLoader(string projectPath, Action <Action> dispatcher)
        {
            if (projectPath == null)
            {
                throw new ArgumentNullException(nameof(projectPath));
            }
            Dispatcher = dispatcher;
            if (!File.Exists(projectPath))
            {
                throw new FileNotFoundException("Project file not found.", projectPath);
            }
            ProjectPath = Path.IsPathRooted(projectPath) ? projectPath : Path.Combine(Environment.CurrentDirectory, projectPath);

            var watcher = new FileSystemWatcher(Path.GetDirectoryName(ProjectPath), Path.GetFileName(ProjectPath));

            watcher.Changed     += ProjectFileChangedHandler;
            watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size;

            ProjectView = new ProjectView();
            InitializeDeserialization();
            LoadProject();
            UpdateProjectView();
            watcher.EnableRaisingEvents = true;
        }
示例#2
0
        private void UpdateProjectView()
        {
            ProjectView.ActionViews.Clear();
            foreach (var p in ProjectView.Perspectives)
            {
                p.Dispose();
            }
            ProjectView.Perspectives.Clear();
            ProjectView.MonitorViews.Clear();
            ProjectView.Title = Project?.Title ?? "Unknown";
            var defaultLogDir = ExpandEnv(Project?.Logs);

            if (Project == null)
            {
                return;
            }

            if (defaultLogDir != null)
            {
                if (!Path.IsPathRooted(defaultLogDir))
                {
                    defaultLogDir = Path.Combine(Environment.CurrentDirectory, defaultLogDir);
                }
                if (!Directory.Exists(defaultLogDir))
                {
                    Directory.CreateDirectory(defaultLogDir);
                }
            }

            void AddActionViews(IEnumerable <ActionView> actionViews)
            {
                foreach (var actionView in actionViews)
                {
                    ProjectView.ActionViews.Add(actionView);
                }
            }

            if (Project.Actions != null)
            {
                AddActionViews(Project.Actions.Select(ActionViewFromCommandAction));
            }
            if (Project.ActionDiscovery != null)
            {
                AddActionViews(Project.ActionDiscovery.SelectMany(DiscoverActions));
            }
            if (Project.ActionPatterns != null)
            {
                AddActionViews(Project.ActionPatterns.SelectMany(ExpandActionPattern));
            }

            ApplyAutoAnnotations();
            foreach (var actionView in ProjectView.ActionViews)
            {
                actionView.Logs = BuildLogDirPath(actionView.Logs, actionView.NoLogs);
                if (Project.KeepActionOpen)
                {
                    actionView.KeepOpen = true;
                }
                if (Project.AlwaysCloseAction)
                {
                    actionView.AlwaysClose = true;
                }
            }

            ProjectView.IsMonitoringPaused = Project.PauseMonitors;
            var defaultMonitorInterval   = new TimeSpan(0, 0, Project.DefaultMonitorInterval);
            var defaultWebMonitorTimeout = new TimeSpan(0, 0, Project.DefaultWebMonitorTimeout);

            void AddMonitorViews(IEnumerable <MonitorView> monitorViews)
            {
                foreach (var monitorView in monitorViews)
                {
                    ProjectView.MonitorViews.Add(monitorView);
                }
            }

            if (Project.Monitors != null)
            {
                AddMonitorViews(Project.Monitors.Select(MonitorViewFromCommandMonitor));
            }
            if (Project.MonitorDiscovery != null)
            {
                AddMonitorViews(Project.MonitorDiscovery.SelectMany(DiscoverMonitors));
            }
            if (Project.MonitorPatterns != null)
            {
                AddMonitorViews(Project.MonitorPatterns.SelectMany(ExpandCommandMonitorPattern));
            }
            if (Project.WebMonitors != null)
            {
                AddMonitorViews(Project.WebMonitors.Select(MonitorViewFromWebMonitor));
            }
            if (Project.WebMonitorPatterns != null)
            {
                AddMonitorViews(Project.WebMonitorPatterns.SelectMany(ExpandWebMonitorPattern));
            }
            foreach (var monitorView in ProjectView.MonitorViews)
            {
                monitorView.Logs = BuildLogDirPath(monitorView.Logs, monitorView.NoLogs);
                var logInfo = monitorView.GetLastLogFileInfo();
                if (logInfo != null && logInfo.HasResult)
                {
                    monitorView.LastExecutionResult    = logInfo.Success;
                    monitorView.HasLastExecutionResult = true;
                }

                if (monitorView.Interval < TimeSpan.Zero)
                {
                    monitorView.Interval = defaultMonitorInterval;
                }
                if (monitorView is WebMonitorView webMonitorView)
                {
                    if (webMonitorView.Timeout < TimeSpan.Zero)
                    {
                        webMonitorView.Timeout = defaultWebMonitorTimeout;
                    }
                }
            }

            ProjectView.AddTagsPerspective();
            ProjectView.AddFacettePerspectives(DEF_PERSPECTIVES);
            ProjectView.AddFacettePerspectives(Project.Perspectives.ToArray());
        }