forked from segmentio/Analytics.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalytics.cs
More file actions
67 lines (60 loc) · 1.78 KB
/
Analytics.cs
File metadata and controls
67 lines (60 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Text;
namespace Segment
{
public class Analytics
{
// REMINDER: don't forget to set Properties.AssemblyInfo.AssemblyVersion as well
public static string VERSION = "3.1.0-alpha";
/// <summary>
/// Lock for thread-safety
/// </summary>
static readonly object padlock = new object();
public static Client Client { get; private set; }
/// <summary>
/// Initialized the default Segment.io client with your API writeKey.
/// </summary>
/// <param name="writeKey"></param>
public static void Initialize(string writeKey)
{
// avoiding double locking as recommended:
// http://www.yoda.arachsys.com/csharp/singleton.html
lock (padlock)
{
if (Client == null)
{
Client = new Client(writeKey);
}
}
}
/// <summary>
/// Initialized the default Segment.io client with your API writeKey.
/// </summary>
/// <param name="writeKey"></param>
public static void Initialize(string writeKey, Config config)
{
lock (padlock)
{
if (Client == null)
{
Client = new Client(writeKey, config);
}
}
}
/// <summary>
/// Disposes of the current client and allows the creation of a new one
/// </summary>
public static void Dispose()
{
lock (padlock)
{
if (Client != null)
{
Client.Dispose();
Client = null;
}
}
}
}
}