-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSparkObjectFactory.cs
53 lines (52 loc) · 1.83 KB
/
SparkObjectFactory.cs
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
using System;
namespace Cisco.Spark
{
class SparkObjectFactory
{
/// <summary>
/// Make a new SparkObject from an ID.
/// </summary>
/// <param name="id">The ID of the SparkObject</param>
/// <param name="type">The SparkType of the SparkObject.</param>
/// <returns>The created/cached SparkObject instance.</returns>
internal static SparkObject Make(string id, SparkType type)
{
SparkObject output;
// If the object hasn't been cached, create it.
if (!SparkObject._LocalCache.TryGetValue(id, out output))
{
switch (type)
{
case SparkType.Membership:
output = new Membership();
break;
case SparkType.Message:
output = new Message();
break;
case SparkType.Person:
output = new Person();
break;
case SparkType.Room:
output = new Room();
break;
case SparkType.Team:
output = new Team();
break;
case SparkType.TeamMembership:
output = new TeamMembership();
break;
case SparkType.Webhook:
output = new Webhook();
break;
default:
throw new ArgumentException("Unsupported SparkType");
}
// Set Id.
output.Id = id;
// Cache.
SparkObject._LocalCache.Add(id, output);
}
return output;
}
}
}