internal static string GetFilename(AnalysisId id) { var fname = string.Format("{0}.{1}", id, Constants.AnalysisExtension); var filename = Path.Combine(Constants.AnalysisDirectory, fname); return(filename); }
public bool TryGetTemplateFor(AnalysisId analysisId, out ActiveAnalysisConfiguration configuration) { lock (_syncRoot) { return(_lastSavedAnalyses.TryGetValue(analysisId, out configuration)); } }
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); }
public ActiveAnalysis( AnalysisId id, 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 = id; _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(); }
/// <inheritdoc /> public Task Save(AnalysisId id) { ActiveAnalysisConfiguration config; if (!TryGetTemplateFor(id, out config)) return Task.FromResult(42); return Save(config); }
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"); }
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); }
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(); }
public void Setup() { _id = AnalysisId.CreateNew(); _template = new PageTemplate(); _analyser = new Mock <IAnalysis>(); _analysisStorage = new Mock <IAnalysisStorage>(); _pluginRegistry = new PluginRegistry(); }
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"); }
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); }
/// <inheritdoc /> public Task SaveAsync(AnalysisId id) { ActiveAnalysisConfiguration config; if (!TryGetTemplateFor(id, out config)) { Log.WarnFormat("Unable to find configuration with id '{0}', it will not be saved!", id); return(Task.FromResult(42)); } return(SaveAsync(config)); }
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); }
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(); }
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(); }
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(); }
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(); }
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(); }
public bool TryReadAttribute(string name, out AnalysisId value) { Guid tmp; if (!TryReadAttribute(name, out tmp)) { value = default(AnalysisId); return(false); } value = new AnalysisId(tmp); return(true); }
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(); }
/// <summary> /// Initializes this object. /// </summary> public ActiveAnalysisConfiguration(AnalysisId id, AnalysisTemplate template, AnalysisViewTemplate viewTemplate) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (viewTemplate == null) { throw new ArgumentNullException(nameof(viewTemplate)); } _id = id; Template = template; ViewTemplate = viewTemplate; }
public bool TryGetAnalysisFor(AnalysisId id, out IAnalysis analysis) { lock (_syncRoot) { ActiveAnalysis tmp; if (_analyses.TryGetValue(id, out tmp)) { analysis = tmp; return(true); } } analysis = null; return(false); }
public void Remove(AnalysisId id) { lock (_syncRoot) { _templates.RemoveAll(x => x.Id == id); ActiveAnalysis analysis; if (_analyses.TryGetValue(id, out analysis)) { analysis.Dispose(); _analyses.Remove(id); var filename = GetFilename(id); _filesystem.DeleteFile(filename); } } }
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"); } }
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); }
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); }
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); }
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"); }
public AnalysisPageViewModel(AnalysisId id, PageTemplate template, IAnalysis analysis, IAnalysisStorage analysisStorage, IPluginLoader pluginLoader) { _id = id; _template = template ?? throw new ArgumentNullException(nameof(template)); _analysis = analysis ?? throw new ArgumentNullException(nameof(analysis)); _analysisStorage = analysisStorage ?? throw new ArgumentNullException(nameof(analysisStorage)); _name = "New Page"; _deletePageCommand = new DelegateCommand(DeletePage, () => _canBeDeleted); _widgets = new List <IWidgetViewModel>(); _analysersPerWidget = new Dictionary <IWidgetViewModel, IDataSourceAnalyser>(); PageLayout = PageLayout.WrapHorizontal; var widgetPlugins = LoadRelevantPlugins(pluginLoader); foreach (var widgetTemplate in template.Widgets) { if (_analysis.TryGetAnalyser(widgetTemplate.AnalyserId, out var analyser)) { if (widgetPlugins.TryGetValue(widgetTemplate.LogAnalyserFactoryId, out var plugin)) { AddExistingWidget(plugin, widgetTemplate, analyser); } else { Log.WarnFormat("Unable to find plugin widget factory '{0}', widget '{1} ({2})' will NOT be displayed", widgetTemplate.LogAnalyserFactoryId, widgetTemplate.Title, widgetTemplate.Id); } } else { Log.WarnFormat("Unable to find analyser '{0}', widget '{1} ({2})' will NOT be displayed", widgetTemplate.AnalyserId, widgetTemplate.Title, widgetTemplate.Id); } } }
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(); }