コード例 #1
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);
        }
コード例 #2
0
 public bool TryGetTemplateFor(AnalysisId analysisId, out ActiveAnalysisConfiguration configuration)
 {
     lock (_syncRoot)
     {
         return(_lastSavedAnalyses.TryGetValue(analysisId, out configuration));
     }
 }
コード例 #3
0
ファイル: AnalysisStorage.cs プロジェクト: tr00p3r/Tailviewer
        public Task Save(ActiveAnalysisConfiguration analysis)
        {
            var filename  = GetFilename(analysis.Id);
            var directory = Path.GetDirectoryName(filename);

            // We don't know if the directory exists, so we'll just create
            // it beforehand...
            _filesystem.CreateDirectory(directory);
            return(_filesystem.OpenWrite(filename).ContinueWith(x => WriteAnalysis(x, analysis), TaskContinuationOptions.AttachedToParent));
        }
コード例 #4
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);
        }
コード例 #5
0
 private void WriteAnalysis(Task <Stream> task, ActiveAnalysisConfiguration analysisConfiguration)
 {
     using (var stream = task.Result)
     {
         // Just in case we're writing over an existing file...
         stream.SetLength(0);
         using (var writer = new Writer(stream, _typeFactory))
         {
             writer.WriteAttribute("Analysis", analysisConfiguration);
         }
     }
 }
コード例 #6
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();
        }
コード例 #7
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);
        }