Skip to content

Commit 01489af

Browse files
committed
Added validation for measurement name
1 parent ff03b3e commit 01489af

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

AdysTech.InfluxDB.Client.Net/InfluxDatapoint.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,48 @@ public InfluxDatapoint()
5959
}
6060
}
6161

62+
/// <summary>
63+
/// Initializes tags with a preexisitng dictionary
64+
/// </summary>
65+
/// <param name="tags">Dictionary of tag/value pairs</param>
66+
/// <returns>True:Success, False:Failure</returns>
67+
public bool InitializeTags(IDictionary<string, string> tags)
68+
{
69+
if ( Tags.Count > 0 )
70+
throw new InvalidOperationException ("Tags can be initialized only when the collection is empty");
71+
try
72+
{
73+
Tags = new Dictionary<string, string> (tags);
74+
return true;
75+
}
76+
catch ( Exception)
77+
{
78+
Tags = new Dictionary<string, string> ();
79+
return false;
80+
}
81+
}
82+
83+
/// <summary>
84+
/// Initializes fields with a preexisting dictionary
85+
/// </summary>
86+
/// <param name="fields">Dictionary of Field/Value pairs</param>
87+
/// <returns>True:Success, False:Failure</returns>
88+
public bool InitializeFields(IDictionary<string, T> fields)
89+
{
90+
if ( Fields.Count > 0 )
91+
throw new InvalidOperationException ("Fields can be initialized only when the collection is empty");
92+
try
93+
{
94+
Fields = new Dictionary<string, T> (fields);
95+
return true;
96+
}
97+
catch ( Exception)
98+
{
99+
Fields = new Dictionary<string, T> ();
100+
return false;
101+
}
102+
}
103+
62104
/// <summary>
63105
/// Returns the string representing the point in InfluxDB Line protocol
64106
/// </summary>
@@ -68,6 +110,8 @@ public string ConvertToInfluxLineProtocol()
68110
{
69111
if ( Fields.Count == 0 )
70112
throw new InvalidOperationException ("InfluxDB needs atleast one field in a line");
113+
if ( String.IsNullOrWhiteSpace (MeasurementName) )
114+
throw new InvalidOperationException ("InfluxDB needs a measurement name to accept a point");
71115

72116
var line = new StringBuilder ();
73117
line.AppendFormat ("{0}", MeasurementName);

0 commit comments

Comments
 (0)