Exemplo n.º 1
0
        public static void Start(
            string localServer,
            string remoteServer,
            int threads = 2,
            IEnumerable <Assembly> assemblies = null,
            IEnumerable <string> classes      = null)
        {
            var concurrentApp = new ThreadedConcurrentApp(new Dictionary <string, Func <IConcurrentApp, object[], IConcurrentObject> >());
            var app           = new DistributedApp(concurrentApp, localServer);

            Loader.FromAssemblies(app, assemblies, null, only: classes);

            app.Connect = _ =>
            {
                var waiter  = new ManualResetEvent(false);
                var errors  = new List <Exception>();
                int waitFor = 2;

                NetMQFunctions.StartServer(app, localServer,
                                           connected: ex =>
                {
                    if (ex != null)
                    {
                        errors.Add(ex);
                    }
                    if (--waitFor == 0)
                    {
                        waiter.Set();
                    }
                });

                NetMQFunctions.StartClient(app, localServer, remoteServer, ex =>
                {
                    if (ex != null)
                    {
                        errors.Add(ex);
                    }
                    if (--waitFor == 0)
                    {
                        waiter.Set();
                    }
                });

                waiter.WaitOne();
                return(errors.Any()
                    ? new AggregateException(errors)
                    : null);
            };

            app.Start();
        }
Exemplo n.º 2
0
        public static void UseExcess(this IAppBuilder app,
                                     __Scope scope,
                                     Action <ConcurrentAppSettings> initializeSettings = null,
                                     Action <IDistributedApp> initializeApp            = null,
                                     IEnumerable <Type> functional        = null,
                                     IEnumerable <FilterFunction> filters = null)
        {
            var settings = new ConcurrentAppSettings();

            initializeSettings?.Invoke(settings);

            var server = new DistributedApp(new ThreadedConcurrentApp(
                                                types: null,
                                                threadCount: settings.Threads,
                                                blockUntilNextEvent: settings.BlockUntilNextEvent));

            initializeApp?.Invoke(server);

            app.Use <ExcessOwinMiddleware>(server, scope, functional, filters);
            server.Start();
        }