/// <summary> /// 提交信息,执行方法 /// </summary> /// <param name="xncfUid"></param> /// <param name="xncfFunctionName"></param> /// <param name="xncfFunctionParams"></param> /// <returns></returns> public async Task <IActionResult> OnPostRunFunctionAsync([FromBody] ExecuteFuncParamDto executeFuncParamDto) { var xncfRegister = XncfRegisterManager.RegisterList.FirstOrDefault(z => z.Uid == executeFuncParamDto.XncfUid); if (xncfRegister == null) { return(new JsonResult(new { success = false, msg = "模块未注册!" })); } var xncfModule = await _xncfModuleService.GetObjectAsync(z => z.Uid == xncfRegister.Uid).ConfigureAwait(false); if (xncfModule == null) { return(new JsonResult(new { success = false, msg = "当前模块未安装!" })); } if (xncfModule.State != XncfModules_State.开放) { return(new JsonResult(new { success = false, msg = $"当前模块状态为【{xncfModule.State}】,必须为【开放】状态的模块才可执行!\r\n此外,如果您强制执行此方法,也将按照未通过验证的程序集执行,因为您之前安装的版本可能已经被新的程序所覆盖。" })); } FunctionBase function = null; foreach (var functionType in xncfRegister.Functions) { var fun = _serviceProvider.GetService(functionType) as FunctionBase;//如:Senparc.Xncf.ChangeNamespace.Functions.ChangeNamespace //var functionParameters = await function.GetFunctionParameterInfoAsync(_serviceProvider, false); if (fun.Name == executeFuncParamDto.XncfFunctionName) { function = fun; break; } } if (function == null) { return(new JsonResult(new { success = false, msg = "方法未匹配上!" })); } var paras = SerializerHelper.GetObject(executeFuncParamDto.XncfFunctionParams, function.FunctionParameterType) as IFunctionParameter; //var paras = function.GenerateParameterInstance(); var result = function.Run(paras); var tempId = "Xncf-FunctionRun-" + Guid.NewGuid().ToString("n"); //记录日志缓存 if (!result.Log.IsNullOrEmpty()) { var cache = _serviceProvider.GetObjectCacheStrategyInstance(); await cache.SetAsync(tempId, result.Log, TimeSpan.FromMinutes(5));//TODO:可设置 } var data = new { success = result.Success, msg = result.Message.HtmlEncode(), log = result.Log, exception = result.Exception?.Message, tempId = tempId }; return(new JsonResult(data)); }
public async Task <IActionResult> OnPostRunFunctionAsync(string xscfUid, string xscfFunctionName, string xscfFunctionParams) { var xscfRegister = Senparc.Scf.XscfBase.Register.RegisterList.FirstOrDefault(z => z.Uid == xscfUid); if (xscfRegister == null) { return(new JsonResult(new { success = false, msg = "模块未注册!" })); } var xscfModule = await _xscfModuleService.GetObjectAsync(z => z.Uid == xscfRegister.Uid).ConfigureAwait(false); if (xscfModule == null) { return(new JsonResult(new { success = false, msg = "当前模块未安装!" })); } if (xscfModule.State != XscfModules_State.开放) { return(new JsonResult(new { success = false, msg = $"当前模块状态为【{xscfModule.State}】,必须为【开放】状态的模块才可执行!\r\n此外,如果您强制执行此方法,也将按照未通过验证的程序集执行,因为您之前安装的版本可能已经被新的程序所覆盖。" })); } FunctionBase function = null; foreach (var functionType in xscfRegister.Functions) { var fun = _serviceProvider.GetService(functionType) as FunctionBase;//如:Senparc.Xscf.ChangeNamespace.Functions.ChangeNamespace var functionParameters = fun.GetFunctionParammeterInfo().ToList(); if (fun.Name == xscfFunctionName) { function = fun; } } if (function == null) { return(new JsonResult(new { success = false, msg = "方法未匹配上!" })); } var paras = SerializerHelper.GetObject(xscfFunctionParams, function.FunctionParameterType) as IFunctionParameter; //var paras = function.GenerateParameterInstance(); var result = function.Run(paras); var data = new { success = true, msg = result }; return(new JsonResult(data)); }
private void OnTriggerEnter(Collider other) { Work.Run(Data); }