Beispiel #1
0
 public void TopicUnsubscribed(object sender, SubscriptionEventArgs e)
 {
     IMessageConsumer consumer;
     if (this.topicConsumers.TryGetValue(e.Topic, out consumer))
     {
         consumer.Dispose();
         this.topicConsumers.Remove(e.Topic);
     }
 }
Beispiel #2
0
        /// <summary>
        /// On subscription change, reset the subscriber tile counter if exist.
        /// </summary>
        protected override void OnSubscribed(SubscriptionEventArgs e)
        {
            // Create a tile message to reset tile count.
            var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High)
            {
                Count = 0,
                BackgroundImageUri = BackgroundImageUri,
                Title = Title
            };

            tileMsg.SendAsync(e.Subscription.ChannelUri, Log, Log);

            ResetCounter(e.Subscription.UserName);
        }
Beispiel #3
0
        private async Task TestObservableObserverService_ObservableUnregistered(SubscriptionEventArgs args)
        {
            try
            {
                EntityId id = await this.GetEntityIdAsync();

                ServiceEventSource.Current.Message($"Observable successfully unregistered.\r\n[Observable]: {args.EntityId}\r\n[Observer]: {id}");
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Error(ex);
                throw;
            }
        }
Beispiel #4
0
        private async Task TestObservableObserverActor_ObserverUnregistered(SubscriptionEventArgs args)
        {
            try
            {
                EntityId entityId = await this.GetEntityIdAsync();

                ActorEventSource.Current.Message($"Observer successfully unregistered.\r\n[Observable]: {entityId}\r\n[Observer]: {args.EntityId}\r\n[Subscription]: Topic=[{args.Topic}]");
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.Error(ex);
                throw;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Once an application is activated again (the client side phone application
        /// has subscription logic on startup), try to update the tile again.
        /// In case that the application is not pinned, send raw notification message
        /// to the client, asking to pin the application. This raw notification message
        /// has to be well-known and handled by the client side phone application.
        /// In our case the raw message is AskToPin.
        /// </summary>
        protected override void OnSubscribed(SubscriptionEventArgs args)
        {
            // Asynchronously try to send Tile message to the relevant subscriber
            // with data already sent before so the tile won't change.
            var tileMsg = GetOrCreateMessage(args.Subscription.UserName, false);

            tileMsg.SendAsync(
                args.Subscription.ChannelUri,
                result =>
            {
                Log(result);
                OnMessageSent(args.Subscription.UserName, result);
            },
                Log);
        }
        private void sipService_onSubscriptionEvent(object sender, SubscriptionEventArgs e)
        {
            if (e.Type != SubscriptionEventTypes.INCOMING_NOTIFY ||
                e.Content == null ||
                (e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.REG && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY)
                )
            {
                return;
            }

            switch (e.Type)
            {
            case SubscriptionEventTypes.INCOMING_NOTIFY:
            {
                new Thread(delegate()
                    {
                        this.Dispatcher.Invoke((System.Threading.ThreadStart) delegate
                        {
                            if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.REG)
                            {
                                this.ParseRegInfo(e.Content);
                            }
                            else if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO)
                            {
                                this.ParseWatcherInfo(e.Content);
                            }
                            else if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY)
                            {
                                MessageSummary ms = MessageSummary.Parse(e.Content);
                                if (ms != null)
                                {
                                    //this.imageMailbox.Visibility = ms.HaveWaitingMessages ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
                                    String tooltip = String.Format("Message-Account: {0}\n", ms.Account);
                                    new String[] { "Voice-Message", "Fax-Message", "Pager-Message", "Multimedia-Message", "Text-Message" }.ToList().ForEach(x =>
                                    {
                                        tooltip += String.Format("{0}: {1}/{2} ({3}/{4})\n", x, ms.GetNewMessages(x), ms.GetOldMessages(x), ms.GetNewUrgentMessages(x), ms.GetOldUrgentMessages(x));
                                    });
                                    //this.imageMailbox.ToolTip = tooltip;
                                }
                            }
                        });
                    })
                .Start();
                break;
            }
            }
        }
        void ClientSubscriptionMessage(object?sender, SubscriptionEventArgs e)
        {
            if (e.Message.Contains("quote."))
            {
                var quote = JsonSerializer.Deserialize <QuoteModel>(e.Message);
                if (quote != null && quote.Params.Data.Instrument == Instrument.Name)
                {
                    var dateKey = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(quote.Params.Data.Timestamp);
                    if (!Instrument.MarketPriceHistory.ContainsKey(dateKey))
                    {
                        Instrument.MarketPriceHistory.Add(dateKey, new Tuple <decimal, decimal>(quote.Params.Data.BestBidPrice, Instrument.IndexPrice));
                    }
                    Dispatcher.Invoke(() =>
                    {
                        LatestBidPrice          = quote.Params.Data.BestBidPrice;
                        LatestAskPrice          = quote.Params.Data.BestAskPrice;
                        LatestBidPriceText.Text = quote.Params.Data.BestBidPrice.ToString("N2");
                        LatestAskPriceText.Text = quote.Params.Data.BestAskPrice.ToString("N2");
                    });
                }
                if (quote != null && quote.Params.Data.Instrument == Instrument.BaseInstrumentName)
                {
                    var dateKey = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(quote.Params.Data.Timestamp);
                    if (!Instrument.BaseMarketPriceHistory.ContainsKey(dateKey))
                    {
                        Instrument.BaseMarketPriceHistory.Add(new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(quote.Params.Data.Timestamp), new Tuple <decimal, decimal>(quote.Params.Data.BestBidPrice, Instrument.IndexPrice));
                    }
                }
            }
            else if (e.Message.Contains("deribit_price_index."))
            {
                var index = JsonSerializer.Deserialize <IndexModel>(e.Message);
                Dispatcher.Invoke(() =>
                {
                    IndexPriceText.Text = index?.Params.Data.Price.ToString("N2");
                    MarkPriceText.Text  = Instrument.MarkPrice().ToString("N2");
                });

                if (index != null)
                {
                    Instrument.IndexPrice = index.Params.Data.Price;
                }
            }
        }
