private bool HandleQueueException(QueueException ex) { log.Notice("QueueException: " + ex.EntryType + " with " + count + " ticks so far."); switch (ex.EntryType) { case EventType.StartHistorical: symbolState = SymbolState.Historical; break; case EventType.EndHistorical: symbolState = SymbolState.None; break; case EventType.StartRealTime: symbolState = SymbolState.RealTime; break; case EventType.EndRealTime: symbolState = SymbolState.None; break; case EventType.StartBroker: brokerState = BrokerState.Connected; if (SyncTicks.Enabled) { while (tickSync.SentSwtichBrokerState) { tickSync.ClearSwitchBrokerState("endbroker"); } } break; case EventType.EndBroker: brokerState = BrokerState.Disconnected; if (SyncTicks.Enabled) { while (tickSync.SentSwtichBrokerState) { tickSync.ClearSwitchBrokerState("endbroker"); } } break; case EventType.Terminate: symbolState = SymbolState.None; return(true); case EventType.RequestPosition: symbolState = SymbolState.None; return(false); default: throw new ApplicationException("Unexpected QueueException: " + ex.EntryType); } return(false); }
/// <summary> /// Creates IOutboundFaFMq implementation with the configuration provided by provider. /// </summary> /// <param name="configurationProvider">The configuration provider</param> /// <param name="logger">The queue logger</param> /// <param name="configurationIdentifier">The configuration identifier</param> public static IOutboundFaFMq <TMessage> CreateOutboundFaF <TMessage>(IQueueConfigurationProvider configurationProvider, string configurationIdentifier, IQueueLogger logger = null) { #region Initialization logger = logger ?? new NoLog(); Dictionary <string, string> configuration = null; #endregion try { #region Configuration Retrieval configuration = RetrieveAndValidateConfiguration(configurationProvider, configurationIdentifier); #endregion #region Creating Implementation // Getting type details. var messageQueueTypeInfo = Type.GetType(configuration[CommonConfigurationKeys.Implementation], true, true); // Substituting generic parameters. var typeParams = new[] { typeof(TMessage) }; var genericTypeInfo = messageQueueTypeInfo.MakeGenericType(typeParams); // Creating instance. var messagingQueue = Activator.CreateInstance(genericTypeInfo, configuration, logger) as IOutboundFaFMq <TMessage>; #endregion #region Return return(messagingQueue); #endregion } catch (QueueException queueException) { #region Logging - Error logger.Error(queueException, queueException.Message); #endregion throw; } catch (Exception ex) { var queueException = new QueueException(QueueErrorCode.FailedToInstantiateOutboundFaFMq, ErrorMessages.FailedToInstantiateOutboundFaF, ex); queueException.Data["Implementation"] = configuration?[CommonConfigurationKeys.Implementation]; #region Logging - Error logger.Error(queueException, queueException.Message); #endregion throw queueException; } }
private bool HandleQueueException(QueueException ex) { log.Notice("QueueException: " + ex.EntryType); switch (ex.EntryType) { case EventType.StartHistorical: receiverState = ReceiverState.Historical; isRealTime = false; break; case EventType.EndHistorical: receiverState = ReceiverState.Ready; isRealTime = false; break; case EventType.StartRealTime: receiverState = ReceiverState.RealTime; isRealTime = true; break; case EventType.EndRealTime: receiverState = ReceiverState.Ready; isRealTime = false; break; case EventType.StartBroker: brokerState = BrokerState.Connected; isRealTime = true; break; case EventType.EndBroker: brokerState = BrokerState.Disconnected; isRealTime = false; break; case EventType.Terminate: receiverState = ReceiverState.Stop; isRealTime = false; return(true); default: throw new ApplicationException("Unexpected QueueException: " + ex.EntryType); } return(false); }
/// <summary> /// Helper method to prepare and log queue exception. /// NOTE: If logger is null, exception will not be logged. /// </summary> public static QueueException PrepareAndLogQueueException(QueueErrorCode errorCode, string message, Exception innerException, string queueContext, string queueName = "", string address = "", Dictionary <string, string> context = null, IQueueLogger logger = null) { #region Preparing Queue Exception var queueException = new QueueException(errorCode, message, context: new Dictionary <string, string> { [CommonContextKeys.QueueContext] = queueContext }, innerException: innerException); if (!string.IsNullOrWhiteSpace(address)) { queueException.Data[CommonContextKeys.Address] = address; } if (!string.IsNullOrWhiteSpace(queueName)) { queueException.Data[CommonContextKeys.QueueName] = queueName; } if (context != null) { foreach (var currentItem in context) { queueException.Data[currentItem.Key] = currentItem.Value; } } #endregion #region Logging - Error logger?.Error(queueException, queueException.Message); #endregion #region Return return(queueException); #endregion }