Added new XML. FInished MetaßCollection

This commit is contained in:
schnulller
2022-06-27 16:14:29 +02:00
parent abe473e9d5
commit 0bbbcc0d44
12 changed files with 361922 additions and 173242 deletions

View File

@@ -21,14 +21,24 @@ public class MetaCollection : HaWeb.XMLParser.IXMLCollection {
public static IDictionary<string, string>? GetDataFields(XElement element) {
var res = new Dictionary<string, string>();
// TODO
var sort = element.Descendants("sort");
if (sort == null || !sort.Any()) return null;
var date = (string?)sort.First().Attribute("value");
var order = (string?)sort.First().Attribute("order");
if (String.IsNullOrWhiteSpace(date) || !DateTime.TryParse(date, out var dt)) return null;
res.Add("day", dt.Day.ToString());
res.Add("month", dt.Month.ToString());
res.Add("year", dt.Year.ToString());
if (!String.IsNullOrWhiteSpace(order)) res.Add("order", order);
else res.Add("order", "0");
return res;
}
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
// TODO
var years = items.Where(x => x["year"] != null);
if (years == null || !years.Any()) return null;
res.Add("year", years.ToLookup(x => x["year"])!);
return res;
}
}

View File

@@ -79,11 +79,11 @@ public class XMLService : IXMLService {
var ret = new ConcurrentDictionary<string, ItemsCollection>(concurrencyLevel, startingSizeAllCollections);
if (_Collections != null)
foreach (var coll in _Collections) {
Parallel.ForEach(_Collections, (coll) => {
var elem = coll.Value.xPath.Aggregate(new List<XElement>(), (x, y) => { x.AddRange(document.XPathSelectElements(y).ToList()); return x; } );
if (elem != null && elem.Any()) {
var items = new ConcurrentDictionary<string, CollectedItem>(concurrencyLevel, startingSize);
Parallel.ForEach(elem, (e) => {
foreach (var e in elem) {
var k = coll.Value.GenerateKey(e);
if (k != null) {
var searchtext = coll.Value.Searchable ?
@@ -94,7 +94,7 @@ public class XMLService : IXMLService {
null;
items[k] = new CollectedItem(k, e, coll.Value, datafileds, searchtext);
}
});
}
if (items.Any()) {
if (!ret.ContainsKey(coll.Key))
ret[coll.Key] = new ItemsCollection(coll.Key, coll.Value);
@@ -102,12 +102,11 @@ public class XMLService : IXMLService {
ret[coll.Key].Items.Add(item.Key, item.Value);
}
}
}
});
if (ret.Any()) {
Parallel.ForEach(ret, (collection) => {
collection.Value.GenerateGroupings();
collection.Value.GenerateSortings();
});
}
_collectedProduction = ret.ToDictionary(x => x.Key, y => y.Value);