private static void registerChannelTopics() { if (channelClient == null) { throw new NullReferenceException("ChannelClient must be created before registering topics."); } channelClient.RegisterTopic <RaiseIntentPayload>(ChannelTopicConstants.Intent, payload => { if (intentListeners.ContainsKey(payload.Intent)) { intentListeners[payload.Intent].Invoke(payload.Context); } }); channelClient.RegisterTopic <ContextBase>(ChannelTopicConstants.Context, payload => { contextListeners?.Invoke(payload); }); channelClient.RegisterTopic <ChannelChangedPayload>(ChannelTopicConstants.Event, @event => { channelChangedHandlers?.Invoke(@event); }); }
public void SubscribeToChannel <T>(string topic, Action <T> responseHandler) { if (_runtime.IsConnected) { _channelClient.RegisterTopic(topic, responseHandler); } }
private void registerChannelTopics() { if (channelClient == null) { throw new NullReferenceException("ChannelClient must be created before registering topics."); } channelClient.RegisterTopic <ReceiveIntentPayload>(ApiToClientTopic.ReceiveIntent, payload => { if (FDC3Handlers.IntentHandlers.ContainsKey(payload.Intent)) { FDC3Handlers.IntentHandlers[payload.Intent].Invoke(payload.Context); } }); channelClient.RegisterTopic <HandleChannelContextPayload>(ApiToClientTopic.ChannelReceiveContext, payload => { foreach (var listener in FDC3Handlers.ChannelContextHandlers.Where(x => x.Channel.ChannelId == payload.ChannelId)) { listener.Handler.Invoke(payload.Context); } }); channelClient.RegisterTopic <object>(ApiToClientTopic.Warn, payload => { Console.WriteLine(payload); }); channelClient.RegisterTopic <EventTransport <FDC3Event> >(ApiToClientTopic.Event, @event => { EventRouter.Instance.DispatchEvent(@event, this); }); channelClient.RegisterTopic <ReceiveContextPayload>(ApiToClientTopic.ReceiveContext, payload => { ContextHandlers?.Invoke(payload.Context); }); }
/// <summary> /// Initializes the Notification Service. /// </summary> /// <param name="manifestUri">The Uri pointing to the notification service manifest.</param> public static void Initialize(Uri manifestUri) { if (OnInitComplete == null) { throw new InvalidOperationException("InitializationComplete handler must be registered before calling Initialize()"); } var runtimeOptions = RuntimeOptions.LoadManifest(manifestUri); runtimeOptions.Arguments += " --inspect"; var entryAssembly = System.Reflection.Assembly.GetEntryAssembly(); if (entryAssembly != null) { var productAttributes = entryAssembly.GetCustomAttributes(typeof(System.Reflection.AssemblyProductAttribute), true); if (productAttributes.Length > 0) { runtimeOptions.UUID = ((System.Reflection.AssemblyProductAttribute)productAttributes[0]).Product; } else { runtimeOptions.UUID = System.Reflection.Assembly.GetEntryAssembly().GetName().Name; } } else { runtimeOptions.UUID = Guid.NewGuid().ToString(); } _runtime = Runtime.GetRuntimeInstance(runtimeOptions); _runtime.Connect(() => { var notificationsService = _runtime.CreateApplication(runtimeOptions.StartupApplicationOptions); notificationsService.isRunning( async ack => { if (!(bool)(ack.getData() as JValue).Value) { notificationsService.run(); } _channelClient = _runtime.InterApplicationBus.Channel.CreateClient(ServiceConstants.NotificationServiceChannelName); _channelClient.RegisterTopic <NotificationEvent>(ChannelTopics.Events, (@event) => { switch (@event.EventType) { case NotificationEventTypes.NotificationAction: NotificationActionOccurred?.Invoke(@event); break; case NotificationEventTypes.NotificationClosed: NotificationClosed?.Invoke(@event); break; case NotificationEventTypes.NotificationCreated: NotificationCreated?.Invoke(@event); break; default: throw new ArgumentException($"Invalid event type : {@event.EventType}"); } }); await _channelClient.ConnectAsync(); await _channelClient.DispatchAsync(ApiTopics.AddEventListener, NotificationEventTypes.NotificationAction); OnInitComplete.Invoke(); }); }); }