Beispiel #1
0
        /// <summary>
        /// This is the method that is invoked on an IPacketFactory to create an IPacket
        /// from the data in an IFieldReader given a specified PacketDefinition.
        /// </summary>
        /// <param name="definition">Definition of the fields expected in the next packet</param>
        /// <param name="reader">Data stream to be read</param>
        /// <returns>An IPacket corresponding to the PacketDefinition and the stream data</returns>
        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_MetricSamplePacketType)
            {
                //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_SampledMetricSamplePacketType)
            {
                //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_EventMetricSamplePacketType)
            {
                packet = new EventMetricSamplePacket(m_Session);
            }
            else if (definition.TypeName == m_CustomSampledMetricSamplePacketType)
            {
                packet = new CustomSampledMetricSamplePacket(m_Session);
            }
            else
            {
                //crap, we don't know what to do here.
                throw new ArgumentOutOfRangeException(nameof(definition), definition.TypeName, "This packet factory doesn't understand 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>
 /// Compare this custom sampled metric sample packet with another to determine if they are the same sample packet.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public int CompareTo(CustomSampledMetricSamplePacket other)
 {
     //we really are just forwarding to the default comparitor; we are just casting types
     return(base.CompareTo(other));
 }
 /// <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(CustomSampledMetricSamplePacket other)
 {
     //We're really just a type cast, refer to our base object
     return(base.Equals(other));
 }