Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Database.cs
1using System;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Events;
13
14namespace Waher.Persistence
15{
20 public static class Database
21 {
22 private static readonly Dictionary<string, Dictionary<string, FlagSource>> toRepair = new Dictionary<string, Dictionary<string, FlagSource>>();
23 private static IDatabaseProvider provider = null;
24 private static bool locked = false;
25
33 public static void Register(IDatabaseProvider DatabaseProvider)
34 {
35 Register(DatabaseProvider, true);
36 }
37
46 public static void Register(IDatabaseProvider DatabaseProvider, bool Lock)
47 {
48 if (!(provider is null) && locked)
49 throw new Exception("A database provider is already registered.");
50
51 provider = DatabaseProvider;
52 locked = Lock;
53 }
54
59 {
60 get
61 {
62 if (!(provider is null))
63 return provider;
64 else
65 throw new Exception("A database provider has not been registered.");
66 }
67 }
68
69 internal static IDatabaseProvider Stop()
70 {
71 IDatabaseProvider Result = provider;
72 provider = new NullDatabaseProvider();
73 locked = false;
74 return Result;
75 }
76
80 public static bool HasProvider
81 {
82 get => !(provider is null) && (!(provider is NullDatabaseProvider) || locked);
83 }
84
88 public static bool Locked
89 {
90 get { return locked; }
91 }
92
97 public async static Task Insert(object Object)
98 {
99 await Provider.Insert(Object);
100 RaiseInserted(Object);
101 }
102
103 private static void RaiseInserted(object Object)
104 {
105 ObjectInserted?.Raise(Provider, new ObjectEventArgs(Object));
106 }
107
108 private static void RaiseInserted(IEnumerable<object> Objects)
109 {
110 foreach (object Object in Objects)
111 RaiseInserted(Object);
112 }
113
117 public static event EventHandler<ObjectEventArgs> ObjectInserted = null;
118
123 public async static Task Insert(params object[] Objects)
124 {
125 if (Objects.Length == 1)
126 await Provider.Insert(Objects[0]);
127 else
128 await Provider.Insert(Objects);
129
130 RaiseInserted(Objects);
131 }
132
137 public async static Task Insert(IEnumerable<object> Objects)
138 {
139 await Provider.Insert(Objects);
140 RaiseInserted(Objects);
141 }
142
147 public static async Task InsertLazy(object Object)
148 {
149 await Provider.InsertLazy(Object, RaiseInserted);
150 }
151
156 public static async Task InsertLazy(params object[] Objects)
157 {
158 if (Objects.Length == 1)
159 await Provider.InsertLazy(Objects[0], RaiseInserted);
160 else
161 await Provider.InsertLazy(Objects, RaiseInserted);
162 }
163
168 public static async Task InsertLazy(IEnumerable<object> Objects)
169 {
170 await Provider.InsertLazy(Objects, RaiseInserted);
171 }
172
180 public static Task<IEnumerable<T>> Find<T>(params string[] SortOrder)
181 where T : class
182 {
183 return Provider.Find<T>(0, int.MaxValue, SortOrder);
184 }
185
194 public static Task<IEnumerable<T>> Find<T>(Filter Filter, params string[] SortOrder)
195 where T : class
196 {
197 return Provider.Find<T>(0, int.MaxValue, Filter, SortOrder);
198 }
199
209 public static Task<IEnumerable<T>> Find<T>(int Offset, int MaxCount, params string[] SortOrder)
210 where T : class
211 {
212 return Provider.Find<T>(Offset, MaxCount, SortOrder);
213 }
214
225 public static Task<IEnumerable<T>> Find<T>(int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
226 where T : class
227 {
228 return Provider.Find<T>(Offset, MaxCount, Filter, SortOrder);
229 }
230
238 public static Task<IEnumerable<object>> Find(string Collection, params string[] SortOrder)
239 {
240 return Provider.Find(Collection, 0, int.MaxValue, SortOrder);
241 }
242
251 public static Task<IEnumerable<object>> Find(string Collection, Filter Filter, params string[] SortOrder)
252 {
253 return Provider.Find(Collection, 0, int.MaxValue, Filter, SortOrder);
254 }
255
265 public static Task<IEnumerable<object>> Find(string Collection, int Offset, int MaxCount, params string[] SortOrder)
266 {
267 return Provider.Find(Collection, Offset, MaxCount, SortOrder);
268 }
269
280 public static Task<IEnumerable<object>> Find(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
281 {
282 return Provider.Find(Collection, Offset, MaxCount, Filter, SortOrder);
283 }
284
293 public static Task<IEnumerable<T>> Find<T>(string Collection, string[] SortOrder) // Note: No params, to avoid confusion with Find<T>(params SortOrder)
294 where T : class
295 {
296 return Provider.Find<T>(Collection, 0, int.MaxValue, null, SortOrder);
297 }
298
308 public static Task<IEnumerable<T>> Find<T>(string Collection, Filter Filter, params string[] SortOrder)
309 where T : class
310 {
311 return Provider.Find<T>(Collection, 0, int.MaxValue, Filter, SortOrder);
312 }
313
324 public static Task<IEnumerable<T>> Find<T>(string Collection, int Offset, int MaxCount, params string[] SortOrder)
325 where T : class
326 {
327 return Provider.Find<T>(Collection, Offset, MaxCount, null, SortOrder);
328 }
329
341 public static Task<IEnumerable<T>> Find<T>(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
342 where T : class
343 {
344 return Provider.Find<T>(Collection, Offset, MaxCount, Filter, SortOrder);
345 }
346
355 public static Task<IPage<T>> FindFirst<T>(int PageSize, params string[] SortOrder)
356 where T : class
357 {
358 return Provider.FindFirst<T>(PageSize, SortOrder);
359 }
360
370 public static Task<IPage<T>> FindFirst<T>(int PageSize, Filter Filter, params string[] SortOrder)
371 where T : class
372 {
373 return Provider.FindFirst<T>(PageSize, Filter, SortOrder);
374 }
375
376
385 public static Task<IPage<object>> FindFirst(string Collection, int PageSize, params string[] SortOrder)
386 {
387 return Provider.FindFirst(Collection, PageSize, SortOrder);
388 }
389
399 public static Task<IPage<object>> FindFirst(string Collection, int PageSize, Filter Filter, params string[] SortOrder)
400 {
401 return Provider.FindFirst(Collection, PageSize, Filter, SortOrder);
402 }
403
414 public static Task<IPage<T>> FindFirst<T>(string Collection, int PageSize, Filter Filter, params string[] SortOrder)
415 where T : class
416 {
417 return Provider.FindFirst<T>(Collection, PageSize, Filter, SortOrder);
418 }
419
426 public static Task<IPage<T>> FindNext<T>(IPage<T> Page)
427 where T : class
428 {
429 return Provider.FindNext(Page);
430 }
431
437 public static Task<IPage<object>> FindNext(IPage<object> Page)
438 {
439 return Provider.FindNext(Page);
440 }
441
452 public static async Task<PaginatedEnumerator<T>> Enumerate<T>(int PageSize, params string[] SortOrder)
453 where T : class
454 {
455 return new PaginatedEnumerator<T>(await FindFirst<T>(PageSize, SortOrder));
456 }
457
467 public static async Task<PaginatedEnumerator<T>> Enumerate<T>(int PageSize, Filter Filter, params string[] SortOrder)
468 where T : class
469 {
470 return new PaginatedEnumerator<T>(await FindFirst<T>(PageSize, Filter, SortOrder));
471 }
472
473
482 public static async Task<PaginatedEnumerator<object>> Enumerate(string Collection, int PageSize, params string[] SortOrder)
483 {
484 return new PaginatedEnumerator<object>(await FindFirst(Collection, PageSize, SortOrder));
485 }
486
496 public static async Task<PaginatedEnumerator<object>> Enumerate(string Collection, int PageSize, Filter Filter, params string[] SortOrder)
497 {
498 return new PaginatedEnumerator<object>(await FindFirst(Collection, PageSize, Filter, SortOrder));
499 }
500
511 public static async Task<PaginatedEnumerator<T>> Enumerate<T>(string Collection, int PageSize, Filter Filter, params string[] SortOrder)
512 where T : class
513 {
514 return new PaginatedEnumerator<T>(await FindFirst<T>(Collection, PageSize, Filter, SortOrder));
515 }
516
525 public async static Task<T> FindFirstDeleteRest<T>(params string[] SortOrder)
526 where T : class
527 {
528 return await FirstDeleteRest(await Provider.Find<T>(0, int.MaxValue, SortOrder));
529 }
530
531 private static async Task<T> FirstDeleteRest<T>(IEnumerable<T> Set)
532 where T : class
533 {
534 T Result = default;
535 bool First = true;
536
537 foreach (T Obj in Set)
538 {
539 if (First)
540 {
541 First = false;
542 Result = Obj;
543 }
544 else
545 {
546 try
547 {
548 await Delete(Obj);
549 }
550 catch (KeyNotFoundException)
551 {
552 // TODO: Inconsistency should flag collection for repairing
553 }
554 }
555 }
556
557 return Result;
558 }
559
569 public static async Task<T> FindFirstDeleteRest<T>(Filter Filter, params string[] SortOrder)
570 where T : class
571 {
572 return await FirstDeleteRest(await Provider.Find<T>(0, int.MaxValue, Filter, SortOrder));
573 }
574
583 public async static Task<T> FindFirstIgnoreRest<T>(params string[] SortOrder)
584 where T : class
585 {
586 return FirstIgnoreRest(await Provider.Find<T>(0, 1, SortOrder));
587 }
588
589 private static T FirstIgnoreRest<T>(IEnumerable<T> Set)
590 where T : class
591 {
592 foreach (T Obj in Set)
593 return Obj;
594
595 return default;
596 }
597
607 public static async Task<T> FindFirstIgnoreRest<T>(Filter Filter, params string[] SortOrder)
608 where T : class
609 {
610 return FirstIgnoreRest(await Provider.Find<T>(0, 1, Filter, SortOrder));
611 }
612
622 public static Task<bool> Process<T>(IProcessor<T> Processor, params string[] SortOrder)
623 where T : class
624 {
625 return Provider.Process(Processor, 0, int.MaxValue, SortOrder);
626 }
627
638 public static Task<bool> Process<T>(IProcessor<T> Processor, Filter Filter, params string[] SortOrder)
639 where T : class
640 {
641 return Provider.Process(Processor, 0, int.MaxValue, Filter, SortOrder);
642 }
643
655 public static Task<bool> Process<T>(IProcessor<T> Processor, int Offset, int MaxCount, params string[] SortOrder)
656 where T : class
657 {
658 return Provider.Process(Processor, Offset, MaxCount, SortOrder);
659 }
660
673 public static Task<bool> Process<T>(IProcessor<T> Processor, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
674 where T : class
675 {
676 return Provider.Process(Processor, Offset, MaxCount, Filter, SortOrder);
677 }
678
688 public static Task<bool> Process(IProcessor<object> Processor, string Collection, params string[] SortOrder)
689 {
690 return Provider.Process(Processor, Collection, 0, int.MaxValue, SortOrder);
691 }
692
703 public static Task<bool> Process(IProcessor<object> Processor, string Collection, Filter Filter, params string[] SortOrder)
704 {
705 return Provider.Process(Processor, Collection, 0, int.MaxValue, Filter, SortOrder);
706 }
707
719 public static Task<bool> Process(IProcessor<object> Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
720 {
721 return Provider.Process(Processor, Collection, Offset, MaxCount, SortOrder);
722 }
723
736 public static Task<bool> Process(IProcessor<object> Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
737 {
738 return Provider.Process(Processor, Collection, Offset, MaxCount, Filter, SortOrder);
739 }
740
751 public static Task<bool> Process<T>(IProcessor<T> Processor, string Collection, string[] SortOrder) // Note: No params, to avoid confusion with Find<T>(params SortOrder)
752 where T : class
753 {
754 return Provider.Process(Processor, Collection, 0, int.MaxValue, null, SortOrder);
755 }
756
768 public static Task<bool> Process<T>(IProcessor<T> Processor, string Collection, Filter Filter, params string[] SortOrder)
769 where T : class
770 {
771 return Provider.Process(Processor, Collection, 0, int.MaxValue, Filter, SortOrder);
772 }
773
786 public static Task<bool> Process<T>(IProcessor<T> Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
787 where T : class
788 {
789 return Provider.Process(Processor, Collection, Offset, MaxCount, null, SortOrder);
790 }
791
805 public static Task<bool> Process<T>(IProcessor<T> Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
806 where T : class
807 {
808 return Provider.Process(Processor, Collection, Offset, MaxCount, Filter, SortOrder);
809 }
810
820 public static Task<bool> Process<T>(Predicate<T> Processor, params string[] SortOrder)
821 where T : class
822 {
823 return Provider.Process(new PredicateProcessor<T>(Processor), 0, int.MaxValue, SortOrder);
824 }
825
836 public static Task<bool> Process<T>(Predicate<T> Processor, Filter Filter, params string[] SortOrder)
837 where T : class
838 {
839 return Provider.Process(new PredicateProcessor<T>(Processor), 0, int.MaxValue, Filter, SortOrder);
840 }
841
853 public static Task<bool> Process<T>(Predicate<T> Processor, int Offset, int MaxCount, params string[] SortOrder)
854 where T : class
855 {
856 return Provider.Process(new PredicateProcessor<T>(Processor), Offset, MaxCount, SortOrder);
857 }
858
871 public static Task<bool> Process<T>(Predicate<T> Processor, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
872 where T : class
873 {
874 return Provider.Process(new PredicateProcessor<T>(Processor), Offset, MaxCount, Filter, SortOrder);
875 }
876
886 public static Task<bool> Process(Predicate<object> Processor, string Collection, params string[] SortOrder)
887 {
888 return Provider.Process(new PredicateProcessor<object>(Processor), Collection, 0, int.MaxValue, SortOrder);
889 }
890
901 public static Task<bool> Process(Predicate<object> Processor, string Collection, Filter Filter, params string[] SortOrder)
902 {
903 return Provider.Process(new PredicateProcessor<object>(Processor), Collection, 0, int.MaxValue, Filter, SortOrder);
904 }
905
917 public static Task<bool> Process(Predicate<object> Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
918 {
919 return Provider.Process(new PredicateProcessor<object>(Processor), Collection, Offset, MaxCount, SortOrder);
920 }
921
934 public static Task<bool> Process(Predicate<object> Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
935 {
936 return Provider.Process(new PredicateProcessor<object>(Processor), Collection, Offset, MaxCount, Filter, SortOrder);
937 }
938
949 public static Task<bool> Process<T>(Predicate<T> Processor, string Collection, string[] SortOrder) // Note: No params, to avoid confusion with Find<T>(params SortOrder)
950 where T : class
951 {
952 return Provider.Process(new PredicateProcessor<T>(Processor), Collection, 0, int.MaxValue, null, SortOrder);
953 }
954
966 public static Task<bool> Process<T>(Predicate<T> Processor, string Collection, Filter Filter, params string[] SortOrder)
967 where T : class
968 {
969 return Provider.Process(new PredicateProcessor<T>(Processor), Collection, 0, int.MaxValue, Filter, SortOrder);
970 }
971
984 public static Task<bool> Process<T>(Predicate<T> Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
985 where T : class
986 {
987 return Provider.Process(new PredicateProcessor<T>(Processor), Collection, Offset, MaxCount, null, SortOrder);
988 }
989
1003 public static Task<bool> Process<T>(Predicate<T> Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1004 where T : class
1005 {
1006 return Provider.Process(new PredicateProcessor<T>(Processor), Collection, Offset, MaxCount, Filter, SortOrder);
1007 }
1008
1018 public static Task<bool> Process<T>(PredicateAsync<T> Processor, params string[] SortOrder)
1019 where T : class
1020 {
1021 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), 0, int.MaxValue, SortOrder);
1022 }
1023
1034 public static Task<bool> Process<T>(PredicateAsync<T> Processor, Filter Filter, params string[] SortOrder)
1035 where T : class
1036 {
1037 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), 0, int.MaxValue, Filter, SortOrder);
1038 }
1039
1051 public static Task<bool> Process<T>(PredicateAsync<T> Processor, int Offset, int MaxCount, params string[] SortOrder)
1052 where T : class
1053 {
1054 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), Offset, MaxCount, SortOrder);
1055 }
1056
1069 public static Task<bool> Process<T>(PredicateAsync<T> Processor, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1070 where T : class
1071 {
1072 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), Offset, MaxCount, Filter, SortOrder);
1073 }
1074
1084 public static Task<bool> Process(PredicateAsync<object> Processor, string Collection, params string[] SortOrder)
1085 {
1086 return Provider.Process(new PredicateAsyncProcessor<object>(Processor), Collection, 0, int.MaxValue, SortOrder);
1087 }
1088
1099 public static Task<bool> Process(PredicateAsync<object> Processor, string Collection, Filter Filter, params string[] SortOrder)
1100 {
1101 return Provider.Process(new PredicateAsyncProcessor<object>(Processor), Collection, 0, int.MaxValue, Filter, SortOrder);
1102 }
1103
1115 public static Task<bool> Process(PredicateAsync<object> Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
1116 {
1117 return Provider.Process(new PredicateAsyncProcessor<object>(Processor), Collection, Offset, MaxCount, SortOrder);
1118 }
1119
1132 public static Task<bool> Process(PredicateAsync<object> Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1133 {
1134 return Provider.Process(new PredicateAsyncProcessor<object>(Processor), Collection, Offset, MaxCount, Filter, SortOrder);
1135 }
1136
1147 public static Task<bool> Process<T>(PredicateAsync<T> Processor, string Collection, string[] SortOrder) // Note: No params, to avoid confusion with Find<T>(params SortOrder)
1148 where T : class
1149 {
1150 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), Collection, 0, int.MaxValue, null, SortOrder);
1151 }
1152
1164 public static Task<bool> Process<T>(PredicateAsync<T> Processor, string Collection, Filter Filter, params string[] SortOrder)
1165 where T : class
1166 {
1167 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), Collection, 0, int.MaxValue, Filter, SortOrder);
1168 }
1169
1182 public static Task<bool> Process<T>(PredicateAsync<T> Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
1183 where T : class
1184 {
1185 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), Collection, Offset, MaxCount, null, SortOrder);
1186 }
1187
1201 public static Task<bool> Process<T>(PredicateAsync<T> Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1202 where T : class
1203 {
1204 return Provider.Process(new PredicateAsyncProcessor<T>(Processor), Collection, Offset, MaxCount, Filter, SortOrder);
1205 }
1206
1211 public async static Task Update(object Object)
1212 {
1213 await Provider.Update(Object);
1214 RaiseUpdated(Object);
1215 }
1216
1217 private static void RaiseUpdated(object Object)
1218 {
1219 ObjectUpdated?.Raise(Provider, new ObjectEventArgs(Object));
1220 }
1221
1222 private static void RaiseUpdated(IEnumerable<object> Objects)
1223 {
1224 foreach (object Object in Objects)
1225 RaiseUpdated(Object);
1226 }
1227
1231 public static event EventHandler<ObjectEventArgs> ObjectUpdated = null;
1232
1237 public async static Task Update(params object[] Objects)
1238 {
1239 if (Objects.Length == 1)
1240 await Provider.Update(Objects[0]);
1241 else
1242 await Provider.Update(Objects);
1243
1244 RaiseUpdated(Objects);
1245 }
1246
1251 public async static Task Update(IEnumerable<object> Objects)
1252 {
1253 await Provider.Update(Objects);
1254 RaiseUpdated(Objects);
1255 }
1256
1261 public async static Task UpdateLazy(object Object)
1262 {
1263 await Provider.UpdateLazy(Object, RaiseUpdated);
1264 }
1265
1270 public async static Task UpdateLazy(params object[] Objects)
1271 {
1272 if (Objects.Length == 1)
1273 await Provider.UpdateLazy(Objects[0], RaiseUpdated);
1274 else
1275 await Provider.UpdateLazy(Objects, RaiseUpdated);
1276 }
1277
1282 public async static Task UpdateLazy(IEnumerable<object> Objects)
1283 {
1284 await Provider.UpdateLazy(Objects, RaiseUpdated);
1285 }
1286
1291 public async static Task Delete(object Object)
1292 {
1293 await Provider.Delete(Object);
1294 RaiseDeleted(Object);
1295 }
1296
1300 public static event EventHandler<ObjectEventArgs> ObjectDeleted = null;
1301
1306 public async static Task Delete(params object[] Objects)
1307 {
1308 if (Objects.Length == 1)
1309 await Provider.Delete(Objects[0]);
1310 else
1311 await Provider.Delete(Objects);
1312
1313 RaiseDeleted(Objects);
1314 }
1315
1320 public async static Task Delete(IEnumerable<object> Objects)
1321 {
1322 await Provider.Delete(Objects);
1323 RaiseDeleted(Objects);
1324 }
1325
1330 public async static Task DeleteLazy(object Object)
1331 {
1332 await Provider.DeleteLazy(Object, RaiseDeleted);
1333 }
1334
1339 public async static Task DeleteLazy(params object[] Objects)
1340 {
1341 if (Objects.Length == 1)
1342 await Provider.DeleteLazy(Objects[0], RaiseDeleted);
1343 else
1344 await Provider.DeleteLazy(Objects, RaiseDeleted);
1345 }
1346
1351 public async static Task DeleteLazy(IEnumerable<object> Objects)
1352 {
1353 await Provider.DeleteLazy(Objects, RaiseDeleted);
1354 }
1355
1356 private static void RaiseDeleted(object Object)
1357 {
1358 ObjectDeleted?.Raise(Provider, new ObjectEventArgs(Object));
1359 }
1360
1361 private static void RaiseDeleted(IEnumerable<object> Objects)
1362 {
1363 foreach (object Object in Objects)
1364 RaiseDeleted(Object);
1365 }
1366
1374 public static Task<IEnumerable<T>> FindDelete<T>(params string[] SortOrder)
1375 where T : class
1376 {
1377 return FindDelete<T>(0, int.MaxValue, SortOrder);
1378 }
1379
1389 public static async Task<IEnumerable<T>> FindDelete<T>(int Offset, int MaxCount, params string[] SortOrder)
1390 where T : class
1391 {
1392 IEnumerable<T> Result = await Provider.FindDelete<T>(Offset, MaxCount, SortOrder);
1393
1394 foreach (T Object in Result)
1395 RaiseDeleted(Object);
1396
1397 return Result;
1398 }
1399
1408 public static Task<IEnumerable<T>> FindDelete<T>(Filter Filter, params string[] SortOrder)
1409 where T : class
1410 {
1411 return FindDelete<T>(0, int.MaxValue, Filter, SortOrder);
1412 }
1413
1424 public static async Task<IEnumerable<T>> FindDelete<T>(int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1425 where T : class
1426 {
1427 IEnumerable<T> Result = await Provider.FindDelete<T>(Offset, MaxCount, Filter, SortOrder);
1428
1429 foreach (T Object in Result)
1430 RaiseDeleted(Object);
1431
1432 return Result;
1433 }
1434
1442 public static Task<IEnumerable<object>> FindDelete(string Collection, params string[] SortOrder)
1443 {
1444 return FindDelete(Collection, 0, int.MaxValue, SortOrder);
1445 }
1446
1456 public static async Task<IEnumerable<object>> FindDelete(string Collection, int Offset, int MaxCount, params string[] SortOrder)
1457 {
1458 IEnumerable<object> Result = await Provider.FindDelete(Collection, Offset, MaxCount, SortOrder);
1459
1460 foreach (object Object in Result)
1461 RaiseDeleted(Object);
1462
1463 return Result;
1464 }
1465
1474 public static Task<IEnumerable<object>> FindDelete(string Collection, Filter Filter, params string[] SortOrder)
1475 {
1476 return FindDelete(Collection, 0, int.MaxValue, Filter, SortOrder);
1477 }
1478
1489 public static async Task<IEnumerable<object>> FindDelete(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1490 {
1491 IEnumerable<object> Result = await Provider.FindDelete(Collection, Offset, MaxCount, Filter, SortOrder);
1492
1493 foreach (object Object in Result)
1494 RaiseDeleted(Object);
1495
1496 return Result;
1497 }
1498
1506 public static Task<int> Delete<T>(params string[] SortOrder)
1507 where T : class
1508 {
1509 return Delete<T>(0, int.MaxValue, SortOrder);
1510 }
1511
1521 public static async Task<int> Delete<T>(int Offset, int MaxCount, params string[] SortOrder)
1522 where T : class
1523 {
1524 int MaxCount2;
1525 int Count = 0;
1526 bool Found;
1527
1528 do
1529 {
1530 Found = false;
1531 MaxCount2 = Math.Min(MaxCount, 1000);
1532
1533 IEnumerable<T> Result = await Provider.FindDelete<T>(Offset, MaxCount2, SortOrder);
1534
1535 foreach (T Object in Result)
1536 {
1537 RaiseDeleted(Object);
1538 MaxCount--;
1539 Count++;
1540 Found = true;
1541 }
1542 }
1543 while (Found && MaxCount > 0);
1544
1545 return Count;
1546 }
1547
1556 public static Task<int> Delete<T>(Filter Filter, params string[] SortOrder)
1557 where T : class
1558 {
1559 return Delete<T>(0, int.MaxValue, Filter, SortOrder);
1560 }
1561
1572 public static async Task<int> Delete<T>(int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1573 where T : class
1574 {
1575 int MaxCount2;
1576 int Count = 0;
1577 bool Found;
1578
1579 do
1580 {
1581 Found = false;
1582 MaxCount2 = Math.Min(MaxCount, 1000);
1583
1584 IEnumerable<T> Result = await Provider.FindDelete<T>(Offset, MaxCount2, Filter, SortOrder);
1585
1586 foreach (T Object in Result)
1587 {
1588 RaiseDeleted(Object);
1589 MaxCount--;
1590 Count++;
1591 Found = true;
1592 }
1593 }
1594 while (Found && MaxCount > 0);
1595
1596 return Count;
1597 }
1598
1606 public static Task<int> Delete(string Collection, params string[] SortOrder)
1607 {
1608 return Delete(Collection, 0, int.MaxValue, SortOrder);
1609 }
1610
1620 public static async Task<int> Delete(string Collection, int Offset, int MaxCount, params string[] SortOrder)
1621 {
1622 int MaxCount2;
1623 int Count = 0;
1624 bool Found;
1625
1626 do
1627 {
1628 Found = false;
1629 MaxCount2 = Math.Min(MaxCount, 1000);
1630
1631 IEnumerable<object> Result = await Provider.FindDelete(Collection, Offset, MaxCount2, SortOrder);
1632
1633 foreach (object Object in Result)
1634 {
1635 RaiseDeleted(Object);
1636 MaxCount--;
1637 Count++;
1638 Found = true;
1639 }
1640 }
1641 while (Found && MaxCount > 0);
1642
1643 return Count;
1644 }
1645
1654 public static Task<int> Delete(string Collection, Filter Filter, params string[] SortOrder)
1655 {
1656 return Delete(Collection, 0, int.MaxValue, Filter, SortOrder);
1657 }
1658
1669 public static async Task<int> Delete(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1670 {
1671 int MaxCount2;
1672 int Count = 0;
1673 bool Found;
1674
1675 do
1676 {
1677 Found = false;
1678 MaxCount2 = Math.Min(MaxCount, 1000);
1679
1680 IEnumerable<object> Result = await Provider.FindDelete(Collection, Offset, MaxCount2, Filter, SortOrder);
1681
1682 foreach (object Object in Result)
1683 {
1684 RaiseDeleted(Object);
1685 MaxCount--;
1686 Count++;
1687 Found = true;
1688 }
1689 }
1690 while (Found && MaxCount > 0);
1691
1692 return Count;
1693 }
1694
1702 public static Task DeleteLazy<T>(params string[] SortOrder)
1703 where T : class
1704 {
1705 return DeleteLazy<T>(0, int.MaxValue, SortOrder);
1706 }
1707
1717 public static Task DeleteLazy<T>(int Offset, int MaxCount, params string[] SortOrder)
1718 where T : class
1719 {
1720 return Provider.DeleteLazy<T>(Offset, MaxCount, SortOrder, RaiseDeleted);
1721 }
1722
1731 public static Task DeleteLazy<T>(Filter Filter, params string[] SortOrder)
1732 where T : class
1733 {
1734 return DeleteLazy<T>(0, int.MaxValue, Filter, SortOrder);
1735 }
1736
1747 public static Task DeleteLazy<T>(int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1748 where T : class
1749 {
1750 return Provider.DeleteLazy<T>(Offset, MaxCount, Filter, SortOrder, RaiseDeleted);
1751 }
1752
1760 public static Task DeleteLazy(string Collection, params string[] SortOrder)
1761 {
1762 return DeleteLazy(Collection, 0, int.MaxValue, SortOrder);
1763 }
1764
1774 public static Task DeleteLazy(string Collection, int Offset, int MaxCount, params string[] SortOrder)
1775 {
1776 return Provider.DeleteLazy(Collection, Offset, MaxCount, SortOrder, RaiseDeleted);
1777 }
1778
1787 public static Task DeleteLazy(string Collection, Filter Filter, params string[] SortOrder)
1788 {
1789 return DeleteLazy(Collection, 0, int.MaxValue, Filter, SortOrder);
1790 }
1791
1802 public static Task DeleteLazy(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
1803 {
1804 return Provider.DeleteLazy(Collection, Offset, MaxCount, Filter, SortOrder, RaiseDeleted);
1805 }
1806
1813 public static Task<T> TryLoadObject<T>(object ObjectId)
1814 where T : class
1815 {
1816 return Provider.TryLoadObject<T>(ObjectId);
1817 }
1818
1826 public static Task<T> TryLoadObject<T>(string CollectionName, object ObjectId)
1827 where T : class
1828 {
1829 return Provider.TryLoadObject<T>(CollectionName, ObjectId);
1830 }
1831
1838 public static Task<object> TryLoadObject(string CollectionName, object ObjectId)
1839 {
1840 return Provider.TryLoadObject(CollectionName, ObjectId);
1841 }
1842
1849 public static async Task<T> LoadObject<T>(object ObjectId)
1850 where T : class
1851 {
1852 T Result = await Provider.TryLoadObject<T>(ObjectId)
1853 ?? throw new KeyNotFoundException("Object not found.");
1854
1855 return Result;
1856 }
1857
1865 public async static Task<T> LoadObject<T>(string CollectionName, object ObjectId)
1866 where T : class
1867 {
1868 T Result = await Provider.TryLoadObject<T>(CollectionName, ObjectId)
1869 ?? throw new KeyNotFoundException("Object not found.");
1870
1871 return Result;
1872 }
1873
1880 public static async Task<object> LoadObject(string CollectionName, object ObjectId)
1881 {
1882 object Result = await Provider.TryLoadObject(CollectionName, ObjectId)
1883 ?? throw new KeyNotFoundException("Object not found.");
1884
1885 return Result;
1886 }
1887
1893 public static Task<bool> Export(IDatabaseExport Output)
1894 {
1895 return Export(Output, null);
1896 }
1897
1904 public static Task<bool> Export(IDatabaseExport Output, string[] CollectionNames)
1905 {
1906 return Provider.Export(Output, CollectionNames);
1907 }
1908
1916 public static Task<bool> Export(IDatabaseExport Output, string[] CollectionNames, ProfilerThread Thread)
1917 {
1918 return Provider.Export(Output, CollectionNames, Thread);
1919 }
1920
1927 public static Task Iterate<T>(IDatabaseIteration<T> Recipient)
1928 where T : class
1929 {
1930 return Iterate(Recipient, null);
1931 }
1932
1940 public static Task Iterate<T>(IDatabaseIteration<T> Recipient, params string[] CollectionNames)
1941 where T : class
1942 {
1943 return Provider.Iterate(Recipient, CollectionNames);
1944 }
1945
1954 public static Task Iterate<T>(IDatabaseIteration<T> Recipient, string[] CollectionNames, ProfilerThread Thread)
1955 where T : class
1956 {
1957 return Provider.Iterate(Recipient, CollectionNames, Thread);
1958 }
1959
1965 public async static Task Clear(string CollectionName)
1966 {
1967 await Provider.Clear(CollectionName);
1968
1969 await CollectionCleared.Raise(Provider, new CollectionEventArgs(CollectionName));
1970 }
1971
1975 public static event EventHandlerAsync<CollectionEventArgs> CollectionCleared = null;
1976
1985 public static Task<string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData)
1986 {
1987 return Provider.Analyze(Output, XsltPath, ProgramDataFolder, ExportData);
1988 }
1989
1999 public static Task<string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData,
2000 ProfilerThread Thread)
2001 {
2002 return Provider.Analyze(Output, XsltPath, ProgramDataFolder, ExportData, Thread);
2003 }
2004
2013 public static Task<string[]> Repair(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData)
2014 {
2015 return Repair(Output, XsltPath, ProgramDataFolder, ExportData, null);
2016 }
2017
2027 public async static Task<string[]> Repair(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData,
2028 ProfilerThread Thread)
2029 {
2030 KeyValuePair<string, Dictionary<string, FlagSource>>[] Flagged = GetFlaggedCollections();
2031
2032 string[] Result = await Provider.Repair(Output, XsltPath, ProgramDataFolder, ExportData, Thread);
2033
2034 if (Result.Length > 0)
2035 await RaiseRepaired(Result, Flagged);
2036
2037 return Result;
2038 }
2039
2040 private static async Task RaiseRepaired(string[] Collections, KeyValuePair<string, Dictionary<string, FlagSource>>[] Flagged)
2041 {
2042 try
2043 {
2044 FlagSource[] FlaggedCollection;
2045 EventHandlerAsync<CollectionRepairedEventArgs> h = CollectionRepaired;
2046
2047 if (!(h is null))
2048 {
2049 foreach (string Collection in Collections)
2050 {
2051 FlaggedCollection = null;
2052
2053 if (!(Flagged is null))
2054 {
2055 foreach (KeyValuePair<string, Dictionary<string, FlagSource>> Rec in Flagged)
2056 {
2057 if (Rec.Key == Collection)
2058 {
2059 FlaggedCollection = new FlagSource[Rec.Value.Count];
2060 Rec.Value.Values.CopyTo(FlaggedCollection, 0);
2061 break;
2062 }
2063 }
2064 }
2065
2066 await h.Raise(Provider, new CollectionRepairedEventArgs(Collection, FlaggedCollection));
2067 }
2068 }
2069 }
2070 catch (Exception ex)
2071 {
2072 Log.Exception(ex);
2073 }
2074 }
2075
2079 public static event EventHandlerAsync<CollectionRepairedEventArgs> CollectionRepaired = null;
2080
2090 public static Task<string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData,
2091 bool Repair)
2092 {
2093 return Analyze(Output, XsltPath, ProgramDataFolder, ExportData, Repair, null);
2094 }
2095
2106 public async static Task<string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData,
2107 bool Repair, ProfilerThread Thread)
2108 {
2109 KeyValuePair<string, Dictionary<string, FlagSource>>[] Flagged = GetFlaggedCollections();
2110
2111 string[] Result = await Provider.Analyze(Output, XsltPath, ProgramDataFolder, ExportData, Repair, Thread);
2112
2113 if (Repair && Result.Length > 0)
2114 await RaiseRepaired(Result, Flagged);
2115
2116 return Result;
2117 }
2118
2119 private static KeyValuePair<string, Dictionary<string, FlagSource>>[] GetFlaggedCollections()
2120 {
2121 KeyValuePair<string, Dictionary<string, FlagSource>>[] Flagged;
2122 int i;
2123
2124 lock (toRepair)
2125 {
2126 Flagged = new KeyValuePair<string, Dictionary<string, FlagSource>>[toRepair.Count];
2127 i = 0;
2128
2129 foreach (KeyValuePair<string, Dictionary<string, FlagSource>> P in toRepair)
2130 Flagged[i++] = P;
2131
2132 toRepair.Clear();
2133 }
2134
2135 return Flagged;
2136 }
2137
2142 public static string[] GetFlaggedCollectionNames()
2143 {
2144 string[] Result;
2145
2146 lock (toRepair)
2147 {
2148 Result = new string[toRepair.Count];
2149 toRepair.Keys.CopyTo(Result, 0);
2150 }
2151
2152 return Result;
2153 }
2154
2159 public static void BeginRepair(string Collection)
2160 {
2161 lock (toRepair)
2162 {
2163 toRepair[Collection] = null;
2164 }
2165 }
2166
2171 public static void EndRepair(string Collection)
2172 {
2173 lock (toRepair)
2174 {
2175 toRepair.Remove(Collection);
2176 }
2177 }
2178
2184 public static Exception FlagForRepair(string Collection, string Reason)
2185 {
2186 if (!string.IsNullOrEmpty(Collection))
2187 {
2188 InconsistencyException Result = new InconsistencyException(Collection, Reason + " (" + Collection + ")");
2189 string StackTrace = Log.CleanStackTrace(Environment.StackTrace);
2190 string Key = Reason + " | " + StackTrace;
2191
2192 lock (toRepair)
2193 {
2194 if (toRepair.TryGetValue(Collection, out Dictionary<string, FlagSource> PerStackTrace))
2195 {
2196 if (!(PerStackTrace is null))
2197 {
2198 if (PerStackTrace.TryGetValue(Key, out FlagSource FlagSource))
2199 FlagSource.Count++;
2200 else
2201 PerStackTrace[Key] = new FlagSource(Reason, StackTrace, 1);
2202 }
2203 }
2204 else
2205 toRepair[Collection] = new Dictionary<string, FlagSource>() { { Key, new FlagSource(Reason, StackTrace, 1) } };
2206 }
2207
2208 return Result;
2209 }
2210 else
2211 return new Exception(Reason);
2212 }
2213
2220 public static Task AddIndex(string CollectionName, string[] FieldNames)
2221 {
2222 return Provider.AddIndex(CollectionName, FieldNames);
2223 }
2224
2231 public static Task RemoveIndex(string CollectionName, string[] FieldNames)
2232 {
2233 return Provider.RemoveIndex(CollectionName, FieldNames);
2234 }
2235
2243 public static Task<string[][]> GetIndices(string CollectionName)
2244 {
2245 return Provider.GetIndices(CollectionName);
2246 }
2247
2251 public static Task StartBulk()
2252 {
2253 return Provider.StartBulk();
2254 }
2255
2259 public static Task EndBulk()
2260 {
2261 return Provider.EndBulk();
2262 }
2263
2269 public static string[] ToStringArray(this CaseInsensitiveString[] A)
2270 {
2271 if (A is null)
2272 return null;
2273
2274 int i, c = A.Length;
2275 string[] B = new string[c];
2276
2277 for (i = 0; i < c; i++)
2278 B[i] = A[i].Value;
2279
2280 return B;
2281 }
2282
2289 {
2290 if (A is null)
2291 return null;
2292
2293 int i, c = A.Length;
2295
2296 for (i = 0; i < c; i++)
2297 B[i] = A[i];
2298
2299 return B;
2300 }
2301
2307 public static Task<IPersistentDictionary> GetDictionary(string Collection)
2308 {
2309 return Provider.GetDictionary(Collection);
2310 }
2311
2316 public static Task<string[]> GetDictionaries()
2317 {
2318 return Provider.GetDictionaries();
2319 }
2320
2326 public static Task<IPersistedQueue> GetQueue(string QueueName)
2327 {
2328 return GetQueue(QueueName, false);
2329 }
2330
2337 public static Task<IPersistedQueue> GetQueue(string QueueName, bool CanBeNull)
2338 {
2339 return Provider.GetQueue(QueueName, CanBeNull);
2340 }
2341
2346 public static Task<string[]> GetQueues()
2347 {
2348 return Provider.GetQueues();
2349 }
2350
2355 public static Task<string[]> GetCollections()
2356 {
2357 return Provider.GetCollections();
2358 }
2359
2365 public static Task<string> GetCollection(Type Type)
2366 {
2367 return Provider.GetCollection(Type);
2368 }
2369
2375 public static Task<string> GetCollection(Object Object)
2376 {
2377 return Provider.GetCollection(Object);
2378 }
2379
2387 public static Task<bool> IsLabel(string Collection, string Label)
2388 {
2389 return Provider.IsLabel(Collection, Label);
2390 }
2391
2396 public static Task<string[]> GetLabels(string Collection)
2397 {
2398 return Provider.GetLabels(Collection);
2399 }
2400
2406 public static Task<object> TryGetObjectId(object Object)
2407 {
2408 return Provider.TryGetObjectId(Object);
2409 }
2410
2415 public static Task DropCollection(string CollectionName)
2416 {
2417 return Provider.DropCollection(CollectionName);
2418 }
2419
2426 public static string WildcardToRegex(string s, string Wildcard)
2427 {
2428 string[] Parts = s.Split(new string[] { Wildcard }, StringSplitOptions.None);
2429 StringBuilder RegEx = new StringBuilder();
2430 bool First = true;
2431 int i, j, c;
2432
2433 foreach (string Part in Parts)
2434 {
2435 if (First)
2436 First = false;
2437 else
2438 RegEx.Append(".*");
2439
2440 i = 0;
2441 c = Part.Length;
2442 while (i < c)
2443 {
2444 j = Part.IndexOfAny(regexSpecialCharaters, i);
2445 if (j < i)
2446 {
2447 RegEx.Append(Part.Substring(i));
2448 i = c;
2449 }
2450 else
2451 {
2452 if (j > i)
2453 RegEx.Append(Part.Substring(i, j - i));
2454
2455 RegEx.Append('\\');
2456 RegEx.Append(Part[j]);
2457
2458 i = j + 1;
2459 }
2460 }
2461 }
2462
2463 return RegEx.ToString();
2464 }
2465
2466 private static readonly char[] regexSpecialCharaters = new char[] { '\\', '^', '$', '{', '}', '[', ']', '(', ')', '.', '*', '+', '?', '|', '<', '>', '-', '&' };
2467
2473 public static Task<GenericObject> Generalize(object Object)
2474 {
2475 return Provider.Generalize(Object);
2476 }
2477
2483 public static Task<object> Specialize(GenericObject Object)
2484 {
2485 return Provider.Specialize(Object);
2486 }
2487
2492 public static string[] GetExcludedCollections()
2493 {
2495 }
2496
2497 }
2498}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
static string CleanStackTrace(string StackTrace)
Cleans a Stack Trace string, removing entries from the asynchronous execution model,...
Definition: Log.cs:194
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1657
Represents a case-insensitive string.
int Length
Gets the number of characters in the current CaseInsensitiveString object.
Event arguments for collection events.
Event arguments for collection repaired events.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static Task< bool > Process(Predicate< object > Processor, string Collection, Filter Filter, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:901
static Task< string[]> GetDictionaries()
Gets an array of available dictionary collections.
Definition: Database.cs:2316
static Task< IEnumerable< object > > FindDelete(string Collection, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1442
static Task< string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData, ProfilerThread Thread)
Analyzes the database and exports findings to XML.
Definition: Database.cs:1999
static Task< T > TryLoadObject< T >(object ObjectId)
Tries to load an object given its Object ID ObjectId and its class type T .
Definition: Database.cs:1813
static Task< int > Delete(string Collection, Filter Filter, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1654
static Task< string > GetCollection(Object Object)
Gets the collection corresponding to a given object.
Definition: Database.cs:2375
static Task< IEnumerable< T > > Find< T >(params string[] SortOrder)
Finds objects of a given class T .
Definition: Database.cs:180
static Task DeleteLazy(string Collection, Filter Filter, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1787
static Task< bool > Process(IProcessor< object > Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:736
static Task< IPage< T > > FindNext< T >(IPage< T > Page)
Finds the next page of objects of a given class T .
Definition: Database.cs:426
static Task< bool > Export(IDatabaseExport Output, string[] CollectionNames)
Performs an export of the database.
Definition: Database.cs:1904
static async Task< IEnumerable< object > > FindDelete(string Collection, int Offset, int MaxCount, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1456
static Task DeleteLazy(string Collection, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1760
static async Task DeleteLazy(object Object)
Deletes an object in the database, if unlocked. If locked, object will be deleted at next opportunity...
Definition: Database.cs:1330
static Task RemoveIndex(string CollectionName, string[] FieldNames)
Removes an index from a collection, if one exist.
Definition: Database.cs:2231
static Task< IPersistentDictionary > GetDictionary(string Collection)
Gets a persistent dictionary containing objects in a collection.
Definition: Database.cs:2307
static async Task< string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData, bool Repair, ProfilerThread Thread)
Analyzes the database and exports findings to XML.
Definition: Database.cs:2106
static Task DeleteLazy< T >(params string[] SortOrder)
Finds objects of a given class T and deletes them in the same atomic operation.
Definition: Database.cs:1702
static Task< IEnumerable< object > > Find(string Collection, Filter Filter, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:251
static Task< IEnumerable< T > > FindDelete< T >(params string[] SortOrder)
Finds objects of a given class T and deletes them in the same atomic operation.
Definition: Database.cs:1374
static void EndRepair(string Collection)
Is called when reparation of a collection is ended.
Definition: Database.cs:2171
static Task EndBulk()
Ends bulk-processing of data. Must be called once for every call to StartBulk.
Definition: Database.cs:2259
static Task< bool > Process(PredicateAsync< object > Processor, string Collection, Filter Filter, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:1099
static bool HasProvider
If a database provider is registered.
Definition: Database.cs:81
static Task< string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData)
Analyzes the database and exports findings to XML.
Definition: Database.cs:1985
static async Task< int > Delete(string Collection, int Offset, int MaxCount, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1620
static Task< bool > Process(IProcessor< object > Processor, string Collection, Filter Filter, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:703
static Task< string[]> Repair(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData)
Analyzes the database and repairs it if necessary. Results are exported to XML.
Definition: Database.cs:2013
static CaseInsensitiveString[] ToCaseInsensitiveStringArray(this string[] A)
Converts a case insensitive string array to a normal string array.
Definition: Database.cs:2288
static Task< int > Delete< T >(params string[] SortOrder)
Finds objects of a given class T and deletes them in the same atomic operation.
Definition: Database.cs:1506
static EventHandler< ObjectEventArgs > ObjectInserted
Event raised when an object has been inserted.
Definition: Database.cs:117
static EventHandler< ObjectEventArgs > ObjectDeleted
Event raised when an object has been deleted.
Definition: Database.cs:1300
static async Task< T > FindFirstIgnoreRest< T >(params string[] SortOrder)
Finds the first object of a given class T and ignores the rest.
Definition: Database.cs:583
static Task< bool > Process(IProcessor< object > Processor, string Collection, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:688
static Task Iterate< T >(IDatabaseIteration< T > Recipient)
Performs an iteration of contents of the entire database.
Definition: Database.cs:1927
static Task< bool > IsLabel(string Collection, string Label)
Checks if a string is a label in a given collection.
Definition: Database.cs:2387
static string[] GetExcludedCollections()
Gets an array of collections that should be excluded from backups.
Definition: Database.cs:2492
static Task< object > TryGetObjectId(object Object)
Tries to get the Object ID of an object, if it exists.
Definition: Database.cs:2406
static async Task InsertLazy(object Object)
Inserts an object into the database, if unlocked. If locked, object will be inserted at next opportun...
Definition: Database.cs:147
static void Register(IDatabaseProvider DatabaseProvider)
Registers a database provider for use from the static Database class, throughout the lifetime of the ...
Definition: Database.cs:33
static EventHandlerAsync< CollectionEventArgs > CollectionCleared
Event raised when a collection has been cleared.
Definition: Database.cs:1975
static Task DeleteLazy(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1802
static EventHandler< ObjectEventArgs > ObjectUpdated
Event raised when an object has been updated.
Definition: Database.cs:1231
static IDatabaseProvider Provider
Registered database provider.
Definition: Database.cs:59
static Task< bool > Process(PredicateAsync< object > Processor, string Collection, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:1084
static Task< IPage< object > > FindNext(IPage< object > Page)
Finds the next page of objects in a given collection.
Definition: Database.cs:437
static async Task Update(params object[] Objects)
Updates a collection of objects in the database.
Definition: Database.cs:1237
static Task< IEnumerable< object > > Find(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:280
static async Task Update(IEnumerable< object > Objects)
Updates a collection of objects in the database.
Definition: Database.cs:1251
static Task DeleteLazy(string Collection, int Offset, int MaxCount, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1774
static Task AddIndex(string CollectionName, string[] FieldNames)
Adds an index to a collection, if one does not already exist.
Definition: Database.cs:2220
static string WildcardToRegex(string s, string Wildcard)
Converts a wildcard string to a regular expression string.
Definition: Database.cs:2426
static Task< string[]> GetCollections()
Gets an array of available collections.
Definition: Database.cs:2355
static Task< bool > Export(IDatabaseExport Output)
Performs an export of the database.
Definition: Database.cs:1893
static Exception FlagForRepair(string Collection, string Reason)
Flags a collection for repairing.
Definition: Database.cs:2184
static Task< IPage< object > > FindFirst(string Collection, int PageSize, params string[] SortOrder)
Finds the first page of objects in a given collection.
Definition: Database.cs:385
static async Task< int > Delete(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1669
static Task StartBulk()
Starts bulk-proccessing of data. Must be followed by a call to EndBulk.
Definition: Database.cs:2251
static Task< int > Delete(string Collection, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1606
static EventHandlerAsync< CollectionRepairedEventArgs > CollectionRepaired
Event raised when a collection has been repaired.
Definition: Database.cs:2079
static Task< bool > Process< T >(IProcessor< T > Processor, params string[] SortOrder)
Processes objects of a given class T .
Definition: Database.cs:622
static async Task Delete(IEnumerable< object > Objects)
Deletes a collection of objects in the database.
Definition: Database.cs:1320
static void BeginRepair(string Collection)
Is called when reparation of a collection is begin.
Definition: Database.cs:2159
static Task< IEnumerable< object > > Find(string Collection, int Offset, int MaxCount, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:265
static Task< bool > Process(IProcessor< object > Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:719
static async Task< PaginatedEnumerator< T > > Enumerate< T >(int PageSize, params string[] SortOrder)
Enumerates objects of a given class T available in the database, by retrieving items from the databa...
Definition: Database.cs:452
static async Task UpdateLazy(object Object)
Updates an object in the database, if unlocked. If locked, object will be updated at next opportunity...
Definition: Database.cs:1261
static async Task UpdateLazy(IEnumerable< object > Objects)
Updates a collection of objects in the database, if unlocked. If locked, objects will be updated at n...
Definition: Database.cs:1282
static bool Locked
If the datbase provider has been locked for the rest of the run-time of the application.
Definition: Database.cs:89
static Task< bool > Export(IDatabaseExport Output, string[] CollectionNames, ProfilerThread Thread)
Performs an export of the database.
Definition: Database.cs:1916
static Task< string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData, bool Repair)
Analyzes the database and exports findings to XML.
Definition: Database.cs:2090
static string[] ToStringArray(this CaseInsensitiveString[] A)
Converts a case insensitive string array to a normal string array.
Definition: Database.cs:2269
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:1211
static Task< GenericObject > Generalize(object Object)
Creates a generalized representation of an object.
Definition: Database.cs:2473
static Task< bool > Process(PredicateAsync< object > Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:1115
static Task< IPersistedQueue > GetQueue(string QueueName, bool CanBeNull)
Gets a persistent dictionary containing objects in a collection.
Definition: Database.cs:2337
static Task< string > GetCollection(Type Type)
Gets the collection corresponding to a given type.
Definition: Database.cs:2365
static async Task Delete(object Object)
Deletes an object in the database.
Definition: Database.cs:1291
static async Task< T > LoadObject< T >(object ObjectId)
Loads an object given its Object ID ObjectId and its base type T .
Definition: Database.cs:1849
static async Task< object > LoadObject(string CollectionName, object ObjectId)
Loads an object given its Object ID ObjectId and its collection name CollectionName .
Definition: Database.cs:1880
static Task< bool > Process(PredicateAsync< object > Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:1132
static Task< string[]> GetQueues()
Gets an array of available queue names.
Definition: Database.cs:2346
static Task< bool > Process(Predicate< object > Processor, string Collection, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:886
static Task< string[]> GetLabels(string Collection)
Gets an array of available labels for a collection.
Definition: Database.cs:2396
static async Task Insert(params object[] Objects)
Inserts a set of objects into the default collection of the database.
Definition: Database.cs:123
static Task< bool > Process(Predicate< object > Processor, string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:934
static string[] GetFlaggedCollectionNames()
Gets the names of the collections that have been flagged as possibly corrupt.
Definition: Database.cs:2142
static Task< string[][]> GetIndices(string CollectionName)
Removes an index from a collection, if one exist.
Definition: Database.cs:2243
static async Task< PaginatedEnumerator< object > > Enumerate(string Collection, int PageSize, Filter Filter, params string[] SortOrder)
Finds the first page of objects in a given collection.
Definition: Database.cs:496
static Task< object > Specialize(GenericObject Object)
Creates a specialized representation of a generic object.
Definition: Database.cs:2483
static async Task DeleteLazy(params object[] Objects)
Deletes a collection of objects in the database, if unlocked. If locked, objects will be deleted at n...
Definition: Database.cs:1339
static async Task< IEnumerable< object > > FindDelete(string Collection, int Offset, int MaxCount, Filter Filter, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1489
static async Task< string[]> Repair(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData, ProfilerThread Thread)
Analyzes the database and repairs it if necessary. Results are exported to XML.
Definition: Database.cs:2027
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:238
static Task< IEnumerable< object > > FindDelete(string Collection, Filter Filter, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1474
static Task< bool > Process(Predicate< object > Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
Processes objects in a given collection.
Definition: Database.cs:917
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
Definition: Database.cs:97
static async Task UpdateLazy(params object[] Objects)
Updates a collection of objects in the database, if unlocked. If locked, objects will be updated at n...
Definition: Database.cs:1270
static Task< object > TryLoadObject(string CollectionName, object ObjectId)
Tries to load an object given its Object ID ObjectId and its collection name CollectionName .
Definition: Database.cs:1838
static async Task< T > FindFirstDeleteRest< T >(params string[] SortOrder)
Finds the first object of a given class T and deletes the rest.
Definition: Database.cs:525
static async Task InsertLazy(params object[] Objects)
Inserts an object into the database, if unlocked. If locked, object will be inserted at next opportun...
Definition: Database.cs:156
static async Task Insert(IEnumerable< object > Objects)
Inserts a set of objects into the default collection of the database.
Definition: Database.cs:137
static void Register(IDatabaseProvider DatabaseProvider, bool Lock)
Registers a database provider for use from the static Database class, throughout the lifetime of the ...
Definition: Database.cs:46
static async Task DeleteLazy(IEnumerable< object > Objects)
Deletes a collection of objects in the database, if unlocked. If locked, objects will be deleted at n...
Definition: Database.cs:1351
static Task DropCollection(string CollectionName)
Drops a collection, if it exist.
Definition: Database.cs:2415
static Task< IPage< object > > FindFirst(string Collection, int PageSize, Filter Filter, params string[] SortOrder)
Finds the first page of objects in a given collection.
Definition: Database.cs:399
static async Task Delete(params object[] Objects)
Deletes a collection of objects in the database.
Definition: Database.cs:1306
static Task< IPage< T > > FindFirst< T >(int PageSize, params string[] SortOrder)
Finds the first page of objects of a given class T .
Definition: Database.cs:355
static async Task< PaginatedEnumerator< object > > Enumerate(string Collection, int PageSize, params string[] SortOrder)
Finds the first page of objects in a given collection.
Definition: Database.cs:482
static Task< IPersistedQueue > GetQueue(string QueueName)
Gets a persistent dictionary containing objects in a collection.
Definition: Database.cs:2326
static async Task InsertLazy(IEnumerable< object > Objects)
Inserts an object into the database, if unlocked. If locked, object will be inserted at next opportun...
Definition: Database.cs:168
static async Task Clear(string CollectionName)
Clears a collection of all objects.
Definition: Database.cs:1965
Database inconsistency exception. Raised when an inconsistency in the database has been found.
Base class for all filter classes.
Definition: Filter.cs:15
Source of code flagging a collection for repair.
Definition: FlagSource.cs:9
int Count
Number of times the collection has been flagged from this source.
Definition: FlagSource.cs:41
Event arguments for database object events.
Processor that uses an asynchronous predicate callback to process objects.
Processor that uses a predicate callback to process objects.
Generic object. Contains a sequence of properties.
Class that keeps track of events and timing for one thread.
Interface for database providers that can be plugged into the static Database class.
Task Update(object Object)
Updates an object in the database.
Task InsertLazy(object Object, ObjectCallback Callback)
Inserts an object into the database, if unlocked. If locked, object will be inserted at next opportun...
Task< string[]> Repair(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData)
Analyzes the database and repairs it if necessary. Results are exported to XML.
Task< object > TryLoadObject(string CollectionName, object ObjectId)
Tries to load an object given its Object ID ObjectId and its collection name CollectionName .
Task< IPage< object > > FindFirst(string Collection, int PageSize, params string[] SortOrder)
Finds the first page of objects in a given collection.
Task< object > TryGetObjectId(object Object)
Tries to get the Object ID of an object, if it exists.
Task AddIndex(string CollectionName, string[] FieldNames)
Adds an index to a collection, if one does not already exist.
Task Delete(object Object)
Deletes an object in the database.
Task< object > Specialize(GenericObject Object)
Creates a specialized representation of a generic object.
Task< IEnumerable< object > > Find(string Collection, int Offset, int MaxCount, params string[] SortOrder)
Finds objects in a given collection.
Task< bool > IsLabel(string Collection, string Label)
Checks if a string is a label in a given collection.
Task< string[]> GetLabels(string Collection)
Gets an array of available labels for a collection.
Task< string > GetCollection(Type Type)
Gets the collection corresponding to a given type.
Task< bool > Export(IDatabaseExport Output, string[] CollectionNames)
Performs an export of the database.
Task< string[]> GetCollections()
Gets an array of available collections.
Task Clear(string CollectionName)
Clears a collection of all objects.
Task< string[]> GetDictionaries()
Gets an array of available dictionary collections.
Task< IPersistedQueue > GetQueue(string QueueName, bool CanBeNull)
Gets a persistent dictionary containing objects in a collection.
Task EndBulk()
Ends bulk-processing of data. Must be called once for every call to StartBulk.
Task UpdateLazy(object Object, ObjectCallback Callback)
Updates an object in the database, if unlocked. If locked, object will be updated at next opportunity...
Task< GenericObject > Generalize(object Object)
Creates a generalized representation of an object.
Task< string[][]> GetIndices(string CollectionName)
Removes an index from a collection, if one exist.
Task Insert(object Object)
Inserts an object into the database.
Task DeleteLazy(object Object, ObjectCallback Callback)
Deletes an object in the database, if unlocked. If locked, object will be deleted at next opportunity...
Task< IPersistentDictionary > GetDictionary(string Collection)
Gets a persistent dictionary containing objects in a collection.
Task< string[]> GetQueues()
Gets an array of available queue names.
Task< bool > Process(IProcessor< object > Processor, string Collection, int Offset, int MaxCount, params string[] SortOrder)
Processes untyped objects.
Task< string[]> Analyze(XmlWriter Output, string XsltPath, string ProgramDataFolder, bool ExportData)
Analyzes the database and exports findings to XML.
string[] GetExcludedCollections()
Gets an array of collections that should be excluded from backups.
Task< IEnumerable< object > > FindDelete(string Collection, int Offset, int MaxCount, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Task DropCollection(string CollectionName)
Drops a collection, if it exist.
Task RemoveIndex(string CollectionName, string[] FieldNames)
Removes an index from a collection, if one exist.
Task< IPage< object > > FindNext(IPage< object > Page)
Finds the next page of objects in a given collection.
Task StartBulk()
Starts bulk-proccessing of data. Must be followed by a call to EndBulk.
Interface for paginated results.
Definition: IPage.cs:11
Interface for processors of objects.
Definition: IProcessor.cs:9
Interface for iterations of database contents.