public MethodInfoFinder(Basics.Context.Request.HttpMethod httpMethod, string searchName) { this._HttpMethod = httpMethod; this._SearchName = searchName; this.Identifier = $"{this._HttpMethod}_{this._SearchName}"; }
public bool Find(MethodInfo mI) { foreach (object aT in mI.GetCustomAttributes(false)) { Type workingType = aT.GetType(); if (workingType != typeof(Basics.Attribute.HttpMethodAttribute)) { continue; } Basics.Context.Request.HttpMethod httpMethod = (Basics.Context.Request.HttpMethod)workingType.InvokeMember("Method", BindingFlags.GetProperty, null, aT, null); object bindProcedureName = workingType.InvokeMember("BindProcedureName", BindingFlags.GetProperty, null, aT, null); if (httpMethod != this._HttpMethod) { return(false); } if (!string.IsNullOrEmpty(bindProcedureName.ToString())) { return(string.CompareOrdinal(bindProcedureName.ToString(), this._SearchName) == 0); } break; } return(string.Compare(this._SearchName, mI.Name, StringComparison.OrdinalIgnoreCase) == 0); }
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.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); }
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 Exception GetMethodException(Basics.Context.Request.HttpMethod httpMethod, string[] classNames, string functionName, IReadOnlyCollection <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.Count); foreach (object param in functionParams) { sB.AppendFormat(", {0}", param.GetType()); } 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)) { return(lineNumber != 1); } switch (lineNumber) { case 1: string[] lineParts = line.Split(' '); if (!Enum.TryParse(lineParts[0], out this._Method)) { this._Method = Basics.Context.Request.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 (Exception) { this.ContentEncoding = null; } break; } } break; case "cookie": this.ParseCookies(value); break; default: AddOrUpdate(key, value); break; } break; } lineNumber++; } return(false); }
// 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.Request.HttpMethod httpMethod, Basics.Execution.Bind bind) => Executer.InvokeBind <T>(httpMethod, bind, ExecuterTypes.Undefined);
public object Invoke(Basics.Context.Request.HttpMethod httpMethod, string[] classNames, string functionName, object[] functionParams, bool instanceExecute, ExecuterTypes executerType) => this._Context.Invoke(httpMethod, classNames, functionName, functionParams, instanceExecute, executerType);