public Entry InvokeMethod(string moduleName, MethodEntry method) { Entry result = null; var serverModule = GetModuleFromManager(moduleName); if (serverModule != null && method != null) { try { result = EntryConvert.InvokeMethod(serverModule.Console, method, CreateEditorSerializeSerialization(serverModule)); } catch (Exception e) { result = new Entry { Description = $"Error while invoking function: {method.DisplayName}", DisplayName = "Error description", Identifier = "0", Value = new EntryValue { Current = e.Message, Type = EntryValueType.String } }; } } else { var ctx = WebOperationContext.Current; // ReSharper disable once PossibleNullReferenceException ctx.OutgoingResponse.StatusCode = HttpStatusCode.NotFound; } return(result); }
public Entry InvokeMethod(string idString, string method, Entry parameters) { return(ExecuteCall <Entry>(delegate { var id = long.Parse(idString); var resource = Graph.Get(id); if (resource == null) { return RequestResult <Entry> .NotFound($"Resource '{idString} not found!"); } return EntryConvert.InvokeMethod(resource.Descriptor, new MethodEntry { Name = method, Parameters = parameters }, Serialization); })); }
/// <inheritdoc /> public ResourceModel Create(string resourceType, MethodEntry constructor = null) { var converter = new ResourceToModelConverter(TypeTree, Serialization); var resource = Graph.Instantiate(resourceType); if (constructor != null) { EntryConvert.InvokeMethod(resource, constructor, Serialization); } var model = converter.GetDetails(resource); model.Methods = new MethodEntry[0]; // Reset methods because the can not be invoked on new objects return(model); }
private ResourceModel Construct(string type, MethodEntry method) { return(ExecuteCall <ResourceModel>(delegate { var converter = new ResourceToModelConverter(TypeTree, Serialization); var resource = Graph.Instantiate(type); if (method != null) { EntryConvert.InvokeMethod(resource, method, Serialization); } var model = converter.GetDetails(resource); model.Methods = new MethodEntry[0]; // Reset methods because they can not be invoked on new objects return model; })); }
private ActionResult <ResourceModel> Construct(string type, MethodEntry method) { var resource = (Resource)Activator.CreateInstance(_resourceTypeTree[type].ResourceType); if (resource is null) { return(NotFound()); } if (method != null) { EntryConvert.InvokeMethod(resource, method, _serialization); } var model = new ResourceToModelConverter(_resourceTypeTree, _serialization).GetDetails(resource); model.Methods = Array.Empty <MethodEntry>(); // Reset methods because they can not be invoked on new objects return(model); }
public ActionResult <Entry> InvokeMethod(long id, string method, Entry parameters) { if (_resourceModification.GetAllResources <IResource>(r => r.Id == id) is null) { return(NotFound($"Resource {id} not found!")); } Entry entry = null; _resourceModification.Modify(id, r => { entry = EntryConvert.InvokeMethod(r.Descriptor, new MethodEntry { Name = method, Parameters = parameters }, _serialization); return(true); }); if (entry is null) { return(Conflict("Method could not be invoked.")); } return(entry); }
/// <inheritdoc /> public Entry InvokeMethod(long id, MethodEntry methodModel) { var resource = Graph.Get(id); return(EntryConvert.InvokeMethod(resource, methodModel, Serialization)); }