public void CallMethod(string requestId, string methodName, string firstArg, string secondArg) { if (methodName == "OfflinePrint") { this.ExecuteOfflinePrint(requestId, firstArg); } else if (!this.ExecuteLocalMethod(requestId, methodName, firstArg, secondArg)) { AsyncCallArgs args = new AsyncCallArgs(); args.IsSelfInvoke = false; //get requested method args.Method = serviceMethods.SingleOrDefault(m => m.Name == methodName); if (args.Method == null) { throw new Exception("Unknown method: " + methodName); } args.RequestId = requestId; if (firstArg != null) { args.MethodArgs = (secondArg == null) ? new object[] { firstArg } } : new object[] { firstArg, secondArg }; //call method in concurent thread System.Threading.ThreadPool.QueueUserWorkItem(DynamicCall, args); } }
public bool ExecuteLocalMethod(string requestId, string methodName, string firstArg, string secondArg) { if (methodName != "CheckRegistration" && methodName != "RegisterFractus" && methodName != "OpenExternalWebBrowser" && methodName != "CloseApplication") { return(false); } AsyncCallArgs args = new AsyncCallArgs(); args.IsSelfInvoke = true; //get requested method args.Method = this.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance); if (args.Method == null) { throw new Exception("Unknown method: " + methodName); } args.RequestId = requestId; if (secondArg != null) { args.MethodArgs = new object[] { requestId, firstArg, secondArg } } ; else if (firstArg != null) { args.MethodArgs = new object[] { requestId, firstArg } } ; else { args.MethodArgs = new object[] { requestId } }; //call method in concurent thread System.Threading.ThreadPool.QueueUserWorkItem(DynamicCall, args); return(true); }
private void ExecuteOfflinePrint(string requestId, string arg) { XDocument inputXml = XDocument.Parse(arg); MemoryStream outputStream = null; string resultContentType = null; bool wasException = false; try { if (inputXml.Root.Element("id") != null) { outputStream = this.printService.PrintBusinessObjectOffline(inputXml.Root.Element("id").Value, inputXml.Root.Element("profileName").Value, ref resultContentType); } else { outputStream = this.printService.PrintXmlOffline(inputXml.Root.Element("xml").FirstNode.ToString(), inputXml.Root.Element("profileName").Value, ref resultContentType); } } catch (Exception ex) { wasException = true; this.SendAsyncErrorResponse(requestId, ex.Message); } if (!wasException) { AsyncCallArgs args = new AsyncCallArgs(); args.IsSelfInvoke = true; //get requested method args.Method = this.GetType().GetMethod("ProcessPrint", BindingFlags.NonPublic | BindingFlags.Instance); args.MethodArgs = new object[] { requestId, outputStream, resultContentType }; //call method in concurent thread System.Threading.ThreadPool.QueueUserWorkItem(DynamicCall, args); } }
private void DynamicCall(object callArgs) { AsyncCallArgs args = (AsyncCallArgs)callArgs; try { object target = args.IsSelfInvoke ? this : (object)this.kernel; object result = args.Method.Invoke(target, args.MethodArgs); object[] responseArgs = new object[1]; responseArgs[0] = new object[] { args.RequestId, result }; if (args.Method.Name == "LogOn") { this.RefreshUserLanguage(); } browserControl.BeginInvoke(this.asyncResponseDelegate, responseArgs); } catch (Exception e) { FaultException faultException = e.InnerException as FaultException; if (faultException != null) { object[] responseArgs = new object[1]; responseArgs[0] = new object[] { args.RequestId, faultException.Message }; browserControl.BeginInvoke(this.asyncErrorResponseDelegate, responseArgs); } else { MessageBox.Show(e.ToString()); } } }