public void SetSampleLabels(IEnumerable <PProfSampleLabel> labels) { if (SamplesCount == 0) { throw new InvalidOperationException($"Cannot invoke {nameof(SetSampleLabels)}(..) because" + $" no samples were added to the current {nameof(PProfBuildSession)}."); } if (_lastSample.Label != null && _lastSample.Label.Count > 0) { throw new InvalidOperationException($"The labels for the {nameof(_lastSample)} of this {nameof(PProfBuildSession)} are already set." + $" The labels for a particular sample cannot be modified once set."); } foreach (PProfSampleLabel label in labels) { PProfInfo.Label labelInfo = OwnerBuilder.CreateNewLabelInfo(label); AddToStringTable(labelInfo.KeyInfo); labelInfo.Item.Key = labelInfo.KeyInfo.OffsetInStringTable; switch (labelInfo.ValueKind) { case PProfSampleLabel.Kind.Number: AddToStringTable(labelInfo.NumberUnitInfo); labelInfo.Item.NumUnit = labelInfo.NumberUnitInfo.OffsetInStringTable; break; case PProfSampleLabel.Kind.String: AddToStringTable(labelInfo.StringValueInfo); labelInfo.Item.Str = labelInfo.StringValueInfo.OffsetInStringTable; break; default: throw new InvalidOperationException($"Invalid {nameof(labelInfo.ValueKind)}: '{labelInfo.ValueKind}'."); } _lastSample.Label.Add(labelInfo.Item); } }
public PProfInfo.Label CreateNewLabelInfo(PProfSampleLabel labelItems) { var labelItem = new PProfProto.Label(); labelItem.Key = ProtoConstants.StringTableIndex.Unresolved; switch (labelItems.ValueKind) { case PProfSampleLabel.Kind.Number: labelItem.Num = labelItems.NumberValue; labelItem.NumUnit = ProtoConstants.StringTableIndex.Unresolved; labelItem.Str = ProtoConstants.StringTableIndex.Unset; break; case PProfSampleLabel.Kind.String: labelItem.Num = ProtoConstants.NumericValue.UnsetInt64; labelItem.NumUnit = ProtoConstants.StringTableIndex.Unset; labelItem.Str = ProtoConstants.StringTableIndex.Unresolved; break; case PProfSampleLabel.Kind.Unknown: default: throw new InvalidOperationException($"Cannot create a {nameof(PProfProto)}.{nameof(PProfProto.Label)}," + $" because the {nameof(PProfSampleLabel.ValueKind)} of the" + $" specified {nameof(PProfSampleLabel)} is {labelItems.ValueKind}." + $" Either {PProfSampleLabel.Kind.Number} or {PProfSampleLabel.Kind.String} was expected." + $" (Did you use the default ctor for {nameof(PProfSampleLabel)}?" + " If so, use a different ctor overload.)"); } var labelInfo = new PProfInfo.Label( labelItems, this, labelItem); return(labelInfo); }