public object Invoke(Basics.Context.Request.HttpMethod httpMethod, string[] classNames, string functionName, object[] functionParams, bool instanceExecute, ExecuterTypes executerType) { if (string.IsNullOrEmpty(functionName)) { throw new ArgumentNullException(nameof(functionName)); } functionParams ??= new object[] { }; string executionId = Guid.NewGuid().ToString(); object result = null; DomainExecutable domainInstance = this.LoadDomainExecutable(out Exception exception); if (exception != null) { return(exception); } try { Type assemblyObject = classNames != null ? this._AssemblyDll.GetType($"Xeora.Domain.{string.Join("+", classNames)}", true, true) : domainInstance.GetType(); MethodInfo assemblyMethod = this.GetAssemblyMethod(ref assemblyObject, httpMethod, functionName, ref functionParams, executerType); if (assemblyMethod == null) { return(this.GetMethodException(httpMethod, classNames, functionName, functionParams)); } ApplicationContext.InvokePreExecution(domainInstance, executionId, assemblyMethod); result = this.InvokeMethod(instanceExecute, assemblyObject, assemblyMethod, functionParams); } catch (Exception ex) { return(this.GetExecutionError(classNames, functionName, functionParams, ex)); } finally { ApplicationContext.InvokePostExecution(domainInstance, executionId, ref result); } return(result); }
public object Invoke(Basics.Context.HttpMethod httpMethod, string[] classNames, string functionName, object[] functionParams, bool instanceExecute, ExecuterTypes executerType) => this._LibraryExecuter.Invoke(httpMethod, classNames, functionName, functionParams, instanceExecute, executerType);
private MethodInfo GetAssemblyMethod(ref Type assemblyObject, Basics.Context.Request.HttpMethod httpMethod, string functionName, ref object[] functionParams, ExecuterTypes executerType) { MethodInfoFinder methodFinder = new MethodInfoFinder(httpMethod, functionName); string searchKey = $"{assemblyObject.FullName}.{methodFinder.Identifier}"; MethodInfo[] possibleMethodInfos; lock (this._AssemblyMethodLock) { if (this._AssemblyMethods.ContainsKey(searchKey)) { possibleMethodInfos = this._AssemblyMethods[searchKey]; } else { possibleMethodInfos = Array.FindAll(assemblyObject.GetMethods(), methodFinder.Find); this._AssemblyMethods[searchKey] = possibleMethodInfos; } } MethodInfo methodInfoResult = this.FindBestMatch(possibleMethodInfos, ref functionParams, executerType); if (methodInfoResult != null) { return(methodInfoResult); } if (assemblyObject.BaseType == null) { return(null); } Type baseType = assemblyObject.BaseType; MethodInfo assemblyMethod = this.GetAssemblyMethod(ref baseType, httpMethod, functionName, ref functionParams, executerType); if (assemblyMethod != null) { assemblyObject = baseType; } return(assemblyMethod); }
private MethodInfo FindBestMatch(IEnumerable <MethodInfo> possibleMethodInfos, ref object[] functionParams, ExecuterTypes executerType) { MethodInfo worstMatch = null; foreach (MethodInfo methodInfo in possibleMethodInfos) { bool isXeoraControl = ApplicationContext.CheckFunctionResultTypeIsXeoraControl(methodInfo.ReturnType); switch (executerType) { case ExecuterTypes.Control: if (!ReferenceEquals(methodInfo.ReturnType, typeof(object)) && !isXeoraControl) { continue; } break; case ExecuterTypes.Other: if (!isXeoraControl) { break; } // These are exceptional controls if (methodInfo.ReturnType == typeof(Basics.ControlResult.RedirectOrder) || methodInfo.ReturnType == typeof(Basics.ControlResult.Message)) { break; } continue; } ParameterInfo[] methodParams = methodInfo.GetParameters(); switch (this.ExamParameters(methodParams, ref functionParams)) { case 0: return(methodInfo); case 1: worstMatch = methodInfo; break; } } return(worstMatch); }
public static Basics.Execution.InvokeResult <T> InvokeBind <T>(Basics.Context.Request.HttpMethod httpMethod, Basics.Execution.Bind bind, ExecuterTypes executerType) { if (bind == null) { throw new NoNullAllowedException("Requires bind!"); } // Check if BindInfo Parameters has been parsed! if (!bind.Ready) { throw new Exception("Bind Parameters should be parsed first!"); } DateTime executionBegins = DateTime.Now; Basics.Execution.InvokeResult <T> rInvokeResult = new Basics.Execution.InvokeResult <T>(bind); object invokedObject = ApplicationFactory.Prepare(bind.Executable).Invoke( httpMethod, bind.Classes, bind.Procedure, bind.Parameters.Values, bind.InstanceExecution, executerType ); if (invokedObject is Exception exception) { rInvokeResult.Exception = exception; } else { rInvokeResult.Result = (T)invokedObject; } if (!Basics.Configurations.Xeora.Application.Main.PrintAnalysis) { return(rInvokeResult); } double totalMs = DateTime.Now.Subtract(executionBegins).TotalMilliseconds; Basics.Console.Push( "analysed - execution duration", $"{totalMs}ms - {bind}", string.Empty, false, groupId: Basics.Helpers.Context.UniqueId, type: totalMs > Basics.Configurations.Xeora.Application.Main.AnalysisThreshold ? Basics.Console.Type.Warn: Basics.Console.Type.Info); return(rInvokeResult); }
public object Invoke(Basics.Context.HttpMethod httpMethod, string[] classNames, string functionName, object[] functionParams, bool instanceExecute, ExecuterTypes executerType) { if (string.IsNullOrEmpty(functionName)) { throw new ArgumentNullException(nameof(functionName)); } if (functionParams == null) { functionParams = new object[] { } } ; string executionID = Guid.NewGuid().ToString(); object result = null; object executeObject = this.LoadDomainExecutable(); if (executeObject is System.Exception) { return(executeObject); } try { Type assemblyObject = null; if (classNames != null) { assemblyObject = this._AssemblyDll.GetType(string.Format("Xeora.Domain.{0}", string.Join("+", classNames)), true, true); } else { assemblyObject = executeObject.GetType(); } MethodInfo assemblyMethod = this.GetAssemblyMethod(ref assemblyObject, httpMethod, functionName, ref functionParams, executerType); if (assemblyMethod == null) { return(this.GetMethodException(httpMethod, classNames, functionName, functionParams)); } this.InvokePreExecution(executeObject, executionID, assemblyMethod); result = this.InvokeMethod(instanceExecute, assemblyObject, assemblyMethod, functionParams); return(result); } catch (System.Exception ex) { return(this.GetExecutionError(classNames, functionName, functionParams, ex)); } finally { this.InvokePostExecution(executeObject, executionID, result); } }
private MethodInfo FindBestMatch(MethodInfo[] possibleMethodInfos, ref object[] functionParams, ExecuterTypes executerType) { MethodInfo worstMatchedMI = null; for (int mC = 0; mC < possibleMethodInfos.Length; mC++) { MethodInfo methodInfo = possibleMethodInfos[mC]; bool isXeoraControl = this.CheckFunctionResultTypeIsXeoraControl(methodInfo.ReturnType); switch (executerType) { case ExecuterTypes.Control: if (!object.ReferenceEquals(methodInfo.ReturnType, typeof(object)) && !isXeoraControl) { continue; } break; case ExecuterTypes.Other: if (isXeoraControl) { // These are exceptional controls if (methodInfo.ReturnType == typeof(Basics.ControlResult.RedirectOrder) || methodInfo.ReturnType == typeof(Basics.ControlResult.Message)) { break; } continue; } break; } ParameterInfo[] methodParams = methodInfo.GetParameters(); switch (this.ExamParameters(methodParams, ref functionParams)) { case 0: return(methodInfo); case 1: worstMatchedMI = methodInfo; break; } } return(worstMatchedMI); }
private MethodInfo GetAssemblyMethod(ref Type assemblyObject, Basics.Context.HttpMethod httpMethod, string functionName, ref object[] functionParams, ExecuterTypes executerType) { MethodInfoFinder mIF = new MethodInfoFinder(httpMethod, functionName); string searchKey = string.Format("{0}.{1}", assemblyObject.FullName, mIF.Identifier); MethodInfo[] possibleMethodInfos = null; if (!this._AssemblyMethods.TryGetValue(searchKey, out possibleMethodInfos)) { possibleMethodInfos = Array.FindAll <MethodInfo>(assemblyObject.GetMethods(), new Predicate <MethodInfo>(mIF.Find)); this._AssemblyMethods.TryAdd(searchKey, possibleMethodInfos); } MethodInfo methodInfoResult = this.FindBestMatch(possibleMethodInfos, ref functionParams, executerType); if (methodInfoResult != null) { return(methodInfoResult); } if (assemblyObject.BaseType == null) { return(null); } Type baseType = assemblyObject.BaseType; MethodInfo assemblyMethod = this.GetAssemblyMethod(ref baseType, httpMethod, functionName, ref functionParams, executerType); if (assemblyMethod != null) { assemblyObject = baseType; } return(assemblyMethod); }
public static Basics.Execution.InvokeResult <T> InvokeBind <T>(Basics.Context.HttpMethod httpMethod, Basics.Execution.Bind bind, ExecuterTypes executerType) { if (bind == null) { throw new NoNullAllowedException("Requires bind!"); } // Check if BindInfo Parameters has been parsed! if (!bind.Ready) { throw new System.Exception("Bind Parameters shoud be parsed first!"); } Basics.Execution.InvokeResult <T> rInvokeResult = new Basics.Execution.InvokeResult <T>(bind); try { object invokedObject = Application.Prepare(bind.Executable).Invoke( httpMethod, bind.Classes, bind.Procedure, bind.Parameters.Values, bind.InstanceExecution, executerType ); if (invokedObject is System.Exception) { throw (System.Exception)invokedObject; } rInvokeResult.Result = (T)invokedObject; } catch (System.Exception ex) { Helper.EventLogger.Log(ex); rInvokeResult.Exception = ex; } return(rInvokeResult); }