public void factory_can_create_Absentfilter_instance() { var factory = new MonitorFactory(new OkanshiMonitorRegistry(), new Tag[0]); GaugeAbsentFilter <long> gauge = factory.WithAbsentFiltering.LongGauge("foo"); gauge.Config.Name.Should().Be("foo"); }
private ISubfolderController CreateFileController() { var monitorFactory = new MonitorFactory(); var folderCreator = new DefaultProjectionFolderCreator(new FolderCreator(new FileUtil())); return(new SubfolderController(folderCreator, monitorFactory, new ProjectionPipelineFactory())); }
public void Setup() { _controller = new Mock <IController>(); _monitorableProcessor = new Mock <IProcessor>(); _outputGateway = new Mock <IOutputGateway <IMessage> >(); _frequenceHelper = new Mock <IFrequenceHelper>(); _businfo = new Mock <IBusInfo>(); _processorEndpoit = new Mock <IEndPoint>(); _controllerEndpoit = new Mock <IEndPoint>(); _businfo.Setup(x => x.Identification).Returns(new Identification()); _processorEndpoit.Setup(x => x.Uri).Returns(new Uri("http://someUrl")); _controllerEndpoit.Setup(x => x.Uri).Returns(new Uri("http://someUrl")); _monitorableProcessor.Setup(x => x.Identification).Returns(new Identification()); _monitorableProcessor.Setup(x => x.JoinedBusInfo).Returns(_businfo.Object); _monitorableProcessor.Setup(x => x.ReceiverEndPoint).Returns(_processorEndpoit.Object); _controller.Setup(x => x.ReceiverEndPoint).Returns(_controllerEndpoit.Object); _controller.SetupProperty(x => x.Processor, _monitorableProcessor.Object); _frequenceHelper.Setup(f => f.GetFrequence(It.IsAny <FrequenceLevel>())).Returns(60); MonitorFactory.Create(_frequenceHelper.Object); }
/// <summary> /// Creates the monitor factory. /// </summary> /// <returns></returns> private MonitorConfigurator CreateMonitorFactory() { var frequenceHelper = new FrequenceHelper(); if (_monitorConfig.FrequenceLevel.Highest.HasValue) { frequenceHelper.ChangeFrequence(FrequenceLevel.Highest, _monitorConfig.FrequenceLevel.Highest.Value); } if (_monitorConfig.FrequenceLevel.High.HasValue) { frequenceHelper.ChangeFrequence(FrequenceLevel.High, _monitorConfig.FrequenceLevel.High.Value); } if (_monitorConfig.FrequenceLevel.Normal.HasValue) { frequenceHelper.ChangeFrequence(FrequenceLevel.Normal, _monitorConfig.FrequenceLevel.Normal.Value); } if (_monitorConfig.FrequenceLevel.Low.HasValue) { frequenceHelper.ChangeFrequence(FrequenceLevel.Low, _monitorConfig.FrequenceLevel.Low.Value); } if (_monitorConfig.FrequenceLevel.Lowest.HasValue) { frequenceHelper.ChangeFrequence(FrequenceLevel.Lowest, _monitorConfig.FrequenceLevel.Lowest.Value); } MonitorFactory.Create(frequenceHelper); return(this); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string logFilename = "kklog_.txt"; Log.Logger = new LoggerConfiguration() .WriteTo.File(logFilename, outputTemplate: "{Timestamp:yyyy-MM-dd,HH:mm:ss},{Message:lj}{NewLine}{Exception}", restrictedToMinimumLevel: LogEventLevel.Information, rollingInterval: RollingInterval.Day) .WriteTo.File("kkdebug.log") .WriteTo.Trace() .CreateLogger(); MainForm mf = new MainForm(); var readerNames = GetReaderNames(); Log.Information("READERLIST," + string.Join(",", readerNames)); List <string> monitoredReaders = new List <String>(); string r0 = ConfigurationManager.AppSettings["exitreadername"]; if (Array.IndexOf(readerNames, r0) < 0) { Log.Information("ERROR,exit reader not found " + r0); } else { monitoredReaders.Add(r0); } string r1 = ConfigurationManager.AppSettings["entrancereadername"]; if (Array.IndexOf(readerNames, r1) < 0) { Log.Information("ERROR,entrance reader not found " + r1); } else { monitoredReaders.Add(r1); } if (monitoredReaders.Count > 0) { var monitorFactory = new MonitorFactory(_contextFactory); var monitor = monitorFactory.Create(SCardScope.System); monitor.CardInserted += (sender, args) => ProcessEvent(mf, args); monitor.MonitorException += MonitorException; monitor.Start(monitoredReaders.ToArray()); } else { Log.Error("ERROR,There are currently useable readers installed. " + readerNames); } Log.Debug("KurtKilepteto Started"); Application.Run(mf); }
public void BeginMonitorBasicTest(int numLines, int interval) { MonitorTestSetUp(); var cts = new CancellationTokenSource(); Monitor = MonitorFactory.CreateMonitor(MonitorType.Timer, TestHelper.CreateOptions(TestOutputDirectory, "*.txt", interval), WriteToFile, cts.Token); Monitor.BeginMonitor(); AddAFile(numLines); Assert.AreEqual(2, AddedFiles.Count); // sleep here so the timer has fired once Thread.Sleep(interval + 500); // check the event output file for 1 created event var lines = ReadLines(AddedFiles[0]); Assert.AreEqual(1, lines.Count); CheckLine(lines[0], "Created", AddedFiles[1], numLines); // change the file AppendAllText(AddedFiles[1], "11\n"); // sleep here so the timer has fired again Thread.Sleep(interval); lines = ReadLines(AddedFiles[0]); Assert.AreEqual(2, lines.Count); CheckLine(lines[0], "Created", AddedFiles[1], numLines); CheckLine(lines[1], "Changed", AddedFiles[1], 1); // change the file WriteAllText(AddedFiles[1], "0\n"); // sleep here so the timer has fired again Thread.Sleep(interval); lines = ReadLines(AddedFiles[0]); Assert.AreEqual(3, lines.Count); CheckLine(lines[0], "Created", AddedFiles[1], numLines); CheckLine(lines[1], "Changed", AddedFiles[1], 1); CheckLine(lines[2], "Changed", AddedFiles[1], -numLines); // delete the file File.Delete(AddedFiles[1]); // sleep here so the timer has fired again Thread.Sleep(interval); lines = ReadLines(AddedFiles[0]); Assert.AreEqual(4, lines.Count); CheckLine(lines[0], "Created", AddedFiles[1], numLines); CheckLine(lines[1], "Changed", AddedFiles[1], 1); CheckLine(lines[2], "Changed", AddedFiles[1], -numLines); CheckLine(lines[3], "Deleted", AddedFiles[1], 0); cts.Cancel(false); }
protected override void EstablishContext() { A.CallTo(() => _contextFactory.Establish(SCardScope.System)) .Returns(_context); A.CallTo(() => _context.IsValid()) .Returns(true); A.CallTo(() => _context.GetStatusChange(A <IntPtr> .Ignored, A <SCardReaderState[]> .Ignored)) .Invokes(call => { _monitorHasBeenStarted = true; }) .Returns(SCardError.Success); _sut = new MonitorFactory(_contextFactory); }
public void CreateMonitorTest(MonitorType monitorType) { var monitor = MonitorFactory.CreateMonitor(monitorType, TestHelper.CreateOptions(), null, new CancellationToken(true)); switch (monitorType) { case MonitorType.Timer: Assert.IsInstanceOf <TimerMonitor>(monitor); break; case MonitorType.FileSystemWatcher: Assert.IsInstanceOf <DirectoryMonitor>(monitor); break; } }
/// <summary> /// Create MA monitor /// </summary> private MessageAnalyzerMonitor(List <string> GroupList = null, bool isMAInstalled = false) { this.isMAInstalled = isMAInstalled; ConfigureEnvironment(); opnlist = new List <string>(); IMonitorSettings monitorSettings = MonitorFactory.CreateDefaultSettings(); string modelpath = null; if (isMAInstalled) { LiveTraceSession.EnsurePowerShellInitiation(); // If MMA installed, use OPNs under local app data, same as MMA UI, otherwise it will re-generate the CompilationCache if using MMA UI simutaneously. monitorSettings.Host = CreateHostForMAInstalled(); string OPNAndConfigurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "MessageAnalyzer", "OPNAndConfiguration"); modelpath = Path.Combine(OPNAndConfigurationPath, "Opns"); //OpnAndConfiguration\Opns\ in local app data } else { monitorSettings.Host = CreateHost(); modelpath = PlatformManager.ModelsDirectory; // PlatformManager.ModelsDirectory is: "OpnAndConfiguration\Opns\" string opnForEtw = Path.Combine(Path.GetDirectoryName(modelpath), "OpnForEtw"); // OpnAndConfiguration\OpnForEtw monitorSettings.ModelLoadPath.Add(opnForEtw); } if (GroupList == null) { monitorSettings.ModelLoadPath.Add(modelpath); opnlist.Add(modelpath); } else { modelpath = Path.GetDirectoryName((PlatformManager.ModelsDirectory)); // modelpath is set to the path of folder "OpnAndConfiguration" GroupList.ForEach(e => monitorSettings.ModelLoadPath.Add(modelpath + "\\" + e)); GroupList.ForEach(e => opnlist.Add(modelpath + "\\" + e)); } monitorSettings.ExtensionLoadPath.Add(PlatformManager.ExtensionsDirectory); monitor = MonitorFactory.CreateLocalMonitor(monitorSettings); monitor.Initialize(); ModelCatalog.WaitForInitialization(); monitor.CatchExceptionOnGetMessageData = true; }
protected override void EstablishContext() { _contextFactory .CallsTo(f => f.Establish(SCardScope.System)) .Returns(_context); _context.CallsTo(f => f.IsValid()).Returns(true); _context .CallsTo(f => f.GetStatusChange(IntPtr.Zero, A <SCardReaderState[]> .That.Matches( states => states.Any(s => s.ReaderName == REQUESTED_READER)))) .Invokes(call => { _get_status_change_call.Set(); _monitor_has_been_started = true; Thread.Sleep(TimeSpan.FromMilliseconds(100)); }) .Returns(SCardError.Success); _sut = new MonitorFactory(_contextFactory); }
private void CreateQuestion(Control parent, IList <AnswersViewRow> responses, Control tabs, string tabName, UpdateAnswer updateAnswer, IDictionary <string, string> alternateTabLabels = null, Dictionary <string, string> alternateHeadings = null) { var row = responses.First(); if (_QuestionTabFont == null) { _QuestionTabFont = new Font(QuestionTabFontFamily, QuestionTabFontSize, FontStyle.Bold); } var monitor = MonitorFactory.GetMonitorInstance(row.QuestionKey); var panel = AddContainer(parent, "tab-" + tabName + "-" + row.QuestionKey.ToLowerInvariant(), "content-panel tab-panel vtab-panel"); panel.ClientIDMode = ClientIDMode.Static; // create vertical tab var tabLabel = alternateTabLabels?.ContainsKey(row.QuestionKey) == true ? alternateTabLabels[row.QuestionKey] : BreakForTab(row.Question, _QuestionTabFont, QuestionTabMaxWidth); var verticalTab = AddVertTab(tabs, "#" + panel.ClientID, tabLabel, " vcentered-tab"); // center the a tag -- the first child of the tab always Center(verticalTab.Controls[0], false, true); AddAsteriskIndicator(verticalTab, "Ast" + row.QuestionKey, monitor.GetAsteriskClass(null), $"There are unsaved changes to \"{row.Question}\""); AddStarIndicator(verticalTab, "Star" + row.QuestionKey, monitor.GetStarClass(null, "hasvalue"), $"We have a response from you for \"{row.Question}\""); updateAnswer.CreateControls(panel, responses, monitor, alternateHeadings); }
public void SetUp() { _uut = new MonitorFactory(); }