예제 #1
0
        public OrderCloudIntegrationsBlobService(BlobServiceConfig config)
        {
            _config = config;
            try
            {
                if (config.ConnectionString == null)
                {
                    throw new Exception("Connection string not supplied");
                }
                if (config.Container == null)
                {
                    throw new Exception("Blob container not specified");
                }

                CloudStorageAccount.TryParse(config.ConnectionString, out var storage);
                var client = storage.CreateCloudBlobClient();
                if (config.Container != null)
                {
                    Container = client.GetContainerReference(config.Container);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}. The blob service must be invoked with a valid configuration");
            }
        }
예제 #2
0
 public GlobalExceptionHandler(BlobServiceConfig blobconfig)
 {
     _blob = new OrderCloudIntegrationsBlobService(blobconfig);
 }
예제 #3
0
 public static IServiceCollection OrderCloudIntegrationsConfigureWebApiServices <T>(this IServiceCollection services, T settings, BlobServiceConfig errorLogBlobConfig, string corsPolicyName = null)
     where T : class
 {
     // false became the default in asp.net core 3.0 to combat application hangs
     // however we're using synchronous APIs when validating webhook hash
     // specifically ComputeHash will trigger an error here
     // TODO: figure out how to compute the hash in an async manner so we can remove this
     services.Configure <KestrelServerOptions>(options =>
     {
         options.AllowSynchronousIO = true;
     });
     services.Configure <IISServerOptions>(options =>
     {
         options.AllowSynchronousIO = true;
     });
     services.AddSingleton(x => new GlobalExceptionHandler(errorLogBlobConfig));
     services.Inject <IOrderCloudClient>();
     services.AddSingleton(settings);
     services
     .AddCors(o =>
              o.AddPolicy(
                  name: corsPolicyName ?? Environment.GetEnvironmentVariable("CORS_POLICY"),
                  builder => {
         builder
         .AllowAnyOrigin()
         .AllowAnyMethod()
         .AllowAnyHeader();
     }));
     services
     .AddControllers(o => { o.Filters.Add(typeof(ValidateModelAttribute)); })
     .AddNewtonsoftJson(o => {
         o.SerializerSettings.ContractResolver = new HSSerializer();
         o.SerializerSettings.Converters.Add(new StringEnumConverter());
     });
     return(services);
 }
 public static IServiceCollection OrderCloudIntegrationsConfigureWebApiServices <T>(this IServiceCollection services, T settings, BlobServiceConfig errorLogBlobConfig, string corsPolicyName = null)
     where T : class
 {
     services.AddSingleton(x => new GlobalExceptionHandler(errorLogBlobConfig));
     services.Inject <IOrderCloudClient>();
     services.AddSingleton(settings);
     services
     .AddCors(o =>
              o.AddPolicy(
                  name: corsPolicyName ?? Environment.GetEnvironmentVariable("CORS_POLICY"),
                  builder => {
         builder
         .AllowAnyOrigin()
         .AllowAnyMethod()
         .AllowAnyHeader();
     }));
     services
     .AddControllers(o => { o.Filters.Add(typeof(ValidateModelAttribute)); })
     .AddNewtonsoftJson(o => {
         o.SerializerSettings.ContractResolver = new HSSerializer();
         o.SerializerSettings.Converters.Add(new StringEnumConverter());
     });
     return(services);
 }