mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 13:33:13 +00:00
WeakRef
This commit is contained in:
@ -33,19 +33,31 @@ namespace Esiur.Stores
|
||||
|
||||
public AsyncReply<IResource> Get(string path)
|
||||
{
|
||||
foreach (var r in resources)
|
||||
if (r.Value.Instance.Name == path)
|
||||
return new AsyncReply<IResource>(r.Value);
|
||||
|
||||
return new AsyncReply<IResource>(null);
|
||||
}
|
||||
|
||||
public bool Put(IResource resource)
|
||||
{
|
||||
resources.Add(resource.Instance.Id, resource);
|
||||
resources.Add(resource.Instance.Id, resource);// new WeakReference<IResource>(resource));
|
||||
resource.Instance.Attributes["children"] = new AutoList<IResource, Instance>(resource.Instance);
|
||||
resource.Instance.Attributes["parents"] = new AutoList<IResource, Instance>(resource.Instance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public AsyncReply<IResource> Retrieve(uint iid)
|
||||
{
|
||||
if (resources.ContainsKey(iid))
|
||||
return new AsyncReply<IResource>(resources[iid]);
|
||||
{
|
||||
if (resources.ContainsKey(iid))// .TryGetTarget(out r))
|
||||
return new AsyncReply<IResource>(resources[iid]);
|
||||
else
|
||||
return new AsyncReply<IResource>(null);
|
||||
}
|
||||
else
|
||||
return new AsyncReply<IResource>(null);
|
||||
}
|
||||
@ -75,6 +87,59 @@ namespace Esiur.Stores
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply<bool> AddChild(IResource parent, IResource child)
|
||||
{
|
||||
if (parent.Instance.Store == this)
|
||||
{
|
||||
(parent.Instance.Attributes["children"] as AutoList<IResource, Instance>).Add(child);
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
else
|
||||
return new AsyncReply<bool>(false);
|
||||
}
|
||||
|
||||
public AsyncReply<bool> RemoveChild(IResource parent, IResource child)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public AsyncReply<bool> AddParent(IResource resource, IResource parent)
|
||||
{
|
||||
|
||||
if (resource.Instance.Store == this)
|
||||
{
|
||||
(resource.Instance.Attributes["parents"] as AutoList<IResource, Instance>).Add(parent);
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
else
|
||||
return new AsyncReply<bool>(false);
|
||||
}
|
||||
|
||||
public AsyncReply<bool> RemoveParent(IResource child, IResource parent)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public AsyncBag<T> Children<T>(IResource resource, string name) where T : IResource
|
||||
{
|
||||
var children = (resource.Instance.Attributes["children"] as AutoList<IResource, Instance>);
|
||||
|
||||
if (name == null)
|
||||
return new AsyncBag<T>(children.Where(x=>x is T).Select(x=>(T)x).ToArray());
|
||||
else
|
||||
return new AsyncBag<T>(children.Where(x => x is T && x.Instance.Name == name).Select(x => (T)x).ToArray());
|
||||
|
||||
}
|
||||
|
||||
public AsyncBag<T> Parents<T>(IResource resource, string name) where T : IResource
|
||||
{
|
||||
var parents = (resource.Instance.Attributes["parents"] as AutoList<IResource, Instance>);
|
||||
|
||||
if (name == null)
|
||||
return new AsyncBag<T>(parents.Where(x => x is T).Select(x => (T)x).ToArray());
|
||||
else
|
||||
return new AsyncBag<T>(parents.Where(x => x is T && x.Instance.Name == name).Select(x => (T)x).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user