/// <summary> /// Verifies received events against events events. /// </summary> public static void VerifyReceive(int count, Type eventObjectType, ICollection <int> eventTypes) { // check if expected event count has been received; Wait returns false if there were none. Assert.IsTrue(ReceivedEvent.Wait(Timeout), "Failed to receive expected number of events. Remaining count: " + ReceivedEvent.CurrentCount); Assert.AreEqual(count, ReceivedEvents.Count); Assert.IsTrue(ReceivedEvents.All(x => x.GetType() == eventObjectType)); Assert.IsTrue(ReceivedEvents.All(x => eventTypes.Contains(x.Type))); AssertFailures(); }
/// <summary> /// Captures network data of the specified device /// </summary> /// <param name="device">Device to capture</param> protected void CaptureData(CaptureDevice captureDevice) { if (captureResetEvent.IsSet) { captureResetEvent.Reset(); } while (true) { if (cancellationTokenSource.IsCancellationRequested) { try { captureDevice.Device.Close(); captureDevice.IsOpened = false; } catch (Exception e) { LogProvider.Log.Error(this, $"Device {captureDevice.Device.Name} has not been closed. [{SiteString}]", e); } if (!captureResetEvent.IsSet && captureDevices.All(x => !x.IsOpened)) { captureResetEvent.Set(); } return; } try { var nextPacket = captureDevice.Device.GetNextPacket(); if (nextPacket != null) { ParsePacket(nextPacket); } else { Task.Delay(NoDataDelay).Wait(); } } catch (Exception e) { if (captureDevice.ParserLogErrorCounter < 3) { LogProvider.Log.Error(this, $"Data from {captureDevice.Device.Name}, {captureDevice.Device.Description} couldn't be parsed due to internal error. [{SiteString}]", e); captureDevice.ParserLogErrorCounter++; } } } }
/// <summary> /// Captures network data of the specified device /// </summary> /// <param name="device">Device to capture</param> protected void CaptureData(CaptureDevice captureDevice) { if (captureResetEvent.IsSet) { captureResetEvent.Reset(); } while (true) { if (cancellationTokenSource.IsCancellationRequested) { try { captureDevice.Device.Close(); captureDevice.IsOpened = false; } catch (Exception e) { LogProvider.Log.Error(this, $"Device {captureDevice.Device.Name} has not been closed.", e); } if (!captureResetEvent.IsSet && captureDevices.All(x => !x.IsOpened)) { captureResetEvent.Set(); } return; } try { var nextPacket = captureDevice.Device.GetNextPacket(); if (nextPacket != null) { ParsePacket(nextPacket); } else { Task.Delay(NoDataDelay).Wait(); } } catch (Exception e) { LogProvider.Log.Error(this, $"Data has not been captured from {captureDevice.Device.Name}.", e); } } }
private void PostProcessHandler() { // Wait until we have forms and none of them are processing while (_processForms.Any() && _processForms.Any(x => x.Status == InstallerStatus.Processing) == false) { Thread.Sleep(TimeSpan.FromSeconds(1)); } if (_processForms.All(x => x.Status == InstallerStatus.Completed)) { // close the open windows if all successful foreach (InstallerForm form in _processForms) { if (form != null && form.InvokeRequired) { form.Invoke(new MethodInvoker(() => form.Close())); } } } else { UpdateStatus("Error Processing"); } }
private void ObjectInvariant() { Contract.Invariant(_pool.All(t => t is PooledSocket)); }