public object TryDynamicApi(MigInterfaceCommand command) { object response = ""; // Dynamic Interface API var registeredApi = command.Domain + "/" + command.Address + "/" + command.Command; var handler = ProgramDynamiApi.Find(registeredApi); if (handler != null) { // explicit command API handlers registered in the form <domain>/<address>/<command> // receives only the remaining part of the request after the <command> var args = command.OriginalRequest.Substring(registeredApi.Length).Trim('/'); response = handler(args); } else { handler = ProgramDynamiApi.FindMatching(command.OriginalRequest.Trim('/')); if (handler != null) { // other command API handlers // receives the full request string response = handler(command.OriginalRequest.Trim('/')); } } return(response); }
public void UnRegisterDynamicApi(string apiCall) { ProgramDynamiApi.UnRegister(apiCall); }
//TODO: should the following 3 methods moved to ProgramEngine? public void RegisterDynamicApi(string apiCall, Func <object, object> handler) { ProgramDynamiApi.Register(apiCall, handler); }