blob: 6e36c417d0cebcbb94b12332a7710bceea594788 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.DAL.Observables
{
/// <summary>
/// Represents a service responsible for caching the collection all loaded observable entities.
/// </summary>
internal static class LoadedEntitiesService
{
private static List<KeyValuePair<String, IObservableEntity>> LoadedObjects; //Holds the collection of cached entities.
/// <summary>
/// Initializes the <see cref="LoadedEntitiesService"/> class.
/// </summary>
static LoadedEntitiesService()
{
LoadedObjects = new List<KeyValuePair<String, IObservableEntity>>();
}
/// <summary>
/// Gets the loaded entity by the specified entity guid.
/// </summary>
/// <param name="guid">The unique identifier.</param>
/// <returns></returns>
public static Object Get(String guid)
{
return LoadedObjects.SingleOrDefault(x => x.Key == guid).Value;
}
/// <summary>
/// Adds the specified observable entity.
/// </summary>
/// <param name="guid">The unique identifier.</param>
/// <param name="observable">The observable.</param>
public static void Add(String guid, IObservableEntity observable)
{
if (!LoadedObjects.Exists(x => x.Key == guid))
{
LoadedObjects.Add(new KeyValuePair<string, IObservableEntity>(guid, observable));
}
}
/// <summary>
/// Determines whether the specified observable entity is loaded.
/// </summary>
/// <param name="guid">The unique identifier.</param>
/// <returns></returns>
public static bool IsLoaded(String guid)
{
return LoadedObjects.Exists(x => x.Key == guid);
}
/// <summary>
/// Resets the entities cache.
/// </summary>
public static void Reset()
{
LoadedObjects.Clear();
}
}
}
|