コード例 #1
0
 public bool UnSubscribeToStockPrice(string stocksym)
 {
     try
     {
         IStockCallback callbackChannel = OperationContext.Current.GetCallbackChannel <IStockCallback>();
         SubscribeInfo  subToRemove     = null;
         foreach (SubscribeInfo sub in SubscriberList)
         {
             if (sub.ChannelToClient == callbackChannel) //found subscriber
             {
                 sub.RemoveSymbol(stocksym);
                 if (sub.GetNumOfSymbolsSubscribed() == 0)
                 {
                     subToRemove = sub;
                 }
             }
         }
         if (subToRemove != null)
         {
             SubscriberList.Remove(subToRemove);
         }
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message, new FaultCode("UnSubscription Error"));
     }
     return(true);
 }
コード例 #2
0
 public bool SubscribeToStockPrice(string stocksym, double triggerPrice)
 {
     try
     {
         IStockCallback callbackChannel = OperationContext.Current.GetCallbackChannel <IStockCallback>();
         bool           ifNewSubscriber = true;
         foreach (SubscribeInfo sub in SubscriberList)
         {
             if (sub.ChannelToClient == callbackChannel) //found subscriber
             {
                 ifNewSubscriber = false;
                 sub.AddSymbol(stocksym, triggerPrice);
             }
         }
         if (ifNewSubscriber)
         {
             SubscribeInfo subscriber = new SubscribeInfo();
             SubscriberList.Add(subscriber);
             subscriber.ChannelToClient = callbackChannel;
             subscriber.AddSymbol(stocksym, triggerPrice);
         }
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message, new FaultCode("Subscription Error"));
     }
     return(true);
 }