コード例 #1
0
        public ActiveAnalysis(AnalysisTemplate template,
                              ITaskScheduler taskScheduler,
                              ILogAnalyserEngine logAnalyserEngine,
                              TimeSpan maximumWaitTime)
        {
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }
            if (logAnalyserEngine == null)
            {
                throw new ArgumentNullException(nameof(logAnalyserEngine));
            }

            _id                = AnalysisId.CreateNew();
            _template          = template;
            _taskScheduler     = taskScheduler;
            _maximumWaitTime   = maximumWaitTime;
            _logFiles          = new List <ILogFile>();
            _logFile           = new LogFileProxy(taskScheduler, maximumWaitTime);
            _logAnalyserEngine = logAnalyserEngine;
            _analysers         = new Dictionary <DataSourceAnalyser, AnalyserTemplate>();
            _syncRoot          = new object();
        }
コード例 #2
0
        public IAnalysis CreateAnalysis(AnalysisTemplate template, AnalysisViewTemplate viewTemplate)
        {
            ActiveAnalysisConfiguration analysisConfiguration;

            var id       = AnalysisId.CreateNew();
            var analysis = new ActiveAnalysis(id,
                                              template,
                                              _taskScheduler,
                                              _dataSourceAnalyserEngine,
                                              TimeSpan.FromMilliseconds(100));

            try
            {
                analysisConfiguration = new ActiveAnalysisConfiguration(id, template, viewTemplate);
                lock (_syncRoot)
                {
                    _templates.Add(analysisConfiguration);
                    _analyses.Add(analysis.Id, analysis);
                    _lastSavedAnalyses.Add(analysis.Id, analysisConfiguration);
                }
            }
            catch (Exception)
            {
                analysis.Dispose();                 //< ActiveAnalysis actually spawns new analyses on the engine so we should cancel those in case an exception si thrown here...
                throw;
            }

            SaveAsync(analysisConfiguration).Wait();

            return(analysis);
        }
コード例 #3
0
        public void Setup()
        {
            _dataSource = new Mock <IDataSource>();
            _dataSource.Setup(x => x.FullFileName).Returns(@"X:\foo\bar\mega log file.txt");

            _analysis   = new Mock <IAnalysisViewModel>();
            _analysisId = AnalysisId.CreateNew();
            _analysis.Setup(x => x.Id).Returns(_analysisId);
        }
コード例 #4
0
        public void TestDispose()
        {
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _dataSourceAnalyserEngine, TimeSpan.Zero);

            activeAnalysis.Dispose();

            _taskScheduler.PeriodicTaskCount.Should()
            .Be(0, "because all tasks should've been stopped when the group is disposed of");
        }
コード例 #5
0
        public void Setup()
        {
            _id       = AnalysisId.CreateNew();
            _template = new PageTemplate();
            _analyser = new Mock <IAnalysis>();

            _analysisStorage = new Mock <IAnalysisStorage>();

            _pluginRegistry = new PluginRegistry();
        }
コード例 #6
0
 public void Setup()
 {
     _dispatcher   = new ManualDispatcher();
     _viewTemplate = new AnalysisViewTemplate();
     _analyser     = new Mock <IAnalysis>();
     _id           = AnalysisId.CreateNew();
     _analyser.Setup(x => x.Id).Returns(_id);
     _analysisStorage = new Mock <IAnalysisStorage>();
     _pluginRegistry  = new PluginRegistry();
 }
コード例 #7
0
        public void TestCtor1()
        {
            var id            = AnalysisId.CreateNew();
            var template      = new AnalysisTemplate();
            var viewTemplate  = new AnalysisViewTemplate();
            var configuration = new ActiveAnalysisConfiguration(id, template, viewTemplate);

            configuration.Id.Should().Be(id);
            configuration.Template.Should().BeSameAs(template);
            configuration.ViewTemplate.Should().BeSameAs(viewTemplate);
        }
コード例 #8
0
        public void TestConstructionTwoAnalysers()
        {
            _template.Add(new AnalyserTemplate());
            _template.Add(new AnalyserTemplate());

            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _dataSourceAnalyserEngine, TimeSpan.Zero);

            activeAnalysis.Analysers.Should().HaveCount(2);

            _template.Analysers.Should().HaveCount(2, "because the template may not have been modified by the ctor");
        }
