コード例 #1
0
        public async void PublishToChannel(object data, string topic = SymbolTopic)
        {
            if (_runtime.IsConnected)
            {
                await _channelClient.DispatchAsync <object>(topic, data);

                //_channel.Broadcast(topic, data);
            }
        }
コード例 #2
0
        private void ChannelClient_Opened(object sender, EventArgs e)
        {
            Console.WriteLine("channel opened");
            var payload = new JObject()
            {
                { "requestedBy", "donet code" }
            };

            _channelClient.DispatchAsync <JObject>("getValue", payload).ContinueWith((data) =>
            {
                Console.WriteLine("getValue returns:");
                Console.WriteLine(data.Result.ToString());
            });
        }
コード例 #3
0
 internal static Task Broadcast(Context.ContextBase context)
 {
     return(channelClient.DispatchAsync <Task>(ApiTopic.Broadcast, context));
 }
コード例 #4
0
        /// <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();
                });
            });
        }
コード例 #5
0
 /// <summary>
 /// Toggles the visibility of the notification center.
 /// </summary>
 /// <returns>A task</returns>
 public static Task ToggleNotificationCenterAsync()
 {
     return(_channelClient.DispatchAsync(ApiTopics.ToggleNotificationCenter, JValue.CreateUndefined()));
 }
コード例 #6
0
 /// <summary>
 /// Creates a notification.
 /// </summary>
 /// <param name="notificationId">The notification Id.</param>
 /// <param name="options">The notification options.</param>
 /// <returns></returns>
 public static Task <NotificationOptions> CreateNotificationAsync(string notificationId, NotificationOptions options)
 {
     options.Id = notificationId;
     return(_channelClient?.DispatchAsync <NotificationOptions>(ApiTopics.CreateNotification, options));
 }