コード例 #1
0
        /// <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     signalLoader  = new SmartSignalLoader(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 signalPackagePath = e.Args.Length != 1 ?
                                       this.GetSignalPackagePath() :
                                       Diagnostics.EnsureStringNotNullOrWhiteSpace(() => e.Args[0]);

            SmartSignalPackage signalPackage;

            using (var fileStream = new FileStream(signalPackagePath, FileMode.Open))
            {
                signalPackage = SmartSignalPackage.CreateFromStream(fileStream, consoleTracer);
            }

            SmartSignalManifest signalManifest = signalPackage.Manifest;
            ISmartSignal        signal         = signalLoader.LoadSignal(signalPackage);

            // 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);

            var signalRunner = new SmartSignalRunner(signal, analysisServicesFactory, queryRunInroProvider, signalManifest, stringTracer);

            // Create a Unity container with all the required models and view models registrations
            Container = new UnityContainer();
            Container
            .RegisterInstance(stringTracer)
            .RegisterInstance(new SignalsResultsRepository())
            .RegisterInstance(authenticationServices)
            .RegisterInstance(azureResourceManagerClient)
            .RegisterInstance(signal)
            .RegisterInstance(signalManifest)
            .RegisterInstance(analysisServicesFactory)
            .RegisterInstance(signalRunner);
        }
コード例 #2
0
        /// <summary>
        /// Reads a smart signal's package from the repository
        /// </summary>
        /// <param name="signalId">The signal's ID</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A <see cref="Task{TResult}"/> returning the signal package</returns>
        public async Task <SmartSignalPackage> ReadSignalPackageAsync(string signalId, CancellationToken cancellationToken)
        {
            this.tracer.TraceInformation($"Getting smart signal {signalId} package");
            try
            {
                CloudBlob latestVersionSignalBlob = await this.GetLatestSignalBlobVersionAsync(signalId, cancellationToken);

                this.tracer.TraceInformation($"Last version signal BLOB is {latestVersionSignalBlob.Name}");

                using (var blobMemoryStream = new MemoryStream())
                {
                    // Download the blob to a stream and generate the signal package from it
                    await latestVersionSignalBlob.DownloadToStreamAsync(blobMemoryStream, cancellationToken);

                    return(SmartSignalPackage.CreateFromStream(blobMemoryStream, this.tracer));
                }
            }
            catch (StorageException e)
            {
                throw new SmartSignalRepositoryException("Failed to get signal package from storage", e);
            }
        }