Beispiel #1
0
        public override IBaseConfiguration Update(IBaseConfiguration config, bool updateConsumers = true)
        {
            var newConfig = (NetworkRequestConfigurationData)config;

            if (RequestsConfig == null)
            {
                RequestsConfig = newConfig;

                Loggers.Default.NetworkLogger.Write(string.Format(
                                                        "{0}->Update(network config assigned)", GetType()));
            }
            else
            {
                if (newConfig.Default != null)
                {
                    RequestsConfig.Default = newConfig.Default;
                }
                if (!newConfig.Services.IsNullOrEmpty())
                {
                    foreach (var svc in newConfig.Services)
                    {
                        RequestsConfig.Services[svc.Key] = svc.Value;
                    }

                    Loggers.Default.NetworkLogger.Write(string.Format(
                                                            "{0}->Update(network config updated with {1} services)",
                                                            GetType(), newConfig.Services.Count));
                }
            }
            if (updateConsumers)
            {
                Messenger.Default.Publish <INetworkConfiguration>(this);
            }
            return(RequestsConfig);
        }
Beispiel #2
0
 internal static Dictionary <string, string> GetRequestHeaders(IBaseConfiguration config,
                                                               ClientEnvironment env)
 {
     return(new Dictionary <string, string> {
         { "Authorization", config.SdkKey },
         { "User-Agent", env.UserAgentType + "/" + env.VersionString }
     });
 }
Beispiel #3
0
        internal static HttpClient MakeHttpClient(IBaseConfiguration config, ClientEnvironment env)
        {
            var httpClient = new HttpClient(handler: config.HttpClientHandler, disposeHandler: false);

            foreach (var h in GetRequestHeaders(config, env))
            {
                httpClient.DefaultRequestHeaders.Add(h.Key, h.Value);
            }
            return(httpClient);
        }
        internal static IEventProcessor CreateEventProcessor(IBaseConfiguration configuration)
        {
            if (configuration.Offline)
            {
                Log.InfoFormat("Was configured to be offline, starting service with NullEventProcessor");
                return(new NullEventProcessor());
            }

            HttpClient httpClient = Util.MakeHttpClient(configuration, MobileClientEnvironment.Instance);

            return(new DefaultEventProcessor(configuration, null, httpClient, Constants.EVENTS_PATH));
        }
