private void ExecuteHandler(HandlerType type, Object[] parameters) { String handler = GetHandlerClassName(type); if (!string.IsNullOrWhiteSpace(handler)) { try { string nSpace = string.Empty; Config.GetValueOf("AppMainNamespace", out nSpace); GXProcedure obj = null; try { obj = (GXProcedure)ClassLoader.FindInstance(string.Empty, nSpace, handler, null, null); } catch (Exception) { LogError("GXWebSocket - Could not create Procedure Instance: " + handler); return; } ClassLoader.Execute(obj, "execute", parameters); } catch (Exception e) { LogError("GXWebSocket - Handler failed executing action: " + handler); LogError(e.Message); } } }
private string PreProcessReplicatorParameteres(GXProcedure procWorker, string innerMethod, Dictionary <string, object> bodyParameters) { var methodInfo = procWorker.GetType().GetMethod(innerMethod); object[] parametersForInvocation = ReflectionHelper.ProcessParametersForInvoke(methodInfo, bodyParameters); var synchroInfo = parametersForInvocation[1]; return(synchroInfo.GetType().GetProperty(Synchronizer.SYNCHRONIZER_INFO).GetValue(synchroInfo) as string); }
private void PreProcessSynchronizerParameteres(GXProcedure instance, string method, Dictionary <string, object> bodyParameters) { var gxParameterName = instance.GetType().GetMethod(method).GetParameters().First().Name.ToLower(); GxUnknownObjectCollection hashList; if (bodyParameters.ContainsKey(string.Empty)) { hashList = (GxUnknownObjectCollection)ReflectionHelper.ConvertStringToNewType(bodyParameters[string.Empty], typeof(GxUnknownObjectCollection)); } else { hashList = new GxUnknownObjectCollection(); } bodyParameters[gxParameterName] = TableHashList(hashList); }
bool GetWrappedStatus(GXProcedure worker, bool wrapped, Dictionary <string, object> outputParameters) { if (worker.IsApiObject) { if (outputParameters.Count == 1) { Object v = outputParameters.First().Value; if (v.GetType().GetInterfaces().Contains(typeof(IGxGenericCollectionWrapped))) { wrapped = (v as IGxGenericCollectionWrapped).GetIsWrapped(); } else { wrapped = true; } } } return(wrapped); }
private void setWorkerStatus(GXProcedure _procWorker) { if (ReflectionHelper.HasMethod(_procWorker, "getrestcode")) { Dictionary <string, object> outVal = ReflectionHelper.CallMethod(_procWorker, "getrestcode", new Dictionary <string, object>()); short statusCode = (short)outVal.Values.First <object>(); if (statusCode > 0) { this.SetStatusCode((HttpStatusCode)statusCode); } } if (ReflectionHelper.HasMethod(_procWorker, "getrestmsg")) { Dictionary <string, object> outVal = ReflectionHelper.CallMethod(_procWorker, "getrestmsg", new Dictionary <string, object>()); string statusMsg = outVal.Values.First <object>().ToString(); if (!String.IsNullOrEmpty(statusMsg)) { this.SetStatusMessage(statusMsg); } } }
public bool IsAuthenticated(string synchronizer) { GXLogging.Debug(log, "IsMainAuthenticated synchronizer:" + synchronizer); bool validSynchronizer = false; try { if (!string.IsNullOrEmpty(synchronizer)) { string nspace; if (!Config.GetValueOf("AppMainNamespace", out nspace)) { nspace = "GeneXus.Programs"; } String assemblyName = synchronizer.ToLower(); String restServiceName = nspace + "." + assemblyName; GXProcedure synchronizerService = (GXProcedure)ClassLoader.GetInstance(assemblyName, restServiceName, null); if (synchronizerService != null && synchronizerService.IsSynchronizer2) { validSynchronizer = true; return(IsAuthenticated(synchronizerService.IntegratedSecurityLevel2, synchronizerService.IntegratedSecurityEnabled2, synchronizerService.ExecutePermissionPrefix2)); } } return(false); } catch (Exception ex) { GXLogging.Error(log, ex, "IsMainAuthenticated error "); return(false); } finally { if (!validSynchronizer) { SetError("0", "Invalid Synchronizer " + synchronizer); } } }
private bool ExecuteHandler(HandlerType type, Object[] parameters) { String handler = GetHandlerClassName(type); if (!string.IsNullOrWhiteSpace(handler)) { try { string nSpace = string.Empty; Config.GetValueOf("AppMainNamespace", out nSpace); GXProcedure obj = null; try { obj = (GXProcedure)ClassLoader.FindInstance(Config.CommonAssemblyName, nSpace, handler, null, null); if (obj == null) { LogError($"GXWebSocket - Could not create Procedure Handler Class. Class Type '{nSpace}.{handler}' not found in Class Loader."); } } catch (Exception e) { LogError("GXWebSocket - Failed to intialize Procedure Handler Class: " + handler, e); } if (obj != null) { ClassLoader.Execute(obj, "execute", parameters); return(true); } } catch (Exception e) { LogError($"GXWebSocket - Procedure Handler Class Found '{handler}', but failed executing action 'execute.", e); } } return(false); }
public override void webExecute() { #if NETCORE GxRestWrapper handler = null; #else Utils.GxRestService handler = null; #endif try { HttpRequest req = context.HttpContext.Request; string gxobj = GetNextPar().ToLower(); string jsonStr = (new StreamReader(req.GetInputStream())).ReadToEnd(); GxSimpleCollection <JArray> parmsColl = new GxSimpleCollection <JArray>(); if (!string.IsNullOrEmpty(jsonStr)) { parmsColl.FromJSonString(jsonStr); } string nspace; if (!Config.GetValueOf("AppMainNamespace", out nspace)) { nspace = "GeneXus.Programs"; } #if NETCORE var controllerInstance = ClassLoader.FindInstance(gxobj, nspace, gxobj, new Object[] { context }, Assembly.GetEntryAssembly()); GXProcedure proc = controllerInstance as GXProcedure; if (proc != null) { handler = new GxRestWrapper(proc, localHttpContext, context as GxContext); } else { var sdtInstance = ClassLoader.FindInstance(Config.CommonAssemblyName, nspace, $"Sdt{gxobj}", new Object[] { context }, Assembly.GetEntryAssembly()) as GxSilentTrnSdt; if (sdtInstance != null) { handler = new GXBCRestService(sdtInstance, localHttpContext, context as GxContext); } } #else handler = (Utils.GxRestService)ClassLoader.FindInstance(gxobj, nspace, gxobj + "_services", null, null); #endif handler.RunAsMain = false; ParameterInfo[] pars = handler.GetType().GetMethod(EXECUTE_METHOD).GetParameters(); int ParmsCount = pars.Length; object[] convertedparms = new object[ParmsCount]; if (parmsColl.Count > 0) { foreach (JArray parmValues in parmsColl) { int idx = 0; for (int i = 0; i < ParmsCount; i++) { if (!pars[i].IsOut) { convertedparms[i] = convertparm(pars, i, parmValues[idx]); } idx++; } handler.GetType().InvokeMember(EXECUTE_METHOD, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, handler, convertedparms); } } } catch (GxClassLoaderException cex) { SendResponseStatus(404, cex.Message); HttpHelper.SetResponseStatusAndJsonError(context.HttpContext, "404", cex.Message); } catch (Exception ex) { SendResponseStatus(500, ex.Message); HttpHelper.SetResponseStatusAndJsonError(context.HttpContext, "500", ex.Message); } finally { if (handler != null) { handler.RunAsMain = true; handler.Cleanup(); } } }
public GxRestWrapper(GXProcedure worker, HttpContext context, IGxContext gxContext) : this(context, gxContext) { _procWorker = worker; }
public GxRestWrapper(GXProcedure worker, HttpContext context, IGxContext gxContext, String serviceMethod) : this(worker, context, gxContext) { ServiceMethod = serviceMethod; }
private bool IsCoreEventReplicator(GXProcedure procWorker) { return(procWorker.GetType().FullName == Synchronizer.CORE_OFFLINE_EVENT_REPLICATOR); }