public override RemoteOrchestrator CreateRemoteOrchestrator(ProviderType providerType, string dbName)
        {
            var cs           = HelperDatabase.GetConnectionString(ProviderType.Sql, dbName);
            var orchestrator = new WebServerOrchestrator(new SqlSyncProvider(cs));

            return(orchestrator);
        }
示例#2
0
        public static IServiceCollection AddSyncServer(this IServiceCollection serviceCollection, IConfiguration configuration, Type providerType,
                                                       string connectionString, string scopeName = SyncOptions.DefaultScopeName, SyncSetup setup = null, SyncOptions options = null, WebServerOptions webServerOptions = null)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            // Create default web server options
            if (webServerOptions == null)
            {
                webServerOptions = new WebServerOptions();
            }

            options ??= new SyncOptions();
            setup = setup ?? throw new ArgumentNullException(nameof(setup));

            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceCollection.AddMemoryCache();

            // Get all registered server providers with schema and options
            var webServerManager = serviceProvider.GetService <WebServerManager>();

            // On first time, inject the singleton in the service collection provider
            if (webServerManager == null)
            {
                var cache = serviceProvider.GetService <IMemoryCache>();
#if NET5_0 || NETCOREAPP3_1
                var env = serviceProvider.GetService <IWebHostEnvironment>();
#elif NETSTANDARD
                var env = serviceProvider.GetService <IHostingEnvironment>();
#endif
                webServerManager = new WebServerManager(cache, env);
                serviceCollection.AddSingleton(webServerManager);
            }

            // Check if we don't have already added this scope name provider to the remote orchestrator list
            if (webServerManager.Contains(scopeName))
            {
                throw new ArgumentException($"Orchestrator with scope name {scopeName} already exists in the service collection");
            }

            // Create provider
            var provider = (CoreProvider)Activator.CreateInstance(providerType);
            provider.ConnectionString = connectionString;

            // Create orchestrator
            var webServerOrchestrator = new WebServerOrchestrator(provider, options, webServerOptions, setup, webServerManager.Cache, scopeName);

            // add it to the singleton collection
            webServerManager.Add(webServerOrchestrator);

            return(serviceCollection);
        }
        public T CreateOrchestrator <T>(ProviderType providerType, string dbName, bool useChangeTracking = false) where T : IOrchestrator
        {
            // Get connection string
            var cs = HelperDatabase.GetConnectionString(providerType, dbName);

            IOrchestrator orchestrator = null;

            if (typeof(T) == typeof(RemoteOrchestrator))
            {
                orchestrator = new RemoteOrchestrator();
            }
            else if (typeof(T) == typeof(LocalOrchestrator))
            {
                orchestrator = new LocalOrchestrator();
            }
            else if (typeof(T) == typeof(WebServerOrchestrator))
            {
                orchestrator = new WebServerOrchestrator();
            }

            if (orchestrator == null)
            {
                throw new Exception("Orchestrator does not exists");
            }

            switch (providerType)
            {
            case ProviderType.Sql:
                orchestrator.Provider = useChangeTracking ? new SqlSyncChangeTrackingProvider(cs) : new SqlSyncProvider(cs);
                break;

            case ProviderType.MySql:
                orchestrator.Provider = new MySqlSyncProvider(cs);
                break;

            case ProviderType.Sqlite:
                orchestrator.Provider = new SqliteSyncProvider(cs);
                break;
            }
            return((T)orchestrator);
        }
示例#4
0
        public KestrellTestServer(WebServerOrchestrator webServerOrchestrator, bool useFidller = false)
        {
            var hostBuilder = new WebHostBuilder()
                              .UseKestrel()
                              .UseUrls("http://127.0.0.1:0/")
                              .ConfigureServices(services =>
            {
                services.AddMemoryCache();
                services.AddDistributedMemoryCache();
                services.AddSession(options =>
                {
                    // Set a long timeout for easy testing.
                    options.IdleTimeout     = TimeSpan.FromDays(10);
                    options.Cookie.HttpOnly = true;
                });

                // add a SqlSyncProvider acting as the server hub
                services.AddSyncServer(webServerOrchestrator);
            });

            this.builder = hostBuilder;

            this.useFiddler = useFidller;
        }
        public static IServiceCollection AddSyncServer(this IServiceCollection serviceCollection, WebServerOrchestrator webServerOrchestrator)
        {
            var serviceProvider = serviceCollection.BuildServiceProvider();

            // Get all registered server providers with schema and options
            var webServerManager = serviceProvider.GetService <WebServerManager>();

            if (webServerManager == null)
            {
                var cache = serviceProvider.GetService <IMemoryCache>();
                var env   = serviceProvider.GetService <IHostingEnvironment>();

                webServerManager = new WebServerManager(cache, env);
                serviceCollection.AddSingleton(webServerManager);
            }

            // Check if we don't have already added this scope name provider to the remote orchestrator list
            if (webServerManager.Contains(webServerOrchestrator.ScopeName))
            {
                throw new ArgumentException($"Orchestrator with scope name {webServerOrchestrator.ScopeName} already exists in the service collection");
            }

            // add it to the singleton collection
            webServerManager.Add(webServerOrchestrator);

            return(serviceCollection);
        }
示例#6
0
 /// <summary>
 /// Intercept the provider when an http message request from the client arrived to the server
 /// </summary>
 public static void OnHttpGettingRequest(this WebServerOrchestrator orchestrator,
                                         Func <HttpGettingRequestArgs, Task> action)
 => orchestrator.SetInterceptor(action);
示例#7
0
 /// <summary>
 /// Intercept the provider when an http response message is sent back to the client
 /// </summary>
 public static void OnHttpSendingResponse(this WebServerOrchestrator orchestrator,
                                          Func <HttpSendingResponseArgs, Task> action)
 => orchestrator.SetInterceptor(action);
示例#8
0
 /// <summary>
 /// Intercept the provider when an http message is downloaded from remote side
 /// </summary>
 public static void OnHttpGettingChanges(this WebServerOrchestrator orchestrator,
                                         Func <HttpGettingClientChangesArgs, Task> action)
 => orchestrator.SetInterceptor(action);
示例#9
0
 /// <summary>
 /// Intercept the provider when an http message is sent
 /// </summary>
 public static void OnHttpSendingChanges(this WebServerOrchestrator orchestrator,
                                         Action <HttpSendingServerChangesArgs> action)
 => orchestrator.SetInterceptor(action);