/// <summary> /// Tries to parse the MessageProcessorID from a string. /// </summary> /// <param name="parser">The Parser to use.</param> /// <param name="value">The string to parse.</param> /// <param name="outValue">If this method returns true, contains the parsed MessageProcessorID.</param> /// <returns>True if the parsing was successfully; otherwise false.</returns> public static bool TryParse(this Parser parser, string value, out MessageProcessorID outValue) { ushort tmp; var ret = parser.TryParse(value, out tmp); outValue = new MessageProcessorID(tmp); return(ret); }
/// <summary> /// Initializes a new instance of the <see cref="MessageProcessor"/> class. /// </summary> /// <param name="msgID">ID of the message to process. Must be non-zero.</param> /// <param name="methodDelegate">Delegate to the processing method.</param> /// <exception cref="ArgumentNullException"><paramref name="methodDelegate" /> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="msgID"/> is zero.</exception> public MessageProcessor(MessageProcessorID msgID, MessageProcessorHandler methodDelegate) { if (methodDelegate == null) { throw new ArgumentNullException("methodDelegate"); } if (msgID.GetRawValue() == 0) { throw new ArgumentOutOfRangeException("msgID", "The message ID may not be zero."); } _msgID = msgID; _call = methodDelegate; }
/// <summary> /// Updates the statistics for an <see cref="IMessageProcessor"/>. /// </summary> /// <param name="processorID">The ID of the <see cref="IMessageProcessor"/>.</param> /// <param name="bits">The number of bits read or written. Does not include the message ID.</param> public void HandleProcessorInvoked(MessageProcessorID processorID, int bits) { var ubits = (ushort)bits; // Check the bitsRead range if (bits < 0) { const string errmsg = "Invalid bitsRead value `{0}`."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, bits); } return; } if (bits < 0) { const string errmsg = "Invalid bitsRead value `{0}` - value was too large to handle. Will use the largest possible value instead ({1})."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, bits, ushort.MaxValue); } ubits = ushort.MaxValue; } // Grab the stats ProcStats stats; lock (_statsSync) { if (!_stats.TryGetValue(processorID, out stats)) { stats = new ProcStats(processorID); _stats[processorID] = stats; } } // Update the stats stats.NotifyCalled(ubits); // Check to dump the output if (_outFilePath != null && _nextDumpTime <= TickCount.Now) { _nextDumpTime = (TickCount)(TickCount.Now + _outDumpRate); Write(_outFilePath); } }
/// <summary> /// Initializes a new instance of the <see cref="ProcStats"/> class. /// </summary> /// <param name="id">The <see cref="IMessageProcessor"/> ID.</param> public ProcStats(MessageProcessorID id) { _id = id; }
/// <summary> /// Gets the <see cref="IMessageProcessorStats"/> for a <see cref="IMessageProcessor"/> identified by the ID. /// </summary> /// <param name="msgID">The ID of the <see cref="IMessageProcessor"/> to get the stats for.</param> /// <returns>The <see cref="IMessageProcessorStats"/> for the given <paramref name="msgID"/>, or null if no /// stats exist for the given <paramref name="msgID"/>.</returns> public IMessageProcessorStats GetStats(MessageProcessorID msgID) { return(_stats[msgID]); }
/// <summary> /// Writes a MessageProcessorID to a IValueWriter. /// </summary> /// <param name="valueWriter">IValueWriter to write to.</param> /// <param name="name">Unique name of the MessageProcessorID that will be used to distinguish it /// from other values when reading.</param> /// <param name="value">MessageProcessorID to write.</param> public static void Write(this IValueWriter valueWriter, string name, MessageProcessorID value) { value.Write(valueWriter, name); }
/// <summary> /// Writes a MessageProcessorID to a BitStream. /// </summary> /// <param name="bitStream">BitStream to write to.</param> /// <param name="value">MessageProcessorID to write.</param> public static void Write(this BitStream bitStream, MessageProcessorID value) { value.Write(bitStream); }
/// <summary> /// Reads the MessageProcessorID from a BitStream. /// </summary> /// <param name="bitStream">BitStream to read the MessageProcessorID from.</param> /// <returns>The MessageProcessorID read from the BitStream.</returns> public static MessageProcessorID ReadMessageProcessorID(this BitStream bitStream) { return(MessageProcessorID.Read(bitStream)); }
/// <summary> /// Reads the MessageProcessorID from an IValueReader. /// </summary> /// <param name="valueReader">IValueReader to read the MessageProcessorID from.</param> /// <param name="name">The unique name of the value to read.</param> /// <returns>The MessageProcessorID read from the IValueReader.</returns> public static MessageProcessorID ReadMessageProcessorID(this IValueReader valueReader, string name) { return(MessageProcessorID.Read(valueReader, name)); }
/// <summary> /// Reads the MessageProcessorID from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the MessageProcessorID from.</param> /// <param name="i">The field index to read.</param> /// <returns>The MessageProcessorID read from the <see cref="IDataRecord"/>.</returns> public static MessageProcessorID GetMessageProcessorID(this IDataRecord r, int i) { return(MessageProcessorID.Read(r, i)); }
/// <summary> /// Reads the MessageProcessorID from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the MessageProcessorID from.</param> /// <param name="name">The name of the field to read the value from.</param> /// <returns>The MessageProcessorID read from the <see cref="IDataRecord"/>.</returns> public static MessageProcessorID GetMessageProcessorID(this IDataRecord r, string name) { return(MessageProcessorID.Read(r, name)); }
/// <summary> /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as type MessageProcessorID. /// </summary> /// <typeparam name="T">The key Type.</typeparam> /// <param name="dict">The IDictionary.</param> /// <param name="key">The key for the value to get.</param> /// <param name="defaultValue">The value to use if the value at the <paramref name="key"/> could not be parsed.</param> /// <returns>The value at the given <paramref name="key"/> parsed as an int, or the /// <paramref name="defaultValue"/> if the <paramref name="key"/> did not exist in the <paramref name="dict"/> /// or the value at the given <paramref name="key"/> could not be parsed.</returns> public static MessageProcessorID AsMessageProcessorID <T>(this IDictionary <T, string> dict, T key, MessageProcessorID defaultValue) { string value; if (!dict.TryGetValue(key, out value)) { return(defaultValue); } MessageProcessorID parsed; if (!Parser.Invariant.TryParse(value, out parsed)) { return(defaultValue); } return(parsed); }
/// <summary> /// Gets the <see cref="IMessageProcessor"/> for the corresponding message ID. Can be overridden by the derived class to allow /// for using a <see cref="IMessageProcessor"/> other than what is acquired by /// <see cref="MessageProcessorManager.GetInternalMessageProcessor"/>. /// </summary> /// <param name="msgID">The ID of the message.</param> /// <returns>The <see cref="IMessageProcessor"/> for the <paramref name="msgID"/>, or null if an invalid ID.</returns> protected virtual IMessageProcessor GetMessageProcessor(MessageProcessorID msgID) { return(GetInternalMessageProcessor(msgID)); }
/// <summary> /// Gets the <see cref="IMessageProcessor"/> with the given ID. This will only ever return the <see cref="IMessageProcessor"/> /// for the method that was specified using a <see cref="MessageHandlerAttribute"/>. Is intended to only be used by /// <see cref="MessageProcessorManager.GetMessageProcessor"/> to allow for access of the <see cref="IMessageProcessor"/>s loaded /// through the attribute. /// </summary> /// <param name="msgID">The ID of the message.</param> /// <returns>The <see cref="IMessageProcessor"/> for the <paramref name="msgID"/>, or null if an invalid ID.</returns> protected IMessageProcessor GetInternalMessageProcessor(MessageProcessorID msgID) { return(_processors[msgID]); }
/// <summary> /// Initializes a new instance of the <see cref="MessageHandlerAttribute"/> class. /// </summary> /// <param name="msgID">The ID of the message that the method this attribute is attached to will handle.</param> public MessageHandlerAttribute(MessageProcessorID msgID) { _msgID = msgID; }
/// <summary> /// Gets the <see cref="IMessageProcessor"/> with the given ID. This will only ever return the <see cref="IMessageProcessor"/> /// for the method that was specified using a <see cref="MessageHandlerAttribute"/>. Is intended to only be used by /// <see cref="MessageProcessorManager.GetMessageProcessor"/> to allow for access of the <see cref="IMessageProcessor"/>s loaded /// through the attribute. /// </summary> /// <param name="msgID">The ID of the message.</param> /// <returns>The <see cref="IMessageProcessor"/> for the <paramref name="msgID"/>, or null if an invalid ID.</returns> protected IMessageProcessor GetInternalMessageProcessor(MessageProcessorID msgID) { return(_processors[msgID.GetRawValue()]); }