Skip to content

Commit 3a10dcb

Browse files
author
Asaf Agami
authored
[ROAD-410] feat: amplitude data integration (#152)
1 parent 609ecea commit 3a10dcb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2239
-487
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//
2+
// CollectionEquality.cs
3+
//
4+
// This file is auto-generated by Amplitude.
5+
// To update run 'ampli pull visual-studio-plugin'
6+
//
7+
// Questions? We're here to help:
8+
// https://developers.data.amplitude.com/dotnet
9+
//
10+
11+
using System.Collections.Generic;
12+
using System.Linq;
13+
14+
namespace Iteratively
15+
{
16+
partial class CollectionUtils
17+
{
18+
private static EqualityComparer<object> _valueComparer = EqualityComparer<object>.Default;
19+
20+
private static bool isDictionary(object maybeDictionary) =>
21+
maybeDictionary.GetType().Equals(typeof(Dictionary<string, object>));
22+
23+
private static Dictionary<string, object> asDictionary(object o) =>
24+
o as Dictionary<string, object>;
25+
26+
private static ICollection<object> asCollection(object o) =>
27+
o as ICollection<object>;
28+
29+
private static List<object> asList(object o) =>
30+
o as List<object>;
31+
32+
public static int GetHashCode(object obj)
33+
{
34+
int code = 0;
35+
36+
if (obj == null)
37+
return code;
38+
39+
var aDictionary = asDictionary(obj);
40+
var aCollection = asCollection(obj);
41+
42+
if (aDictionary != null)
43+
foreach(var kvp in aDictionary) {
44+
code += kvp.Key.GetHashCode();
45+
code += GetHashCode(kvp.Value);
46+
}
47+
else if (aCollection != null)
48+
foreach(var item in aCollection)
49+
code += GetHashCode(item);
50+
else
51+
code += obj.GetHashCode();
52+
53+
return code;
54+
}
55+
56+
/// <summary>
57+
///
58+
/// There is no pre-given implementation of .Equals
59+
/// that deeply compares based on value instead of
60+
/// reference. The standard .Equals only returns
61+
/// true if the two Dictionaries are the same object
62+
///
63+
/// </summary>
64+
/// <param name="a"></param>
65+
/// <param name="b"></param>
66+
/// <returns></returns>
67+
/// <remarks></remarks>
68+
public static bool CollectionsAreEqual(object a, object b)
69+
{
70+
if ((a.Equals(b)))
71+
return true;
72+
if ((a == null | b == null))
73+
return true;
74+
var aCollection = asCollection(a);
75+
var bCollection = asCollection(b);
76+
if (aCollection != null && bCollection != null
77+
&& aCollection.Count() != bCollection.Count())
78+
return false;
79+
if ((!a.GetType().Equals(b.GetType())))
80+
return false;
81+
82+
var aDictionary = asDictionary(a);
83+
if (aDictionary != null)
84+
return CollectionDictionariesAreEqualHelper(
85+
aDictionary, asDictionary(b)
86+
);
87+
88+
var aList = asList(a);
89+
if (aList != null)
90+
return CollectionListsAreEqualHelper(
91+
aList, asList(b)
92+
);
93+
94+
if (aCollection != null)
95+
return CollectionListsAreEqualHelper(
96+
aCollection.ToList(), bCollection.ToList()
97+
);
98+
99+
// Nothing to iterate over, we should have returned before getting here
100+
return a.Equals(b);
101+
}
102+
103+
private static bool CollectionDictionariesAreEqualHelper(Dictionary<string, object> a, Dictionary<string, object> b)
104+
{
105+
bool result = true;
106+
107+
foreach (KeyValuePair<string, object> kvp in a)
108+
{
109+
object valueA = kvp.Value;
110+
object valueB;
111+
112+
// if the second dictionary has the key
113+
if ((!b.TryGetValue(kvp.Key, out valueB)))
114+
return false;
115+
116+
// We don't care what a and b are, but the CollectionsAreEqual
117+
// Function should take care of every case of object
118+
result = (result & CollectionsAreEqual(valueA, valueB));
119+
120+
// Terminate if this loop caused an inequality
121+
if ((!result))
122+
return false;
123+
}
124+
125+
return result;
126+
}
127+
128+
private static bool CollectionListsAreEqualHelper(List<object> a, List<object> b)
129+
{
130+
bool result = true;
131+
132+
int i;
133+
for (i = 0; i <= a.Count - 1; i++)
134+
{
135+
object valueA = a[i];
136+
object valueB = b[i];
137+
138+
// We don't care what a and b are, but the CollectionsAreEqual
139+
// Function should take care of every case of object
140+
result = (result & CollectionsAreEqual(valueA, valueB));
141+
if ((!result))
142+
return false;
143+
}
144+
145+
return result;
146+
}
147+
}
148+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Destination.cs
3+
//
4+
// This file is auto-generated by Amplitude.
5+
// To update run 'ampli pull visual-studio-plugin'
6+
//
7+
// Questions? We're here to help:
8+
// https://developers.data.amplitude.com/dotnet
9+
//
10+
11+
using System;
12+
13+
namespace Iteratively
14+
{
15+
public interface IDestination : IDisposable
16+
{
17+
void Init();
18+
void Alias(string userId, string previousId);
19+
void Identify(string userId, Properties properties);
20+
void Group(string userId, string groupId, Properties properties);
21+
void Track(string userId, string eventName, Properties properties);
22+
}
23+
24+
internal interface IClientDestination : IDestination
25+
{
26+
object Client();
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Destinations/Custom.cs
3+
//
4+
// This file is auto-generated by Amplitude.
5+
// To update run 'ampli pull visual-studio-plugin'
6+
//
7+
// Questions? We're here to help:
8+
// https://developers.data.amplitude.com/dotnet
9+
//
10+
11+
using System;
12+
13+
namespace Iteratively
14+
{
15+
public sealed class CustomOptions
16+
{
17+
public IDestination Adapter { get; }
18+
19+
public CustomOptions(IDestination adapter)
20+
{
21+
if (adapter == null)
22+
throw new ArgumentNullException(nameof(adapter));
23+
24+
Adapter = adapter;
25+
}
26+
}
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Environment.cs
3+
//
4+
// This file is auto-generated by Amplitude.
5+
// To update run 'ampli pull visual-studio-plugin'
6+
//
7+
// Questions? We're here to help:
8+
// https://developers.data.amplitude.com/dotnet
9+
//
10+
11+
namespace Iteratively
12+
{
13+
public enum Environment
14+
{
15+
Development,
16+
Production
17+
}
18+
}

Snyk.Analytics.Itly/Itly/Event.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Event.cs
3+
//
4+
// This file is auto-generated by Amplitude.
5+
// To update run 'ampli pull visual-studio-plugin'
6+
//
7+
// Questions? We're here to help:
8+
// https://developers.data.amplitude.com/dotnet
9+
//
10+
11+
using System.Collections.Generic;
12+
13+
namespace Iteratively
14+
{
15+
/// <summary>
16+
/// Base class for all Events.
17+
/// </summary>
18+
public abstract class Event : Properties
19+
{
20+
internal string Name { get; }
21+
internal string Schema { get; }
22+
23+
protected Event(string name, string schema, Dictionary<string, object> properties = null)
24+
: base(properties)
25+
{
26+
Name = name;
27+
Schema = schema;
28+
}
29+
30+
public override bool Equals(object obj)
31+
{
32+
if (obj == null || GetType() != obj.GetType())
33+
return false;
34+
35+
var other = (Event) obj;
36+
37+
return Name == other.Name
38+
&& Schema == other.Schema
39+
&& base.Equals(other as Properties);
40+
}
41+
42+
public override int GetHashCode() =>
43+
Name.GetHashCode() + Schema.GetHashCode() + base.GetHashCode();
44+
}
45+
}

Snyk.Analytics.Itly/Itly/Ide.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Collections.Generic;
2+
3+
namespace Iteratively
4+
{
5+
public enum Ide
6+
{
7+
VisualStudioCode,
8+
VisualStudio,
9+
Eclipse,
10+
JetBrains
11+
}
12+
13+
public static class IdeExtensions
14+
{
15+
private static readonly Dictionary<Ide, string> IdeValues = new Dictionary<Ide, string>
16+
{
17+
[Ide.VisualStudioCode] = "Visual Studio Code",
18+
[Ide.VisualStudio] = "Visual Studio",
19+
[Ide.Eclipse] = "Eclipse",
20+
[Ide.JetBrains] = "JetBrains"
21+
};
22+
23+
public static string ToString(this Ide ide) => IdeValues[ide];
24+
}
25+
}

0 commit comments

Comments
 (0)