Beispiel #8
0
        private static void Client_VehicleSubscriptionUsingResponses(object sender, SubscriptionEventArgs e)
        {
            var objectID = e.ObjectId;

            Console.WriteLine("*** Vehicle Variable Subscription OLD WAY for compatability. (using Responses) ***");
            Console.WriteLine("Subscription Object Id: " + objectID);
            Console.WriteLine("Variable Count        : " + e.VariableCount); // Prints the number of variables that were subscribed to

            foreach (var r in e.Responses)
            {
                /* Responses are object that can be casted to IResponseInfo so we can retrieve
                 * the variable type. */
                var respInfo     = (r as IResponseInfo);
                var variableCode = respInfo.Variable;

                /*We can then cast to TraCIResponse to get the Content
                 * We can also use IResponseInfo.GetContentAs<> ()s*/
                // WARNING using TraCIResponse<> we must use the exact type (i.e for speed, accel, angle, is double and not float)
                switch (variableCode)
                {
                case TraCIConstants.ID_COUNT:
                    NumberOfVehcicles = respInfo.GetContentAs <int>();
                    break;

                case TraCIConstants.VAR_SPEED:
                    Console.WriteLine(" VAR_SPEED  " + (r as TraCIResponse <double>).Content);
                    break;

                case TraCIConstants.VAR_ANGLE:
                    Console.WriteLine(" VAR_ANGLE  " + respInfo.GetContentAs <float> ());
                    break;

                case TraCIConstants.VAR_ROUTE_ID:
                    Console.WriteLine(" VAR_ROUTE_ID  " + (r as TraCIResponse <string>).Content);
                    break;

                default:
                    /* Intentionaly ommit VAR_ACCEL*/
                    Console.WriteLine($" Variable with code {ByteToHex(variableCode)} not handled ");
                    break;
                }
            }
        }
