private static void ConfigureForAzureStorage(ContainerBuilder builder, ConfigurationService configuration)
        {
            builder.RegisterInstance(new CloudBlobClientWrapper(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <ICloudBlobClient>()
            .SingleInstance();

            builder.RegisterType <CloudBlobFileStorageService>()
            .AsSelf()
            .As <IFileStorageService>()
            .SingleInstance();

            // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs
            builder.RegisterInstance(new JsonAggregateStatsService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IAggregateStatsService>()
            .SingleInstance();

            // when running on Windows Azure, pull the statistics from the warehouse via storage
            builder.RegisterInstance(new CloudReportService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IReportService>()
            .SingleInstance();

            // when running on Windows Azure, download counts come from the downloads.v1.json blob
            var downloadCountService = new CloudDownloadCountService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant);

            builder.RegisterInstance(downloadCountService)
            .AsSelf()
            .As <IDownloadCountService>()
            .SingleInstance();
            ObjectMaterializedInterception.AddInterceptor(new DownloadCountObjectMaterializedInterceptor(downloadCountService));

            builder.RegisterType <JsonStatisticsService>()
            .AsSelf()
            .As <IStatisticsService>()
            .SingleInstance();

            string instanceId;

            try
            {
                instanceId = RoleEnvironment.CurrentRoleInstance.Id;
            }
            catch
            {
                instanceId = Environment.MachineName;
            }

            var localIp = AuditActor.GetLocalIP().Result;

            builder.RegisterInstance(new CloudAuditingService(instanceId, localIp, configuration.Current.AzureStorageConnectionString, CloudAuditingService.AspNetActorThunk))
            .AsSelf()
            .As <AuditingService>()
            .SingleInstance();
        }
Exemple #2
0
        private static void ConfigureForAzureStorage(ContainerBuilder builder, IGalleryConfigurationService configuration)
        {
            builder.RegisterInstance(new CloudBlobClientWrapper(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <ICloudBlobClient>()
            .SingleInstance();

            builder.RegisterType <CloudBlobFileStorageService>()
            .AsSelf()
            .As <IFileStorageService>()
            .SingleInstance();

            // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs
            builder.RegisterInstance(new JsonAggregateStatsService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IAggregateStatsService>()
            .SingleInstance();

            // when running on Windows Azure, pull the statistics from the warehouse via storage
            builder.RegisterInstance(new CloudReportService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IReportService>()
            .SingleInstance();

            // when running on Windows Azure, download counts come from the downloads.v1.json blob
            var downloadCountService = new CloudDownloadCountService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant);

            builder.RegisterInstance(downloadCountService)
            .AsSelf()
            .As <IDownloadCountService>()
            .SingleInstance();
            ObjectMaterializedInterception.AddInterceptor(new DownloadCountObjectMaterializedInterceptor(downloadCountService));

            builder.RegisterType <JsonStatisticsService>()
            .AsSelf()
            .As <IStatisticsService>()
            .SingleInstance();
        }
        private static void ConfigureForAzureStorage(ContainerBuilder builder, IGalleryConfigurationService configuration, ITelemetryClient telemetryClient)
        {
            /// The goal here is to initialize a <see cref="ICloudBlobClient"/> and <see cref="IFileStorageService"/>
            /// instance for each unique connection string. Each dependent of <see cref="IFileStorageService"/> (that
            /// is, each service that has a <see cref="IFileStorageService"/> constructor parameter) is registered in
            /// <see cref="StorageDependent.GetAll(IAppConfiguration)"/> and is grouped by the respective storage
            /// connection string. Each group is given a binding key which refers to the appropriate instance of the
            /// <see cref="IFileStorageService"/>.
            var completedBindingKeys = new HashSet <string>();

            foreach (var dependent in StorageDependent.GetAll(configuration.Current))
            {
                if (completedBindingKeys.Add(dependent.BindingKey))
                {
                    builder.RegisterInstance(new CloudBlobClientWrapper(dependent.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
                    .AsSelf()
                    .As <ICloudBlobClient>()
                    .SingleInstance()
                    .Keyed <ICloudBlobClient>(dependent.BindingKey);

                    builder.RegisterType <CloudBlobFileStorageService>()
                    .WithParameter(new ResolvedParameter(
                                       (pi, ctx) => pi.ParameterType == typeof(ICloudBlobClient),
                                       (pi, ctx) => ctx.ResolveKeyed <ICloudBlobClient>(dependent.BindingKey)))
                    .AsSelf()
                    .As <IFileStorageService>()
                    .As <ICloudStorageStatusDependency>()
                    .SingleInstance()
                    .Keyed <IFileStorageService>(dependent.BindingKey);
                }

                var registration = builder.RegisterType(dependent.ImplementationType)
                                   .WithParameter(new ResolvedParameter(
                                                      (pi, ctx) => pi.ParameterType == typeof(IFileStorageService),
                                                      (pi, ctx) => ctx.ResolveKeyed <IFileStorageService>(dependent.BindingKey)))
                                   .AsSelf()
                                   .As(dependent.InterfaceType);

                if (dependent.IsSingleInstance)
                {
                    registration.SingleInstance();
                }
                else
                {
                    registration.InstancePerLifetimeScope();
                }
            }

            // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs
            builder.RegisterInstance(new JsonAggregateStatsService(configuration.Current.AzureStorage_Statistics_ConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IAggregateStatsService>()
            .SingleInstance();

            // when running on Windows Azure, pull the statistics from the warehouse via storage
            builder.RegisterInstance(new CloudReportService(configuration.Current.AzureStorage_Statistics_ConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IReportService>()
            .As <ICloudStorageStatusDependency>()
            .SingleInstance();

            // when running on Windows Azure, download counts come from the downloads.v1.json blob
            var downloadCountService = new CloudDownloadCountService(
                telemetryClient,
                configuration.Current.AzureStorage_Statistics_ConnectionString,
                configuration.Current.AzureStorageReadAccessGeoRedundant);

            builder.RegisterInstance(downloadCountService)
            .AsSelf()
            .As <IDownloadCountService>()
            .SingleInstance();
            ObjectMaterializedInterception.AddInterceptor(new DownloadCountObjectMaterializedInterceptor(downloadCountService));

            builder.RegisterType <JsonStatisticsService>()
            .AsSelf()
            .As <IStatisticsService>()
            .SingleInstance();

            builder.RegisterInstance(new TableErrorLog(configuration.Current.AzureStorage_Errors_ConnectionString))
            .As <ErrorLog>()
            .SingleInstance();
        }
 private void ObjectContextOnObjectMaterialized(object sender, ObjectMaterializedEventArgs objectMaterializedEventArgs)
 {
     ObjectMaterializedInterception.InterceptObjectMaterialized(objectMaterializedEventArgs.Entity);
 }