コード例 #9
0
        public AnalysisSnapshot(Percentage progress, IEnumerable <DataSourceAnalyserSnapshot> analysers)
        {
            if (analysers == null)
            {
                throw new ArgumentNullException(nameof(analysers));
            }

            _id           = AnalysisId.CreateNew();
            _creationDate = DateTime.Now;
            _progress     = progress;
            _analysers    = analysers.ToArray();
        }
コード例 #10
0
        public void TestTryGetAnalyser()
        {
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _analysisEngine.Object, TimeSpan.Zero);

            _template.Analysers.Should().BeEmpty();

            var configuration = new Mock <ILogAnalyserConfiguration>().Object;
            var analyser      = activeAnalysis.Add(new LogAnalyserFactoryId("foobar"), configuration);

            activeAnalysis.TryGetAnalyser(analyser.Id, out var actualAnalyser).Should().BeTrue();
            actualAnalyser.Should().BeSameAs(analyser);
        }
コード例 #11
0
        public void Setup()
        {
            _id       = AnalysisId.CreateNew();
            _template = new PageTemplate {
                Title = "A page", Layout = new HorizontalWidgetLayoutTemplate()
            };
            _analyser = new Mock <IAnalysis>();

            _analysisStorage = new Mock <IAnalysisStorage>();

            _pluginRegistry = new PluginRegistry();
        }
コード例 #12
0
        public void TestTryGetNonExistentAnalyser()
        {
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _dataSourceAnalyserEngine, TimeSpan.Zero);

            _template.Analysers.Should().BeEmpty();

            var configuration = new Mock <ILogAnalyserConfiguration>().Object;

            activeAnalysis.Add(new AnalyserPluginId("foobar"), configuration);
            activeAnalysis.TryGetAnalyser(AnalyserId.CreateNew(), out var actualAnalyser).Should().BeFalse();
            actualAnalyser.Should().BeNull();
        }
コード例 #13
0
        public void TestRoundtripEmpty()
        {
            var id            = AnalysisId.CreateNew();
            var template      = new AnalysisTemplate();
            var viewTemplate  = new AnalysisViewTemplate();
            var configuration = new ActiveAnalysisConfiguration(id, template, viewTemplate);

            var actualConfiguration = configuration.Roundtrip();

            actualConfiguration.Id.Should().Be(id);
            actualConfiguration.Template.Should().NotBeNull();
            actualConfiguration.ViewTemplate.Should().NotBeNull();
        }
コード例 #14
0
        public void TestAddRemove1()
        {
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _dataSourceAnalyserEngine, TimeSpan.Zero);

            _template.Analysers.Should().BeEmpty();

            var analyser = activeAnalysis.Add(new AnalyserPluginId("foobar"), null);

            _template.Analysers.Should().HaveCount(1);

            activeAnalysis.Remove(analyser);
            _template.Analysers.Should().BeEmpty();
        }
コード例 #15
0
        public void TestAddRemove1()
        {
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _analysisEngine.Object, TimeSpan.Zero);

            _template.Analysers.Should().BeEmpty();

            var analyser = activeAnalysis.Add(new LogAnalyserFactoryId("foobar"), null);

            _template.Analysers.Should().HaveCount(1);

            activeAnalysis.Remove(analyser);
            _template.Analysers.Should().BeEmpty();
        }
コード例 #16
0
        public void TestAdd1()
        {
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _dataSourceAnalyserEngine, TimeSpan.Zero);

            _template.Analysers.Should().BeEmpty();

            var configuration = new Mock <ILogAnalyserConfiguration>().Object;
            var analyser      = activeAnalysis.Add(new AnalyserPluginId("foobar"), configuration);

            _template.Analysers.Should().HaveCount(1);
            var template = _template.Analysers.First();

            template.Id.Should().Be(analyser.Id);
            template.AnalyserPluginId.Should().Be(new AnalyserPluginId("foobar"));
            template.Configuration.Should().Be(configuration);
        }
コード例 #17
0
        public void TestAnalyse()
        {
            var settings = CreateDataSource();

            using (var dataSource = new SingleDataSource(_scheduler, settings, _logFile.Object, TimeSpan.Zero))
            {
                var analysisId = AnalysisId.CreateNew();
                dataSource.IsAnalysisActive(analysisId).Should().BeFalse("because the file isn't part of any analysis");

                dataSource.EnableAnalysis(analysisId);
                dataSource.IsAnalysisActive(analysisId).Should().BeTrue("because we've just activated that");

                dataSource.DisableAnalysis(analysisId);
                dataSource.IsAnalysisActive(analysisId).Should().BeFalse("because we've just disabled that");
            }
        }
