/// <summary> /// Adds the specified security to this universe /// </summary> /// <param name="utcTime">The current utc date time</param> /// <param name="security">The security to be added</param> /// <returns>True if the security was successfully added, /// false if the security was already in the universe</returns> internal override bool AddMember(DateTime utcTime, Security security) { // never add members to disposed universes if (DisposeRequested) { return(false); } if (Securities.ContainsKey(security.Symbol)) { return(false); } // method take into account the case, when the option has experienced an adjustment // we update member reference in this case if (Securities.Any(x => x.Value.Security == security)) { Member member; Securities.TryRemove(security.Symbol, out member); } var added = Securities.TryAdd(security.Symbol, new Member(utcTime, security)); if (added && _liveMode) { _addTimesBySymbol[security.Symbol] = utcTime; } return(added); }
/// <summary> /// Tries to remove the specified security from the universe. This /// will first check to verify that we can remove the security by /// calling the <see cref="CanRemoveMember"/> function. /// </summary> /// <param name="utcTime">The current utc time</param> /// <param name="security">The security to be removed</param> /// <returns>True if the security was successfully removed, false if /// we're not allowed to remove or if the security didn't exist</returns> internal virtual bool RemoveMember(DateTime utcTime, Security security) { if (CanRemoveMember(utcTime, security)) { Member member; return(Securities.TryRemove(security.Symbol, out member)); } return(false); }
/// <summary> /// Adds the specified security to this universe /// </summary> /// <param name="utcTime">The current utc date time</param> /// <param name="security">The security to be added</param> /// <returns>True if the security was successfully added, /// false if the security was already in the universe</returns> internal override bool AddMember(DateTime utcTime, Security security) { if (Securities.ContainsKey(security.Symbol)) { return(false); } // method take into account the case, when the option has experienced an adjustment // we update member reference in this case if (Securities.Any(x => x.Value.Security == security)) { Member member; Securities.TryRemove(security.Symbol, out member); } return(Securities.TryAdd(security.Symbol, new Member(utcTime, security))); }