Beispiel #5
0
 /// <summary>
 /// Constructs a StreamManager instance.
 /// </summary>
 /// <param name="streamProcessor">A platform-specific implementation of IStreamProcessor.</param>
 /// <param name="streamProperties">HTTP request properties for the stream.</param>
 /// <param name="config">An implementation of IBaseConfiguration.</param>
 /// <param name="clientEnvironment">A subclass of ClientEnvironment.</param>
 /// <param name="eventSourceCreator">Null in normal usage; pass a non-null delegate if you
 /// are in a unit test and want to mock out the event source.</param>
 public StreamManager(IStreamProcessor streamProcessor, StreamProperties streamProperties,
                      IBaseConfiguration config, ClientEnvironment clientEnvironment,
                      EventSourceCreator eventSourceCreator)
 {
     _streamProcessor   = streamProcessor;
     _streamProperties  = streamProperties;
     _config            = config;
     _clientEnvironment = clientEnvironment;
     _esCreator         = eventSourceCreator ?? DefaultEventSourceCreator;
     _initTask          = new TaskCompletionSource <bool>();
     _backOff           = new EventSource.ExponentialBackoffWithDecorrelation(_config.ReconnectTime, TimeSpan.FromMilliseconds(30000));
 }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        public static void RegisterTypes(IServiceCollection services)
        {
            services.AddRefitClient <IFacebookGraphClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Facebook.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();
            services.AddRefitClient <IGoogleGraphClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Google.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();

            IBaseConfiguration configurationProvider = null;

            services.AddSingleton <IExternalIdentityProvider, FacebookIdentityProvider>(serviceProvider =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                IFacebookGraphClient facebookGraphClient = serviceProvider.GetService <IFacebookGraphClient>();
                return(new FacebookIdentityProvider(configurationProvider.FaceBookAuthenticationSettings, facebookGraphClient));
            });

            services.AddSingleton <IExternalIdentityProvider, GoogleIdentityProvider>(serviceProvider =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                IGoogleGraphClient googleGraphClient = serviceProvider.GetService <IGoogleGraphClient>();
                return(new GoogleIdentityProvider(configurationProvider.GoogleAuthenticationSettings, googleGraphClient));
            });

            services.AddSingleton <IExternalIdentityProviderFactory, ExternalIdentityProviderFactory>();

            services.AddRefitClient <IFacebookUserClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Facebook.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();
            services.AddRefitClient <IGoogleUserClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Google.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();

            services.AddSingleton <IFacebookUserServiceClient, FacebookUserServiceClient>();
            services.AddSingleton <IGoogleUserServiceClient, GoogleUserServiceClient>();

            services.AddDbContextPool <IAccountDbContext, AccountDbContext>((serviceProvider, options) =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                options.UseLazyLoadingProxies();
                options.UseMySql(configurationProvider.DatabaseConnectionIdentifier.RootConnection,
                                 builderOptions => builderOptions.ServerVersion(new Version(5, 7), Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql));
            });

            services.AddScoped <IRoleRepository, RoleRepository>();
            services.AddScoped <IUserRepository, UserRepository>();

            services.AddScoped <IRoleProvider, RoleProvider>();
            services.AddScoped <IAccountProvider, AccountProvider>();
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        public static void RegisterTypes(IServiceCollection services)
        {
            IBaseConfiguration configurationProvider = null;

            services.AddDbContextPool <ICampaignDbContext, CampaignDbContext>((serviceProvider, options) =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                options.UseLazyLoadingProxies();
                options.UseMySql(configurationProvider.DatabaseConnectionIdentifier.RootConnection,
                                 builderOptions => builderOptions.ServerVersion(new Version(5, 7), Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql));
            });

            services.AddRefitClient <ISubscriptionClient>()
            .ConfigureHttpClient((serviceProvider, httpClient) =>
            {
                configurationProvider  = serviceProvider.GetService <IBaseConfiguration>();
                httpClient.BaseAddress = new Uri(configurationProvider.SubscriptionServiceEndpointSettings.PrivateEndpoint);
            })
            .AddHttpMessageHandler <HttpBootstrapHandler>();

            services.AddSingleton <ISubscriptionServiceClient, SubscriptionServiceClient>();

            services.AddSingleton <IMessageBusFactory, MessageBusFactory>((serviceProvider) =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                return(new MessageBusFactory(configurationProvider.IntegrationConnectionIdentifier.RootConnection));
            });
            services.AddSingleton <IMessageBusMessageFactory, MessageBusMessageFactory>();

            services.AddSingleton <IMessageSender, MessageSender>((serviceProvider) =>
            {
                var messageBusFactory = serviceProvider.GetService <IMessageBusFactory>();
                return(new MessageSender(messageBusFactory, AppMessageType.CampaignManagement, Constants.ServiceBus.Topics.CampaignManagement));
            });
            services.AddSingleton <IMessageSenderFactory, MessageSenderFactory>();

            services.AddScoped <ICampaignRepository, CampaignRepository>();
            services.AddScoped <ICampaignInstanceRepository, CampaignInstanceRepository>();
            services.AddScoped <ICampaignInstanceExceptionRepository, CampaignInstanceExceptionRepository>();
            services.AddScoped <IMessageTemplateRepository, MessageTemplateRepository>();
            services.AddScoped <IScheduleRepository, ScheduleRepository>();

            services.AddScoped <ICampaignProvider, CampaignProvider>();
            services.AddScoped <ICampaignInstanceProvider, CampaignInstanceProvider>();
            services.AddScoped <ICampaignInstanceExceptionProvider, CampaignInstanceExceptionProvider>();
            services.AddScoped <IMessageTemplateProvider, MessageTemplateProvider>();
            services.AddScoped <IScheduleProvider, ScheduleProvider>();
        }
 internal DefaultEventProcessor(IBaseConfiguration config,
                                IUserDeduplicator userDeduplicator, HttpClient httpClient, string eventsUriPath)
 {
     _messageQueue = new BlockingCollection <IEventMessage>(config.EventQueueCapacity);
     _dispatcher   = new EventDispatcher(config, _messageQueue, userDeduplicator, httpClient, eventsUriPath);
     _flushTimer   = new Timer(DoBackgroundFlush, null, config.EventQueueFrequency,
                               config.EventQueueFrequency);
     if (userDeduplicator != null && userDeduplicator.FlushInterval.HasValue)
     {
         _flushUsersTimer = new Timer(DoUserKeysFlush, null, userDeduplicator.FlushInterval.Value,
                                      userDeduplicator.FlushInterval.Value);
     }
     else
     {
         _flushUsersTimer = null;
     }
     _stopped = new AtomicBoolean(false);
     _inputCapacityExceeded = new AtomicBoolean(false);
 }
