public AlertsControlViewModel(SmartDetectorRunner smartDetectorRunner) { this.SmartDetectorRunner = smartDetectorRunner; this.AlertDetailsControlViewModel = null; this.AlertDetailsControlClosed += () => { this.SelectedAlert = null; }; }
public void Setup() { Mock <IExtendedAzureResourceManagerClient> azureResourceManagerClientMock = new Mock <IExtendedAzureResourceManagerClient>(); this.smartDetectorRunner = new SmartDetectorRunner( new Mock <ISmartDetector>().Object, new Mock <IInternalAnalysisServicesFactory>().Object, null, new Mock <IStateRepositoryFactory>().Object, azureResourceManagerClientMock.Object, new Mock <IPageableLogArchive>().Object); }
/// <summary> /// Raises the <see cref="E:System.Windows.Application.Startup" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param> protected override void OnStartup(StartupEventArgs e) { ITracer stringTracer = new StringTracer(string.Empty); ITracer consoleTracer = new ConsoleTracer(string.Empty); var smartDetectorLoader = new SmartDetectorLoader(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 ? this.GetSmartDetectorPackagePath() : Diagnostics.EnsureStringNotNullOrWhiteSpace(() => e.Args[0]); SmartDetectorPackage smartDetectorPackage; using (var fileStream = new FileStream(smartDetectorPackagePath, FileMode.Open)) { smartDetectorPackage = SmartDetectorPackage.CreateFromStream(fileStream, consoleTracer); } SmartDetectorManifest smartDetectorManifest = smartDetectorPackage.Manifest; ISmartDetector detector = smartDetectorLoader.LoadSmartDetector(smartDetectorPackage); // Authenticate the user to Active Directory var authenticationServices = new AuthenticationServices(); authenticationServices.AuthenticateUser(); ICredentialsFactory credentialsFactory = new ActiveDirectoryCredentialsFactory(authenticationServices); IAzureResourceManagerClient azureResourceManagerClient = new AzureResourceManagerClient(credentialsFactory, consoleTracer); // Create analysis service factory var queryRunInroProvider = new QueryRunInfoProvider(azureResourceManagerClient); var httpClientWrapper = new HttpClientWrapper(); IAnalysisServicesFactory analysisServicesFactory = new AnalysisServicesFactory(consoleTracer, httpClientWrapper, credentialsFactory, azureResourceManagerClient, queryRunInroProvider); // Create state repository factory IStateRepositoryFactory stateRepositoryFactory = new InMemoryStateRepositoryFactory(); var smartDetectorRunner = new SmartDetectorRunner(detector, analysisServicesFactory, queryRunInroProvider, smartDetectorManifest, stateRepositoryFactory, smartDetectorManifest.Id, stringTracer); // Create a Unity container with all the required models and view models registrations Container = new UnityContainer(); Container .RegisterInstance(stringTracer) .RegisterInstance(new AlertsRepository()) .RegisterInstance(authenticationServices) .RegisterInstance(azureResourceManagerClient) .RegisterInstance(detector) .RegisterInstance(smartDetectorManifest) .RegisterInstance(analysisServicesFactory) .RegisterInstance(smartDetectorRunner) .RegisterInstance(stateRepositoryFactory); }
public void Setup() { Mock <IExtendedAzureResourceManagerClient> azureResourceManagerClientMock = new Mock <IExtendedAzureResourceManagerClient>(); this.smartDetectorRunner = new SmartDetectorRunner( new Mock <ISmartDetector>().Object, new Mock <IInternalAnalysisServicesFactory>().Object, new QueryRunInfoProvider(azureResourceManagerClientMock.Object), null, new Mock <IStateRepositoryFactory>().Object, azureResourceManagerClientMock.Object, new Mock <ITracer>().Object); this.systemProcessClientMock = new Mock <ISystemProcessClient>(); }
public SmartDetectorConfigurationControlViewModel( IAzureResourceManagerClient azureResourceManagerClient, ITracer tracer, SmartDetectorManifest smartDetectorManifest, SmartDetectorRunner smartDetectorRunner) { this.azureResourceManagerClient = azureResourceManagerClient; this.smartDetectorManifes = smartDetectorManifest; this.tracer = tracer; this.SmartDetectorRunner = smartDetectorRunner; this.SmartDetectorName = this.smartDetectorManifes.Name; this.ShouldShowStatusControl = false; // Initialize cadences combo box IEnumerable <SmartDetectorCadence> cadences = this.smartDetectorManifes.SupportedCadencesInMinutes .Select(cadence => new SmartDetectorCadence(TimeSpan.FromMinutes(cadence))); this.Cadences = new ObservableCollection <SmartDetectorCadence>(cadences); // Set selected cadence to be the first one. If non, pick 10 minutes cadence as default this.SelectedCadence = this.Cadences.Any() ? this.Cadences.First() : new SmartDetectorCadence(TimeSpan.FromMinutes(10)); // Initialize combo boxes read tasks this.ReadSubscriptionsTask = new ObservableTask <ObservableCollection <AzureSubscription> >( this.GetSubscriptionsAsync()); this.ReadResourceGroupsTask = new ObservableTask <ObservableCollection <string> >( Task.FromResult(new ObservableCollection <string>())); this.ReadResourceTypesTask = new ObservableTask <ObservableCollection <string> >( Task.FromResult(new ObservableCollection <string>())); this.ReadResourcesTask = new ObservableTask <ObservableCollection <ResourceIdentifier> >( Task.FromResult(new ObservableCollection <ResourceIdentifier>())); this.IterativeRunModeEnabled = false; this.StartTimePickerViewModel = new TimePickerControlViewModel("Start time:"); this.EndTimePickerViewModel = new TimePickerControlViewModel("End time:"); }
public MainWindowViewModel(AlertsRepository alertsRepository, AuthenticationServices authenticationServices, SmartDetectorRunner smartDetectorRunner) { this.NumberOfAlertssFound = 0; alertsRepository.Alerts.CollectionChanged += (sender, args) => { this.NumberOfAlertssFound = args.NewItems.Count; }; this.UserName = authenticationServices.AuthenticationResult.UserInfo.GivenName; this.SmartDetectorRunner = smartDetectorRunner; }
public EmulationStatusControlViewModel(SmartDetectorRunner smartDetectorRunner, ITracer tracer) { this.SmartDetectorRunner = smartDetectorRunner; this.Tracer = tracer; }
/// <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); } }