/// <summary> /// Create a new value definition from the provided information. /// </summary> /// <param name="definition">The metric definition that owns this value definition</param> /// <param name="packet">The prepopulated value definition packet.</param> internal EventMetricValueDefinition(EventMetricDefinition definition, EventMetricValueDefinitionPacket packet) { m_Definition = definition; m_Packet = packet; //and determine if it is trendable or not m_Trendable = EventMetricDefinition.IsTrendableValueType(m_Packet.Type); MyIndex = -1; // Mark it as unknown. }
/// <summary> /// Create a new value definition with the supplied name and type. The name must be unique in this collection /// </summary> /// <remarks>Internally, only simple type are supported. Any non-numeric, non-DateTimeOffset type will be converted to a string /// using the default ToString capability when it is recorded.</remarks> /// <param name="name">The unique name for this value definition</param> /// <param name="type">The simple type of this value</param> /// <param name="caption">The end-user display caption for this value</param> /// <param name="description">The end-user description for this value.</param> /// <returns>The newly created value definition</returns> public EventMetricValueDefinition Add(string name, Type type, string caption, string description) { lock (m_Definition.Lock) // Is this really needed? Can't hurt.... { //if we are read-only, you can't add a new value if (IsReadOnly) { throw new NotSupportedException("The collection is read-only"); } //make sure we got everything we require if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } //make sure the name is unique if (m_Dictionary.ContainsKey(name)) { throw new ArgumentException("There is already a value definition with the provided name.", nameof(name)); } //create a new value definition EventMetricValueDefinitionPacket newPacket = new EventMetricValueDefinitionPacket(m_Definition.Packet, name, type, caption, description); EventMetricValueDefinition newDefinition = new EventMetricValueDefinition(m_Definition, newPacket); //forward the call to our one true add method Add(newDefinition); //and return the new object to our caller so the have the object we created from their input. return(newDefinition); } }
internal EventMetricValueDefinition Add(EventMetricValueDefinitionPacket packet) { //Even though this is an internal method used just during rehydration of data, we are going to //enforce all of the integrity checks to be sure we have good data //The one thing we CAN'T check is read only, because we're used when the collection IS read only. //make sure we got everything we require if (string.IsNullOrEmpty(packet.Name)) { throw new ArgumentNullException(nameof(packet)); } if (packet.Type == null) { throw new ArgumentNullException(nameof(packet)); } lock (m_Definition.Lock) { //make sure the name is unique if (m_Dictionary.ContainsKey(packet.Name)) { throw new ArgumentException("There is already a value definition with the provided name.", nameof(packet)); } //create a new value definition EventMetricValueDefinition newDefinition = new EventMetricValueDefinition(m_Definition, packet); //forward the call to our one true add method Add(newDefinition); //and return the new object to our caller so they have the object we created from their input. return(newDefinition); } }