/// <summary> /// Start a live capture to capture messages. /// </summary> /// <param name="isVerify">Specifies whether to verify the messages during capture. If true, verify the messages during capturing; If false, don't verify the messages.</param> public void StartCapture(bool isVerify = true) { //Set whether verify the messages verifyInLiveCapture = isVerify; if (isVerify) { this.site.Log.Add(LogEntryKind.Comment, "MessageAnalyzerAdapter.StartCapture: If isVerify is true, Make sure the expected Sequence has been loaded."); LoadExpectedSequence(); } //If monitor is not created, create a new monitor. if (monitor == null) { monitor = MessageAnalyzerMonitor.CreateMonitor(null, true); } //If liveCapture is not created, create a new live capture if (liveCapture == null) { // Using default providers if there's no parameter. MMA library will select proper provider according to Windows OS version liveCapture = monitor.CreateLiveTraceSession(); } // If verify the message, parse the message during capturing liveCapture.Start(capturedMessagesSavePath, filter); }
/// <summary> /// Parse and verify a capture file. /// </summary> /// <param name="captureFilePath">Specifies the path of the capture file.</param> /// <param name="saveResult">Specifies whether to save the result or not. If true, save the captured messages and selected messages. If false, don't save.</param> public void ParseAndVerify(string captureFilePath, bool saveResult = false) { // Make sure the expected Sequence has been loaded this.site.Log.Add(LogEntryKind.Comment, "MessageAnalyzerAdapter.StartCapture: Make sure the expected Sequence has been loaded."); LoadExpectedSequence(); // If monitor is not created, create a new monitor. if (monitor == null) { monitor = MessageAnalyzerMonitor.CreateMonitor(null, true); } // Create fileCapture from a capture file fileCapture = (CaptureFileSession)monitor.CreateCaptureFileSession(captureFilePath); // Add verify process to onNewMessageEvent and start the capture fileCapture.Start(filter); // Wait until parse completed fileCapture.WaitUntilParsingComplete(); // Stop the capture fileCapture.Stop(); VerifyMessageSequence(fileCapture); if (saveResult) { fileCapture.SaveCapturedMessages(capturedMessagesSavePath); } }
/// <summary> /// Parse and verify a capture file /// </summary> /// <param name="captureFilePath">Path of the capture file</param> /// <param name="saveResult">If true, save the captured messages and selected messages. If false, don't save</param> public bool ParseAndVerify(string captureFilePath, bool saveResult = false) { // Make sure the expected Sequence has been loaded this.site.Log.Add(LogEntryKind.Comment, "MessageAnalyzerAdapter.StartCapture: Make sure the expected Sequence has been loaded"); LoadExpectedSequence(); // If monitor is not created, create a new monitor. if (monitor == null) { monitor = MessageAnalyzerMonitor.CreateMonitor(null, true); } // Create fileCapture from a capture file fileCapture = (CaptureFileSession)monitor.CreateCaptureFileSession(captureFilePath); // Add verify process to onNewMessageEvent and start the capture fileCapture.Start(filter); // Wait until parse completed fileCapture.WaitUntilParsingComplete(); // Stop the capture fileCapture.Stop(); bool isSuccess = VerifyMessageSequence(fileCapture); if (saveResult) { // Save messages if saveResult is true if (capturedMessagesSavePath != null) { fileCapture.SaveCapturedMessages(capturedMessagesSavePath); } if (selectedMessagesSavePath != null) { fileCapture.SaveCapturedMessages(selectedMessagesSavePath); } } if (isSuccess) { this.site.Log.Add(LogEntryKind.Comment, "MessageAnalyzerAdapter verify stopped. The capture matches the expected sequences."); } else { this.site.Log.Add(LogEntryKind.Comment, "MessageAnalyzerAdapter verify stopped. The capture doesn't match the expected sequences."); } return(isSuccess); }
/// <summary> /// Start a live capture to capture messages /// </summary> /// <param name="capturePath">The capture file path</param> /// <param name="filter">The filter applied to the capture</param> public void StartCapture(string capturePath, string filter = null) { //If monitor is not created, create a new monitor. if (monitor == null) { monitor = MessageAnalyzerMonitor.CreateMonitor(null, true); } //If liveCapture is not created, create a new live capture if (liveCapture == null) { // Using default providers if there's no parameter. MMA library will select proper provider according to Windows OS version liveCapture = monitor.CreateLiveTraceSession(); } liveCapture.Start(capturePath, filter); }
/// <summary> /// Dispose /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { if (liveCapture != null) { liveCapture = null; } if (fileCapture != null) { fileCapture.Dispose(); liveCapture = null; } if (monitor != null) { monitor.Dispose(); monitor = null; } } }
/// <summary> /// Get Messages with filter applied to the capture /// </summary> /// <param name="capturePath">The capture file path</param> /// <param name="frameFilter">The filter applied to the capture</param> /// <returns>Return the filtered messages</returns> public List <Message> GetMessages(string capturePath, string frameFilter) { // If monitor is not created, create a new monitor. if (monitor == null) { monitor = MessageAnalyzerMonitor.CreateMonitor(null, true); } // Create fileCapture from a capture file fileCapture = (CaptureFileSession)monitor.CreateCaptureFileSession(capturePath); // Add verify process to onNewMessageEvent and start the capture fileCapture.Start(frameFilter); // Wait until parse completed fileCapture.WaitUntilParsingComplete(); // Stop the capture fileCapture.Stop(); return(fileCapture.SortedMessagesWithOperationChildrenList.ToList <Message>()); }
/// <summary> /// Initial the Adapter /// </summary> /// <param name="testSite">Test Site</param> public override void Initialize(ITestSite testSite) { this.site = testSite; // Initialize MA environment monitor = MessageAnalyzerMonitor.CreateMonitor(null, true); }