-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSplitWrapper.cs
More file actions
64 lines (58 loc) · 1.71 KB
/
SplitWrapper.cs
File metadata and controls
64 lines (58 loc) · 1.71 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
using Splitio.Services.Client.Classes;
using Splitio.Services.Client.Interfaces;
using Splitio.Services.Logger;
using Splitio.Services.Shared.Classes;
using System;
namespace Splitio.OpenFeature.Provider
{
public class SplitWrapper
{
readonly ISplitClient splitClient;
bool SDKReady = false;
protected readonly ISplitLogger _log;
public SplitWrapper(ISplitClient splitClient)
{
this.splitClient = splitClient;
}
public SplitWrapper(string SdkKey, ConfigurationOptions Configs, int ReadyBlockTime=Constants.DefaultReadyBlockTime)
{
var factory = new SplitFactory(SdkKey, Configs);
_log = WrapperAdapter.Instance().GetLogger(typeof(SplitWrapper));
splitClient = (SplitClient)factory.Client();
try
{
splitClient.BlockUntilReady(ReadyBlockTime);
SDKReady = true;
}
catch (Exception)
{
LogIfNotNull($"Split SDK Not ready within {ReadyBlockTime} ms!");
}
}
public ISplitClient getSplitClient()
{
return splitClient;
}
public bool IsSDKReady()
{
if (SDKReady) return true;
try
{
splitClient.BlockUntilReady(1);
SDKReady = true;
}
catch (Exception)
{
LogIfNotNull($"Split client is not ready");
}
return SDKReady;
}
private void LogIfNotNull(string message)
{
if (_log != null)
{
_log.Error(message);
}
}
}
}