public TripleStoreRemotingClientService(StatelessServiceContext context) : base(context) { m_TripleStoreMemoryCloudClient = new TrinityClient(TripleStoreMemoryCloudServiceString); //m_TripleStoreMemoryCloudClient.RegisterCommunicationModule<TripleStoreMemoryCloudServiceImpl>(); m_TripleStoreMemoryCloudClient.Start(); }
static async Task Main(string[] args) { TrinityConfig.LoggingLevel = LogLevel.Verbose; m_trinity = new TrinityClient("testcluster100.southcentralus.cloudapp.azure.com:8800"); m_trinity.Start(); long iterations = 0; PingMessagePayload syncPingMessage = new PingMessagePayload("Ping Message from External Synchronous GE Client over Native TCP. Hello GE/SF"); PingMessagePayload asyncPingMessage = new PingMessagePayload("Ping Message from External Asynchronous GE Client over Native TCP.Hello GE/SF"); while (true) { m_trinity?.ExternalClientPing(new PingMessagePayloadWriter(syncPingMessage.PingMessage)); var response = await m_trinity ?.ExternalClientPingAsync(new PingMessagePayloadWriter(asyncPingMessage.PingMessage)); Console.WriteLine($"Async Response from GE/SF Graph Data Service: {response.PingMessage}"); await Task.Delay(TimeSpan.FromSeconds(1)); } }
public RemotingClient(StatelessServiceContext context) : base(context) { m_trinity = new TrinityClient("fabric:/TrinityServiceFabric.NativeClusterRemoting.Application/GraphEngine.ServiceFabric.GraphDataService"); m_trinity.Start(); }
public GraphDataClient(StatelessServiceContext context) : base(context) { m_trinity = new TrinityClient("fabric:/GraphEngine.ServiceFabric.TripleStoreApplication/Stateful.TripleStore.GraphDataService"); m_trinity.Start(); }
public GraphEngineRemotingClient(StatelessServiceContext context) : base(context) { TrinityClient trinityClient = new TrinityClient("fabric:/Trinity.ServiceFabric.SampleApplication/Trinity.ServiceFabric.GraphEngineService"); //TrinityClient trinityClient = new TrinityClient("fabric:/Trinity.ServiceFabric.SampleApplication/Trinity.ServiceFabric.GraphEngineService"); m_trinity = trinityClient; m_trinity.Start(); }
static void Main(string[] args) { TrinityClient client = new TrinityClient("localhost:5304"); client.RegisterCommunicationModule <TrinityClientTestModule>(); client.Start(); while (true) { Thread.Sleep(1000000); } }
static void Main(string[] args) { TrinityConfig.LoggingLevel = Diagnostics.LogLevel.Debug; TrinityClient client = new TrinityClient("localhost:5304"); client.RegisterCommunicationModule <TrinityClientTestModule>(); client.Start(); while (true) { Thread.Sleep(1000000); } }
static async Task Main(string[] args) { LoggingLevel = Trinity.Diagnostics.LogLevel.Debug; client = new TrinityClient("localhost:5304"); client.RegisterCommunicationModule <TripleStoreServiceModule>(); //client.RegisterCommunicationModule<TrinityClientModule>(); client.Start(); var clientModule = client.GetCommunicationModule <TrinityClientModule>(); var clientModuleInstance = clientModule.Clients; var tctm = Global.CloudStorage.GetCommunicationModule <TripleStoreServiceModule>(); while (true) { try { var tripleStatement = new TripleStatement() { BaseUri = @"http:\\www.inknowworks.semanticweb\ontology", Subject = "GraphEngine", Predicate = "IsAwesome", Object = "DataManagementSystem" }; using (var message = new StoreTripleRequestWriter(tripleStatement)) using (var rsp = client.StoreTriple(message)) { if (rsp != null) { Console.WriteLine($"Server responses with rsp code={rsp.Triple.BaseUri}"); } } } catch (Exception e) { Console.WriteLine(e.Message); } await Task.Delay(1000); } }
public Client(StatelessServiceContext context) : base(context) { TrinityConfig.LoadConfig(); TrinityConfig.CurrentRunningMode = RunningMode.Client; TrinityConfig.LogEchoOnConsole = false; TrinityConfig.LoggingLevel = LogLevel.Debug; TrinityConfig.SaveConfig(); Log.LogsWritten += Log_LogsWritten; TrinityTripleModuleClient = new TrinityClient("fabric:/GraphEngine.ServiceFabric.TripleStoreApplication/Stateful.TripleStore.GraphDataService"); TrinityTripleModuleClient.UnhandledException += TrinityTripleModuleClient_UnhandledException1; TrinityTripleModuleClient.Started += TrinityTripleModuleClientStarted; TrinityTripleModuleClient.Start(); }
/// <summary> /// This is the entry point of the service host process. /// </summary> private static void Main() { try { // The ServiceManifest.XML file defines one or more service type names. // Registering a service maps a service type name to a .NET type. // When Service Fabric creates an instance of this service type, // an instance of the class is created in this host process. //ServiceRuntime.RegisterServiceAsync("SFCluster.Stateful.TripleStore.GraphDataClientType", // context => new GraphDataClient(context)).GetAwaiter().GetResult(); TrinityConfig.LogEchoOnConsole = false; TrinityConfig.LoggingLevel = LogLevel.Debug; //TrinityConfig.StorageRoot = @"C:\GE-TripleStore-Storage"; // The ServiceManifest.XML file defines one or more service type names. // Registering a service maps a service type name to a .NET type. // When Service Fabric creates an instance of this service type, // an instance of the class is created in this host process. GraphEngineService.StartServiceAsync("SFCluster.Stateful.TripleStore.GraphDataClientType").GetAwaiter() .GetResult(); Log.WriteLine(nameof(TripleModule) + " SFCluster Client is Up, Ready and Active"); var m_trinity = new TrinityClient("fabric:/GraphEngine.ServiceFabric.TripleStoreApplication/Stateful.TripleStore.GraphDataService"); m_trinity.Start(); //ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(GraphDataClient).Name); // Prevents this host process from terminating so services keep running. Thread.Sleep(Timeout.Infinite); } catch (Exception e) { //ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); throw; } }
public GraphEngineRemotingClient(StatelessServiceContext context) : base(context) { //TrinityConfig.LoadConfig(); //TrinityConfig.CurrentRunningMode = RunningMode.Client; TrinityConfig.LogEchoOnConsole = false; TrinityConfig.LoggingLevel = LogLevel.Verbose; //TrinityConfig.SaveConfig(); Log.LogsWritten += Log_LogsWritten; TrinityTripleModuleClient = new TrinityClient("fabric:/Trinity.ServiceFabric.TestHarnes.Application/Trinity.SF.GraphEngineDataService"); //TrinityTripleModuleClient = new TrinityClient("GenNexusPrime.inknowworks.dev.net:8800"); TrinityTripleModuleClient.UnhandledException += TrinityTripleModuleClient_UnhandledException; TrinityTripleModuleClient.Started += TrinityTripleModuleClientStarted; TrinityTripleModuleClient.RegisterCommunicationModule <TripleModule>(); TrinityTripleModuleClient.Start(); }
static async Task Main(string[] args) { //TrinityConfig.LoadConfig(); //TrinityConfig.CurrentRunningMode = RunningMode.Client; //TrinityConfig.LogEchoOnConsole = false; TrinityConfig.LoggingLevel = LogLevel.Debug; //TrinityConfig.SaveConfig(); //Log.LogsWritten += Log_LogsWritten; //TrinityTripleModuleClient = new TrinityClient("testcluster100.southcentralus.cloudapp.azure.com:8800"); TrinityTripleModuleClient = new TrinityClient("GenNexusPrime.inknowworksdev.net:12333"); //TrinityTripleModuleClient = new TrinityClient("truesparksf01.inknowworksdev.net:8808"); // truesparksf03.inknowworksdev.net:8808 TrinityTripleModuleClient.UnhandledException += TrinityTripleModuleClient_UnhandledException; TrinityTripleModuleClient.Started += TrinityTripleModuleClientOnStarted; TrinityTripleModuleClient.RegisterCommunicationModule <TripleModule>(); TrinityTripleModuleClient.Start(); Log.WriteLine("Setup Reactive Event Stream Processing!"); TripleClientSideModule = TrinityTripleModuleClient.GetCommunicationModule <TripleModule>(); TripleClientSideModule.TripleBySubjectReceivedAction .ObserveOn(TripleClientSideModule.ObserverOnNewThreadScheduler) .Do(onNext: subscriberSource => { var msg = "TripleBySubjectReceivedAction-1"; Log.WriteLine("{0} Subscription happened on this Thread: {1}", msg, Thread.CurrentThread.ManagedThreadId); }) .SubscribeOn(TripleClientSideModule.SubscribeOnEventLoopScheduler) .Subscribe(onNext: async tripleStore => { using var reactiveGetTripleBySubjectTask = Task.Factory.StartNew(async() => { //await Task.Yield(); await Task.Delay(0).ConfigureAwait(false); Log.WriteLine( "Reactive Async - Parallel-Tasking return from Server-Side Get Request on behalf of the Client."); Log.WriteLine( $"Processing Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}"); Log.WriteLine($"Triple Object CellID: {tripleStore.CellId}."); Log.WriteLine($"Triple Subject Node: {tripleStore.TripleCell.Subject}"); Log.WriteLine( $"Triple Predicate Node: {tripleStore.TripleCell.Predicate}"); Log.WriteLine($"Triple Object Node: {tripleStore.TripleCell.Object}."); var getTripleByCellRequestWriter = new TripleGetRequestWriter() { TripleCellId = tripleStore.CellId, Subject = tripleStore.TripleCell.Subject, Predicate = tripleStore.TripleCell.Predicate, Object = tripleStore.TripleCell.Object, Namespace = tripleStore.TripleCell.Namespace }; await TrinityTripleModuleClient.GetTripleSubject(getTripleByCellRequestWriter); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0); Log.WriteLine("Task TripleObjectStreamedFromServerReceivedAction Complete..."); }, cancellationToken: CancellationToken.None); var writeToConsoleTask = reactiveGetTripleBySubjectTask; await writeToConsoleTask; }); // TripleObjectStreamedFromServerReceivedAction TripleClientSideModule.TripleObjectStreamedFromServerReceivedAction .ObserveOn(TripleClientSideModule.ObserverOnNewThreadScheduler) .Do(onNext: subscriberSource => { var msg = "TripleObjectStreamedFromServerReceivedAction-1"; Log.WriteLine("{0} Subscription happened on this Thread: {1}", msg, Thread.CurrentThread.ManagedThreadId); }) .SubscribeOn(TripleClientSideModule.SubscribeOnEventLoopScheduler) .Subscribe(onNext: async tripleObjectFromServer => { using var reactiveGraphEngineResponseTask = Task.Factory.StartNew(async() => { //await Task.Yield(); await Task.Delay(0).ConfigureAwait(false); Log.WriteLine("Incoming Triple Object Received from GE Server."); Log.WriteLine( $"Processing Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}"); Log.WriteLine($"Triple Subject Node: {tripleObjectFromServer.Subject}"); Log.WriteLine($"Triple Predicate Node: {tripleObjectFromServer.Predicate}"); Log.WriteLine($"Triple Object Node: {tripleObjectFromServer.Object}"); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0); Log.WriteLine("Task TripleObjectStreamedFromServerReceivedAction Complete..."); }, cancellationToken: CancellationToken.None); var writeToConsoleTask = reactiveGraphEngineResponseTask; await writeToConsoleTask; }); // ServerStreamedTripleSavedToMemoryCloudAction TripleClientSideModule.ServerStreamedTripleSavedToMemoryCloudAction .ObserveOn(TripleClientSideModule.ObserverOnNewThreadScheduler) .Do(onNext: subscriberSource => { var msg = "ServerStreamedTripleSavedToMemoryCloudAction-1"; Log.WriteLine("{0} Subscription happened on this Thread: {1}", msg, Thread.CurrentThread.ManagedThreadId); }) .SubscribeOn(TripleClientSideModule.SubscribeOnEventLoopScheduler) .Subscribe(onNext: async tripleObjectFromMC => { using var reactiveGraphEngineResponseTask = Task.Factory.StartNew(async() => { await Task.Delay(0).ConfigureAwait(false); var myTripleStore = tripleObjectFromMC.NewTripleStore; Log.WriteLine("Incoming TripleStore Object retrieved from MemoryCloud."); Log.WriteLine( $"Processing Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}"); Log.WriteLine($"Triple Object CellID: {myTripleStore.CellId}"); Log.WriteLine($"Triple Subject Node: {myTripleStore.TripleCell.Subject}"); Log.WriteLine($"Triple Predicate Node: {myTripleStore.TripleCell.Predicate}"); Log.WriteLine($"Triple Object Node: {myTripleStore.TripleCell.Object}"); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0); Log.WriteLine("Task ServerStreamedTripleSavedToMemoryCloudAction Complete..."); }, cancellationToken: CancellationToken.None); var writeToConsoleTask = reactiveGraphEngineResponseTask; await writeToConsoleTask; }); // ClientPostedTripleStoreReadyInMemoryCloudAction TripleClientSideModule.ClientPostedTripleStoreReadyInMemoryCloudAction .ObserveOn(TripleClientSideModule.ObserverOnNewThreadScheduler) .Do(onNext: subscriberSource => { var msg = "ClientPostedTripleStoreReadyInMemoryCloudAction-1"; Log.WriteLine("{0} Subscription happened on this Thread: {1}", msg, Thread.CurrentThread.ManagedThreadId); }) .SubscribeOn(TripleClientSideModule.SubscribeOnEventLoopScheduler) .Synchronize() .Subscribe(onNext: async tripleObject => { using var getTripleByCellIdTask = Task.Factory.StartNew(async() => { // await Task.Yield(); await Task.Delay(0).ConfigureAwait(false); using var getRequest = new TripleGetRequestWriter() { TripleCellId = tripleObject.CellId, Subject = tripleObject.TripleCell.Subject, Predicate = tripleObject.TripleCell.Predicate, Namespace = tripleObject.TripleCell.Namespace, Object = tripleObject.TripleCell.Object }; await TrinityTripleModuleClient.GetTripleByCellId(getRequest); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0); Log.WriteLine("Task ClientPostedTripleStoreReadyInMemoryCloudAction Complete..."); }, cancellationToken: CancellationToken.None); var writeToConsoleTask = getTripleByCellIdTask; await writeToConsoleTask; }); // Reactive: ClientPostedTripleStoreReadyInMemoryCloudHotAction TripleClientSideModule.ClientPostedTripleStoreReadyInMemoryCloudHotAction .ObserveOn(TripleClientSideModule.HotObservableSchedulerContext) .Do(onNext: subscriberSource => { var msg = "ClientPostedTripleStoreReadyInMemoryCloudHotAction-1"; Log.WriteLine("{0} Subscription happened on this Thread: {1}", msg, Thread.CurrentThread.ManagedThreadId); }) .SubscribeOn(TripleClientSideModule.HotObservableSchedulerContext) .Synchronize() .Subscribe(onNext: async tripleObject => { using var getTripleByCellIdTask = Task.Factory.StartNew(async() => { // await Task.Yield(); await Task.Delay(0).ConfigureAwait(false); Log.WriteLine("Reactive Event Stream Processing from Hot Observable"); using var getRequest = new TripleGetRequestWriter() { TripleCellId = tripleObject.CellId, Subject = tripleObject.TripleCell.Subject, Predicate = tripleObject.TripleCell.Predicate, Namespace = tripleObject.TripleCell.Namespace, Object = tripleObject.TripleCell.Object }; await TrinityTripleModuleClient.GetTripleByCellId(getRequest); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0); Log.WriteLine("Task ClientPostedTripleStoreReadyInMemoryCloudHotAction Complete..."); }, cancellationToken: CancellationToken.None); var writeToConsoleTask = getTripleByCellIdTask; await writeToConsoleTask; }); TripleClientSideModule.ClientPostedTripleStoreReadyInMemoryCloudHotAction.Connect(); TripleClientSideModule.TripleByCellIdReceivedAction .ObserveOn(TripleClientSideModule.ObserverOnNewThreadScheduler) .Do(onNext: subscriberSource => { var msg = "TripleByCellIdReceivedAction-1"; Log.WriteLine("{0} Subscription happened on this Thread: {1}", msg, Thread.CurrentThread.ManagedThreadId); }) .SubscribeOn(TripleClientSideModule.SubscribeOnEventLoopScheduler) .Synchronize() .Subscribe(onNext: async tripleObjectFromGetRequest => { using var getTripleBySubjectTask = Task.Factory.StartNew(async() => { //await Task.Yield(); await Task.Delay(0).ConfigureAwait(false); Log.WriteLine( "Reactive Async - Server-Side Get Request on behalf of the Client."); Log.WriteLine( $"Processing Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}"); Log.WriteLine($"Triple Object CellID: {tripleObjectFromGetRequest.CellId}."); Log.WriteLine( $"Triple Subject Node: {tripleObjectFromGetRequest.TripleCell.Subject}"); Log.WriteLine( $"Triple Predicate Node: {tripleObjectFromGetRequest.TripleCell.Predicate}"); Log.WriteLine( $"Triple Object Node: {tripleObjectFromGetRequest.TripleCell.Object}."); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0); Log.WriteLine("Task TripleByCellIdReceivedAction Complete..."); }, cancellationToken: CancellationToken.None); var writeToConsoleTask = getTripleBySubjectTask; await writeToConsoleTask; }); TripleClientSideModule.ClientPostedTripleSavedToMemoryCloudAction .ObserveOn(TripleClientSideModule.ObserverOnNewThreadScheduler) .Do(onNext: subscriberSource => { var msg = "ClientPostedTripleSavedToMemoryCloudAction-1"; Log.WriteLine("{0} Subscription happened on this Thread: {1}", msg, Thread.CurrentThread.ManagedThreadId); }) .SubscribeOn(TripleClientSideModule.SubscribeOnEventLoopScheduler) .Synchronize() .Subscribe(onNext: async tripleStoreMemoryContext => { using var reactToTriplePostedSavedToMemoryCloudTask = Task.Factory.StartNew(async() => { //await Task.Yield(); await Task.Delay(0).ConfigureAwait(false); Log.WriteLine("Success! Found the Triple in the TripleStore MemoryCloud"); var tripleStore = tripleStoreMemoryContext.NewTripleStore; var subjectNode = tripleStore.TripleCell.Subject; var predicateNode = tripleStore.TripleCell.Predicate; var objectNode = tripleStore.TripleCell.Object; Log.WriteLine($"Triple CellId in MemoryCloud: {tripleStoreMemoryContext.NewTripleStore.CellId}"); Log.WriteLine($"Subject Node: {subjectNode}"); Log.WriteLine($"Predicate Node: {predicateNode}"); Log.WriteLine($"Object Node: {objectNode}"); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0); Log.WriteLine("Task ClientPostedTripleSavedToMemoryCloudAction Complete..."); }, cancellationToken: CancellationToken.None); var storeFromMemoryCloudTask = reactToTriplePostedSavedToMemoryCloudTask; await storeFromMemoryCloudTask; }); //Log.WriteLine($"Please press the enter to continue!"); //Log.ReadLine(); // Prevents this host process from terminating so services keep running. //Thread.Sleep(Timeout.Infinite); // Main Processing Loop! using var trinityClientProcessingLoopTask = Task.Factory.StartNew(async() => { while (true) { try { //await Task.Yield(); var sampleTriple = new List <Triple> { new Triple { Subject = "Test-GraphEngineClient", Predicate = "is", Object = "Running" } }; using var tripleStreamWriter = new TripleStreamWriter(sampleTriple); await TrinityTripleModuleClient.PostTriplesToServer(tripleStreamWriter).ConfigureAwait(false); } catch (Exception ex) { Log.WriteLine(ex.ToString()); } await Task.Delay(0).ConfigureAwait(false); } /* * return; */ }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap(); var mainLoopTask = trinityClientProcessingLoopTask; await mainLoopTask; }
static async Task Main(string[] args) { TrinityConfig.CurrentRunningMode = RunningMode.Client; TrinityConfig.LogEchoOnConsole = true; TrinityConfig.LoggingLevel = LogLevel.Info; Log.LogsWritten += Log_LogsWritten; TrinityClient client = new TrinityClient("localhost:5304"); client.RegisterCommunicationModule <TripleModule>(); client.Start(); tripleModule = client.GetCommunicationModule <TripleModule>(); tripleModule.ExternalTripleReceivedAction.Subscribe(onNext: async tripleObjectFromServer => { using var reactiveGraphEngineResponseTask = Task.Factory.StartNew(async() => { await Task.Delay(0).ConfigureAwait(false); Console.WriteLine($"Processing Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}"); Console.WriteLine($"Triple Subject Node: {tripleObjectFromServer.Subject}"); Console.WriteLine($"Triple Predicate Node: {tripleObjectFromServer.Predicate}"); Console.WriteLine($"Triple Object Node: {tripleObjectFromServer.Object}"); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0).ConfigureAwait(false); Console.WriteLine("Task ExternalTripleReceivedAction Complete..."); }, cancellationToken: CancellationToken.None); var writeToConsoleTask = reactiveGraphEngineResponseTask.ConfigureAwait(false); await writeToConsoleTask; }); tripleModule.ExternalTripleSavedToMemoryAction.Subscribe(onNext: async tripleStoreMemoryContext => { using var retrieveTripleStoreFromMemoryCloudTask = Task.Factory.StartNew(async() => { await Task.Delay(0).ConfigureAwait(false); Console.WriteLine("Try locate the Triple in the TripleStore MemoryCloud"); foreach (var tripleNode in Global.LocalStorage.TripleStore_Selector()) { if (tripleStoreMemoryContext.CellId != tripleNode.CellId) { continue; } Console.WriteLine("Success! Found the Triple in the TripleStore MemoryCloud"); var node = tripleNode.TripleCell; var subjectNode = node.Subject; var predicateNode = node.Predicate; var objectNode = node.Object; Console.WriteLine($"Triple CellId in MemoryCloud: {tripleNode.CellId}"); Console.WriteLine($"Subject Node: {subjectNode}"); Console.WriteLine($"Predicate Node: {predicateNode}"); Console.WriteLine($"Object Node: {objectNode}"); break; } }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.HideScheduler, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(0).ConfigureAwait(false); Console.WriteLine("Task ExternalTripleSavedToMemoryAction Complete..."); }, cancellationToken: CancellationToken.None); var storeFromMemoryCloudTask = retrieveTripleStoreFromMemoryCloudTask.ConfigureAwait(false); await storeFromMemoryCloudTask; }); // ------------------------------------------------------- while (true) { try { using var trinityClientProcessingLoopTask = Task.Factory.StartNew(async() => { await Task.Delay(500).ConfigureAwait(false); List <Triple> triples = new List <Triple> { new Triple { Subject = "foo", Predicate = "is", Object = "bar" } }; using var message = new TripleStreamWriter(triples); using var rsp = await client.PostTriplesToServer(message).ConfigureAwait(false); Console.WriteLine($"Server responses with rsp code={rsp.errno}"); }, cancellationToken: CancellationToken.None, creationOptions: TaskCreationOptions.LongRunning, scheduler: TaskScheduler.Current).Unwrap().ContinueWith(async _ => { await Task.Delay(1000).ConfigureAwait(false); Console.WriteLine("Task ExternalTripleSavedToMemoryAction Complete..."); }, cancellationToken: CancellationToken.None); var mainLoopTask = trinityClientProcessingLoopTask.ConfigureAwait(false); await mainLoopTask; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } await Task.Delay(500).ConfigureAwait(false); } }
public MainWindow() { InitializeComponent(); client.RegisterCommunicationModule <TripleModule>(); // Hook up to Graph Engine Reactive .. client.Start(); var tripleModule = client.GetCommunicationModule <TripleModule>(); var uiSyncContext = TaskScheduler.FromCurrentSynchronizationContext(); var token = Task.Factory.CancellationToken; // Setup Reactive Processing .. tripleModule.ExternalTripleReceivedAction.Subscribe(onNext: async tripleObjectFromServer => { using var reactiveGraphEngineResponseTask = Task.Factory.StartNew(async() => { await Task.Factory.StartNew(() => { NameSpaceTB.Text = DateTime.Now.ToString(CultureInfo.InvariantCulture); SubjectTB.Text = tripleObjectFromServer.Subject; PredicateTB.Text = tripleObjectFromServer.Predicate; ObjectTB.Text = tripleObjectFromServer.Object; }, token, TaskCreationOptions.None, uiSyncContext).ConfigureAwait(false); }).ContinueWith(_ => { ResponseTextBlock.Items.Add("Task ExternalTripleReceivedAction Complete..."); }, uiSyncContext); var upDateOnUITread = reactiveGraphEngineResponseTask.ConfigureAwait(false); await upDateOnUITread; }); tripleModule.ExternalTripleSavedToMemoryAction.Subscribe(onNext: async tripleStoreMemoryContext => { using var retrieveTripleStoreFromMemoryCloudTask = Task.Factory.StartNew(async() => { await Task.Factory.StartNew(() => { foreach (var tripleNode in Global.LocalStorage.TripleStore_Selector()) { if (tripleStoreMemoryContext.CellId != tripleNode.CellId) { continue; } var node = tripleNode.TripleCell; var subjectNode = node.Subject; var predicateNode = node.Predicate; var objectNode = node.Object; ResponseTextBlock.Items.Add($"Triple CellId in MemoryCloud: {tripleNode.CellId}"); ResponseTextBlock.Items.Add($"Subject Node: {subjectNode}"); ResponseTextBlock.Items.Add($"Predicate Node: {predicateNode}"); ResponseTextBlock.Items.Add($"Object Node: {objectNode}"); break; } }, token, TaskCreationOptions.None, uiSyncContext).ConfigureAwait(false); }).ContinueWith(_ => { ResponseTextBlock.Items.Add("Task ExternalTripleSavedToMemoryAction Complete..."); }, uiSyncContext); var upDateOnUITread = retrieveTripleStoreFromMemoryCloudTask.ConfigureAwait(false); await upDateOnUITread; }); }