private void OnStorageNewIdentifierAdded(string storageName, SecurityId securityId, object nativeId) { if (!InnerAdapter.StorageName.CompareIgnoreCase(storageName)) { return; } bool added; lock (_syncRoot) added = _securityIds.TryAdd(nativeId, securityId); if (added) { RaiseNewOutMessage(new ProcessSuspendedSecurityMessage(this, securityId)); } }
/// <summary> /// Process <see cref="MessageAdapterWrapper.InnerAdapter"/> output message. /// </summary> /// <param name="message">The message.</param> protected override void OnInnerAdapterNewOutMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: { lock (_syncRoot) { _securityIds.Clear(); _suspendedMessages.Clear(); _nativeIds.Clear(); } break; } case MessageTypes.Security: { var secMsg = (SecurityMessage)message; var securityId = secMsg.SecurityId; var nativeSecurityId = securityId.Native; var securityCode = securityId.SecurityCode; var boardCode = securityId.BoardCode; if (securityCode.IsEmpty()) { throw new InvalidOperationException(); } if (securityId.SecurityType == null) { securityId.SecurityType = secMsg.SecurityType; } var isNativeIdNull = nativeSecurityId == null; if (!boardCode.IsEmpty()) { lock (_syncRoot) { _securityIds[securityId] = securityId; var temp = securityId; // GetHashCode shouldn't calc based on native id temp.Native = null; if (!isNativeIdNull && !_nativeIds.TryAdd(temp, nativeSecurityId)) { SecurityId prevId; if (_nativeIds.TryGetKey(nativeSecurityId, out prevId)) { if (temp != prevId) { throw new InvalidOperationException(LocalizedStrings.Str687Params.Put(temp, prevId, nativeSecurityId)); } } else { throw new InvalidOperationException(LocalizedStrings.Str687Params.Put(nativeSecurityId, _nativeIds[temp], temp)); } } } } else { // TODO } base.OnInnerAdapterNewOutMessage(message); ProcessSuspendedSecurityMessages(securityId); break; } case MessageTypes.Position: { var positionMsg = (PositionMessage)message; ProcessMessage(positionMsg.SecurityId, positionMsg, null); break; } case MessageTypes.PositionChange: { var positionMsg = (PositionChangeMessage)message; ProcessMessage(positionMsg.SecurityId, positionMsg, (prev, curr) => { foreach (var pair in prev.Changes) { curr.Changes.TryAdd(pair.Key, pair.Value); } return(curr); }); break; } case MessageTypes.Execution: { var execMsg = (ExecutionMessage)message; ProcessMessage(execMsg.SecurityId, execMsg, null); break; } case MessageTypes.Level1Change: { var level1Msg = (Level1ChangeMessage)message; ProcessMessage(level1Msg.SecurityId, level1Msg, (prev, curr) => { foreach (var pair in prev.Changes) { curr.Changes.TryAdd(pair.Key, pair.Value); } return(curr); }); break; } case MessageTypes.QuoteChange: { var quoteChangeMsg = (QuoteChangeMessage)message; ProcessMessage(quoteChangeMsg.SecurityId, quoteChangeMsg, (prev, curr) => curr); break; } case MessageTypes.News: { var newsMsg = (NewsMessage)message; if (newsMsg.SecurityId != null) { ProcessMessage(newsMsg.SecurityId.Value, newsMsg, null); } break; } default: base.OnInnerAdapterNewOutMessage(message); break; } }