73 lines
1.8 KiB
C#
73 lines
1.8 KiB
C#
namespace Thor.Shared.Inspect;
|
|
|
|
public class InspectionRegister
|
|
: RegisterBase<InspectionEntry, ItemAnswer>
|
|
{
|
|
|
|
public ItemAnswer Forge(string itemid)
|
|
{
|
|
var entries = GetEntriesOrdered(itemid);
|
|
|
|
ItemAnswer ret = new();
|
|
ret.TargetId = itemid;
|
|
|
|
// fastpass ☺
|
|
if (entries.Count == 0)
|
|
return ret;
|
|
|
|
foreach (var entry in entries)
|
|
{
|
|
if (entry.Type == InspectionEntry.EntryType.Set)
|
|
{
|
|
if (!entry.State.HasValue)
|
|
throw new Exception("Entry typed Set send without any State.");
|
|
|
|
ret.CurrentState = entry.State.Value;
|
|
}
|
|
else
|
|
throw new NotImplementedException();
|
|
|
|
Entries.Add(entry);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
public ItemAnswer.State GetItemState(string itemid)
|
|
{
|
|
var entries = Entries
|
|
.Where(e
|
|
=> e.Target == itemid
|
|
&& e.Type == InspectionEntry.EntryType.Set)
|
|
.OrderByDescending(e => e.When)
|
|
.ToList();
|
|
|
|
if (entries.Count == 0)
|
|
return default;
|
|
|
|
var firstEntryState = entries.First().State;
|
|
|
|
return firstEntryState ?? default;
|
|
}
|
|
|
|
public IEnumerable<Attachment> GetAttachments(string itemid)
|
|
{
|
|
var entries = Entries
|
|
.Where(e
|
|
=> e.Target == itemid
|
|
&& e.Type == InspectionEntry.EntryType.Attachement)
|
|
.OrderByDescending(e => e.When)
|
|
.ToList();
|
|
|
|
foreach (var entry in entries)
|
|
yield return new()
|
|
{
|
|
Id = entry.Identifier,
|
|
Author = entry.Author,
|
|
When = entry.When,
|
|
Name = entry.AttachmentName,
|
|
Content = entry.Attachment
|
|
};
|
|
}
|
|
}
|