public SignalConfigurationControlViewModel(
            IAzureResourceManagerClient azureResourceManagerClient,
            ITracer tracer,
            SmartSignalManifest smartSignalManifest,
            SmartSignalRunner signalRunner)
        {
            this.azureResourceManagerClient = azureResourceManagerClient;
            this.smartSignalManifes         = smartSignalManifest;
            this.tracer = tracer;

            this.SignalRunner            = signalRunner;
            this.SignalName              = this.smartSignalManifes.Name;
            this.ShouldShowStatusControl = false;

            // Initialize cadences combo box
            IEnumerable <SignalCadence> cadences = this.smartSignalManifes.SupportedCadencesInMinutes
                                                   .Select(cadence => new SignalCadence(TimeSpan.FromMinutes(cadence)));

            this.Cadences = new ObservableCollection <SignalCadence>(cadences);

            // 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>()));
        }
        public async Task WhenCreatingArmClientThenItIsCreatedSuccessfully()
        {
            IAnalysisServicesFactory    factory = new AnalysisServicesFactory(this.tracerMock.Object, this.httpClientWrapperMock.Object, this.credentialsFactoryMock.Object, this.azureResourceManagerClientMock.Object);
            IAzureResourceManagerClient client  = await factory.CreateArmClientAsync(default(CancellationToken));

            Assert.IsNotNull(client);
            Assert.IsTrue(client == this.azureResourceManagerClientMock.Object);
        }
Exemplo n.º 3
0
 public Actions(
     IAzureResourceManagerClient resourceManagerClient,
     ILogger <Actions> logger,
     IActionSettings emailActionSettings)
 {
     this.resourceManagerClient = resourceManagerClient;
     this.logger = logger;
     this.emailActionSettings = emailActionSettings;
 }
 public Actions(
     IAzureResourceManagerClient resourceManagerClient,
     IServicesConfig servicesConfig,
     ILogger log)
 {
     this.resourceManagerClient = resourceManagerClient;
     this.servicesConfig        = servicesConfig;
     this.log = log;
 }
Exemplo n.º 5
0
        public EmailActionSettings(
            IAzureResourceManagerClient resourceManagerClient,
            AppConfig config,
            ILogger <EmailActionSettings> logger)
        {
            this.resourceManagerClient = resourceManagerClient;
            this.config = config;
            this.logger = logger;

            this.Type     = ActionType.Email;
            this.Settings = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
        }
