com.amanotes.gdk 0.2.47 → 0.2.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -1
- package/Editor/AmaGDKEditor.cs +133 -65
- package/Editor/AmaGDKExtra.cs +31 -0
- package/Editor/AmaGDKExtra.cs.meta +11 -0
- package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +1 -1
- package/Extra/AmaGDKInstaller.unitypackage +0 -0
- package/Extra/AmaGDKProject.unitypackage +0 -0
- package/Extra/SDKVersionTracking.unitypackage +0 -0
- package/Extra/SDKVersionTracking.unitypackage.meta +7 -0
- package/Packages/AmaGDKConfig.unitypackage +0 -0
- package/Packages/AmaGDKExample.unitypackage +0 -0
- package/Packages/AmaGDKTest.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.unitypackage +0 -0
- package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
- package/Packages/IronSourceAdapter.unitypackage +0 -0
- package/Packages/RevenueCatAdapter.unitypackage +0 -0
- package/Runtime/AmaGDK.Adapters.cs +0 -4
- package/Runtime/AmaGDK.Ads.cs +89 -29
- package/Runtime/AmaGDK.Analytics.cs +97 -64
- package/Runtime/AmaGDK.IAP.cs +39 -45
- package/Runtime/AmaGDK.RemoteConfig.cs +76 -52
- package/Runtime/AmaGDK.UserProfile.cs +106 -124
- package/Runtime/AmaGDK.cs +46 -35
- package/Runtime/Internal/AmaGDK.Event.cs +185 -0
- package/Runtime/Internal/AmaGDK.Event.cs.meta +3 -0
- package/Runtime/Internal/AmaGDK.Internal.cs +3 -0
- package/Runtime/Internal/AmaGDK.Utils.cs +85 -24
- package/Runtime/Klavar/Attributes/AccumulatedCountAttribute.cs +19 -0
- package/Runtime/Klavar/Attributes/AccumulatedCountAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/ConnectionAttribute.cs +18 -0
- package/Runtime/Klavar/Attributes/ConnectionAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/CountInSessionAttribute.cs +27 -0
- package/Runtime/Klavar/Attributes/CountInSessionAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/DescriptionAttribute.cs +7 -0
- package/Runtime/Klavar/Attributes/DescriptionAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/DynamicValidateAttribute.cs +30 -0
- package/Runtime/Klavar/Attributes/DynamicValidateAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/IgnoreAttribute.cs +16 -0
- package/Runtime/Klavar/Attributes/IgnoreAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/MinMaxAttribute.cs +130 -0
- package/Runtime/Klavar/Attributes/MinMaxAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/MinMaxLengthAttribute.cs +88 -0
- package/Runtime/Klavar/Attributes/MinMaxLengthAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/NameAttribute.cs +35 -0
- package/Runtime/Klavar/Attributes/NameAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/NotNullAttribute.cs +16 -0
- package/Runtime/Klavar/Attributes/NotNullAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/RegexPatternAttribute.cs +58 -0
- package/Runtime/Klavar/Attributes/RegexPatternAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/TimeDiffLastFireAttribute.cs +28 -0
- package/Runtime/Klavar/Attributes/TimeDiffLastFireAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/ToStringAttribute.cs +97 -0
- package/Runtime/Klavar/Attributes/ToStringAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes/ValueAttribute.cs +30 -0
- package/Runtime/Klavar/Attributes/ValueAttribute.cs.meta +11 -0
- package/Runtime/Klavar/Attributes.meta +8 -0
- package/Runtime/Klavar/KlavarEvent.cs +91 -0
- package/Runtime/Klavar/KlavarEvent.cs.meta +11 -0
- package/Runtime/Klavar/KlavarEventAttribute.cs +39 -0
- package/Runtime/Klavar/KlavarEventAttribute.cs.meta +11 -0
- package/Runtime/Klavar/KlavarEventTools.cs +92 -0
- package/Runtime/Klavar/KlavarEventTools.cs.meta +11 -0
- package/Runtime/Klavar/KlavarEventUtils.cs +58 -0
- package/Runtime/Klavar/KlavarEventUtils.cs.meta +11 -0
- package/Runtime/{Core.meta → Klavar.meta} +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Reflection;
|
|
3
|
+
|
|
4
|
+
namespace Amanotes.Core
|
|
5
|
+
{
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Min, Max validate param
|
|
8
|
+
/// </summary>
|
|
9
|
+
public class MinMaxAttribute : ValidateLogEventAttribute
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
public readonly double min;
|
|
13
|
+
|
|
14
|
+
public readonly double max;
|
|
15
|
+
|
|
16
|
+
public MinMaxAttribute(double min, double max)
|
|
17
|
+
{
|
|
18
|
+
this.min = min;
|
|
19
|
+
this.max = max;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
24
|
+
{
|
|
25
|
+
if (!(param is int) && !(param is float) && !(param is double))
|
|
26
|
+
throw new ArgumentException($"type of `{fieldInfo.Name}` is must be int, float or double");
|
|
27
|
+
|
|
28
|
+
double val = Convert.ToDouble(param);
|
|
29
|
+
if (val < min) throw new ArgumentException($"Field `{fieldInfo.Name}` must be in range [{min}, {max}]. Current value: {param}");
|
|
30
|
+
if (val > max) throw new ArgumentException($"Field `{fieldInfo.Name}` must be in range [{min}, {max}]. Current value: {param}");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
public class MinimumAttribute : ValidateLogEventAttribute
|
|
36
|
+
{
|
|
37
|
+
|
|
38
|
+
public readonly double min;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
public MinimumAttribute(double min)
|
|
42
|
+
{
|
|
43
|
+
this.min = min;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
48
|
+
{
|
|
49
|
+
if (!(param is int) && !(param is float) && !(param is double))
|
|
50
|
+
throw new ArgumentException($"type of `{fieldInfo.Name}` is must be int, float or double");
|
|
51
|
+
|
|
52
|
+
double val = Convert.ToDouble(param);
|
|
53
|
+
if (val < min) throw new ArgumentException($"Field `{fieldInfo.Name}` must be greater or equal to {min}. Current value: {param}");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public class ExclusiveMinimumAttribute : ValidateLogEventAttribute
|
|
59
|
+
{
|
|
60
|
+
|
|
61
|
+
public readonly double min;
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
public ExclusiveMinimumAttribute(double min)
|
|
65
|
+
{
|
|
66
|
+
this.min = min;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
71
|
+
{
|
|
72
|
+
if (!(param is int) && !(param is float) && !(param is double))
|
|
73
|
+
throw new ArgumentException($"type of `{fieldInfo.Name}` is must be int, float or double");
|
|
74
|
+
|
|
75
|
+
double val = Convert.ToDouble(param);
|
|
76
|
+
if (val <= min) throw new ArgumentException($"Field `{fieldInfo.Name}` must be greater {min}. Current value: {param}");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
public class MaximumAttribute : ValidateLogEventAttribute
|
|
85
|
+
{
|
|
86
|
+
|
|
87
|
+
public readonly double max;
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
public MaximumAttribute(double max)
|
|
91
|
+
{
|
|
92
|
+
this.max = max;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
97
|
+
{
|
|
98
|
+
if (!(param is int) && !(param is float) && !(param is double))
|
|
99
|
+
throw new ArgumentException($"type of `{fieldInfo.Name}` is must be int, float or double");
|
|
100
|
+
|
|
101
|
+
double val = Convert.ToDouble(param);
|
|
102
|
+
if (val > max) throw new ArgumentException($"Field `{fieldInfo.Name}` must be smaller or equal to {max}. Current value: {param}");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
public class ExclusiveMaximumAttribute : ValidateLogEventAttribute
|
|
108
|
+
{
|
|
109
|
+
|
|
110
|
+
public readonly double max;
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
public ExclusiveMaximumAttribute(double max)
|
|
114
|
+
{
|
|
115
|
+
this.max = max;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
120
|
+
{
|
|
121
|
+
if (!(param is int) && !(param is float) && !(param is double))
|
|
122
|
+
throw new ArgumentException($"type of `{fieldInfo.Name}` is must be int, float or double");
|
|
123
|
+
|
|
124
|
+
double val = Convert.ToDouble(param);
|
|
125
|
+
if (val >= max) throw new ArgumentException($"Field `{fieldInfo.Name}` must be smaller to {max}. Current value: {param}");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Reflection;
|
|
3
|
+
|
|
4
|
+
namespace Amanotes.Core
|
|
5
|
+
{
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Min, Max length valudate validate param. (Just apply for string only)
|
|
8
|
+
/// </summary>
|
|
9
|
+
public class MinMaxLengthAttribute : ValidateLogEventAttribute
|
|
10
|
+
{
|
|
11
|
+
public readonly int min;
|
|
12
|
+
public readonly int max;
|
|
13
|
+
|
|
14
|
+
public MinMaxLengthAttribute(int min, int max)
|
|
15
|
+
{
|
|
16
|
+
this.min = min;
|
|
17
|
+
this.max = max;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
22
|
+
{
|
|
23
|
+
if (!(param is string text)) throw new ArgumentException($"Field {fieldInfo.Name} must be string.");
|
|
24
|
+
if (param is null) throw new ArgumentException($"Field {fieldInfo.Name} must not be null.");
|
|
25
|
+
if (text.Length < min) throw new ArgumentException($"The length of string field `{fieldInfo.Name}` must be in range [{min}, {max}]. Current length: {text.Length}");
|
|
26
|
+
if (text.Length > max) throw new ArgumentException($"The length of string field `{fieldInfo.Name}` must be in range [{min}, {max}]. Current length: {text.Length}");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
public class MinLengthAttribute : ValidateLogEventAttribute
|
|
32
|
+
{
|
|
33
|
+
public readonly int min;
|
|
34
|
+
|
|
35
|
+
public MinLengthAttribute(int min)
|
|
36
|
+
{
|
|
37
|
+
this.min = min;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
42
|
+
{
|
|
43
|
+
if (!(param is string text)) throw new ArgumentException($"Field {fieldInfo.Name} must be string.");
|
|
44
|
+
if (param is null) throw new ArgumentException($"Field {fieldInfo.Name} must not be null.");
|
|
45
|
+
if (text.Length < min) throw new ArgumentException($"The length of string field `{fieldInfo.Name}` must be greater or equal to {min}. Current length: {text.Length}");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
public class MaxLengthAttribute : ValidateLogEventAttribute
|
|
51
|
+
{
|
|
52
|
+
public readonly int max;
|
|
53
|
+
|
|
54
|
+
public MaxLengthAttribute(int max)
|
|
55
|
+
{
|
|
56
|
+
this.max = max;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
61
|
+
{
|
|
62
|
+
if (!(param is string text)) throw new ArgumentException($"Field {fieldInfo.Name} must be string.");
|
|
63
|
+
if (param is null) throw new ArgumentException($"Field {fieldInfo.Name} must not be null.");
|
|
64
|
+
if (text.Length > max) throw new ArgumentException($"The length of string field `{fieldInfo.Name}` must be smaller or equal to {max}. Current length: {text.Length}");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
public class FixedLengthAttribute : ValidateLogEventAttribute
|
|
70
|
+
{
|
|
71
|
+
public readonly int length;
|
|
72
|
+
|
|
73
|
+
public FixedLengthAttribute(int length)
|
|
74
|
+
{
|
|
75
|
+
this.length = length;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
79
|
+
{
|
|
80
|
+
if (!(param is string text)) throw new ArgumentException($"Field {fieldInfo.Name} must be string.");
|
|
81
|
+
if (param is null) throw new ArgumentException($"Field {fieldInfo.Name} must not be null.");
|
|
82
|
+
if (text.Length != length)
|
|
83
|
+
throw new ArgumentException($"The length of string field `{fieldInfo.Name}` must be equal to {length}. Current length: {text.Length}");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
using System.Reflection;
|
|
3
|
+
|
|
4
|
+
namespace Amanotes.Core
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Change the Name of param
|
|
9
|
+
/// </summary>
|
|
10
|
+
public class NameAttribute : NamingLogEventAttribute
|
|
11
|
+
{
|
|
12
|
+
public readonly string name;
|
|
13
|
+
|
|
14
|
+
public NameAttribute(string name)
|
|
15
|
+
{
|
|
16
|
+
this.name = name;
|
|
17
|
+
}
|
|
18
|
+
public override string GetName(object parent, FieldInfo fieldInfo) => name;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/// <summary>
|
|
24
|
+
/// Set the event name
|
|
25
|
+
/// </summary>
|
|
26
|
+
public class EventNameAttribute : KlavarEventAttribute
|
|
27
|
+
{
|
|
28
|
+
public readonly string name;
|
|
29
|
+
|
|
30
|
+
public EventNameAttribute(string name)
|
|
31
|
+
{
|
|
32
|
+
this.name = name;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Reflection;
|
|
3
|
+
|
|
4
|
+
namespace Amanotes.Core
|
|
5
|
+
{
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Not null validate param
|
|
8
|
+
/// </summary>
|
|
9
|
+
public class NotNullAttribute : ValidateLogEventAttribute
|
|
10
|
+
{
|
|
11
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
12
|
+
{
|
|
13
|
+
if (param is null) throw new ArgumentException($"Field `{fieldInfo.Name}` must not be null");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Reflection;
|
|
3
|
+
using System.Text.RegularExpressions;
|
|
4
|
+
|
|
5
|
+
namespace Amanotes.Core
|
|
6
|
+
{
|
|
7
|
+
#pragma warning disable CS3015
|
|
8
|
+
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// Apply Regex Validation for param
|
|
11
|
+
/// </summary>
|
|
12
|
+
public class RegexPatternAttribute : ValidateLogEventAttribute
|
|
13
|
+
{
|
|
14
|
+
public readonly string[] regexes;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
public RegexPatternAttribute(string regex)
|
|
18
|
+
{
|
|
19
|
+
this.regexes = new string[] { regex };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
public RegexPatternAttribute(string[] regexes)
|
|
24
|
+
{
|
|
25
|
+
this.regexes = regexes;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
30
|
+
{
|
|
31
|
+
if (param is null) throw new ArgumentException($"Field `{fieldInfo.Name}` must not be null");
|
|
32
|
+
foreach (var regex in regexes)
|
|
33
|
+
{
|
|
34
|
+
var match = Regex.Match(param.ToString(), regex);
|
|
35
|
+
if (match != null && match.Success) return;
|
|
36
|
+
}
|
|
37
|
+
throw new ArgumentException($"Field `{fieldInfo.Name}` is not match as {this.GetType().Name.Replace("Attribute", "")}");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#pragma warning restore CA2200
|
|
42
|
+
|
|
43
|
+
/// <summary>
|
|
44
|
+
/// Is Email validate Param
|
|
45
|
+
/// </summary>
|
|
46
|
+
public class IsEmailAddressAttribute : RegexPatternAttribute
|
|
47
|
+
{
|
|
48
|
+
public IsEmailAddressAttribute() : base(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$") { }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// <summary>
|
|
52
|
+
/// Is ObjectID validate param
|
|
53
|
+
/// </summary>
|
|
54
|
+
public class IsObjectIDAttribute : RegexPatternAttribute
|
|
55
|
+
{
|
|
56
|
+
public IsObjectIDAttribute() : base(@"^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)") { }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
using System.Collections.Generic;
|
|
2
|
+
using System.Reflection;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
|
|
5
|
+
namespace Amanotes.Core
|
|
6
|
+
{
|
|
7
|
+
public class TimeDiffLastFireAttribute : ConverterLogEventAttribute
|
|
8
|
+
{
|
|
9
|
+
static readonly Dictionary<string, float> lastFireInSessions = new Dictionary<string, float>();
|
|
10
|
+
|
|
11
|
+
public override object Convert(object parent, FieldInfo fieldInfo, object param)
|
|
12
|
+
{
|
|
13
|
+
// return AmaGDK.Ads.InterstitialShowCalledInSession;
|
|
14
|
+
string name = parent.GetType().FullName;
|
|
15
|
+
if (!lastFireInSessions.TryGetValue(name, out var lastFire))
|
|
16
|
+
{
|
|
17
|
+
lastFireInSessions[name] = Time.realtimeSinceStartup;
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var current = Time.realtimeSinceStartup;
|
|
22
|
+
var diff = Mathf.RoundToInt(current - lastFire);
|
|
23
|
+
lastFireInSessions[name] = current;
|
|
24
|
+
return diff;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Reflection;
|
|
4
|
+
|
|
5
|
+
namespace Amanotes.Core
|
|
6
|
+
{
|
|
7
|
+
#pragma warning disable CS3005
|
|
8
|
+
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// Convert param to string
|
|
11
|
+
/// </summary>
|
|
12
|
+
public class ToStringAttribute : ConverterLogEventAttribute
|
|
13
|
+
{
|
|
14
|
+
public enum Converter
|
|
15
|
+
{
|
|
16
|
+
NoThing,
|
|
17
|
+
|
|
18
|
+
ToLowerCase,
|
|
19
|
+
ToUpperCase,
|
|
20
|
+
|
|
21
|
+
ToSnakeCase,
|
|
22
|
+
ToCamelCase,
|
|
23
|
+
ToPascalCase,
|
|
24
|
+
ToKebabCase
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static readonly Dictionary<Converter, Func<string, string>> convertMethods = new Dictionary<Converter, Func<string, string>>()
|
|
28
|
+
{
|
|
29
|
+
{Converter.NoThing, val=>val},
|
|
30
|
+
{Converter.ToLowerCase, KlavarEventUtils.ToLowerCase},
|
|
31
|
+
{Converter.ToUpperCase, KlavarEventUtils.ToUpperCase},
|
|
32
|
+
{Converter.ToSnakeCase, KlavarEventUtils.ToSnakeCase},
|
|
33
|
+
{Converter.ToCamelCase, KlavarEventUtils.ToCamelCase},
|
|
34
|
+
{Converter.ToPascalCase, KlavarEventUtils.ToPascalCase},
|
|
35
|
+
{Converter.ToKebabCase, KlavarEventUtils.ToKebabCase},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
public readonly Converter converter;
|
|
39
|
+
|
|
40
|
+
public ToStringAttribute() { converter = Converter.NoThing; }
|
|
41
|
+
|
|
42
|
+
public ToStringAttribute(Converter converter)
|
|
43
|
+
{
|
|
44
|
+
this.converter = converter;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private string GetValueAsString(object enumVal)
|
|
48
|
+
{
|
|
49
|
+
// get the field
|
|
50
|
+
var field = enumVal.GetType().GetField(enumVal.ToString());
|
|
51
|
+
var attr = field.GetCustomAttribute<ValueAttribute>();
|
|
52
|
+
|
|
53
|
+
return attr != null ? convertMethods[converter](attr.sValue) : convertMethods[converter](enumVal.ToString());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public override object Convert(object parent, FieldInfo fieldInfo, object param)
|
|
57
|
+
{
|
|
58
|
+
return GetValueAsString(param);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
public class ToStringLowerCase : ToStringAttribute
|
|
64
|
+
{
|
|
65
|
+
public ToStringLowerCase() : base(ToStringAttribute.Converter.ToLowerCase) { }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
public class ToStringUpperCase : ToStringAttribute
|
|
70
|
+
{
|
|
71
|
+
public ToStringUpperCase() : base(ToStringAttribute.Converter.ToUpperCase) { }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
public class ToStringToSnakeCase : ToStringAttribute
|
|
76
|
+
{
|
|
77
|
+
public ToStringToSnakeCase() : base(ToStringAttribute.Converter.ToSnakeCase) { }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public class ToStringCamelCase : ToStringAttribute
|
|
81
|
+
{
|
|
82
|
+
public ToStringCamelCase() : base(ToStringAttribute.Converter.ToCamelCase) { }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public class ToStringPascalCase : ToStringAttribute
|
|
86
|
+
{
|
|
87
|
+
public ToStringPascalCase() : base(ToStringAttribute.Converter.ToPascalCase) { }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
public class ToStringKebabCase : ToStringAttribute
|
|
92
|
+
{
|
|
93
|
+
public ToStringKebabCase() : base(ToStringAttribute.Converter.ToKebabCase) { }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#pragma warning restore CS3005
|
|
97
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
namespace Amanotes.Core
|
|
2
|
+
{
|
|
3
|
+
/// <summary>
|
|
4
|
+
/// Change the value of param to new value in the attribute
|
|
5
|
+
/// </summary>
|
|
6
|
+
public class ValueAttribute : KlavarEventAttribute
|
|
7
|
+
{
|
|
8
|
+
public readonly int iValue;
|
|
9
|
+
public readonly string sValue;
|
|
10
|
+
public readonly float fValue;
|
|
11
|
+
public readonly double dValue;
|
|
12
|
+
public ValueAttribute(int value)
|
|
13
|
+
{
|
|
14
|
+
this.iValue = value;
|
|
15
|
+
}
|
|
16
|
+
public ValueAttribute(string value)
|
|
17
|
+
{
|
|
18
|
+
this.sValue = value;
|
|
19
|
+
}
|
|
20
|
+
public ValueAttribute(float value)
|
|
21
|
+
{
|
|
22
|
+
this.fValue = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public ValueAttribute(double value)
|
|
26
|
+
{
|
|
27
|
+
this.dValue = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
using System.Reflection;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
namespace Amanotes.Core
|
|
8
|
+
{
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// LogEvent parameters Schema
|
|
11
|
+
/// </summary>
|
|
12
|
+
public abstract class KlavarEvent
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// LogEvent
|
|
16
|
+
/// </summary>
|
|
17
|
+
/// <exception cref="ArgumentException"></exception>
|
|
18
|
+
public void LogEvent()
|
|
19
|
+
{
|
|
20
|
+
var type = this.GetType();
|
|
21
|
+
var eventNameAttr = (EventNameAttribute)Attribute.GetCustomAttribute(type, typeof(EventNameAttribute));
|
|
22
|
+
|
|
23
|
+
if (eventNameAttr == null)
|
|
24
|
+
throw new ArgumentException($"Add `EventName` attribute to class {type.FullName}");
|
|
25
|
+
|
|
26
|
+
var @params = this.ToDict();
|
|
27
|
+
var eventName = eventNameAttr.name;
|
|
28
|
+
AmaGDK.Analytics.LogEvent(eventName, @params);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/// <summary>
|
|
33
|
+
/// throw exception from attribute if field is invalid.
|
|
34
|
+
/// </summary>
|
|
35
|
+
/// <param name="field"></param>
|
|
36
|
+
/// <returns></returns>
|
|
37
|
+
/// <exception cref="ArgumentException">when field go wrong.</exception>
|
|
38
|
+
private FieldInfo Validate(FieldInfo field)
|
|
39
|
+
{
|
|
40
|
+
var param = field.GetValue(this);
|
|
41
|
+
var attrs = field.GetCustomAttributes<ValidateLogEventAttribute>(true);
|
|
42
|
+
foreach (var attr in attrs) attr.Validate(this, field, param);
|
|
43
|
+
|
|
44
|
+
return field;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// <summary>
|
|
48
|
+
/// Apply converter attribute in field.
|
|
49
|
+
/// </summary>
|
|
50
|
+
/// <param name="field"></param>
|
|
51
|
+
/// <returns></returns>
|
|
52
|
+
private object Convert(FieldInfo field)
|
|
53
|
+
{
|
|
54
|
+
var attrs = field.GetCustomAttributes<ConverterLogEventAttribute>(true);
|
|
55
|
+
var param = field.GetValue(this);
|
|
56
|
+
foreach (var attr in attrs) param = attr.Convert(this, field, param);
|
|
57
|
+
return param;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/// <summary>
|
|
62
|
+
/// Convert the name in field to new name by attribute.
|
|
63
|
+
/// </summary>
|
|
64
|
+
/// <param name="field"></param>
|
|
65
|
+
/// <returns>the new param name</returns>
|
|
66
|
+
private string GetName(FieldInfo field)
|
|
67
|
+
{
|
|
68
|
+
var attr = field.GetCustomAttribute<NamingLogEventAttribute>(true);
|
|
69
|
+
var param = field.GetValue(this);
|
|
70
|
+
return attr?.GetName(this, field) ?? field.Name;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/// <summary>
|
|
75
|
+
/// Convert all params to dict by field name.
|
|
76
|
+
/// </summary>
|
|
77
|
+
/// <returns>dictionary of params</returns>
|
|
78
|
+
public Dictionary<string, object> ToDict()
|
|
79
|
+
{
|
|
80
|
+
return this
|
|
81
|
+
.GetType()
|
|
82
|
+
.GetFields()
|
|
83
|
+
.Where(field => field.GetCustomAttribute<IgnoreAttribute>() == null)
|
|
84
|
+
.Select(field => Validate(field))
|
|
85
|
+
.ToDictionary(
|
|
86
|
+
field => GetName(field),
|
|
87
|
+
field => Convert(field)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|