public void Subscribe(string portfolioId) { if (!PortfolioFeedSimulator.CheckPortfolio(portfolioId)) { throw new SubscriptionException("No such portfolio: " + portfolioId); } // Complete the subscription operation asynchronously executor.Add(delegate() { Debug.Assert(!subscriptions.ContainsKey(portfolioId)); Portfolio portfolio = feed.GetPortfolio(portfolioId); if (portfolio == null) { _log.Error("No such portfolio: " + portfolioId); Debug.Assert(false); return; } // Add the new item to the list of subscribed items; // the "true" value is a placeholder, as we use a Hashtable. subscriptions.Add(portfolioId, true); // Create a new listener for the portfolio MyPortfolioListener listener = new MyPortfolioListener(portfolioId, this); // Set the listener on the feed portfolio.SetListener(listener); _log.Info(portfolioId + " subscribed"); }); }
private void CheckForNewNotifications(object sender, EventArgs e) { var world = WarframeInfoProvider.GetWorldState(); var newAlerts = WarframeInfoProvider.GetAlerts(world); var tmpAlerts = new ObservableCollection <Alert>(); foreach (Alert alert in newAlerts) { if (!(Alerts.Any(x => x._id.oid == alert._id.oid)) && alert != null) { NotificationQueue.Add(alert); } alert.ToNotificationString(); tmpAlerts.Add(alert); } Alerts = tmpAlerts; WarframeInfoProvider.GetInvasions(world); var newInvasions = WarframeInfoProvider.GetInvasions(world); var tmpInvasions = new ObservableCollection <Invasion>(); foreach (Invasion invasion in newInvasions) { if (!(Invasions.Any(x => x._id.oid == invasion._id.oid)) && invasion != null) { NotificationQueue.Add(invasion); } invasion.ToNotificationString(); tmpInvasions.Add(invasion); } Invasions = tmpInvasions; }
public void AddNotificationQueue(NotificationContainer noti) { lock (NotificationQueue) { NotificationQueue.Add(noti); } }
/// <summary> /// Notifies the specified data. /// </summary> /// <param name="data">The data.</param> public virtual void Notify(T data) { if (Subscribed) { OnNotify?.Invoke(data); NotificationQueue.Add(data); } }
public void AddIdentityToNotifiticationQueue(long identityId) { var cooldownKey = new EntityIdCooldownKey(identityId); var delay = Config.NotifyDelaySeconds * 1000L; CooldownManagerNotificationQueue.StartCooldown(cooldownKey, NOTIFICATION_COOLDOWN_COMMAND, delay); NotificationQueue.Add(cooldownKey); }
private void ChangeQty(string stock, int qty) { //Get the old quantity for the stock Object oldQtyObject = quantities[stock]; int newQty; int oldQty; if (oldQtyObject == null) { //If oldQtyObject is null it means that we don't have that stock on our portfolio if (qty <= 0) { //We can't sell something we don't have, warn and return. _log.Warn(this.id + "|No stock to sell: " + stock); return; } //Set oldQty to 0 to let the listener know that we previously didn't have such stock oldQty = 0; //The new quantity is equal to the bought value newQty = qty; } else { oldQty = Convert.ToInt32(quantities[stock]); Debug.Assert(oldQty > 0); //The new quantity will be the value of the old quantity plus the qty value. //If qty is a negative number than we are selling, in the other case we're buying newQty = oldQty + qty; // overflow check; just in case if (qty > 0 && newQty <= qty) { newQty = oldQty; _log.Warn(this.id + "|Quantity overflow; order ignored: " + stock); return; } } if (newQty < 0) { //We sold more than we had _log.Warn(this.id + "|Not enough stock to sell: " + stock); //We interpret this as "sell everything" newQty = 0; } if (newQty == 0) { //If we sold everything we remove the stock from the internal structure quantities.Remove(stock); } else { //Save the actual quantity in internal structure quantities[stock] = newQty; } if (this.listener != null) { //copy the actual listener to a constant that will be used //by the asynchronous notification PortfolioListener localListener = this.listener; //copy the values to constant to be used //by the asynchronous notification int newVal = newQty; int oldVal = oldQty; string stockId = stock; //If we have a listener, create a task to asynchronously //notify the listener of the actual status executor.Add(delegate() { // call the update on the listener; // in case the listener has just been detached, // the listener should detect the case localListener.Update(stockId, newVal, oldVal); }); } }