public IPacket CreatePacket(PacketDefinition definition, IFieldReader reader)
        {
            IPacket packet;

            if (definition.TypeName == m_SampledMetricDefinitionPacketType)
            {
                //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.");
            }

            //what we create varies by what specific definition they're looking for
            if (definition.TypeName == m_MetricDefinitionPacketType)
            {
                packet = new MetricDefinitionPacket(m_Session);
            }
            else if (definition.TypeName == m_EventMetricDefinitionPacketType)
            {
                packet = new EventMetricDefinitionPacket(m_Session);
            }
            else if (definition.TypeName == m_EventMetricValueDefinitionPacketType)
            {
                packet = new EventMetricValueDefinitionPacket(m_Session);
            }
            else if (definition.TypeName == m_CustomSampledMetricDefinitionPacketType)
            {
                packet = new CustomSampledMetricDefinitionPacket(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(CustomSampledMetricDefinitionPacket other)
 {
     //We're really just a type cast, refer to our base object
     return(base.Equals(other));
 }
 /// <summary>
 /// Compares this object to the provided comparison object
 /// </summary>
 /// <param name="other"></param>
 /// <returns>Zero if objects are the same object, -1 or 1 to indicate relative order (see CompareTo for more information)</returns>
 public int CompareTo(CustomSampledMetricDefinitionPacket other)
 {
     //we just gateway to our base object.
     return(base.CompareTo(other));
 }
Пример #4
0
 /// <summary>
 /// Create a new custom sampled metric packet for the provided metric definition and a specific instance.
 /// </summary>
 /// <param name="metricDefinitionPacket">The metric definition packet that defines this metric</param>
 /// <param name="instanceName">The unique instance name of this metric or null for the default instance.</param>
 public CustomSampledMetricPacket(CustomSampledMetricDefinitionPacket metricDefinitionPacket, string instanceName)
     : base(metricDefinitionPacket, instanceName)
 {
 }