public void WhenCreatingPageableLogArchiveThenLogArchiveIsCreatedEmpty() { var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); Assert.IsFalse(pageableLogArchive.LogNames.Any(), "Expected to get an empty log archive"); AssertArchiveFile(expectedNumberOfEntries: 0); }
public async Task WhenSendingTracesThenTracesAreSaved() { // Create the log tracer, trace a bit, and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); var log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); using (ILogArchiveTracer tracer = log.CreateTracer()) { Assert.AreEqual("mylog", tracer.SessionId, "Mismatch on the tracer's session ID"); tracer.TraceVerbose("0"); tracer.TraceInformation("1"); tracer.TraceWarning("2"); tracer.TraceError("3"); } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(0, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(0, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(3, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(1, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(4, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(4, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); AssertTraceLine(log, 0, TraceLevel.Verbose, "0"); AssertTraceLine(log, 1, TraceLevel.Info, "1"); AssertTraceLine(log, 2, TraceLevel.Warning, "2"); AssertTraceLine(log, 3, TraceLevel.Error, "3"); // Now reopen the tracer and validate again pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(0, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(0, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(3, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(1, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(4, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(4, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); AssertTraceLine(log, 0, TraceLevel.Verbose, "0"); AssertTraceLine(log, 1, TraceLevel.Info, "1"); AssertTraceLine(log, 2, TraceLevel.Warning, "2"); AssertTraceLine(log, 3, TraceLevel.Error, "3"); }
public async Task WhenGettingLogFromEmptyArchiveThenLogIsCreatedOnce() { // Create the log tracer and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); IPageableLog log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); AssertEmptyLogTracer(log, "mylog"); AssertArchiveFile(expectedNumberOfEntries: 1); AssertEmptyArchiveLogEntry("mylog"); // Create the log tracer again, and validate that nothing has happened pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); AssertEmptyLogTracer(log, "mylog"); AssertArchiveFile(expectedNumberOfEntries: 1); AssertEmptyArchiveLogEntry("mylog"); }
public async Task WhenGettingTwoLogsFromEmptyArchiveThenLogsAreCreated() { // Create the first log tracer and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); IPageableLog log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); AssertEmptyLogTracer(log, "mylog"); AssertArchiveFile(expectedNumberOfEntries: 1); AssertEmptyArchiveLogEntry("mylog"); // Create the second log tracer and validate pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog2", TestPageSize); AssertEmptyLogTracer(log, "mylog2"); AssertArchiveFile(expectedNumberOfEntries: 2); AssertEmptyArchiveLogEntry("mylog"); AssertEmptyArchiveLogEntry("mylog2"); }
public async Task WhenUpdatingPageSizeThenPagesAreHandledCorrectly() { // Create the log tracer, trace a lot, validate, update page size, trace and validate more var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); var log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); using (ILogArchiveTracer tracer = log.CreateTracer()) { for (int i = 0; i < TestPageSize * 10; i++) { tracer.TraceInformation($"{i}"); } } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(9, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(90, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(99, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(10, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 10, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); for (int i = 0; i < 10; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } log.CurrentPageIndex = 3; log.PageSize = 7; Assert.AreEqual(4, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(28, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(34, log.CurrentPageEnd, "Mismatch on the log's current page end"); for (int i = 0; i < 7; i++) { AssertTraceLine(log, i, TraceLevel.Info, $"{(4 * 7) + i}"); } }
public async Task WhenSendingManyTracesThenPagesAreHandledCorrectly() { // Create the log tracer, trace a lot, and validate var pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); var log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); using (ILogArchiveTracer tracer = log.CreateTracer()) { for (int i = 0; i < TestPageSize * 10; i++) { tracer.TraceInformation($"{i}"); } } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(9, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(90, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(99, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(10, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 10, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); log.CurrentPageIndex = 4; for (int i = 0; i < 10; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } // Now reopen the tracer, validate, trace some more and validate again pageableLogArchive = new PageableLogArchive("test/detector", LogsFolder); log = await pageableLogArchive.GetLogAsync("mylog", TestPageSize); Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(0, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(0, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(9, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(10, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 10, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); for (int i = 0; i < 10; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } using (ILogArchiveTracer tracer = log.CreateTracer()) { for (int i = TestPageSize * 10; i < TestPageSize * 11; i++) { tracer.TraceInformation($"{i}"); } } Assert.AreEqual(TestPageSize, log.PageSize, "Mismatch on the log's page size"); Assert.AreEqual(10, log.CurrentPageIndex, "Mismatch on the log's current page"); Assert.AreEqual(100, log.CurrentPageStart, "Mismatch on the log's current page start"); Assert.AreEqual(109, log.CurrentPageEnd, "Mismatch on the log's current page end"); Assert.AreEqual(11, log.NumberOfPages, "Mismatch on the log's number of pages"); Assert.AreEqual(TestPageSize * 11, log.NumberOfTraceLines, "Mismatch on the log's number of trace lines"); Assert.AreEqual("mylog", log.Name, "Mismatch on the log's name"); Assert.AreEqual(TestPageSize, log.CurrentPageTraces.Count, "Mismatch on the log's current page traces count"); for (int i = 0; i < 11; i++) { log.CurrentPageIndex = i; AssertPageTraces(log, i); } }
/// <summary> /// Raises the <see cref="Application.Startup" /> event. /// </summary> /// <param name="e">A <see cref="StartupEventArgs" /> that contains the event data.</param> protected override void OnStartup(StartupEventArgs e) { // Cleanup previous temp folders (that are at least 2 days old), and create a new temp folder FileSystemExtensions.CleanupTempFolders(TempSubFolderName, 48); tempFolder = FileSystemExtensions.CreateTempFolder(TempSubFolderName); NotificationService notificationService = new NotificationService(); ITracer consoleTracer = new ConsoleTracer(string.Empty); var smartDetectorLoader = new SmartDetectorLoader(tempFolder, consoleTracer); // *Temporary*: if package file path wasn't accepted, raise file selection window to allow package file selection. // This option should be removed before launching version for customers (bug for tracking: 1177247) string smartDetectorPackagePath = e.Args.Length != 1 ? GetSmartDetectorPackagePath() : Diagnostics.EnsureStringNotNullOrWhiteSpace(() => e.Args[0]); SmartDetectorPackage smartDetectorPackage; using (var fileStream = new FileStream(smartDetectorPackagePath, FileMode.Open)) { smartDetectorPackage = SmartDetectorPackage.CreateFromStream(fileStream); } try { SmartDetectorManifest smartDetectorManifest = smartDetectorPackage.Manifest; ISmartDetector detector = smartDetectorLoader.LoadSmartDetector(smartDetectorPackage); // Authenticate the user to Active Directory IAuthenticationServices authenticationServices = new AuthenticationServices(); authenticationServices.AuthenticateUserAsync().Wait(); ICredentialsFactory credentialsFactory = new ActiveDirectoryCredentialsFactory(authenticationServices); IHttpClientWrapper httpClientWrapper = new HttpClientWrapper(); IExtendedAzureResourceManagerClient azureResourceManagerClient = new ExtendedAzureResourceManagerClient(httpClientWrapper, credentialsFactory, consoleTracer); // Create analysis service factory IInternalAnalysisServicesFactory analysisServicesFactory = new AnalysisServicesFactory(consoleTracer, httpClientWrapper, credentialsFactory, azureResourceManagerClient); // Create state repository factory IStateRepositoryFactory stateRepositoryFactory = new EmulationStateRepositoryFactory(); // Load user settings var userSettings = UserSettings.LoadUserSettings(); // Create the detector runner IPageableLogArchive logArchive = new PageableLogArchive(smartDetectorManifest.Name); IEmulationSmartDetectorRunner smartDetectorRunner = new SmartDetectorRunner( detector, analysisServicesFactory, smartDetectorManifest, stateRepositoryFactory, azureResourceManagerClient, logArchive); // Create a Unity container with all the required models and view models registrations Container = new UnityContainer(); Container .RegisterInstance(notificationService) .RegisterInstance <ITracer>(consoleTracer) .RegisterInstance(new AlertsRepository()) .RegisterInstance(authenticationServices) .RegisterInstance(azureResourceManagerClient) .RegisterInstance(detector) .RegisterInstance(smartDetectorManifest) .RegisterInstance(analysisServicesFactory) .RegisterInstance(logArchive) .RegisterInstance(smartDetectorRunner) .RegisterInstance(stateRepositoryFactory) .RegisterInstance(userSettings); } catch (Exception exception) { var message = $"{exception.Message}. {Environment.NewLine}{exception.InnerException?.Message}"; MessageBox.Show(message); System.Diagnostics.Trace.WriteLine(message); Environment.Exit(1); } }