private static void Run(Func <ReactiveClientContext, Task> action) { var platform = default(IReactivePlatform); try { platform = new TcpReactivePlatform(); try { var clientProvider = new System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider(); var serverProvider = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider { TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full }; var props = new System.Collections.Hashtable { { "port", 0 }, { "name", System.Guid.NewGuid().ToString() }, { "typeFilterLevel", System.Runtime.Serialization.Formatters.TypeFilterLevel.Full } }; System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Tcp.TcpChannel(props, clientProvider, serverProvider), ensureSecurity: false); platform.StartAsync(CancellationToken.None).Wait(); Console.WriteLine("Running demo with the TCP platform."); } #pragma warning disable CA1031 // Do not catch general exception types. (Demo code.) catch { try { platform.StopAsync(CancellationToken.None).Wait(); } catch { } platform = new InMemoryReactivePlatform(); platform.StartAsync(CancellationToken.None).Wait(); Console.WriteLine("Running demo with the in-memory platform."); } #pragma warning restore CA1031 new ReactivePlatformDeployer(platform, new Deployable.CoreDeployable()).Deploy(); action(platform.CreateClient().Context).Wait(); } finally { platform?.Dispose(); } }
static void ForeignFunctions2() { using var environment = new InMemoryReactiveEnvironment(); using var platform = new InMemoryReactivePlatform(environment); Initialize(environment, platform); var ctx = platform.CreateClient().Context; Console.WriteLine("Creating stream..."); var streamFactory = ctx.GetStreamFactory <Person, Person>(Platform.Constants.Identifiers.Observable.FireHose.Uri); var stream = streamFactory.CreateAsync(new Uri("reactor://stream/foo"), null).Result; var people = ctx.GetObservable <Person>(new Uri("reactor://stream/foo")); var cout = ctx.GetObserver <string>(Platform.Constants.Identifiers.Observer.ConsoleObserver.Uri); Console.WriteLine("Creating subscription..."); var sub = people .Select(p => Json.Serialize(p)) // NB: fast serialization doesn't work at the moment; no support for enums yet .SubscribeAsync(cout, new Uri("reactor://test/subscription"), null).Result; Console.WriteLine("Publishing events..."); var observer = ctx.GetObserver <Person>(new Uri("reactor://stream/foo")); observer.OnNextAsync(new Person { FirstName = "John", LastName = "Smith", Location = "Home" }).Wait(); observer.OnNextAsync(new Person { FirstName = "Bob", LastName = "Smith", Location = "Home" }).Wait(); observer.OnNextAsync(new Person { FirstName = "Joe", LastName = "Smith", Location = "Home" }).Wait(); Task.Delay(10000).Wait(); sub.DisposeAsync().Wait(); }
static void ForeignFunctions1() { using var environment = new InMemoryReactiveEnvironment(); using var platform = new InMemoryReactivePlatform(environment); Initialize(environment, platform); var ctx = platform.CreateClient().Context; var range = ctx.GetObservable <int, int>(Reactor.Constants.Identifiers.Observable.Range.Uri); var cout = ctx.GetObserver <string>(Platform.Constants.Identifiers.Observer.ConsoleObserver.Uri); Console.WriteLine("Press ENTER to dispose..."); var sub = range(5) .Select(value => GenerateLanguage(value, "en-us")) .SubscribeAsync(cout, new Uri("reactor://test/subscription"), null).Result; Task.Delay(1000).Wait(); sub.DisposeAsync().Wait(); }