Example #1
0
        public bool ChangeStockPrice(string symbol, double newprice)
        {
            try
            {
                // trigger call to the subscribers
                foreach (KeyValuePair <IStocksCallback, StockInfo> Pair in SubscriberList)
                {
                    IStocksCallback icbChannel = Pair.Key;
                    if ((symbol == Pair.Value.Symbol) && (newprice > Pair.Value.Price))
                    {
                        StockInfo si = new StockInfo( );
                        si.Price  = newprice;
                        si.Symbol = symbol;
                        si.STime  = DateTime.Now;
                        if ((( ICommunicationObject )icbChannel).State == CommunicationState.Opened)
                        {
                            icbChannel.OnPriceChange(si);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message, new FaultCode("Change Price Error"));
            }

            return(true);
        }
Example #2
0
        public bool UnsubscribeToStockPrice(string stocksym)
        {
            try
            {
                IStocksCallback callbackChannel = OperationContext.Current.GetCallbackChannel <IStocksCallback>( );
                if (SubscriberList.ContainsKey(callbackChannel) == true)
                {
                    SubscriberList.Remove(callbackChannel);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message, new FaultCode("Unsubcription Error"));
            }

            return(true);
        }
Example #3
0
        public bool SubscribeToStockPrice(string stocksym, double triggerPrice)
        {
            try
            {
                IStocksCallback callbackChannel = OperationContext.Current.GetCallbackChannel <IStocksCallback>( );
                if (SubscriberList.ContainsKey(callbackChannel) == false)
                {
                    SubscriberList.Add(callbackChannel, new StockInfo()
                    {
                        Symbol = stocksym,
                        Price  = triggerPrice,
                        STime  = DateTime.Now
                    });
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message, new FaultCode("Subscription Error"));
            }

            return(true);
        }