/// <summary> /// Runs the smart signal. /// </summary> /// <param name="resources">The resources which the signal should run on.</param> /// <param name="analysisCadence">The analysis cadence.</param> /// <returns>A task that runs the smart signal.</returns> public async Task RunAsync(List <ResourceIdentifier> resources, TimeSpan analysisCadence) { this.cancellationTokenSource = new CancellationTokenSource(); this.Results.Clear(); var analysisRequest = new AnalysisRequest(resources, null, analysisCadence, this.analysisServicesFactory); try { // Run Signal this.IsSignalRunning = true; SmartSignalResult signalResults = await this.smartSignal.AnalyzeResourcesAsync( analysisRequest, this.Tracer, this.cancellationTokenSource.Token); // Create signal result items List <SignalResultItem> signalResultItems = new List <SignalResultItem>(); foreach (var resultItem in signalResults.ResultItems) { // Create result item presentation var resourceIds = resources.Select(resource => resource.ResourceName).ToList(); var smartSignalsSettings = new SmartSignalSettings(); var smartSignalRequest = new SmartSignalRequest(resourceIds, this.smartSignalManifes.Id, null, analysisCadence, smartSignalsSettings); SmartSignalResultItemQueryRunInfo queryRunInfo = await this.queryRunInfoProvider.GetQueryRunInfoAsync(new List <ResourceIdentifier>() { resultItem.ResourceIdentifier }, this.cancellationTokenSource.Token); SmartSignalResultItemPresentation resultItemPresentation = SmartSignalResultItemPresentation.CreateFromResultItem( smartSignalRequest, this.smartSignalManifes.Name, resultItem, queryRunInfo); // Create Azure resource identifier ResourceIdentifier resourceIdentifier = ResourceIdentifier.CreateFromResourceId(resultItemPresentation.ResourceId); signalResultItems.Add(new SignalResultItem(resultItemPresentation, resourceIdentifier)); } this.Results = new ObservableCollection <SignalResultItem>(signalResultItems); this.tracer.TraceInformation($"Found {this.Results.Count} results"); } catch (OperationCanceledException) { this.Tracer.TraceError("Signal run was canceled."); } catch (Exception e) { this.Tracer.ReportException(e); } finally { this.IsSignalRunning = false; this.cancellationTokenSource?.Dispose(); } }
/// <summary> /// Initializes a new instance of the <see cref="SmartSignalRequest"/> class /// </summary> /// <param name="resourceIds">The resource IDs on which to run the signal</param> /// <param name="signalId">The signal ID</param> /// <param name="lastExecutionTime">The last execution of the signal. This can be null if the signal never ran.</param> /// <param name="cadence">The signal configured cadence</param> /// <param name="settings">The analysis settings</param> public SmartSignalRequest(IList <string> resourceIds, string signalId, DateTime?lastExecutionTime, TimeSpan cadence, SmartSignalSettings settings) { this.ResourceIds = resourceIds; this.SignalId = signalId; this.LastExecutionTime = lastExecutionTime; this.Settings = settings; this.Cadence = cadence; }