Beispiel #9
0
        /// <summary>
        /// Registers all the custom types used by API
        /// </summary>
        /// <param name="services">services collection</param>
        protected virtual void RegisterTypes(IServiceCollection services)
        {
            services.AddSingleton <IBaseConfiguration, DefaultConfigurationProvider>();
            services.AddSingleton <ITokenProvider, JwtBearerTokenProvider>();
            services.AddSingleton <ICachePolicyProvider, StaticCachePolicyProvider>();
            services.AddSingleton <IResourceUrlBuilder, ResourceUrlBuilder>();

            services.AddSingleton <ICacheProvider>((serviceProvider) =>
            {
                IBaseConfiguration configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                var cachePolicyProvider = serviceProvider.GetService <ICachePolicyProvider>();

                return(new RedisCacheProvider(cachePolicyProvider, configurationProvider.CacheConnectionIdentifier.RootConnection));
            });

            services.AddTransient <HttpBootstrapHandler>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IPrincipal>(provider => provider.GetService <IHttpContextAccessor>().HttpContext.User);
            services.AddTransient <IIdentityProvider, IdentityProvider>();
        }
        internal EventDispatcher(IBaseConfiguration config,
                                 BlockingCollection <IEventMessage> messageQueue,
                                 IUserDeduplicator userDeduplicator,
                                 HttpClient httpClient,
                                 string eventsUriPath)
        {
            _config              = config;
            _userDeduplicator    = userDeduplicator;
            _flushWorkersCounter = new CountdownEvent(1);
            _httpClient          = httpClient;
            _uri    = new Uri(_config.EventsUri, eventsUriPath);
            _random = new Random();

            _httpClient.DefaultRequestHeaders.Add("X-LaunchDarkly-Event-Schema",
                                                  DefaultEventProcessor.CurrentSchemaVersion);

            EventBuffer buffer = new EventBuffer(config.EventQueueCapacity);

            Task.Run(() => RunMainLoop(messageQueue, buffer));
        }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        public static void RegisterTypes(IServiceCollection services)
        {
            IBaseConfiguration configurationProvider = null;

            services.AddDbContextPool <ISubscriptionDbContext, SubscriptionDbContext>((serviceProvider, options) =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                options.UseLazyLoadingProxies();
                options.UseMySql(configurationProvider.DatabaseConnectionIdentifier.RootConnection,
                                 builderOptions => builderOptions.ServerVersion(new Version(5, 7), Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql));
            });

            services.AddScoped <ISubscriptionRepository, SubscriptionRepository>();
            services.AddScoped <IGroupRepository, GroupRepository>();
            services.AddScoped <IContactRepository, ContactRepository>();

            services.AddScoped <ISubscriptionProvider, SubscriptionProvider>();
            services.AddScoped <IGroupProvider, GroupProvider>();
            services.AddScoped <IContactProvider, ContactProvider>();
        }
Beispiel #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="baseConfiguration"></param>
 public JwtBearerTokenProvider(IBaseConfiguration baseConfiguration, IMapper mapper)
 {
     _baseConfiguration = baseConfiguration;
     _mapper            = mapper;
 }
        internal static EventUser FromUser(User user, IBaseConfiguration config)
        {
            EventUserBuilder eub = new EventUserBuilder(user, config);

            return(eub.Build());
        }
 internal EventUserBuilder(User user, IBaseConfiguration config)
 {
     _user   = user;
     _config = config;
     _result = new EventUser();
 }
 void IBaseWidget.Configure(IBaseConfiguration configuration)
 {
     throw new NotImplementedException();
 }
Beispiel #16
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IBaseConfiguration config, ILog log)
        {
            loggerFactory.AddFrameworkLogger(config, log);

            if (env.IsDevelopment())
            {
                loggerFactory.AddDebug();
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            //app.UseLogReceiverMiddleware();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseSwagger("swagger/{apiVersion}/swagger.json");
            app.UseSwaggerUi();
        }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultConnectionStringResolver"/> class.
 /// </summary>
 public DefaultConnectionStringResolver(IBaseConfiguration configuration)
 {
     _configuration = configuration;
 }
Beispiel #18
0
 public virtual IBaseConfiguration Update(IBaseConfiguration newConfig, bool updateConsumers = true)
 {
     throw new NotImplementedException();
 }
Beispiel #19
0
 internal EventOutputFormatter(IBaseConfiguration config)
 {
     _config = config;
 }
Beispiel #20
0
 public AppDBManager(IBaseConfiguration config, ILog log, IDBInfo dbInfo)
     : base(config, log, dbInfo)
 {
 }
 private IEventProcessor MakeProcessor(IBaseConfiguration config)
 {
     return(new DefaultEventProcessor(config, new TestUserDeduplicator(),
                                      Util.MakeHttpClient(config, SimpleClientEnvironment.Instance), EventsUriPath));
 }