public MethodInfoFinder(Basics.Context.HttpMethod httpMethod, string searchName) { this._HttpMethod = httpMethod; this._SearchName = searchName; this.Identifier = string.Format("{0}_{1}", this._HttpMethod, this._SearchName); }
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); } }
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); }
public bool Find(MethodInfo mI) { bool attributeCheck = (string.Compare(this._SearchName, mI.Name, true) == 0); foreach (object aT in mI.GetCustomAttributes(false)) { Type workingType = aT.GetType(); if (workingType == typeof(Basics.Attribute.HttpMethodAttribute)) { Basics.Context.HttpMethod httpMethod = (Basics.Context.HttpMethod)workingType.InvokeMember("Method", BindingFlags.GetProperty, null, aT, null); object bindProcedureName = workingType.InvokeMember("BindProcedureName", BindingFlags.GetProperty, null, aT, null); return((httpMethod == this._HttpMethod) && (string.Compare(bindProcedureName.ToString(), this._SearchName) == 0)); } } return(attributeCheck); }
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); }
private System.Exception GetMethodException(Basics.Context.HttpMethod httpMethod, string[] classNames, string functionName, object[] functionParams) { System.Text.StringBuilder sB = new System.Text.StringBuilder(); sB.AppendLine("Assembly does not have following procedure!"); sB.AppendLine("--------------------------------------------------"); sB.AppendFormat("ExecutableName: {0}", this._ExecutableName); sB.AppendLine(); sB.AppendFormat("ClassName: {0}", string.Join(".", classNames)); sB.AppendLine(); sB.AppendFormat("FunctionName: {0}", functionName); sB.AppendLine(); sB.AppendFormat("FunctionParamsLength: {0}", functionParams.Length); foreach (object Param in functionParams) { sB.AppendFormat(", {0}", Param.GetType().ToString()); } sB.AppendLine(); sB.AppendFormat("HttpMethod: {0}", httpMethod); sB.AppendLine(); return(new TargetException(sB.ToString())); }
public bool Parse() { string header = this.ExtractHeader(); StringReader sR = new StringReader(header); int lineNumber = 1; while (sR.Peek() > -1) { string line = sR.ReadLine(); if (string.IsNullOrEmpty(line)) { if (lineNumber == 1) { return(false); } return(true); } switch (lineNumber) { case 1: string[] lineParts = line.Split(' '); if (!System.Enum.TryParse <Basics.Context.HttpMethod>(lineParts[0], out this._Method)) { this._Method = Basics.Context.HttpMethod.GET; } this.URL = new URL(lineParts[1]); this.Protocol = lineParts[2]; break; default: int colonIndex = line.IndexOf(':'); if (colonIndex == -1) { return(false); } string key = line.Substring(0, colonIndex); string value = line.Substring(colonIndex + 1); value = value.Trim(); switch (key.ToLowerInvariant()) { case "host": this.Host = value; break; case "user-agent": this.UserAgent = value; break; case "content-length": int.TryParse(value, out this._ContentLength); break; case "content-type": string[] contentTypeValues = value.Split(';'); this.ContentType = contentTypeValues[0]; for (int cC = 1; cC < contentTypeValues.Length; cC++) { string keyAndValue = contentTypeValues[cC]; int equalsIndex = keyAndValue.IndexOf('='); if (equalsIndex == -1) { continue; } string contentKey = keyAndValue.Substring(0, equalsIndex).Trim(); switch (contentKey) { case "boundary": string boundaryValue = keyAndValue.Substring(equalsIndex + 1).Trim(); this.Boundary = boundaryValue.Replace("\"", string.Empty); break; case "charset": string charsetValue = keyAndValue.Substring(equalsIndex + 1).Trim(); try { this.ContentEncoding = Encoding.GetEncoding(charsetValue); } catch (System.Exception) { this.ContentEncoding = null; } break; } } break; case "cookie": this.ParseCookies(value); break; default: base.AddOrUpdate(key, value); break; } break; } lineNumber++; } return(false); }
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);
// This function is for external call out side of the project DO NOT DISABLE IT public static Basics.Execution.InvokeResult <T> InvokeBind <T>(Basics.Context.HttpMethod httpMethod, Basics.Execution.Bind bind) => AssemblyCore.InvokeBind <T>(httpMethod, bind, ExecuterTypes.Undefined);