17 using System.Collections.Generic;
19 using erminas.SmartAPI.CMS;
21 namespace erminas.SmartAPI.Utils.CachedCollections
23 public interface IIndexedRDList<in TK, T> : IIndexedCachedList<TK, T>, IRDList<T> where T : class,
IRedDotObject
25 new IIndexedRDList<TK, T> Refreshed();
26 void WaitFor(Func<IIndexedRDList<TK, T>,
bool> predicate, TimeSpan maxWait, TimeSpan retryEverySecond);
29 public class IndexedRDList<TK, T> : IndexedCachedList<TK, T>, IIndexedRDList<TK, T> where T : class,
IRedDotObject
31 public IndexedRDList(Func<List<T>> retrieveFunc, Func<T, TK> indexFunc,
Caching caching)
32 : base(retrieveFunc, indexFunc, caching)
36 protected IndexedRDList(Func<T, TK> indexFunc,
Caching caching) : base(indexFunc, caching)
40 public bool Contains(T element)
42 return ContainsGuid(element.Guid);
45 public bool ContainsGuid(Guid guid)
48 return TryGetByGuid(guid, out tmp);
51 public bool ContainsName(
string name)
54 return TryGetByName(name, out tmp);
57 public virtual T GetByGuid(Guid guid)
60 return List.First(x => x.Guid == guid);
63 public virtual T GetByName(
string name)
66 return List.First(x => x.Name == name);
69 public new IIndexedRDList<TK, T> Refreshed()
75 public virtual bool TryGetByGuid(Guid guid, out T output)
78 output = List.FirstOrDefault(x => x.Guid == guid);
79 return output != null;
82 public virtual bool TryGetByName(
string name, out T output)
85 output = List.FirstOrDefault(x => x.Name == name);
86 return output != null;
89 public void WaitFor(Func<IIndexedRDList<TK, T>,
bool> predicate, TimeSpan maxWait, TimeSpan retryPeriod)
91 Wait.For(() => predicate(Refreshed()), maxWait, retryPeriod);
94 public void WaitFor(Predicate<
IRDList<T>> predicate, TimeSpan maxWait, TimeSpan retryPeriod)
96 Wait.For(() => predicate(Refreshed()), maxWait, retryPeriod);
110 public class NameIndexedRDList<T> : IndexedRDList<String, T> where T : class,
IRedDotObject
112 public NameIndexedRDList(Func<List<T>> retrieveFunc,
Caching caching) : base(retrieveFunc, x => x.Name, caching)
116 protected NameIndexedRDList(
Caching caching) : base(x => x.Name, caching)
120 public override T GetByName(
string name)
131 public override bool TryGetByName(
string name, out T output)
133 return TryGet(name, out output);
141 public class GuidIndexedRDList<T> : IndexedRDList<Guid, T> where T : class,
IRedDotObject
143 public GuidIndexedRDList(Func<List<T>> retrieveFunc,
Caching caching) : base(retrieveFunc, x => x.Guid, caching)
147 protected GuidIndexedRDList(
Caching caching) : base(x => x.Guid, caching)
151 public override T GetByGuid(Guid guid)
162 public override bool TryGetByGuid(Guid guid, out T output)
164 return TryGet(guid, out output);