private static IEnumerable <AConFlowStep> FindSteps(string ComId, ISysDatabaseService codeService) { IEnumerable <AConFlowStep> cons = null; if (APPCommon.AppConfig.IsUseGloableCahe) { cons = APP.AConFlowSteps.Where(p => p.AComposityId == ComId); if (cons == null || cons.Count() == 0) { cons = codeService.GetAConStateSteps(ComId).OrderBy(p => p.StepOrder).ToList(); if (cons != null) { APP.AConFlowSteps.AddRange(cons); } } } else { cons = codeService.GetAConStateSteps(ComId).OrderBy(p => p.StepOrder).ToList(); } if (cons == null) { Logger.LogError(logName, "FindStep -> FindStep null"); } return(cons); }
public GodWorker(ISysDatabaseService codeService, ISqlSugarClient dbFactory, IConfiguration config) { WorkerName = Guid.NewGuid().ToString("N"); DbFactory = dbFactory; CodeService = codeService; Config = config; appConfig = config.GetSection("App").Get <AppConfig>(); //ModuleManager = new DefaultModuleManager(); }
private static async Task CheckAndRunNextRuntimeComposity(int requsetHash, HttpContext httpContext, RuntimeStepModel newrunmodel, ISqlSugarClient dbFactory, ISysDatabaseService codeService, IConfiguration config) { var resouce = newrunmodel.Resuce(newrunmodel.NextRunTimeKey); if (resouce != null) { var guid = (string)resouce; if (string.IsNullOrEmpty(guid)) { //newrunmodel.ResouceInfos.Remove(newrunmodel.NextRunTimeKey); return; } var nextcon = codeService.GetConposity(guid).FirstOrDefault(); if (nextcon == null) { nextcon = new ComposeEntity() { Guid = guid, RunMode = RunMode.Coding }; var reint = codeService.InsertCode(nextcon); } else { var nextRnmodel = new RuntimeStepModel(config) { ParentRuntimeModel = newrunmodel, Res = newrunmodel.Res, ComposeEntity = nextcon, HashCode = nextcon.GetHash() }; nextRnmodel.Res.Remove(newrunmodel.NextRunTimeKey); await RunComposity(requsetHash, httpContext, nextRnmodel, dbFactory, codeService, config); } } }
public DbFormController(ISysDatabaseService codeService) { m_codeService = codeService; }
//public void GetRequestHash(ActionExecutingContext actionExecutingContext) //{ // //actionExecutingContext.HttpContext.req //} private async static Task RunComposity(int requsetHash, HttpContext httpContext, RuntimeStepModel newrunmodel, ISqlSugarClient dbFactory, ISysDatabaseService codeService, IConfiguration config) { var cons = newrunmodel.ComposeEntity; if (cons.RunMode == RunMode.Coding) { if (newrunmodel.ComposeTemplate != null) { //TODO :add template } //Manager.RuntimeModels.Add(newrunmodel); else { var steps = FindSteps(cons.Guid, codeService); foreach (var s in steps) { object rebject = null; object DynaObject = null; if (s.IsUsingAuth.ToBool()) { await httpContext.AuthenticateAsync(); if (httpContext.User.Identity.Name != s.UserName || !httpContext.User.Identity.IsAuthenticated) { APPCommon.ResponseUnAuth((ActionExecutingContext)newrunmodel.Res["__actioncontext"], s.LoginUrl); return; } } var cacheKey = string.Concat(cons.Guid, "_", s.ExcuteType, "_", s.FlowStepType, "_", s.Guid, "_", s.ArgNames); object stepResult = APP.RuntimeCache.GetOrCreate(cacheKey, entry => { object newobj = null; APP.RuntimeCache.Set(cacheKey, newobj); return(newobj); }); if (s.IsUsingCache && stepResult != null) { rebject = stepResult; } else { if (!s.IsUsingCache || stepResult == null) { switch (s.FlowStepType) { case FlowStepType.Declare: { lock (lockobj) { //root.Usings[2].Name.ToString() // var rebject2 = Manager.GetData(spec.InParamter1, spec.InParamter2); var runcode = APP.FindOrAddRumtimeCode(s.Guid); var so_default = ScriptOptions.Default; if (runcode == null) { runcode = new RuntimeCode() { StepGuid = s.Guid, CodeLines = s.ProxyCode, }; List <string> dlls = new List <string>(); var isref = false; string dllbase = APPCommon.AppRootDir; if (!string.IsNullOrEmpty(s.TypeLib)) { var dllfile = dllbase + s.TypeLib; if (APP.DynamicReferenceDlls.Contains(dllfile)) { isref = false; } else { APP.DynamicReferenceDlls.Add(dllfile); isref = true; dlls.Add(dllfile); } } if (!string.IsNullOrEmpty(s.ReferenceDlls)) { isref = true; string[] dllnams = s.ReferenceDlls.Split(','); foreach (var n in dllnams) { APP.DynamicReferenceDlls.Add(dllbase + n); } dlls.AddRange(dllnams); } if (isref) { so_default = so_default.WithReferences(dlls.ToArray()); } so_default = so_default.WithReferences(Assembly.GetExecutingAssembly()); var state = CSharpScript.Create <object>(s.ProxyCode, so_default, typeof(Dictionary <string, object>)); runcode.Script = state; APP.RuntimeCodes.Add(s.Guid, runcode); } if (!string.IsNullOrEmpty(s.ReferenceDlls)) { string dllbase = APPCommon.AppRootDir; } rebject = runcode.Script.RunAsync(newrunmodel.Res).Result.ReturnValue; Logger.LogInfo(LoggerName, $"AComposityId id {s.AComposityId} ,step {s.StepOrder}, Declare: result {rebject} "); } } break; case FlowStepType.GetData: { DynaObject = HandleGetData(httpContext, newrunmodel, dbFactory, s); } break; case FlowStepType.CallMethod: { var methodsub = APP.GetMethodFromConfig(s.IsBuildIn.Value, s.TypeLib, s.TypeFullName, s.MethodName); var objParams = new List <object>(); if (!string.IsNullOrEmpty(s.ArgNames)) { objParams = newrunmodel.GetPoolResuce(s.ArgNames.Split(',')); } else { objParams = null; } try { if (methodsub.IsStatic) { DynaObject = methodsub.Invoke(null, objParams.ToArray()); } else { var instance = newrunmodel.Res[s.InstanceName]; DynaObject = methodsub.Invoke(instance, objParams.ToArray()); } } catch (Exception exp) { Logger.LogError(logName, "Run -> FlowStepType.CallMethod error,composity:{0},step:{1},-------------exception:{2}", cons.Id, s.Guid, LoggerHelper.GetExceptionString(exp)); break; } Logger.LogInfo(LoggerName, $"AComposityId id {s.AComposityId} ,step {s.StepOrder}, CallMethod {s.MethodName}: result {DynaObject} "); } break; case FlowStepType.Text: { rebject = s.OutPutText; } break; case FlowStepType.Function: { DynaObject = DealTheFunction(newrunmodel, s, httpContext); Logger.LogInfo(LoggerName, $"DealTheFunction: result {DynaObject} "); } break; case FlowStepType.RazorKey: try { rebject = stepResult = await HandleRazorKey(newrunmodel, s); } catch (Exception exp) { Logger.LogError(logName, $"parser RazorText wrong: {exp.Message}-------{LoggerHelper.GetExceptionString(exp)}"); } break; case FlowStepType.RazorText: try { rebject = stepResult = await HandleRazorText(newrunmodel, s, httpContext, s.ProxyCode); } catch (Exception exp) { Logger.LogError(logName, $"parser RazorText wrong: {exp.Message}-------{LoggerHelper.GetExceptionString(exp)}"); } break; case FlowStepType.RazorFile: try { var filePath = s.ProxyCode; string template = File.ReadAllText(Path.Combine(APPCommon.UserUploadBaseDir, filePath)); rebject = stepResult = await HandleRazorText(newrunmodel, s, httpContext, template); } catch (Exception exp) { Logger.LogError(logName, "parser RazorFile wrong: " + exp.Message + "-------" + LoggerHelper.GetExceptionString(exp)); } break; } if (rebject == null) { rebject = MagicExtension.BackToInst(DynaObject); } if (s.IsUsingCache) { APP.RuntimeCache.Set(cacheKey, rebject); } } } if (!string.IsNullOrEmpty(s.StorePoolKey) && rebject != null) { newrunmodel.SetComposityResourceValue(s.StorePoolKey, rebject); } } await CheckAndRunNextRuntimeComposity(requsetHash, httpContext, newrunmodel, dbFactory, codeService, config); } //Manager.RuntimeModels.Remove(newrunmodel); } }
public DictionaryController(ISysDatabaseService codeService) { m_codeService = codeService; }
public AssemblyInjection(ISysDatabaseService dbclient) { Dbclient = dbclient; }
public UserController(ISysDatabaseService codeService) { m_codeService = codeService; }
public FactController(ISysDatabaseService codeService) { m_codeService = codeService; //var ss = HttpContext.Session["admin"] ?? ""; //if( ) }
public FactController(ISysDatabaseService codeService, DynamicActionProvider dynamicActionProvider, DynamicChangeTokenProvider dynamicChangeToken) { m_codeService = codeService; //var ss = HttpContext.Session["admin"] ?? ""; //if( ) }