Exemplo n.º 6
0
        // In order to initialize all settings, call InitializeAsync
        // to retrieve all settings due to async call to logic app
        public EmailActionSettings(
            IAzureResourceManagerClient resourceManagerClient,
            IServicesConfig servicesConfig,
            ILogger log)
        {
            this.resourceManagerClient = resourceManagerClient;
            this.servicesConfig        = servicesConfig;
            this.log = log;

            this.Type     = ActionType.Email;
            this.Settings = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AnalysisServicesFactory"/> class.
        /// </summary>
        /// <param name="tracer">The tracer</param>
        /// <param name="httpClientWrapper">The HTTP client wrapper.</param>
        /// <param name="credentialsFactory">The credentials factory.</param>
        /// <param name="azureResourceManagerClient">The azure resource manager client.</param>
        /// <param name="queryRunInfoProvider">The query run information provider.</param>
        public AnalysisServicesFactory(ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IAzureResourceManagerClient azureResourceManagerClient, IQueryRunInfoProvider queryRunInfoProvider)
        {
            this.tracer                     = tracer;
            this.httpClientWrapper          = httpClientWrapper;
            this.credentialsFactory         = credentialsFactory;
            this.azureResourceManagerClient = azureResourceManagerClient;
            this.queryRunInfoProvider       = queryRunInfoProvider;

            // string timeoutString = ConfigurationReader.ReadConfig("AnalyticsQueryTimeoutInMinutes", required: true);
            string timeoutString = "15";

            this.queryTimeout = TimeSpan.FromMinutes(int.Parse(timeoutString));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SmartSignalRunner"/> class
 /// </summary>
 /// <param name="smartSignalRepository">The smart signals repository</param>
 /// <param name="smartSignalLoader">The smart signals loader</param>
 /// <param name="analysisServicesFactory">The analysis services factory</param>
 /// <param name="azureResourceManagerClient">The azure resource manager client</param>
 /// <param name="queryRunInfoProvider">The query run information provider</param>
 /// <param name="tracer">The tracer</param>
 public SmartSignalRunner(
     ISmartSignalRepository smartSignalRepository,
     ISmartSignalLoader smartSignalLoader,
     IAnalysisServicesFactory analysisServicesFactory,
     IAzureResourceManagerClient azureResourceManagerClient,
     IQueryRunInfoProvider queryRunInfoProvider,
     ITracer tracer)
 {
     this.smartSignalRepository      = Diagnostics.EnsureArgumentNotNull(() => smartSignalRepository);
     this.smartSignalLoader          = Diagnostics.EnsureArgumentNotNull(() => smartSignalLoader);
     this.analysisServicesFactory    = Diagnostics.EnsureArgumentNotNull(() => analysisServicesFactory);
     this.azureResourceManagerClient = Diagnostics.EnsureArgumentNotNull(() => azureResourceManagerClient);
     this.queryRunInfoProvider       = Diagnostics.EnsureArgumentNotNull(() => queryRunInfoProvider);
     this.tracer = tracer;
 }
Exemplo n.º 9
0
        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:");
        }
Exemplo n.º 10
0
        public AlertDetailsControlViewModel(
            EmulationAlert alert,
            AlertDetailsControlClosedEventHandler alertDetailsControlClosed,
            IAzureResourceManagerClient armClient)
        {
            this.Alert = alert;

            this.EssentialsSectionProperties = new ObservableCollection <AzureResourceProperty>(new List <AzureResourceProperty>()
            {
                new AzureResourceProperty("Subscription id", this.Alert.ResourceIdentifier.SubscriptionId),
                new AzureResourceProperty("Resource group", this.Alert.ResourceIdentifier.ResourceGroupName),
                new AzureResourceProperty("Resource type", this.Alert.ResourceIdentifier.ResourceType.ToString()),
                new AzureResourceProperty("Resource name", this.Alert.ResourceIdentifier.ResourceName)
            });

            this.DisplayablePropertiesTask = new ObservableTask <ObservableCollection <DisplayableAlertProperty> >(
                this.ComposeAlertProperties(armClient), null);

            this.CloseControlCommand = new CommandHandler(() =>
            {
                alertDetailsControlClosed.Invoke();
            });
        }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryRunInfoProvider"/> class
 /// </summary>
 /// <param name="azureResourceManagerClient">The azure resource manager client</param>
 public QueryRunInfoProvider(IAzureResourceManagerClient azureResourceManagerClient)
 {
     this.azureResourceManagerClient = azureResourceManagerClient;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Retrieves and composes all the alert properties asynchronously
        /// </summary>
        /// <param name="armClient">Support for ARM request</param>
        /// <returns>Observable task to the UI, Result: Alerts displayable properties</returns>
        private async Task <ObservableCollection <DisplayableAlertProperty> > ComposeAlertProperties(IAzureResourceManagerClient armClient)
        {
            try
            {
                // Calls ComposeArmProperties for each ARM request property in Alert, to preform the request and compose its properties.
                IEnumerable <Task <List <DisplayableAlertProperty> > > armPropertiesTasks = this.Alert.ContractsAlert.AlertProperties.OfType <AzureResourceManagerRequestAlertProperty>()
                                                                                            .Select(armProperty => this.ComposeArmProperties(armProperty, armClient));
                List <DisplayableAlertProperty> armProperties = (await Task.WhenAll(armPropertiesTasks)).SelectMany(props => props).ToList();

                // Compose all non ARM properties, and the final display list.
                List <DisplayableAlertProperty> displayableAlertProperties = this.Alert.ContractsAlert.AlertProperties.OfType <DisplayableAlertProperty>()
                                                                             .Where(prop => this.supportedPropertiesTypes.Contains(prop.Type))
                                                                             .Union(armProperties)        // Combine all properties into a single list.
                                                                             .OrderBy(prop => prop.Order) // Reorder properies
                                                                             .ThenBy(prop => prop.PropertyName)
                                                                             .ToList();

                return(new ObservableCollection <DisplayableAlertProperty>(displayableAlertProperties));
            }
            catch (Exception e)
            {
                throw new InvalidSmartDetectorPackageException($"Failed to create alert details for display, Error: {e.Message}", e);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Retrieves and composes Alert propeties, for an Arm request Alert property.
        /// </summary>
        /// <param name="armProperty">Alert property of type ARM request to retrieve and compose</param>
        /// <param name="armClient">Support for ARM request</param>
        /// <returns>List of displayable properties from Arm request</returns>
        private async Task <List <DisplayableAlertProperty> > ComposeArmProperties(AzureResourceManagerRequestAlertProperty armProperty, IAzureResourceManagerClient armClient)
        {
            List <DisplayableAlertProperty> displayableArmProperties = new List <DisplayableAlertProperty>();

            try
            {
                List <JObject> response = await armClient.ExecuteArmQueryAsync(armProperty.AzureResourceManagerRequestUri, CancellationToken.None);

                foreach (IReferenceAlertProperty propertyRef in armProperty.PropertiesToDisplay.OfType <IReferenceAlertProperty>())
                {
                    JToken propertyVal = response[0].SelectToken(propertyRef.ReferencePath);

                    if (propertyVal == null)
                    {
                        displayableArmProperties.Add(this.CreateErrorProperty(propertyRef, $"Property {propertyRef.ReferencePath} doesn't exist in Response"));
                    }
                    else
                    {
                        switch (propertyRef)
                        {
                        case TextReferenceAlertProperty textRef:
                            TextAlertProperty displayText = new TextAlertProperty(textRef.PropertyName, textRef.DisplayName, textRef.Order, (string)propertyVal);
                            displayableArmProperties.Add(displayText);
                            break;

                        case LongTextReferenceAlertProperty longTextRef:
                            LongTextAlertProperty displayLongText = new LongTextAlertProperty(longTextRef.PropertyName, longTextRef.DisplayName, longTextRef.Order, (string)propertyVal);
                            displayableArmProperties.Add(displayLongText);
                            break;

                        case KeyValueReferenceAlertProperty keyValueRef:
                            IDictionary <string, string> keyValueField = new Dictionary <string, string> {
                                { keyValueRef.ReferencePath, (string)propertyVal }
                            };
                            KeyValueAlertProperty displayKeyValue = new KeyValueAlertProperty(keyValueRef.PropertyName, keyValueRef.DisplayName, keyValueRef.Order, keyValueField);
                            displayableArmProperties.Add(displayKeyValue);
                            break;

                        case TableReferenceAlertProperty tableRef:
                            JArray tableValue;
                            if (response.Count == 1)
                            {
                                tableValue = response[0].SelectToken(tableRef.ReferencePath) as JArray;
                            }
                            else
                            {
                                tableValue = (new JArray(response)).SelectToken(tableRef.ReferencePath) as JArray;
                            }

                            List <Dictionary <string, JToken> > values = tableValue
                                                                         .OfType <IDictionary <string, JToken> >()
                                                                         .Select(value => value.ToDictionary(item => item.Key, item => item.Value))
                                                                         .ToList();
                            TableAlertProperty <Dictionary <string, JToken> > displayTable = new TableAlertProperty <Dictionary <string, JToken> >(tableRef.PropertyName, tableRef.DisplayName, tableRef.Order, true, tableRef.Columns, values);
                            displayableArmProperties.Add(displayTable);
                            break;
                        }
                    }
                }
            }
            catch (HttpRequestException e)
            {
                string errorValue = $"Failed to get Arm Response, Error: {e.Message}";

                foreach (IReferenceAlertProperty propertyRef in armProperty.PropertiesToDisplay.OfType <IReferenceAlertProperty>())
                {
                    displayableArmProperties.Add(this.CreateErrorProperty(propertyRef, errorValue));
                }
            }

            return(displayableArmProperties);
        }