-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLanguageRepository.cs
More file actions
65 lines (52 loc) · 1.76 KB
/
LanguageRepository.cs
File metadata and controls
65 lines (52 loc) · 1.76 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
65
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.Threading;
namespace ColorCode.Common
{
public class LanguageRepository : ILanguageRepository
{
private readonly Dictionary<string, ILanguage> loadedLanguages;
private readonly ReaderWriterLockSlim loadLock;
public LanguageRepository(Dictionary<string, ILanguage> loadedLanguages)
{
this.loadedLanguages = loadedLanguages;
loadLock = new ReaderWriterLockSlim();
}
public IEnumerable<ILanguage> All
{
get { return loadedLanguages.Values; }
}
public ILanguage FindById(string languageId)
{
Guard.ArgNotNullAndNotEmpty(languageId, "languageId");
ILanguage language = null;
loadLock.EnterReadLock();
try
{
if (loadedLanguages.ContainsKey(languageId))
language = loadedLanguages[languageId];
}
finally
{
loadLock.ExitReadLock();
}
return language;
}
public void Load(ILanguage language)
{
Guard.ArgNotNull(language, "language");
if (string.IsNullOrEmpty(language.Id))
throw new ArgumentException("The language identifier must not be null or empty.", "language");
loadLock.EnterWriteLock();
try
{
loadedLanguages[language.Id] = language;
}
finally
{
loadLock.ExitWriteLock();
}
}
}
}