コード例 #18
0
        public void Setup()
        {
            _dispatcher    = new ManualDispatcher();
            _taskScheduler = new ManualTaskScheduler();

            _analysisStorage = new Mock <IAnalysisStorage>();
            _analysisStorage.Setup(x => x.CreateAnalysis(It.IsAny <AnalysisTemplate>(), It.IsAny <AnalysisViewTemplate>()))
            .Returns((AnalysisTemplate templates, AnalysisViewTemplate viewTemplate) =>
            {
                var analysis = new Mock <IAnalysis>();
                var id       = AnalysisId.CreateNew();
                analysis.Setup(x => x.Id).Returns(id);
                return(analysis.Object);
            });

            _sidePanel = new AnalysesSidePanel(_dispatcher, _taskScheduler, _analysisStorage.Object);
        }
コード例 #19
0
        private IAnalysis AddAnalysis()
        {
            var analysis = new Mock <IAnalysis>();
            var id       = AnalysisId.CreateNew();

            analysis.Setup(x => x.Id).Returns(id);
            _analyses.Add(analysis.Object);

            var config = new ActiveAnalysisConfiguration();

            _templates.Add(id, config);

            _analysisStorage.Setup(x => x.TryGetTemplateFor(It.Is <AnalysisId>(y => y == id), out config))
            .Returns(true);

            return(analysis.Object);
        }
コード例 #20
0
        public void TestAddLogFileThenAddWidget()
        {
            var engine   = new Mock <IDataSourceAnalyserEngine>();
            var analyser = new Mock <IDataSourceAnalyser>();

            engine.Setup(x => x.CreateAnalyser(It.IsAny <ILogFile>(), It.IsAny <AnalyserTemplate>()))
            .Returns(analyser.Object);

            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, engine.Object, TimeSpan.Zero);

            var id      = DataSourceId.CreateNew();
            var logFile = new Mock <ILogFile>();

            activeAnalysis.Add(id, logFile.Object);

            activeAnalysis.Add(AnalyserPluginId.Empty, new TestLogAnalyserConfiguration());
            analyser.Verify(x => x.OnLogFileAdded(id, logFile.Object), Times.Once, "because we've just added a log file for analysis and thus the analyser should have been notified");
        }
コード例 #21
0
        public void TestAddRemoveCustomAnalyzer1()
        {
            var pluginLoader = new PluginRegistry();
            var id           = new AnalyserPluginId("stuff");
            var plugin       = new Mock <IDataSourceAnalyserPlugin>();

            plugin.Setup(x => x.Id).Returns(id);
            pluginLoader.Register(plugin.Object);
            _dataSourceAnalyserEngine = new DataSourceAnalyserEngine(_taskScheduler, _logAnalyserEngine.Object, pluginLoader);
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _dataSourceAnalyserEngine, TimeSpan.Zero);

            _template.Analysers.Should().BeEmpty();

            var analyser = activeAnalysis.Add(id, null);

            _template.Analysers.Should().HaveCount(1);

            activeAnalysis.Remove(analyser);
            _template.Analysers.Should().BeEmpty();
        }
コード例 #22
0
        public void Setup()
        {
            _settings   = new Mock <IApplicationSettings>();
            _mainWindow = new Mock <IMainWindowSettings>();
            _settings.Setup(x => x.MainWindow).Returns(_mainWindow.Object);

            _dataSources     = new Mock <IDataSources>();
            _dispatcher      = new ManualDispatcher();
            _taskScheduler   = new ManualTaskScheduler();
            _pluginRegistry  = new PluginRegistry();
            _analysisStorage = new Mock <IAnalysisStorage>();
            _analysisStorage
            .Setup(x => x.CreateAnalysis(It.IsAny <AnalysisTemplate>(), It.IsAny <AnalysisViewTemplate>()))
            .Returns(() =>
            {
                var analysis = new Mock <IAnalysis>();
                var id       = AnalysisId.CreateNew();
                analysis.Setup(x => x.Id).Returns(id);
                return(analysis.Object);
            });
        }
コード例 #23
0
        public void TestConstructionEmptyTemplate()
        {
            var activeAnalysis = new ActiveAnalysis(AnalysisId.CreateNew(), _template, _taskScheduler, _dataSourceAnalyserEngine, TimeSpan.Zero);

            activeAnalysis.Analysers.Should().BeEmpty();
        }