From 31706e31a88c347c1154dcc71754d8eb21effcad Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 30 Nov 2010 17:38:25 +0100 Subject: [PATCH] dotnet plugin: Add copy constructors and ToString() methods to the C# code. --- bindings/csharp/collectd.cs | 62 +++++++++++++++++++++++++++++++++++++++++++++ bindings/csharp/test.cs | 3 +-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/bindings/csharp/collectd.cs b/bindings/csharp/collectd.cs index fc0633f5..bc092679 100644 --- a/bindings/csharp/collectd.cs +++ b/bindings/csharp/collectd.cs @@ -26,6 +26,7 @@ using System; using System.Collections; +using System.Text; using System.Runtime.CompilerServices; namespace CollectdAPI @@ -64,6 +65,11 @@ namespace CollectdAPI public override long toLong () { return ((long) this._value); } public override double toDouble () { return (this._value); } + + public override string ToString () + { + return (this._value.ToString ()); + } } /* }}} class gaugeValue */ public class deriveValue: Value /* {{{ */ @@ -77,6 +83,11 @@ namespace CollectdAPI public override long toLong () { return (this._value); } public override double toDouble () { return ((double) this._value); } + + public override string ToString () + { + return (this._value.ToString ()); + } } /* }}} class deriveValue */ public class Identifier /* {{{ */ @@ -98,6 +109,15 @@ namespace CollectdAPI this._typeInstance = typeInstance; } /* Identifier() */ + public Identifier (Identifier id) + { + this._host = id._host; + this._plugin = id._plugin; + this._pluginInstance = id._pluginInstance; + this._type = id._type; + this._typeInstance = id._typeInstance; + } /* Identifier() */ + public string getHost () { return (this._host); } public string getPlugin () { return (this._plugin); } public string getPluginInstance () { return (this._pluginInstance); } @@ -109,6 +129,20 @@ namespace CollectdAPI public void setPluginInstance (string s) { this._pluginInstance = s; } public void setType (string s) { this._type = s; } public void setTypeInstance (string s) { this._typeInstance = s; } + + public override string ToString () + { + StringBuilder sb = new StringBuilder (); + + sb.Append (this._host).Append ("/").Append (this._plugin); + if (!String.Equals ("", this._pluginInstance)) + sb.Append ("-").Append (this._pluginInstance); + sb.Append ("/").Append (this._type); + if (!String.Equals ("", this._typeInstance)) + sb.Append ("-").Append (this._typeInstance); + + return (sb.ToString ()); + } /* string ToString */ } /* }}} class Identifier */ public class ValueList: Identifier /* {{{ */ @@ -127,6 +161,14 @@ namespace CollectdAPI this.setTime (DateTime.Now); } + public ValueList (ValueList vl) + :base (vl) + { + this._interval = vl._interval; + this._values = new ArrayList (vl._values); + this._time = vl._time; + } + public IList getValues () { return (this._values); @@ -176,6 +218,26 @@ namespace CollectdAPI if (t > 0.0) this._time = t; } + + public override string ToString () + { + StringBuilder sb = new StringBuilder ("{"); + + sb.Append ("\"identifier\":\"").Append (base.ToString ()).Append ("\", "); + sb.Append ("\"time\":").Append (this._time).Append (", "); + sb.Append ("\"interval\":").Append (this._interval).Append (", "); + sb.Append ("\"values\":["); + + for (int i = 0; i < this._values.Count; i++) + { + if (i != 0) + sb.Append (","); + sb.Append (this._values[i]); + } + + sb.Append ("]}"); + return (sb.ToString ()); + } /* string ToString */ } /* }}} class ValueList */ } diff --git a/bindings/csharp/test.cs b/bindings/csharp/test.cs index 92ee1f15..6e563261 100644 --- a/bindings/csharp/test.cs +++ b/bindings/csharp/test.cs @@ -15,8 +15,7 @@ public class EmbedTest: IRead vl.setInterval (10.0); vl.addValue (new gaugeValue (3.1337)); - System.Console.WriteLine ("vl.getHost () = " - + vl.getHost ()); + System.Console.WriteLine ("vl: " + vl); Collectd.dispatchValues (vl); return (0); -- 2.11.0