Beispiel #9
0
        private async Task TestObservableObserverActor_ObserverRegistered(SubscriptionEventArgs args)
        {
            try
            {
                EntityId entityId = await this.GetEntityIdAsync();

                StringBuilder stringBuilder = new StringBuilder($"Observer successfully registered.\r\n[Observable]: {entityId}\r\n[Observer]: {args.EntityId}\r\n[Subscription]: Topic=[{args.Topic}]");
                int           i             = 1;
                foreach (string expression in args.FilterExpressions.Where(expression => !string.IsNullOrWhiteSpace(expression)))
                {
                    stringBuilder.Append($" FilterExpression[{i++}]=[{expression}]");
                }
                ActorEventSource.Current.Message(stringBuilder.ToString());
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.Error(ex);
                throw;
            }
        }
Beispiel #10
0
        private async Task <bool> MethodWrapper <T>(SubscriptionEventArgs eventArgs, Func <T, Task> serviceMethod)
        {
            try
            {
                OnSubscriberExecuting(eventArgs);

                //var result = await serviceMethod?.Invoke((T)eventArgs.Message); // If result type is object
                await serviceMethod?.Invoke((T)eventArgs.Message); // Converting to void

                //if(MessageBusConfiguration.AutomaticRequeueIsEnabled)
                //Task.Run(() => RabbitRequeueMessageHandler.RequeueMessage(result, eventArgs.Message, eventArgs.CorrelationId));
            }
            catch (Exception ex)
            {
                eventArgs.ServiceCallException = ex;
                throw ex;
            }
            finally
            {
                OnSubscriberExecuted(eventArgs);
            }
            return(true);
        }
Beispiel #11
0
 internal void OnPOISubscription(SubscriptionEventArgs eventArgs)
 {
     PointOfIntrestSubscription?.Invoke(this, eventArgs);
 }
Beispiel #12
0
 internal void OnRouteSubscription(SubscriptionEventArgs eventArgs)
 {
     RouteSubscription?.Invoke(this, eventArgs);
 }
Beispiel #13
0
 internal void OnJunctionSubscription(SubscriptionEventArgs eventArgs)
 {
     JunctionSubscription?.Invoke(this, eventArgs);
 }
Beispiel #14
0
 internal void OnPolygonSubscription(SubscriptionEventArgs eventArgs)
 {
     PolygonSubscription?.Invoke(this, eventArgs);
 }
 public void TopicSubscribed(object sender, SubscriptionEventArgs e)
 {
     var topic = e.Topic;
     Subscribe(topic);
 }
Beispiel #16
0
 internal void OnSimulationSubscription(SubscriptionEventArgs eventArgs)
 {
     SimulationSubscription?.Invoke(this, eventArgs);
 }
Beispiel #17
0
 internal void OnTrafficLightSubscription(SubscriptionEventArgs eventArgs)
 {
     TrafficLightSubscription?.Invoke(this, eventArgs);
 }
Beispiel #18
0
 public void OnSubscribed(object source, SubscriptionEventArgs args)
 {
     SendEmail(args.ToAddress, args.Subject, args.Body, args.CcAddress, null, null, null);
 }
 public void TopicUnsubscribed(object sender, SubscriptionEventArgs e)
 {
     unsubscribedTopics.Add(e.Topic);
 }
        private void subscr_notified(object sender, SubscriptionEventArgs args)
        {
            // get the value from the dictionary
            touchInfo v = (touchInfo) sharedDictionary1["/pointOne"];
            txtPtX.Text = v.X.ToString();
            txtPtY.Text = v.Y.ToString();

            //int valx = (int)this.sharedDictionary1.GetEntry("/pointOne/xcoord").Value;
            //int valy = (int)this.sharedDictionary1.GetEntry("/pointOne/ycoord").Value;
            //this.btnClear.Text = "Increment " + valx.ToString(); // and display it on the button
            //this.txtPtX.Text = valx.ToString();
            //this.txtPtY.Text = valy.ToString();
        }
Beispiel #21
0
 public void TopicSubscribed(object sender, SubscriptionEventArgs e)
 {
     string topic = e.Topic;
     this.Subscribe(topic);
 }
