示例#1
0
        public IPacket CreatePacket(PacketDefinition definition, IFieldReader reader)
        {
            IPacket packet;

            //what we create varies by what specific definition they're looking for
            if (definition.TypeName == m_MetricPacketType)
            {
                //metrics can't be created directly - they're an abstract class.
                throw new ArgumentOutOfRangeException(nameof(definition), definition.TypeName, "Metric objects can't be created, only derived classes can.");
            }

            if (definition.TypeName == m_SampledMetricPacketType)
            {
                //sampled metrics can't be created directly - they're an abstract class.
                throw new ArgumentOutOfRangeException(nameof(definition), definition.TypeName, "Sampled Metric objects can't be created, only derived classes can.");
            }

            if (definition.TypeName == m_EventMetricPacketType)
            {
                packet = new EventMetricPacket(m_Session);
            }
            else if (definition.TypeName == m_CustomSampledMetricPacketType)
            {
                packet = new CustomSampledMetricPacket(m_Session);
            }
            else
            {
                //crap, we don't know what to do here.
                throw new ArgumentOutOfRangeException(nameof(definition), definition.TypeName, "This packet factory doesn't undersatnd how to create packets for the provided type.");
            }

            //this feels a little crazy, but you have to do your own read call here - we aren't just creating the packet
            //object, we actually have to make the standard call to have it read data...
            definition.ReadFields(packet, reader);

            return(packet);
        }
 /// <summary>
 /// Determines if the provided object is identical to this object.
 /// </summary>
 /// <param name="other">The object to compare this object to</param>
 /// <returns>True if the objects represent the same data.</returns>
 public bool Equals(EventMetricPacket other)
 {
     //We're really just a type cast, refer to our base object
     return(base.Equals(other));
 }
 /// <summary>
 /// Compare this event metric packet to another to determine sort order
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public int CompareTo(EventMetricPacket other)
 {
     //we just gateway to our base object.
     return(base.CompareTo(other));
 }