mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-07-30 17:30:40 +00:00
Esiur CLI
This commit is contained in:
@@ -1012,9 +1012,20 @@ public class Warehouse
|
||||
var parent = await Get<IResource>(string.Join("/", location.Take(location.Length - 1)));
|
||||
|
||||
if (parent == null)
|
||||
throw new Exception("Can't find parent");
|
||||
{
|
||||
// Stores may expose hierarchical links without materializing every
|
||||
// intermediate path segment (for example, database/Type/42).
|
||||
// In that case the root store still owns the complete relative path.
|
||||
var root = await Get<IResource>(location[0]);
|
||||
if (root is not IStore rootStore)
|
||||
throw new Exception("Can't find parent or root store.");
|
||||
|
||||
store = parent.Instance.Store;// GetStore(location[0]);
|
||||
store = rootStore;
|
||||
}
|
||||
else
|
||||
{
|
||||
store = parent.Instance.Store;// GetStore(location[0]);
|
||||
}
|
||||
|
||||
//if (store == null)
|
||||
// throw new Exception("Store not found.");
|
||||
|
||||
@@ -119,12 +119,25 @@ public class MemoryStore : IStore
|
||||
|
||||
public AsyncBag<T> Children<T>(IResource resource, string name) where T : IResource
|
||||
{
|
||||
var parentLink = ReferenceEquals(resource, this)
|
||||
? string.Empty
|
||||
: (Link(resource) ?? string.Empty).Trim('/');
|
||||
var prefix = parentLink.Length == 0 ? string.Empty : parentLink + "/";
|
||||
|
||||
var rt = new AsyncBag<T>();
|
||||
var children = resources
|
||||
.Where(entry => entry.Value is T)
|
||||
.Select(entry => new { Resource = (T)entry.Value, Link = Link(entry.Value)?.Trim('/') })
|
||||
.Where(entry => entry.Link is not null && entry.Link.StartsWith(prefix, StringComparison.Ordinal))
|
||||
.Where(entry =>
|
||||
{
|
||||
var relative = entry.Link!.Substring(prefix.Length);
|
||||
return relative.Length > 0 && !relative.Contains('/');
|
||||
})
|
||||
.Where(entry => name is null || entry.Resource.Instance.Name == name)
|
||||
.Select(entry => entry.Resource)
|
||||
.ToArray();
|
||||
|
||||
var location = Link(resource) + "/";
|
||||
|
||||
return new AsyncBag<T>(resources.Where(r => r.Value is T && Link(r.Value).StartsWith(location)).Select(r => (T)r.Value).ToArray());
|
||||
return new AsyncBag<T>(children);
|
||||
|
||||
//var children = (resource.Instance.Variables["children"] as AutoList<IResource, Instance>);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user