Beispiel #22
0
 static void HandleConsumerOnUnsubscribe(object sender, SubscriptionEventArgs args)
 {
     Console.WriteLine("Unsubscribed from channel :" + args.GetChannel());
     //redis.Publish("gameplay", "WTF");
 }
Beispiel #23
0
        public void TopicSubscribed(object sender, SubscriptionEventArgs e)
        {
            var topic = e.Topic;

            Subscribe(topic);
        }
Beispiel #24
0
 internal void OnVehicleSubscription(SubscriptionEventArgs eventArgs)
 {
     VehicleSubscription?.Invoke(this, eventArgs);
 }
Beispiel #25
0
 internal virtual void OnInductionLoopSubscription(SubscriptionEventArgs eventArgs)
 {
     InductionLoopSubscription?.Invoke(this, eventArgs);
 }
Beispiel #26
0
 internal void OnLaneSubscription(SubscriptionEventArgs eventArgs)
 {
     LaneSubscription?.Invoke(this, eventArgs);
 }
 void OnSubscribe(object sender, SubscriptionEventArgs args) /* Do nothing */ }
Beispiel #28
0
 internal void OnMultiEntryExitSubscription(SubscriptionEventArgs eventArgs)
 {
     MultiEntryMultiExitDetectorSubscription?.Invoke(this, eventArgs);
 }
Beispiel #29
0
 private void PushService_Subscribed(object sender, SubscriptionEventArgs args)
 {
     OnSubscribed(args);
 }
        protected virtual void OnClientSubscriptionMessage(SubscriptionEventArgs e)
        {
            EventHandler <SubscriptionEventArgs>?handler = ClientSubscriptionMessage;

            handler?.Invoke(this, e);
        }
Beispiel #31
0
 internal void OnGUISubscription(SubscriptionEventArgs eventArgs)
 {
     GUISubscription?.Invoke(this, eventArgs);
 }
        public static async Task ExecuteEventHandlerAsync(Func <SubscriptionEventArgs, Task> func, SubscriptionEventArgs eventArgs)
        {
            for (int k = 1; k <= ConfigurationHelper.MaxQueryRetryCount; k++)
            {
                try
                {
                    await func(eventArgs);

                    return;
                }
                catch (FabricTransientException ex)
                {
                    ActorEventSource.Current.Error(ex);
                    if (k == ConfigurationHelper.MaxQueryRetryCount)
                    {
                        throw;
                    }
                }
                catch (AggregateException ex)
                {
                    foreach (Exception innerException in ex.InnerExceptions)
                    {
                        ActorEventSource.Current.Error(innerException);
                    }
                    if (k == ConfigurationHelper.MaxQueryRetryCount)
                    {
                        throw;
                    }
                }
                catch (Exception ex)
                {
                    ActorEventSource.Current.Error(ex);
                    if (k == ConfigurationHelper.MaxQueryRetryCount)
                    {
                        throw;
                    }
                }
                await Task.Delay(ConfigurationHelper.BackoffQueryDelay);
            }
        }
