Repository navigation
Expand file tree
/
Copy pathLocalizationService.cs
More file actions
782 lines (653 loc) · 24 KB
/
Copy pathLocalizationService.cs
File metadata and controls
782 lines (653 loc) · 24 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using SmartStore.Core;
using SmartStore.Core.Caching;
using SmartStore.Core.Data;
using SmartStore.Core.Domain.DataExchange;
using SmartStore.Core.Domain.Localization;
using SmartStore.Core.Events;
using SmartStore.Core.Logging;
using SmartStore.Core.Plugins;
using SmartStore.Core.Localization;
using System.Globalization;
namespace SmartStore.Services.Localization
{
public partial class LocalizationService : ILocalizationService
{
/// <summary>
/// 0 = segment (first 3 chars of key), 1 = language id
/// </summary>
const string LOCALESTRINGRESOURCES_SEGMENT_KEY = "localization:{0}-lang-{1}";
const string LOCALESTRINGRESOURCES_SEGMENT_PATTERN = "localization:{0}*";
private readonly IRepository<LocaleStringResource> _lsrRepository;
private readonly IWorkContext _workContext;
private readonly ILogger _logger;
private readonly ILanguageService _languageService;
private readonly ICacheManager _cacheManager;
private readonly IDbContext _dbContext;
private readonly IEventPublisher _eventPublisher;
private int _notFoundLogCount = 0;
private int? _defaultLanguageId;
public LocalizationService(
ICacheManager cacheManager,
ILogger logger,
IWorkContext workContext,
IRepository<LocaleStringResource> lsrRepository,
ILanguageService languageService,
IEventPublisher eventPublisher)
{
_cacheManager = cacheManager;
_logger = logger;
_workContext = workContext;
_lsrRepository = lsrRepository;
_languageService = languageService;
_dbContext = lsrRepository.Context;
_eventPublisher = eventPublisher;
}
public virtual void DeleteLocaleStringResource(LocaleStringResource resource)
{
Guard.NotNull(resource, nameof(resource));
// cache
ClearCacheSegment(resource.ResourceName, resource.LanguageId);
// db
_lsrRepository.Delete(resource);
}
public virtual int DeleteLocaleStringResources(string key, bool keyIsRootKey = true) {
int result = 0;
if (key.HasValue())
{
try
{
var sqlDelete = "Delete From LocaleStringResource Where ResourceName Like '{0}%'".FormatWith(key.EndsWith(".") || !keyIsRootKey ? key : key + ".");
result = _dbContext.ExecuteSqlCommand(sqlDelete);
ClearCacheSegment(key);
}
catch (Exception exc)
{
exc.Dump();
}
}
return result;
}
public virtual LocaleStringResource GetLocaleStringResourceById(int localeStringResourceId)
{
if (localeStringResourceId == 0)
return null;
var localeStringResource = _lsrRepository.GetById(localeStringResourceId);
return localeStringResource;
}
public virtual LocaleStringResource GetLocaleStringResourceByName(string resourceName)
{
if (_workContext.WorkingLanguage != null)
return GetLocaleStringResourceByName(resourceName, _workContext.WorkingLanguage.Id);
return null;
}
public virtual LocaleStringResource GetLocaleStringResourceByName(string resourceName, int languageId, bool logIfNotFound = true)
{
var query = from lsr in _lsrRepository.Table
orderby lsr.ResourceName
where lsr.LanguageId == languageId && lsr.ResourceName == resourceName
select lsr;
var localeStringResource = query.FirstOrDefault();
if (localeStringResource == null && logIfNotFound)
_logger.Warn(string.Format("Resource string ({0}) not found. Language ID = {1}", resourceName, languageId));
return localeStringResource;
}
public virtual IQueryable<LocaleStringResource> All(int languageId)
{
var query = from lsr in _lsrRepository.Table
orderby lsr.ResourceName
where lsr.LanguageId == languageId
select lsr;
return query;
}
public virtual IList<LocaleStringResource> GetResourcesByPattern(string pattern, int languageId)
{
Guard.NotEmpty(pattern, nameof(pattern));
var query = from l in _lsrRepository.Table
where l.ResourceName.StartsWith(pattern) && l.LanguageId == languageId
select l;
var resources = query.ToList();
return resources;
}
public virtual void InsertLocaleStringResource(LocaleStringResource resource)
{
Guard.NotNull(resource, nameof(resource));
_lsrRepository.Insert(resource);
// cache
ClearCacheSegment(resource.ResourceName, resource.LanguageId);
}
public virtual void UpdateLocaleStringResource(LocaleStringResource resource)
{
Guard.NotNull(resource, nameof(resource));
// cache
object origKey = null;
if (_dbContext.TryGetModifiedProperty(resource, "ResourceName", out origKey))
{
ClearCacheSegment((string)origKey, resource.LanguageId);
}
ClearCacheSegment(resource.ResourceName, resource.LanguageId);
_lsrRepository.Update(resource);
}
protected virtual IDictionary<string, string> GetCacheSegment(string forKey, int languageId)
{
Guard.NotEmpty(forKey, nameof(forKey));
var segmentKey = GetSegmentKeyPart(forKey);
var cacheKey = BuildCacheSegmentKey(segmentKey, languageId);
return _cacheManager.Get(cacheKey, () =>
{
var resources = _lsrRepository.TableUntracked
.Where(x => x.ResourceName.StartsWith(segmentKey) && x.LanguageId == languageId)
//.OrderBy(x => x.ResourceName)
.ToList();
var dict = new Dictionary<string, string>(resources.Count);
foreach (var res in resources)
{
dict[res.ResourceName.ToLowerInvariant()] = res.ResourceValue;
}
return dict;
});
}
/// <summary>
/// Clears the cached resource segment from the cache
/// </summary>
/// <param name="forKey">The resource key for which a segment key should be created</param>
/// <param name="languageId">Language Id. If <c>null</c>, segments for all cached languages will be invalidated</param>
protected virtual void ClearCacheSegment(string forKey, int? languageId = null)
{
var segmentKey = GetSegmentKeyPart(forKey);
if (languageId.HasValue && languageId.Value > 0)
{
_cacheManager.Remove(BuildCacheSegmentKey(segmentKey, languageId.Value));
}
else
{
_cacheManager.RemoveByPattern(LOCALESTRINGRESOURCES_SEGMENT_PATTERN.FormatInvariant(segmentKey));
}
}
public virtual string GetResource(
string resourceKey,
int languageId = 0,
bool logIfNotFound = true,
string defaultValue = "",
bool returnEmptyIfNotFound = false)
{
if (languageId <= 0)
{
if (_workContext.WorkingLanguage == null)
{
return defaultValue;
}
languageId = _workContext.WorkingLanguage.Id;
}
string result = string.Empty;
resourceKey = resourceKey.EmptyNull().Trim().ToLowerInvariant();
var cachedSegment = GetCacheSegment(resourceKey, languageId);
if (!cachedSegment.TryGetValue(resourceKey, out result))
{
if (logIfNotFound)
{
if (_notFoundLogCount < 50)
{
_logger.Warn(string.Format("Resource string ({0}) does not exist. Language ID = {1}", resourceKey, languageId));
}
else if (_notFoundLogCount == 50)
{
_logger.Warn("Too many language resources do not exist (> 50). Stopped logging missing resources to prevent performance drop.");
}
_notFoundLogCount++;
}
if (!String.IsNullOrEmpty(defaultValue))
{
result = defaultValue;
}
else
{
// try fallback to default language
if (!_defaultLanguageId.HasValue)
{
_defaultLanguageId = _languageService.GetDefaultLanguageId();
}
var defaultLangId = _defaultLanguageId.Value;
if (defaultLangId > 0 && defaultLangId != languageId)
{
var fallbackResult = GetResource(resourceKey, defaultLangId, false, resourceKey);
if (fallbackResult != resourceKey)
{
result = fallbackResult;
}
}
if (!returnEmptyIfNotFound && result.IsEmpty())
{
result = resourceKey;
}
}
}
return result;
}
public virtual string ExportResourcesToXml(Language language)
{
Guard.NotNull(language, nameof(language));
var sb = new StringBuilder();
var stringWriter = new StringWriter(sb);
var xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Language");
xmlWriter.WriteAttributeString("Name", language.Name);
using (var scope = new DbContextScope(forceNoTracking: true))
{
var resources = All(language.Id).ToList();
foreach (var resource in resources)
{
if (resource.IsFromPlugin.GetValueOrDefault() == false)
{
xmlWriter.WriteStartElement("LocaleResource");
xmlWriter.WriteAttributeString("Name", resource.ResourceName);
xmlWriter.WriteElementString("Value", null, resource.ResourceValue);
xmlWriter.WriteEndElement();
}
}
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
return stringWriter.ToString();
}
public virtual void ImportPluginResourcesFromXml(
PluginDescriptor pluginDescriptor,
IList<LocaleStringResource> targetList = null,
bool updateTouchedResources = true,
IList<Language> filterLanguages = null)
{
var directory = new DirectoryInfo(Path.Combine(pluginDescriptor.OriginalAssemblyFile.Directory.FullName, "Localization"));
if (!directory.Exists)
return;
if (targetList == null && updateTouchedResources)
{
DeleteLocaleStringResources(pluginDescriptor.ResourceRootKey);
}
var unprocessedLanguages = new List<Language>();
var defaultLanguageId = _languageService.GetDefaultLanguageId();
var languages = filterLanguages ?? _languageService.GetAllLanguages(true);
string code = null;
foreach (var language in languages)
{
code = ImportPluginResourcesForLanguage(
language,
null,
directory,
pluginDescriptor.ResourceRootKey,
targetList,
updateTouchedResources,
false);
if (code == null)
{
unprocessedLanguages.Add(language);
}
}
if (filterLanguages == null && unprocessedLanguages.Count > 0)
{
// There were unprocessed languages (no corresponding resource file could be found).
// In order for GetResource() to be able to gracefully fallback to the default language's resources,
// we need to import resources for the current default language....
var processedLanguages = languages.Except(unprocessedLanguages).ToList();
if (!processedLanguages.Any(x => x.Id == defaultLanguageId))
{
// ...but only if no resource file could be mapped to the default language before,
// namely because in this case the following operation would be redundant.
var defaultLanguage = _languageService.GetLanguageById(_languageService.GetDefaultLanguageId());
if (defaultLanguage != null)
{
ImportPluginResourcesForLanguage(
defaultLanguage,
"en-us",
directory,
pluginDescriptor.ResourceRootKey,
targetList,
updateTouchedResources,
true);
}
}
}
}
private string ImportPluginResourcesForLanguage(
Language language,
string fileCode,
DirectoryInfo directory,
string resourceRootKey,
IList<LocaleStringResource> targetList,
bool updateTouchedResources,
bool canFallBackToAnyResourceFile)
{
var fileNamePattern = "resources.{0}.xml";
var codeCandidates = GetResourceFileCodeCandidates(
fileCode ?? language.LanguageCulture,
directory,
canFallBackToAnyResourceFile);
string path = null;
string code = null;
foreach (var candidate in codeCandidates)
{
var pathCandidate = Path.Combine(directory.FullName, fileNamePattern.FormatInvariant(candidate));
if (File.Exists(pathCandidate))
{
code = candidate;
path = pathCandidate;
break;
}
}
if (code != null)
{
var doc = new XmlDocument();
doc.Load(path);
doc = FlattenResourceFile(doc);
if (targetList == null)
{
ImportResourcesFromXml(language, doc, resourceRootKey, true, updateTouchedResources: updateTouchedResources);
}
else
{
var nodes = doc.SelectNodes(@"//Language/LocaleResource");
foreach (XmlNode node in nodes)
{
var valueNode = node.SelectSingleNode("Value");
var res = new LocaleStringResource
{
ResourceName = node.Attributes["Name"].InnerText.Trim(),
ResourceValue = (valueNode == null ? "" : valueNode.InnerText),
LanguageId = language.Id,
IsFromPlugin = true
};
if (res.ResourceName.HasValue())
{
targetList.Add(res);
}
}
}
}
return code;
}
private IEnumerable<string> GetResourceFileCodeCandidates(string code, DirectoryInfo directory, bool canFallBackToAnyResourceFile)
{
// exact match (de-DE)
yield return code;
// neutral culture (de)
var ci = CultureInfo.GetCultureInfo(code);
if (ci.Parent != null && !ci.IsNeutralCulture)
{
code = ci.Parent.Name;
yield return code;
}
var rgFileName = new Regex("^resources.(.+?).xml$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
// any other region with same language (de-*)
foreach (var fi in directory.EnumerateFiles("resources.{0}-*.xml".FormatInvariant(code), SearchOption.TopDirectoryOnly))
{
code = rgFileName.Match(fi.Name).Groups[1].Value;
if (LocalizationHelper.IsValidCultureCode(code))
{
yield return code;
yield break;
}
}
if (canFallBackToAnyResourceFile)
{
foreach (var fi in directory.EnumerateFiles("resources.*.xml", SearchOption.TopDirectoryOnly))
{
code = rgFileName.Match(fi.Name).Groups[1].Value;
if (LocalizationHelper.IsValidCultureCode(code))
{
yield return code;
yield break;
}
}
}
}
public virtual int ImportResourcesFromXml(
Language language,
XmlDocument xmlDocument,
string rootKey = null,
bool sourceIsPlugin = false,
ImportModeFlags mode = ImportModeFlags.Insert | ImportModeFlags.Update,
bool updateTouchedResources = false)
{
using (var scope = new DbContextScope(autoDetectChanges: false, proxyCreation: false, validateOnSave: false, autoCommit: false, forceNoTracking: true, hooksEnabled: false))
{
var toAdd = new List<LocaleStringResource>();
var toUpdate = new List<LocaleStringResource>();
var nodes = xmlDocument.SelectNodes(@"//Language/LocaleResource");
var resources = language.LocaleStringResources.ToDictionarySafe(x => x.ResourceName, StringComparer.OrdinalIgnoreCase);
LocaleStringResource resource;
foreach (var xel in nodes.Cast<XmlElement>())
{
string name = xel.GetAttribute("Name").TrimSafe();
string value = "";
var valueNode = xel.SelectSingleNode("Value");
if (valueNode != null)
value = valueNode.InnerText;
if (String.IsNullOrEmpty(name))
continue;
if (rootKey.HasValue())
{
if (!xel.GetAttributeText("AppendRootKey").IsCaseInsensitiveEqual("false"))
name = "{0}.{1}".FormatWith(rootKey, name);
}
resource = null;
// do not use "Insert"/"Update" methods because they clear cache
// let's bulk insert
//var resource = language.LocaleStringResources.Where(x => x.ResourceName.Equals(name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
if (resources.TryGetValue(name, out resource))
{
if (mode.HasFlag(ImportModeFlags.Update))
{
if (updateTouchedResources || !resource.IsTouched.GetValueOrDefault())
{
if (value != resource.ResourceValue)
{
resource.ResourceValue = value;
resource.IsTouched = null;
toUpdate.Add(resource);
}
}
}
}
else
{
if (mode.HasFlag(ImportModeFlags.Insert))
{
toAdd.Add(
new LocaleStringResource
{
LanguageId = language.Id,
ResourceName = name,
ResourceValue = value,
IsFromPlugin = sourceIsPlugin
});
}
}
}
//_lsrRepository.AutoCommitEnabled = true;
if (toAdd.Any() || toUpdate.Any())
{
var segmentKeys = new HashSet<string>();
toAdd.Each(x => segmentKeys.Add(GetSegmentKeyPart(x.ResourceName)));
toUpdate.Each(x => segmentKeys.Add(GetSegmentKeyPart(x.ResourceName)));
_lsrRepository.InsertRange(toAdd);
toAdd.Clear();
_lsrRepository.UpdateRange(toUpdate);
toUpdate.Clear();
int num = _lsrRepository.Context.SaveChanges();
// clear cache
foreach (var segmentKey in segmentKeys)
{
ClearCacheSegment(segmentKey, language.Id);
}
return num;
}
return 0;
}
}
public virtual XmlDocument FlattenResourceFile(XmlDocument source)
{
Guard.NotNull(source, nameof(source));
if (source.SelectNodes("//Children").Count == 0)
{
// the document contains absolutely NO nesting,
// so don't bother parsing.
return source;
}
var resources = new List<LocaleStringResourceParent>();
foreach (XmlNode resNode in source.SelectNodes(@"//Language/LocaleResource"))
{
resources.Add(new LocaleStringResourceParent(resNode));
}
resources.Sort((x1, x2) => x1.ResourceName.CompareTo(x2.ResourceName));
foreach (var resource in resources)
{
RecursivelySortChildrenResource(resource);
}
var sb = new StringBuilder();
using (var writer = XmlWriter.Create(sb))
{
writer.WriteStartDocument();
writer.WriteStartElement("Language", "");
writer.WriteStartAttribute("Name", "");
writer.WriteString(source.SelectSingleNode(@"//Language").Attributes["Name"].InnerText.Trim());
writer.WriteEndAttribute();
foreach (var resource in resources)
{
RecursivelyWriteResource(resource, writer, null);
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
var result = new XmlDocument();
result.LoadXml(sb.ToString());
return result;
}
private void RecursivelyWriteResource(LocaleStringResourceParent resource, XmlWriter writer, bool? parentAppendRootKey)
{
//The value isn't actually used, but the name is used to create a namespace.
if (resource.IsPersistable)
{
writer.WriteStartElement("LocaleResource", "");
writer.WriteStartAttribute("Name", "");
writer.WriteString(resource.NameWithNamespace);
writer.WriteEndAttribute();
if (resource.AppendRootKey.HasValue)
{
writer.WriteStartAttribute("AppendRootKey", "");
writer.WriteString(resource.AppendRootKey.Value ? "true" : "false");
writer.WriteEndAttribute();
parentAppendRootKey = resource.AppendRootKey;
}
else if (parentAppendRootKey.HasValue)
{
writer.WriteStartAttribute("AppendRootKey", "");
writer.WriteString(parentAppendRootKey.Value ? "true" : "false");
writer.WriteEndAttribute();
}
writer.WriteStartElement("Value", "");
writer.WriteString(resource.ResourceValue);
writer.WriteEndElement();
writer.WriteEndElement();
}
foreach (var child in resource.ChildLocaleStringResources)
{
RecursivelyWriteResource(child, writer, resource.AppendRootKey ?? parentAppendRootKey);
}
}
private void RecursivelySortChildrenResource(LocaleStringResourceParent resource)
{
ArrayList.Adapter((IList)resource.ChildLocaleStringResources).Sort(new LocalizationService.ComparisonComparer<LocaleStringResourceParent>((x1, x2) => x1.ResourceName.CompareTo(x2.ResourceName)));
foreach (var child in resource.ChildLocaleStringResources)
{
RecursivelySortChildrenResource(child);
}
}
private string BuildCacheSegmentKey(string segment, int languageId)
{
return String.Format(LOCALESTRINGRESOURCES_SEGMENT_KEY, segment, languageId);
}
private string GetSegmentKeyPart(string forKey)
{
return forKey.Substring(0, Math.Min(forKey.Length, 3)).ToLowerInvariant();
}
private class LocaleStringResourceParent : LocaleStringResource
{
public LocaleStringResourceParent(XmlNode localStringResource, string nameSpace = "")
{
Namespace = nameSpace;
var resNameAttribute = localStringResource.Attributes["Name"];
var resValueNode = localStringResource.SelectSingleNode("Value");
if (resNameAttribute == null)
{
throw new SmartException("All language resources must have an attribute Name=\"Value\".");
}
var resName = resNameAttribute.Value.Trim();
if (string.IsNullOrEmpty(resName))
{
throw new SmartException("All languages resource attributes 'Name' must have a value.'");
}
ResourceName = resName;
var appendRootKeyAttribute = localStringResource.Attributes["AppendRootKey"];
if (appendRootKeyAttribute != null)
{
AppendRootKey = appendRootKeyAttribute.Value.ToBool(true);
}
if (resValueNode == null || string.IsNullOrEmpty(resValueNode.InnerText.Trim()))
{
IsPersistable = false;
}
else
{
IsPersistable = true;
ResourceValue = resValueNode.InnerText.Trim();
}
foreach (XmlNode childResource in localStringResource.SelectNodes("Children/LocaleResource"))
{
ChildLocaleStringResources.Add(new LocaleStringResourceParent(childResource, NameWithNamespace));
}
}
public string Namespace { get; set; }
public IList<LocaleStringResourceParent> ChildLocaleStringResources = new List<LocaleStringResourceParent>();
public bool IsPersistable { get; set; }
public bool? AppendRootKey { get; set; }
public string NameWithNamespace
{
get
{
var newNamespace = Namespace;
if (!string.IsNullOrEmpty(newNamespace))
{
newNamespace += ".";
}
return newNamespace + ResourceName;
}
}
}
private class ComparisonComparer<T> : IComparer<T>, IComparer
{
private readonly Comparison<T> _comparison;
public ComparisonComparer(Comparison<T> comparison)
{
_comparison = comparison;
}
public int Compare(T x, T y)
{
return _comparison(x, y);
}
public int Compare(object o1, object o2)
{
return _comparison((T)o1, (T)o2);
}
}
}
}