Example #1
0
        /// <summary>
        /// Constructs a new instance of <see cref="AzPredictor"/> to use in PowerShell's prediction subsystem.
        /// </summary>
        public AzPredictor()
        {
            _powerShellRuntime = new PowerShellRuntime();
            _surveyHelper      = new AzPredictorSurveyHelper(_powerShellRuntime);

            // To make import-module fast, we'll do all the initialization in a task.
            // Slow initialization may make opening a PowerShell window slow if "Import-Module" is added to the user's profile.
            Task.Run(() =>
            {
                _settings  = Settings.GetSettings();
                _azContext = new AzContext(_powerShellRuntime)
                {
                    IsInternal = (_settings.SetAsInternal == true) ? true : false,
                };

                _azContext.UpdateContext();
                // This will run the script in the right context.
                var _            = _azContext.PowerShellVersion;
                _telemetryClient = new AzPredictorTelemetryClient(_azContext);
                _service         = new AzPredictorService(_settings.ServiceUri, _telemetryClient, _azContext);
                _isInitialized   = true;
            });
        }
Example #2
0
        /// <inhericdoc/>
        public void Dispose()
        {
            if (_predictionRequestCancellationSource != null)
            {
                _predictionRequestCancellationSource.Dispose();
                _predictionRequestCancellationSource = null;
            }

            if (_surveyHelper is IDisposable disposableSurveyHelper)
            {
                disposableSurveyHelper.Dispose();
                _surveyHelper = null;
            }

            if (_powerShellRuntime != null)
            {
                _powerShellRuntime.Dispose();
                _powerShellRuntime = null;
            }

            _externalDisposableObjects.ForEach((o) => o?.Dispose());
            _externalDisposableObjects.Clear();
        }