Beispiel #33
0
            public void SubscriptionEventArgsTest()
            {
                var eventArgs = new SubscriptionEventArgs("Hello world");

                Assert.AreEqual("Hello world", eventArgs.Message);
            }
        /// <summary>
        ///     Unregisters an observable. This method is invoked by an observable.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="entityId">The entity id of the observable.</param>
        /// <param name="observers">
        ///     A list of observers in the same cluster node. This field is optional.
        ///     When the list if not null or empty, the observer will forward the message to each observer which EntityId is in the
        ///     list.
        /// </param>
        /// <returns>The asynchronous result of the operation.</returns>
        public async Task UnregisterObservableAsync(string topic, EntityId entityId, IEnumerable <EntityId> observers)
        {
            EntityId id = await this.GetEntityIdAsync();

            if (id == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(topic))
            {
                throw new ArgumentException($"The {nameof(topic)} parameter cannot be null.", nameof(topic));
            }
            if (entityId == null)
            {
                throw new ArgumentException($"The {nameof(entityId)} parameter cannot be null.", nameof(entityId));
            }
            for (int k = 1; k <= ConfigurationHelper.MaxQueryRetryCount; k++)
            {
                try
                {
                    ConditionalValue <Dictionary <Uri, EntityId> > topicState = await this.StateManager.TryGetStateAsync <Dictionary <Uri, EntityId> >(topic);

                    if (!topicState.HasValue)
                    {
                        ActorEventSource.Current.Message(
                            $"Observer not registered to the specified topic.\r\n[Observable]: {entityId}\r\n[Observer]: {id}\r\n[Publication]: Topic=[{topic}]");
                        return;
                    }
                    Dictionary <Uri, EntityId> observableDictionary = topicState.Value;
                    if (!observableDictionary.ContainsKey(entityId.EntityUri))
                    {
                        ActorEventSource.Current.Message(
                            $"Observer not registered to the specified observable.\r\n[Observable]: {entityId}\r\n[Observer]: {id}\r\n[Publication]: Topic=[{topic}]");
                        return;
                    }
                    observableDictionary.Remove(entityId.EntityUri);
                    if (!observableDictionary.Any())
                    {
                        await this.StateManager.TryRemoveStateAsync(topic);
                    }
                    else
                    {
                        await this.StateManager.SetStateAsync(topic, observableDictionary);
                    }
                    ActorEventSource.Current.Message(
                        $"Observable successfully unregistered.\r\n[Observable]: {entityId}\r\n[Observer]: {id}\r\n[Publication]: Topic=[{topic}]");
                    break;
                }
                catch (FabricTransientException ex)
                {
                    ActorEventSource.Current.Error(ex);
                    if (k == ConfigurationHelper.MaxQueryRetryCount)
                    {
                        throw new TimeoutException(Constants.RetryTimeoutExhausted);
                    }
                }
                catch (AggregateException ex)
                {
                    foreach (Exception e in ex.InnerExceptions)
                    {
                        ActorEventSource.Current.Error(e);
                    }
                    throw;
                }
                catch (Exception ex)
                {
                    ActorEventSource.Current.Error(ex);
                    throw;
                }
                await Task.Delay(ConfigurationHelper.BackoffQueryDelay);
            }
            try
            {
                if (observers != null)
                {
                    IList <EntityId> observerList = observers as IList <EntityId> ?? observers.ToList();
                    if (observerList.Any())
                    {
                        StringBuilder builder = new StringBuilder($"Observer Proxy:\r\n[From]: {id}");
                        foreach (EntityId item in observerList)
                        {
                            builder.Append($"\r\n[To]: {item}");
                        }
                        ActorEventSource.Current.Message(builder.ToString());
                        List <Task> taskList = new List <Task>();
                        taskList.AddRange(observerList.Select(observer => ProcessingHelper.UnregisterObservableAsync(topic, observer, entityId, null)));
                        await Task.WhenAll(taskList.ToArray());
                    }
                }
            }
            catch (AggregateException ex)
            {
                foreach (Exception e in ex.InnerExceptions)
                {
                    ActorEventSource.Current.Error(e);
                }
                throw;
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.Error(ex);
                throw;
            }
            if (this.ObservableUnregistered == null)
            {
                return;
            }
            try
            {
                Delegate[]            invocationList = this.ObservableUnregistered.GetInvocationList();
                Task[]                handlerTasks   = new Task[invocationList.Length];
                SubscriptionEventArgs args           = new SubscriptionEventArgs(topic, entityId);
                for (int i = 0; i < invocationList.Length; i++)
                {
                    handlerTasks[i] = ProcessingHelper.ExecuteEventHandlerAsync((Func <SubscriptionEventArgs, Task>)invocationList[i], args);
                }
                await Task.WhenAll(handlerTasks);
            }
            catch (AggregateException ex)
            {
                foreach (Exception e in ex.InnerExceptions)
                {
                    ActorEventSource.Current.Error(e);
                }
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.Error(ex);
            }
        }
Beispiel #35
0
 /// <summary>
 /// Override this to add logic when clients login.
 /// </summary>
 protected virtual void OnSubscribed(SubscriptionEventArgs args)
 {
 }