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); }
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); }
public void RegisterForQuote(string stockId) { lock (_registrations) { if (!_registrations.ContainsKey(stockId)) { _registrations[stockId] = new List <IStockCallback>(); } } IStockCallback callback = OperationContext.Current.GetCallbackChannel <IStockCallback>(); _registrations[stockId].Add(callback); }
public bool SubscribeToStockPrice(string stocksym, double triggerPrice) { try { IStockCallback callbackChannel = OperationContext.Current.GetCallbackChannel <IStockCallback>(); if (SubscriberList.Contains(callbackChannel) == false) { SubscriberList.Add(callbackChannel); } } catch (Exception ex) { throw new FaultException(ex.Message, new FaultCode("Subscription Error")); } return(true); }
public void Login() { string sessionID = OperationContext.Current.SessionId; IStockCallback client = OperationContext.Current.GetCallbackChannel <IStockCallback>(); if (!m_Clients.ContainsKey(sessionID)) { Console.WriteLine("Client '{0} logged in.", sessionID); //add new ClientContainer that stores the client callback object and sets IsActive to false m_Clients.TryAdd(sessionID, new ClientContainer(client, false)); } else { var msg = string.Format("A client with the token '{0}' has already logged in!", sessionID); Console.WriteLine(msg); throw new FaultException(msg); } }
public ClientContainer(IStockCallback clientCallBack, bool isActive) { this.ClientCallback = clientCallBack; this.IsActive = isActive; }
public bool IsActive; //Indicates if the given client is set to receive callback messages public ClientContainer() { this.ClientCallback = default; this.IsActive = default; }
public ClientContainer(IStockCallback clientCallback, bool isActive) { ClientCallback = clientCallback; IsActive = isActive; }