private static string GetEventText(MonitorEvent ev) { var sb = new StringBuilder(); sb.Append($"{ev.GetType().Name} - reader: {ev.ReaderName}"); switch (ev) { case CardStatusChanged changed: sb.AppendLine($", previous state: {changed.PreviousState}, new state: {changed.NewState}"); break; case CardRemoved removed: sb.AppendLine($", state: {removed.State}"); break; case CardInserted inserted: sb.AppendLine($", state: {inserted.State}, ATR: {BitConverter.ToString(inserted.Atr)}"); break; case MonitorInitialized initialized: sb.AppendLine($", state: {initialized.State}, ATR: {BitConverter.ToString(initialized.Atr)}"); break; case MonitorCardInfoEvent infoEvent: sb.AppendLine($", state: {infoEvent.State}, ATR: {BitConverter.ToString(infoEvent.Atr)}"); break; } return(sb.ToString()); }
public void When_Monitoring_We_Should_Record_But_Rethrow_Exceptions_Async() { _thrownException = Catch.Exception(() => AsyncContext.Run(async() => await _commandProcessor.SendAsync(_command))); _controlBusSender.Observe <MonitorEvent>(); _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_pass_through_the_exception_not_swallow Assert.NotNull(_thrownException); //_should_monitor_the_exception Assert.IsInstanceOf(typeof(Exception), _afterEvent.Exception); //_should_surface_the_error_message StringAssert.Contains("monitored", _afterEvent.Exception.Message); //_should_have_an_instance_name_after Assert.AreEqual("UnitTests", _afterEvent.InstanceName); //_should_post_the_handler_fullname_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandlerThatThrowsAsync).AssemblyQualifiedName, _afterEvent.HandlerFullAssemblyName); //_should_post_the_handler_name_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandlerThatThrowsAsync).FullName, _afterEvent.HandlerName); //_should_include_the_underlying_request_details_after Assert.AreEqual(_originalRequestAsJson, _afterEvent.RequestBody); //should_post_the_time_of_the_request_after Assert.Greater(_afterEvent.EventTime, _at); //should_post_the_elapsedtime_of_the_request_after Assert.AreEqual((_afterEvent.EventTime - _at).Milliseconds, _afterEvent.TimeElapsedMs); }
public void g2() { MouseKeyboardEvent empty = null; var now = DateTime.Now; var e1 = new MonitorEvent() { EventStart = now, TotalTimeMs = 500 }; _service.AddEvent(e1, out empty).Should().BeFalse(); empty.Should().BeNull(); now = now.AddMilliseconds(750); var e2 = new MonitorEvent() { EventStart = now, TotalTimeMs = 2000 }; _service.AddEvent(e2, out empty).Should().BeFalse(); empty.Should().BeNull(); var created = _service.Flush(); created.Should().NotBeNull(); created.EventsTimeline.Should().BeEquivalentTo(new[] { 0, 500, 750, 2750 }); created.TotalTime.Should().Be(2500); created.End.Should().Be(e1.EventStart.AddMilliseconds(2750)); }
public void When_Monitoring_We_Should_Record_But_Rethrow_Exceptions() { _thrownException = Catch.Exception(() => _commandProcessor.Send(_command)); _controlBusSender.Observe <MonitorEvent>(); //pop but don't inspect before. _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_pass_through_the_exception_not_swallow Assert.NotNull(_thrownException); //_should_monitor_the_exception Assert.IsInstanceOf(typeof(Exception), _afterEvent.Exception); //_should_surface_the_error_message StringAssert.Contains("monitored", _afterEvent.Exception.Message); //_should_have_an_instance_name_after Assert.AreEqual("UnitTests", _afterEvent.InstanceName); //_should_post_the_handler_fullname_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandler).FullName, _afterEvent.HandlerName); //_should_post_the_handler_name_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandler).AssemblyQualifiedName, _afterEvent.HandlerFullAssemblyName); //should_post_the_time_of_the_request_after Assert.Greater(_afterEvent.EventTime, _at); //should_post_the_elapsedtime_of_the_request_after Assert.Greater(_afterEvent.EventTime, _at); //should_post_the_elapsedtime_of_the_request_after Assert.AreEqual((_afterEvent.EventTime - _at).Milliseconds, _afterEvent.TimeElapsedMs); }
public void Event_behind_window_forces_build() { MouseKeyboardEvent empty = null; var now = DateTime.Now; var e1 = new MonitorEvent() { EventStart = now, TotalTimeMs = 1200 }; _service.AddEvent(e1, out empty).Should().BeFalse(); empty.Should().BeNull(); now = now.AddMilliseconds(WindowSz * 2); var e2 = new MonitorEvent() { EventStart = now.AddMilliseconds(2000), TotalTimeMs = 2000 }; _service.AddEvent(e2, out var created).Should().BeTrue(); created.Should().NotBeNull(); created.EventsTimeline.Should().BeEquivalentTo(new[] { 0, 1200 }); created.TotalTime.Should().Be(1200); created.End.Should().Be(e1.EventStart.AddMilliseconds(1200)); }
private void onNext(MonitorEvent ev) { try { sp.isoReaderInit(); if (ev.ToString() == "PCSC.Reactive.Events.CardInserted") { var user = sp.ReadBlock(0x00, BlockId); var pass = sp.ReadBlockRange(0x00, BlockPasswordFrom, BlockPasswordTo); if (cmd.Login(Util.ToASCII(user, 0, user.Length, false), Util.ToASCII(pass, 0, pass.Length, false))) { Dispatcher.Invoke(() => { sh(); }); } else { MessageBox.Show("Staf Pendaftaran tidak terdaftar, hubungi administrator untuk mendaftar.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } catch (Exception) { MessageBox.Show("Pastikan reader sudah terpasang dan kartu sudah berada pada jangkauan reader.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); sp.isoReaderInit(); } }
public async Task When_Monitoring_Is_on_For_A_Handler_Async() { await _commandProcessor.SendAsync(_command); _beforeEvent = _controlBusSender.Observe <MonitorEvent>(); _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_have_an_instance_name_before _beforeEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_event_type_to_the_control_bus_before _beforeEvent.EventType.Should().Be(MonitorEventType.EnterHandler); //_should_post_the_handler_fullname_to_the_control_bus_before _beforeEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandlerAsync).AssemblyQualifiedName); //_should_post_the_handler_name_to_the_control_bus_before _beforeEvent.HandlerName.Should().Be(typeof(MyMonitoredHandlerAsync).FullName); //_should_include_the_underlying_request_details_before _beforeEvent.RequestBody.Should().Be(_originalRequestAsJson); //should_post_the_time_of_the_request_before _beforeEvent.EventTime.AsUtc().Should().BeCloseTo(_at.AsUtc(), 1000); //_should_have_an_instance_name_after _afterEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_event_type_to_the_control_bus_after _afterEvent.EventType.Should().Be(MonitorEventType.ExitHandler); //_should_post_the_handler_fullname_to_the_control_bus_after _afterEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandlerAsync).AssemblyQualifiedName); //_should_post_the_handler_name_to_the_control_bus_after _afterEvent.HandlerName.Should().Be(typeof(MyMonitoredHandlerAsync).FullName); //_should_include_the_underlying_request_details_after _afterEvent.RequestBody.Should().Be(_originalRequestAsJson); //should_post_the_time_of_the_request_after _afterEvent.EventTime.AsUtc().Should().BeAfter(_at.AsUtc()); }
public void When_Monitoring_Is_On_For_A_Handler() { _commandProcessor.Send(_command); _beforeEvent = _controlBusSender.Observe <MonitorEvent>(); _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_have_an_instance_name_before Assert.AreEqual("UnitTests", _beforeEvent.InstanceName); //_should_post_the_event_type_to_the_control_bus_before Assert.AreEqual(MonitorEventType.EnterHandler, _beforeEvent.EventType); //_should_post_the_handler_fullname_to_the_control_bus_before Assert.AreEqual(typeof(MyMonitoredHandler).AssemblyQualifiedName, _beforeEvent.HandlerFullAssemblyName); //_should_post_the_handler_name_to_the_control_bus_before Assert.AreEqual(typeof(MyMonitoredHandler).FullName, _beforeEvent.HandlerName); //_should_include_the_underlying_request_details_before Assert.AreEqual(_originalRequestAsJson, _beforeEvent.RequestBody); //_should_post_the_time_of_the_request_before Assert.AreEqual(_at, _beforeEvent.EventTime); //_should_elapsed_before_as_zero Assert.AreEqual(0, _beforeEvent.TimeElapsedMs); //_should_have_an_instance_name_after Assert.AreEqual("UnitTests", _afterEvent.InstanceName); //_should_post_the_handler_fullname_to_the_control_bus_after Assert.AreEqual(MonitorEventType.ExitHandler, _afterEvent.EventType); //_should_post_the_handler_fullname_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandler).AssemblyQualifiedName, _afterEvent.HandlerFullAssemblyName); //_should_post_the_handler_name_to_the_control_bus_after Assert.AreEqual(typeof(MyMonitoredHandler).FullName, _afterEvent.HandlerName); //_should_include_the_underlying_request_details_after Assert.AreEqual(_originalRequestAsJson, _afterEvent.RequestBody); //should_post_the_time_of_the_request_after Assert.Greater(_afterEvent.EventTime, _at); //should_post_the_elapsedtime_of_the_request_after Assert.AreEqual((_afterEvent.EventTime - _beforeEvent.EventTime).Milliseconds, _afterEvent.TimeElapsedMs); }
public void When_Monitoring_Is_On_For_A_Handler() { _commandProcessor.Send(_command); _beforeEvent = _controlBusSender.Observe <MonitorEvent>(); _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_have_an_instance_name_before _beforeEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_event_type_to_the_control_bus_before _beforeEvent.EventType.Should().Be(MonitorEventType.EnterHandler); //_should_post_the_handler_fullname_to_the_control_bus_before _beforeEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandler).AssemblyQualifiedName); //_should_post_the_handler_name_to_the_control_bus_before _beforeEvent.HandlerName.Should().Be(typeof(MyMonitoredHandler).FullName); //_should_include_the_underlying_request_details_before _beforeEvent.RequestBody.Should().Be(_originalRequestAsJson); //_should_post_the_time_of_the_request_before _beforeEvent.EventTime.AsUtc().Should().BeCloseTo(_at.AsUtc(), TimeSpan.FromSeconds(1)); //_should_elapsed_before_as_zero _beforeEvent.TimeElapsedMs.Should().Be(0); //_should_have_an_instance_name_after _afterEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_handler_fullname_to_the_control_bus_after _afterEvent.EventType.Should().Be(MonitorEventType.ExitHandler); //_should_post_the_handler_fullname_to_the_control_bus_after _afterEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandler).AssemblyQualifiedName); //_should_post_the_handler_name_to_the_control_bus_after _afterEvent.HandlerName.Should().Be(typeof(MyMonitoredHandler).FullName); //_should_include_the_underlying_request_details_after _afterEvent.RequestBody.Should().Be(_originalRequestAsJson); //should_post_the_time_of_the_request_after _afterEvent.EventTime.AsUtc().Should().BeAfter(_at.AsUtc()); }
public bool AddEvent(MonitorEvent ev, out MouseKeyboardEvent created) { var ret = false; if (!_start.HasValue) { _start = ev.EventStart; created = null; } else { var start = ev.EventStart - _start.Value; if (start.TotalMilliseconds >= _windowSizeMs) { created = BuildEvent(); _start = ev.EventStart; ret = true; } else { created = null; } } AddNewEvent(ev); return(ret); }
private void OnNext(MonitorEvent ev) { if (ev.GetType().ToString().Contains("CardInserted")) { String id = GetCardNumber(); SendToActiveWindow(id); } }
private void SetEventEnd(MonitorEvent ev) { _lastMkEventEnd = ev.EventStart.AddMilliseconds(ev.TotalTimeMs); _lastActiveWinExecutable = ev.Executable ?? UnknownExecutableName; if (_lastMkEventStart.HasValue && ev.EventStart == _lastMkEventStart.Value) { _lastMkEventStart = null; _lastMouseOrKey = null; } }
public override void MonitorEvent(MonitorEvent eventCode, LoadedClass c, ulong objectId, ulong counter) { //Console.WriteLine ("MonitorEvent {0} class {1} object {2} counter {3}", eventCode, c.Name, objectId, counter); StackTrace trace = stackTraceFactory.NewStackTrace(stack); if (trace == null) { trace = StackTrace.StackTraceUnavailable; } globalMonitorStatistics.HandleEvent(stack.ThreadId, eventCode, c, objectId, trace, counter); }
internal void Handle(object sender, NetMQSocketEventArgs socketEventArgs) { MonitorEvent monitorEvent = MonitorEvent.Read(MonitoringSocket.SocketHandle); if (monitorEvent != null) { switch (monitorEvent.Event) { case SocketEvent.Connected: InvokeEvent(Connected, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (Socket)monitorEvent.Arg)); break; case SocketEvent.ConnectDelayed: InvokeEvent(ConnectDelayed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg)); break; case SocketEvent.ConnectRetried: InvokeEvent(ConnectRetried, new NetMQMonitorIntervalEventArgs(this, monitorEvent.Addr, (int)monitorEvent.Arg)); break; case SocketEvent.Listening: InvokeEvent(Listening, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (Socket)monitorEvent.Arg)); break; case SocketEvent.BindFailed: InvokeEvent(BindFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg)); break; case SocketEvent.Accepted: InvokeEvent(Accepted, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (Socket)monitorEvent.Arg)); break; case SocketEvent.AcceptFailed: InvokeEvent(AcceptFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg)); break; case SocketEvent.Closed: InvokeEvent(Closed, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (Socket)monitorEvent.Arg)); break; case SocketEvent.CloseFailed: InvokeEvent(CloseFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg)); break; case SocketEvent.Disconnected: InvokeEvent(Disconnected, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (Socket)monitorEvent.Arg)); break; default: throw new Exception("unknown event " + monitorEvent.Event.ToString()); } } }
public MonitorEventMessageMapperTests() { _at = DateTime.UtcNow.AddMilliseconds(-500); _monitorEventMessageMapper = new MonitorEventMessageMapper(); _originalRequestAsJson = JsonConvert.SerializeObject(new MyCommand()); _elapsedMilliseconds = 34; var @event = new MonitorEvent(InstanceName, MonitorEventType.EnterHandler, HandlerName, HandlerFullAssemblyName, _originalRequestAsJson, _at, _elapsedMilliseconds); _message = _monitorEventMessageMapper.MapToMessage(@event); }
TrafficFlow GetTrafficFlow(MonitorEvent e) { if (e == MonitorEvent.Send || e == MonitorEvent.SendTo) { return(TrafficFlow.Outbound); } if (e == MonitorEvent.Recv || e == MonitorEvent.RecvFrom) { return(TrafficFlow.Inbound); } return(TrafficFlow.Undefined); }
private void Handle(object sender, NetMQSocketEventArgs socketEventArgs) { var monitorEvent = MonitorEvent.Read(m_monitoringSocket.SocketHandle); T GetArg <T>() => monitorEvent.Arg is T v ? v : throw new ArgumentException($"Command argument must be of type {typeof(T).Name}."); switch (monitorEvent.Event) { case SocketEvents.Connected: InvokeEvent(Connected, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, GetArg <AsyncSocket>(), SocketEvents.Connected)); break; case SocketEvents.ConnectDelayed: InvokeEvent(ConnectDelayed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)GetArg <int>(), SocketEvents.ConnectDelayed)); break; case SocketEvents.ConnectRetried: InvokeEvent(ConnectRetried, new NetMQMonitorIntervalEventArgs(this, monitorEvent.Addr, GetArg <int>(), SocketEvents.ConnectRetried)); break; case SocketEvents.Listening: InvokeEvent(Listening, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, GetArg <AsyncSocket>(), SocketEvents.Listening)); break; case SocketEvents.BindFailed: InvokeEvent(BindFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)GetArg <int>(), SocketEvents.BindFailed)); break; case SocketEvents.Accepted: InvokeEvent(Accepted, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, GetArg <AsyncSocket>(), SocketEvents.Accepted)); break; case SocketEvents.AcceptFailed: InvokeEvent(AcceptFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)GetArg <int>(), SocketEvents.AcceptFailed)); break; case SocketEvents.Closed: InvokeEvent(Closed, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, GetArg <AsyncSocket>(), SocketEvents.Closed)); break; case SocketEvents.CloseFailed: InvokeEvent(CloseFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)GetArg <int>(), SocketEvents.CloseFailed)); break; case SocketEvents.Disconnected: InvokeEvent(Disconnected, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, GetArg <AsyncSocket>(), SocketEvents.Disconnected)); break; default: throw new Exception("unknown event " + monitorEvent.Event); } }
public void Establish() { _overrideTime = DateTime.UtcNow; Clock.OverrideTime = _overrideTime; _monitorEventMessageMapper = new MonitorEventMessageMapper(); _originalRequestAsJson = JsonConvert.SerializeObject(new MyCommand()); _elapsedMilliseconds = 34; var @event = new MonitorEvent(InstanceName, MonitorEventType.EnterHandler, HandlerName, HandlerFullAssemblyName, _originalRequestAsJson, Clock.Now(), _elapsedMilliseconds); _message = _monitorEventMessageMapper.MapToMessage(@event); }
public static ResponseSnap PreResponse(MonitorEvent item, string traceId) { var success = GetValue <bool>(item.Data, MonitorKeys.response_success); var body = GetValue <string>(item.Data, MonitorKeys.response_body); if (false) { if (success && item.EventType == RequestTypeEnum.Http.ToString().ToLowerInvariant()) { success = TryParseJson(body, out JObject jObject); if (success) { success = jObject.TryGetValue("code", out JToken jToken); if (success) { success = jToken != null && jToken.ToString() == "0"; } } } else if (success && item.EventType == RequestTypeEnum.Signalr.ToString().ToLowerInvariant()) { success = TryParseJson(body, out JObject jObject); if (success) { success = jObject.TryGetValue("success", out JToken jToken); if (success) { success = jToken != null && jToken.ToString().ToLowerInvariant() == "true"; } } } } // response var contentlength = body == null ? 0 : Encoding.Default.GetByteCount(body); var elapsed = GetValue <long>(item.Data, MonitorKeys.response_elapsed); var statusCode = GetValue <int?>(item.Data, MonitorKeys.response_statuscode); var snap = new ResponseSnap { TraceId = traceId, StatusCode = statusCode, Success = success, ContentLength = contentlength, ResponseBody = body, Elapsed = elapsed, CreateTime = DateTime.Now, }; return(snap); }
public void f() { MouseKeyboardEvent empty = null; var now = DateTime.Now; var e1 = new MonitorEvent() { EventStart = now, TotalTimeMs = 250 }; _service.AddEvent(e1, out empty).Should().BeFalse(); empty.Should().BeNull(); var e2 = new MonitorEvent() { EventStart = now.AddMilliseconds(500), TotalTimeMs = 250 }; _service.AddEvent(e2, out empty).Should().BeFalse(); empty.Should().BeNull(); var e3 = new MonitorEvent() { //EventStart = now.AddMilliseconds(500), EventStart = now.AddMilliseconds(1000), TotalTimeMs = 250 }; _service.AddEvent(e3, out empty).Should().BeFalse(); empty.Should().BeNull(); now = now.AddMilliseconds(WindowSz * 2); var e4 = new MonitorEvent() { EventStart = now.AddMilliseconds(500), TotalTimeMs = 250 }; _service.AddEvent(e4, out var created).Should().BeTrue(); created.Should().NotBeNull(); created.EventsTimeline.Should().BeEquivalentTo(new[] { 0, 500, 1000, 1250 }); created.TotalTime.Should().Be(750); created.End.Should().Be(e1.EventStart.AddMilliseconds(1250)); }
private void Handle(object sender, NetMQSocketEventArgs socketEventArgs) { MonitorEvent monitorEvent = MonitorEvent.Read(this.m_monitoringSocket.SocketHandle); switch (monitorEvent.Event) { case SocketEvents.Connected: this.InvokeEvent(this.Connected, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (AsyncSocket)monitorEvent.Arg, SocketEvents.Connected)); break; case SocketEvents.ConnectDelayed: this.InvokeEvent(this.ConnectDelayed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg, SocketEvents.ConnectDelayed)); break; case SocketEvents.ConnectRetried: this.InvokeEvent(this.ConnectRetried, new NetMQMonitorIntervalEventArgs(this, monitorEvent.Addr, (int)monitorEvent.Arg, SocketEvents.ConnectRetried)); break; case SocketEvents.Listening: this.InvokeEvent(this.Listening, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (AsyncSocket)monitorEvent.Arg, SocketEvents.Listening)); break; case SocketEvents.BindFailed: this.InvokeEvent(this.BindFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg, SocketEvents.BindFailed)); break; case SocketEvents.Accepted: this.InvokeEvent(this.Accepted, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (AsyncSocket)monitorEvent.Arg, SocketEvents.Accepted)); break; case SocketEvents.AcceptFailed: this.InvokeEvent(this.AcceptFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg, SocketEvents.AcceptFailed)); break; case SocketEvents.Closed: this.InvokeEvent(this.Closed, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (AsyncSocket)monitorEvent.Arg, SocketEvents.Closed)); break; case SocketEvents.CloseFailed: this.InvokeEvent(this.CloseFailed, new NetMQMonitorErrorEventArgs(this, monitorEvent.Addr, (ErrorCode)monitorEvent.Arg, SocketEvents.CloseFailed)); break; case SocketEvents.Disconnected: this.InvokeEvent(this.Disconnected, new NetMQMonitorSocketEventArgs(this, monitorEvent.Addr, (AsyncSocket)monitorEvent.Arg, SocketEvents.Disconnected)); break; default: throw new Exception("unknown event " + monitorEvent.Event); } }
public static SqlSnap PreSql(MonitorEvent item, string traceId) { var sqlRaw = GetValue <string>(item.Data, MonitorKeys.sql_raw); var sqlBody = GetValue <string>(item.Data, MonitorKeys.sql_body); var snap = new SqlSnap { TraceId = traceId, SqlRaw = sqlRaw, SqlBody = sqlBody, Elapsed = 0, CreateTime = DateTime.Now, }; return(snap); }
public void AddKeyboardEvent(MonitorEvent ev) { Debug.Assert(WorkTime != null); SetEventEnd(ev); if (GetEventBuilder(ev.Executable).KeyboardEventBuilder.AddEvent(ev, out var created)) { WorkTime.AddKeyboardAction(created); SaveIfBufferSz(); _allKeyboardBuilder.AddEvent(ev, out created); } else if (_allKeyboardBuilder.AddEvent(ev, out created)) { SaveIfBufferSz(); } }
private string CreateJsonObject(MonitorEvent monitorEvent) { return(JsonConvert.SerializeObject(new { userName = GetUserName(), timestamp = GetTimestamp(), appVersion = GetAppVersion(), description = monitorEvent.Description, logged = string.Format("{0:yyyy MM dd HH:mm:ss.fff}", monitorEvent.Logged), settings = monitorEvent.Settings }, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore })); }
private void onNext(MonitorEvent ev) { try { if (ev.ToString() == "PCSC.Reactive.Events.CardInserted") { //Debug.WriteLine(ev.ToString()); var user = sp.ReadBlock(0x00, BlockId); var user2 = sp.ReadBlock(0x00, BlockId2); var pass = sp.ReadBlockRange(0x00, BlockPasswordFrom, BlockPasswordTo); var pass2 = sp.ReadBlockRange(0x00, BlockPasswordFrom2, BlockPasswordTo2); //MessageBox.Show(Utils.Util.ToASCII(user2, 0, user.Length, false)); //MessageBox.Show(Utils.Util.ToASCII(pass2, 0, pass2.Length, false)); if (cmd.Login(Util.ToASCII(user, 0, user.Length), Util.ToASCII(pass, 0, pass.Length))) { Settings.Default.role = "admin"; Dispatcher.Invoke(() => { sh(); }); } else { if (cmd.LoginK(Util.ToASCII(user2, 0, user2.Length), Util.ToASCII(pass2, 0, pass2.Length))) { Settings.Default.role = "keuangan"; Dispatcher.Invoke(() => { sh(); }); } else { MessageBox.Show("Admin tidak terdaftar, hubungi administrator untuk mendaftar.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } catch (Exception ex) { //MessageBox.Show("Pastikan reader sudah terpasang dan kartu sudah berada pada jangkauan reader.", // "Error", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(ex.Message); sp.isoReaderInit(); } }
public void When_Serializing_A_Monitoring_Event() { _monitorEvent = _monitorEventMessageMapper.MapToRequest(_message); //_should_have_the_correct_instance_name _monitorEvent.InstanceName.Should().Be(InstanceName); //_should_have_the_correct_handler_name _monitorEvent.HandlerName.Should().Be(HandlerName); //_should_have_the_correct_handler_full_assembly_name _monitorEvent.HandlerFullAssemblyName.Should().Be(HandlerFullAssemblyName); //_should_have_the_correct_monitor_type _monitorEvent.EventType.Should().Be(MonitorEventType.EnterHandler); //_should_have_the_original_request_as_json _monitorEvent.RequestBody.Should().Be(_originalRequestAsJson); //_should_have_the_correct_event_time _monitorEvent.EventTime.AsUtc().Should().BeCloseTo(_at.AsUtc(), 1000); //_should_have_the_correct_time_elapsed _monitorEvent.TimeElapsedMs.Should().Be(_elapsedMilliseconds); }
private void PullAndPushPasswordByApiKey(string apiKey, IEnumerable <AccountMapping> selectedAccounts) { using var password = _a2AContext.RetrievePassword(apiKey.ToSecureString()); foreach (var account in selectedAccounts) { var monitorEvent = new MonitorEvent() { Event = $"Sending password for account {account.AccountName} to {account.VaultName}.", Result = WellKnownData.SentPasswordSuccess, Date = DateTime.UtcNow }; if (_pluginManager.IsDisabledPlugin(account.VaultName)) { monitorEvent.Event = $"{account.VaultName} is disabled or not loaded. No password sent for account {account.AccountName}."; monitorEvent.Event = WellKnownData.SentPasswordFailure; } else { try { _logger.Information(monitorEvent.Event); if (!_pluginManager.SendPassword(account.VaultName, account.AssetName, account.AccountName, password, string.IsNullOrEmpty(account.AltAccountName) ? null : account.AltAccountName)) { _logger.Error( $"Unable to set the password for {account.AccountName} to {account.VaultName}."); monitorEvent.Result = WellKnownData.SentPasswordFailure; } } catch (Exception ex) { _logger.Error(ex, $"Unable to set the password for {account.AccountName} to {account.VaultName}: {ex.Message}."); monitorEvent.Result = WellKnownData.SentPasswordFailure; } } _lastEventsQueue.Enqueue(monitorEvent); } }
public void When_Serializing_A_Monitoring_Event() { _monitorEvent = _monitorEventMessageMapper.MapToRequest(_message); //_should_have_the_correct_instance_name Assert.AreEqual(InstanceName, _monitorEvent.InstanceName); //_should_have_the_correct_handler_name Assert.AreEqual(HandlerName, _monitorEvent.HandlerName); //_should_have_the_correct_handler_full_assembly_name Assert.AreEqual(HandlerFullAssemblyName, _monitorEvent.HandlerFullAssemblyName); //_should_have_the_correct_monitor_type Assert.AreEqual(MonitorEventType.EnterHandler, _monitorEvent.EventType); //_should_have_the_original_request_as_json Assert.AreEqual(_originalRequestAsJson, _monitorEvent.RequestBody); //_should_have_the_correct_event_time Assert.AreEqual(_overrideTime, _monitorEvent.EventTime); //_should_have_the_correct_time_elapsed Assert.AreEqual(_elapsedMilliseconds, _monitorEvent.TimeElapsedMs); }
public static TrackSnap PreTrace(MonitorEvent item, string traceId) { var traceName = GetValue <string>(item.Data, MonitorKeys.service_name); if (string.IsNullOrEmpty(traceName)) { return(null); } var elapsed = GetValue <long>(item.Data, MonitorKeys.response_elapsed); var snap = new TrackSnap { TraceId = traceId, TraceName = traceName, TraceData = item.Data.ToJson(), Elapsed = elapsed, CreateTime = DateTime.Now, }; return(snap); }
public void When_Monitoring_We_Should_Record_But_Rethrow_Exceptions() { _thrownException = Catch.Exception(() => _commandProcessor.Send(_command)); _controlBusSender.Observe <MonitorEvent>(); //pop but don't inspect before. _afterEvent = _controlBusSender.Observe <MonitorEvent>(); //_should_pass_through_the_exception_not_swallow _thrownException.Should().NotBeNull(); //_should_monitor_the_exception _afterEvent.Exception.Should().BeOfType <Exception>(); //_should_surface_the_error_message _afterEvent.Exception.Message.Should().Contain("monitored"); //_should_have_an_instance_name_after _afterEvent.InstanceName.Should().Be("UnitTests"); //_should_post_the_handler_fullname_to_the_control_bus_after _afterEvent.HandlerName.Should().Be(typeof(MyMonitoredHandler).FullName); //_should_post_the_handler_name_to_the_control_bus_after _afterEvent.HandlerFullAssemblyName.Should().Be(typeof(MyMonitoredHandler).AssemblyQualifiedName); //should_post_the_time_of_the_request_after _afterEvent.EventTime.AsUtc().Should().BeAfter(_at.AsUtc()); }
public IHttpActionResult Get() { MonitorEvent evt = new MonitorEvent("OfferService"); int status = 1; String apiUser = RequestContext.Principal.Identity.Name; OffersResponse _responseEnvelope = new OffersResponse(Request.Properties["requestId"].ToString(), true); OperationName = operationName.GetAllLiveOffers.ToString(); try { _responseEnvelope.Data = OffersManager.GetOffers(Request, apiUser); } catch (Exception e) { //In case of an internal application error, we will end up with the internal error id //In case of an internal web service call, we will end up with the back-end unavailable error id //Edit for R184 _responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(errorKey)); //We add the exception with the stack-trace in the OfferServiceLog file LoggerFactory.GetLogger().ErrorJson(new Methods().Exception_ToLogObject(_responseEnvelope.Meta.Id, RequestContext.Principal.Identity.Name, OperationType, OperationName, e)); status = 0; } finally { if (_responseEnvelope.Data.Errors.Count > 0) { if (_responseEnvelope.Data.Errors.Exists(i => i.Id == ErrorKey.ERR_INTERNAL_FATAL)) status = 0; _responseEnvelope.Status = false; } else _responseEnvelope.Data.Errors = null; evt.Log(_responseEnvelope.Meta.Id, "GetOffers", status); } return Ok(_responseEnvelope); }
public IHttpActionResult GetAttribute([FromUri] string id) { OperationName = operationName.GetAttributeOptions.ToString(); MonitorEvent evt = new MonitorEvent("OfferService"); String apiUser = RequestContext.Principal.Identity.Name; int status = 1; AttributeResponse _responseEnvelope = new AttributeResponse(Request.Properties["requestId"].ToString(), true); parameters.Add("AttributeId", id); try { _responseEnvelope.Data = AttributesManager.GetAttribute(Request, apiUser, id); } catch (Exception e) { //Edit for R184 _responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); LoggerFactory.GetLogger().InfoJson(new Methods().Exception_ToLogObject(_responseEnvelope.Meta.Id, RequestContext.Principal.Identity.Name, OperationType, OperationName, e)); status = 0; } finally { if (_responseEnvelope.Data.Errors.Count > 0) { if (_responseEnvelope.Data.Errors.Exists(i => i.Id == ErrorKey.ERR_INTERNAL_FATAL)) status = 0; _responseEnvelope.Status = false; } else _responseEnvelope.Data.Errors = null; evt.Log(_responseEnvelope.Meta.Id, "GetAttributeOptions", status); } return Ok(_responseEnvelope); }
public IHttpActionResult GetAttributes() { MonitorEvent evt = new MonitorEvent("OfferService"); int status = 1; CodebookResponse _responseEnvelope = new CodebookResponse(Request.Properties["requestId"].ToString(), true); String apiUser = RequestContext.Principal.Identity.Name; OperationName = operationName.GetAttributes.ToString(); //Get the attributes and put them into the response envelope try { _responseEnvelope.Data = AttributesManager.GetPublishedAttributes(Request, apiUser); } catch (Exception e) { //Edit for R184 _responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); //R185 Modification //_responseEnvelope.Data.Errors.Add(new ErrorObject(ErrorKey.ERR_INTERNAL_FATAL)); LoggerFactory.GetLogger().InfoJson(new Methods().Exception_ToLogObject(_responseEnvelope.Meta.Id, apiUser, OperationType, OperationName, e)); status = 0; } finally { if (_responseEnvelope.Data.Errors.Count > 0) { if (_responseEnvelope.Data.Errors.Exists(i => i.Id == ErrorKey.ERR_INTERNAL_FATAL)) status = 0; _responseEnvelope.Status = false; } else _responseEnvelope.Data.Errors = null; evt.Log(_responseEnvelope.Meta.Id, "GetAttributeList", status); } return Ok(_responseEnvelope); }