Exemple #1
0
        public void CloseMultiple()
        {
            var libHoney = new LibHoney("key1", "HelloHoney", 1);

            libHoney.Close();

            // Again, a few times.
            libHoney.Close();
            libHoney.Close();
        }
Exemple #2
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "dynamic";

        var honey   = new LibHoney(writeKey, dataSet);
        var builder = new Builder(honey);

        // Attach fields to the Builder instance
        builder.AddField("start", DateTime.Now);
        builder.AddDynamicField("end", () => DateTime.Now);

        var tasks = new Task [8];

        foreach (int i in Enumerable.Range(0, tasks.Length))
        {
            var t = Task.Run(async() => {
                // Simulate some work.
                await Task.Delay(new Random().Next(100));

                // builder comes with the "start" and "end" fields
                // already populated ("end" being a dynamic field)
                var ev = builder.NewEvent();
                ev.AddField("id", i);
                ev.Send();
            });
            tasks [i] = t;
        }

        Task.WaitAll(tasks);
        honey.Close();
    }
Exemple #3
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "factorial";

        var honey = new LibHoney(writeKey, dataSet);

        Task.Run(() => ReadResponses(honey.Responses));

        // Attach fields to the top-level instance.
        honey.AddField("version", "3.4.5");
        honey.AddDynamicField("num_threads", () => Process.GetCurrentProcess().Threads.Count);

        // Sends an event with "version", "num_threads", and "status" fields.
        honey.SendNow("status", "starting run");

        RunFact(1, 2, new Builder(honey, new Dictionary <string, object> ()
        {
            ["range"] = "low"
        }));
        RunFact(31, 32, new Builder(honey, new Dictionary <string, object> ()
        {
            ["range"] = "high"
        }));

        honey.SendNow("status", "sending now");
        honey.Close();
    }
Exemple #4
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "event_values";

        var honey = new LibHoney(writeKey, dataSet);
        var rand  = new Random();

        // Send 3 events with a random number.
        for (int i = 0; i < 10; i++)
        {
            honey.SendNow(new Dictionary <string, object> ()
            {
                ["counter"] = rand.Next(100),
            });
        }

        // Send an event with the same writeKey but different
        // dataSet.
        var ev = new Event(honey);

        ev.DataSet = "master_values";
        ev.AddField("latest_event", DateTime.Now.ToString("O"));
        ev.Send();

        // Close the client.
        honey.Close();
    }
Exemple #5
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "responses";

        var honey     = new LibHoney(writeKey, dataSet);
        var responses = honey.Responses;

        Task.Run(() => ReadResponses(responses));

        var tasks = new Task [8];

        foreach (int i in Enumerable.Range(0, tasks.Length))
        {
            var t = Task.Run(async() => {
                // Simulate work.
                var start = DateTime.Now;
                await Task.Delay(new Random().Next(100));

                // Work is done, send the task id and its elapsed time.
                var ev = new Event(honey);
                ev.AddField("id", i);
                ev.AddField("elapsed", (DateTime.Now - start).TotalMilliseconds);
                ev.Send();
            });
            tasks [i] = t;
        }

        Task.WaitAll(tasks);
        honey.Close();
    }
Exemple #6
0
        public void SendPreSampledDisposed()
        {
            // Create our own LibHoney so we can dispose it right away.
            var honey = new LibHoney("key1", "data1");
            var ev    = new Event(honey);

            honey.Close();

            bool excThrown = false;

            try { ev.SendPreSampled(); } catch (SendException) { excThrown = true; }
            Assert.True(excThrown);
        }
Exemple #7
0
        public void SendNowClosed()
        {
            var libHoney = new LibHoney("key1", "HelloHoney", 1);

            libHoney.Close();

            bool excThrown = false;

            try { libHoney.SendNow(new Dictionary <string, object> ()); } catch (SendException) { excThrown = true; }
            Assert.True(excThrown);

            excThrown = false;
            try { libHoney.SendNow("name", "value"); } catch (SendException) { excThrown = true; }
            Assert.True(excThrown);
        }
Exemple #8
0
    static void Main()
    {
        string writeKey = "abcabc123123defdef456456";
        string dataSet  = "simple";

        var honey = new LibHoney(writeKey, dataSet);
        var rand  = new Random();

        // Send 10 events with a random number.
        for (int i = 0; i < 10; i++)
        {
            honey.SendNow(new Dictionary <string, object> ()
            {
                ["message"] = "Diagnostic #" + i,
                ["counter"] = rand.Next(100),
            });

            Thread.Sleep(TimeSpan.FromMilliseconds(100));
        }

        // Close the client.
        honey.Close();
    }
Exemple #9
0
 public void Dispose()
 {
     LibHoney.Close();
 }