newResource<T extends IResource> static method
Implementation
static AsyncReply<T> newResource<T extends IResource>(String name,
[IStore? store = null,
IResource? parent = null,
IPermissionsManager? manager = null,
Map<String, dynamic>? attributes = null,
Map<String, dynamic>? properties = null]) {
if (_factory[T] == null)
throw Exception("No Instance Creator was found for type ${T}");
var resource = _factory[T]?.instanceCreator.call() as T;
if (properties != null) {
dynamic d = resource;
for (var i = 0; i < properties.length; i++)
d[properties.keys.elementAt(i)] = properties.values.elementAt(i);
//setProperty(resource, properties.keys.elementAt(i), properties.at(i));
}
var rt = AsyncReply<T>();
put<T>(name, resource, store, parent, null, 0, manager, attributes)
..then((value) {
if (value != null)
rt.trigger(resource);
else
rt.triggerError(AsyncException(
ErrorType.Management,
ExceptionCode.GeneralFailure.index,
"Can't put the resource")); // .trigger(null);
})
..error((ex) => rt.triggerError(ex));
return rt;
/*
var type = ResourceProxy.GetProxy<T>();
var res = Activator.CreateInstance(type) as IResource;
put(res, name, store, parent, null, 0, manager, attributes);
return (T)res;
*/
}