public bool LoadAssembly(string path, ProxyBase coreHandler, PluginHandler pluginHandler) { var assembly = Assembly.LoadFile(path); var types = assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(CoreBase))).ToArray(); for (int i = 0; i < types.Length; i++) { FieldInfo coreBase = types[i].GetField ("proxyBase", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo pluginRun = types[i].GetMethod("PluginRun"); pluginStop = types[i].GetMethod("PluginStop"); if (pluginRun != null) { pluginObj = assembly.CreateInstance(types[i].FullName); coreBase.SetValue(pluginObj, coreHandler); pluginHandler.IsLoaded = true; pluginHandler.CorePlugin = pluginObj; if (!coreHandler.LaunchedPlugins.Contains(pluginHandler)) { coreHandler.LaunchedPlugins.Add(pluginHandler); } pluginRun.Invoke(pluginObj, null); return(true); } } return(false); }
public CamLoader(Client client, ProxyBase proxy, Action <string> logMethod) { this.client = client; this.proxy = proxy; this.logMethod = logMethod; InitializeComponent(); }
/// <summary> /// 获取代理请求对象 /// </summary> /// <param name="proxyType"></param> /// <returns></returns> public ReturnMessage <Proxy> GetProxy(ProxyType proxyType) { ProxyBase proxyBase = ProxyHelper.GetProxyBaseObject(proxyType); if (proxyBase == null) { throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not proxy base object", proxyType.FullName, proxyType.AssemblyName)); } if (proxyType.InMaxExpandDepth <= 0) { proxyType.InMaxExpandDepth = ProxyJsonHelper.DefaultInMaxWritingDepth; } if (proxyType.InMaxExpandDepth > ProxyJsonHelper.MaxInMaxWritingDepth) { throw new ProxyServiceException(string.Format("inMaxExpandDepth max value is {0}", ProxyJsonHelper.MaxInMaxWritingDepth)); } ReturnMessage <Proxy> ret = new ReturnMessage <Proxy>(); Proxy proxy = new Proxy(); proxy.ProxyType = proxyType; proxy.ProxyJsonString = ProxyJsonHelper.ProxyObjectToJsonString(proxyBase, true, proxyType.UseDataMemberTransData, proxyType.InMaxExpandDepth); ret.Result = proxy; return(ret); }
/// <summary> /// Initializes a new instance of the <see cref="ContractAndInstanceStruct"/> class. /// </summary> /// <param name="channel">The channel.</param> /// <param name="contractType">Type of the contract.</param> /// <param name="implType">Type of the impl.</param> /// <param name="sessionId">The session id.</param> /// <param name="proxyId">The proxy id.</param> /// <param name="instance">The instance.</param> public ContractAndInstanceStruct(Channel channel, Type contractType, Type implType, String sessionId, long proxyId, ProxyBase instance) { if (channel == null) { ThrowHelper.ThrowArgumentNullException("channel"); } if (contractType == null) { ThrowHelper.ThrowArgumentNullException("contractType"); } if (implType == null) { ThrowHelper.ThrowArgumentNullException("implType"); } if (string.IsNullOrEmpty(sessionId)) { ThrowHelper.ThrowArgumentNullException("sessionId"); } if (instance == null) { ThrowHelper.ThrowArgumentNullException("instance"); } if (!typeof(ProxyBase).IsAssignableFrom(implType)) { ThrowHelper.ThrowArgumentException("Type of implementation is not assignable from ProxyBase."); } this.mChannel = channel; this.mContractType = contractType; this.mImplType = implType; this.mSessionId = sessionId; this.mProxyId = proxyId; this.mInstance = instance; }
/// <summary> /// Gets the peer proxy id. /// </summary> /// <param name="proxy">The proxy.</param> /// <returns>Identifier of the proxy</returns> /// <exception cref="Forge.Net.Remoting.ProxyNotRegisteredException"></exception> public static long GetPeerProxyId(ProxyBase proxy) { if (proxy == null) { ThrowHelper.ThrowArgumentNullException("proxy"); } long result = -1; lock (mContractAndInstancePerSessionAndChannel) { foreach (ContractAndInstanceStruct s in mContractAndInstancePerSessionAndChannel) { if (s.Instance.Equals(proxy)) { result = s.ProxyId; break; } } } if (result == -1) { throw new ProxyNotRegisteredException(); } return(result); }
/// <summary> /// Checks the proxy registered. /// </summary> /// <param name="proxy">The proxy.</param> /// <exception cref="Forge.Net.Remoting.ProxyNotRegisteredException"></exception> public static void CheckProxyRegistered(ProxyBase proxy) { if (proxy == null) { ThrowHelper.ThrowArgumentNullException("proxy"); } bool result = false; lock (mContractAndInstancePerSessionAndChannel) { foreach (ContractAndInstanceStruct s in mContractAndInstancePerSessionAndChannel) { if (s.Instance.Equals(proxy)) { result = true; break; } } } if (!result) { throw new ProxyNotRegisteredException(); } }
public static void AfterDo <T>(ProxyBase __instance, T __result) { try { if (__result == null) { return; } Type type = __instance.GetType(); Logger.Error(type.FullName + "-AfterDo-SessionID:" + ServiceSession.SessionID); ProxyType proxyType = null; if (!string.IsNullOrEmpty(type.FullName)) { ProxyTypeDict.TryGetValue(type.FullName, out proxyType); } Logger.Error("ReturnData:" + (proxyType == null ? ProxyJsonHelper.ProxyResultToJsonString(__result) : ProxyJsonHelper.ProxyResultToJsonString(__result, proxyType.UseDataMemberTransData, proxyType.OutMaxExpandDepth))); } catch (Exception ex) { Logger.Error(ex); } }
public static bool BeforeDo(ProxyBase __instance) { try { if (__instance == null) { return(true); } Type type = __instance.GetType(); Logger.Error(type.FullName + "-BeforeDo-SessionID:" + ServiceSession.SessionID); ProxyType proxyType = null; if (!string.IsNullOrEmpty(type.FullName)) { ProxyTypeDict.TryGetValue(type.FullName, out proxyType); } Logger.Error("PostData:" + (proxyType == null ? ProxyJsonHelper.ProxyObjectToJsonString(__instance) : ProxyJsonHelper.ProxyObjectToJsonString(__instance, false, proxyType.UseDataMemberTransData, proxyType.InMaxExpandDepth))); //输出调用堆栈 Logger.Error("StackTrace:\r\n" + StackTraceHelper.GetCurrentStackTraceString(3)); } catch (Exception ex) { Logger.Error(ex); } return(true); }
public async Task <T> ProcessResponseAsync <T>(IHttpResponse <T> response, ProxyBase proxy) where T : class { if (response.RefusedConnection) { proxy.SetConnectionRefusedError(); return(null); } if (response.Message.IsSuccessStatusCode) { return(response.Data); } if (response.Message.IsBad()) { await proxy.ProcessErrorAsync(response.Message); return(null); } if (response.Message.IsUnauthorised()) { await proxy.ProcessErrorAsync(response.Message); return(null); } proxy.SetConnectionRefusedError(); return(null); }
public async Task ProcessResponseAsync(IHttpResponse response, ProxyBase proxy) { if (response.RefusedConnection) { proxy.SetConnectionRefusedError(); return; } if (response.Message.IsSuccessStatusCode) { return; } if (response.Message.IsBad()) { await proxy.ProcessErrorAsync(response.Message); return; } if (response.Message.IsUnauthorised()) { await proxy.ProcessErrorAsync(response.Message); return; } proxy.SetConnectionRefusedError(); }
/// <summary> /// Job执行代理请求 /// </summary> /// <param name="proxy"></param> /// <returns></returns> public ReturnMessage <bool> ProxyDoByJob(Proxy proxy) { if (proxy == null) { throw new ProxyServiceException("proxy is null"); } var proxyType = proxy.ProxyType; Type proxyBaseType = ProxyHelper.GetType(proxyType); if (string.IsNullOrEmpty(proxy.ProxyJsonString)) { throw new ProxyServiceException("proxy.ProxyJsonString is empty"); } ProxyBase proxyBase = ProxyJsonHelper.ProxyObjectFromJsonString(proxy.ProxyJsonString, proxyBaseType, proxyType.UseDataMemberTransData) as ProxyBase; if (proxyBase == null) { throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not a proxy base object", proxyType.FullName, proxyType.AssemblyName)); } string[] arrTypeName = proxy.ProxyType.FullName.Split('.'); string requestCode = arrTypeName[arrTypeName.Length - 1]; string requestName = requestCode; string bpFullName = string.Join(".", new List <string>(arrTypeName).GetRange(0, arrTypeName.Length - 2).ToArray()); bpFullName += "." + requestCode.Substring(0, requestCode.Length - 5); RequestSubmit rs = new RequestSubmit(); //参数applicaiton表示应用模块的代号. rs.Application = 3000; //参数priority表示调度执行的优先级,1表示最高优先级 rs.Priority = 1; //参数bpfullname表示服务的全名,包括命名空间 rs.BPFullName = bpFullName; //表示需要调度执行的应用,及调度具体执行的应用 rs.BPAgentObj = proxyBase; //表示请求执行的应用代码,即具体的服务名称 rs.RequestCode = requestCode; //在表示请求执行的服务名称,即在请求监控中看到的进程名称 rs.RequestName = requestName; //任何语言都可以的描述 rs.RequestDescription = requestName; // 是否成功执行不能重新执行 rs.IsSuccessCanNotReStart = true; //表示任务执行的时限,以秒为单位,即指定秒后开始进行调度执行 rs.SchedulerProject = new PatternRunOnce().PatternInstant(); //参数表示 提交到job进程里,可以保证在设定时间进行应用程序的执行 rs.Submit(); ReturnMessage <bool> ret = new ReturnMessage <bool>(); ret.IsSuccess = true; ret.Result = true; return(ret); }
public override void Enable() { Host.DefaultProfile.Set(this, "test", "hello world"); client = this.Host.Client; proxy = this.Host.Proxy; proxy.ReceivedSelfAppearIncomingPacket += new ProxyBase.IncomingPacketListener(ReceivedSelfAppearIncomingPacket); proxy.ReceivedPlayerSpeechOutgoingPacket += new ProxyBase.OutgoingPacketListener(ReceivedPlayerSpeechOutgoingPacket); }
private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { var test = new ProxyBase(); //test.LaunchPlugin(@"G:\SoftwareDev\CSharp\BotRelay\Plugin\bin\Debug\Plugin.dll"); UpdatePluginsList(); }
public static object Create(Type interfaceType, object coreInstance, IEnforce enforce, string parentNamingSequence) { var x = new ProxyBase(interfaceType, coreInstance, enforce, parentNamingSequence); MethodInfo castMethod = typeof(ProxyBase).GetMethod( "Cast").MakeGenericMethod(interfaceType); return(castMethod.Invoke(null, new object[] { x.GetTransparentProxy() })); }
/// <summary> /// 执行请求 /// </summary> /// <param name="proxy"></param> /// <returns></returns> public ReturnMessage <string> ProxyDo(Proxy proxy) { if (proxy == null) { throw new ProxyServiceException("proxy is null"); } var proxyType = proxy.ProxyType; Type proxyBaseType = ProxyHelper.GetType(proxyType); if (string.IsNullOrEmpty(proxy.ProxyJsonString)) { throw new ProxyServiceException("proxy.ProxyJsonString is empty"); } if (proxyType.OutMaxExpandDepth <= 0) { proxyType.OutMaxExpandDepth = ProxyJsonHelper.DefaultOutMaxWritingDepth; } if (proxyType.OutMaxExpandDepth > ProxyJsonHelper.MaxOutMaxWritingDepth) { throw new ProxyServiceException(string.Format("outMaxExpandDepth is max value is {0}", ProxyJsonHelper.MaxOutMaxWritingDepth)); } ProxyBase proxyBase = ProxyJsonHelper.ProxyObjectFromJsonString(proxy.ProxyJsonString, proxyBaseType, proxyType.UseDataMemberTransData) as ProxyBase; if (proxyBase == null) { throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not proxy base object", proxyType.FullName, proxyType.AssemblyName)); } MethodInfo methodInfo = proxyBase.GetType().GetMethod("Do", new Type[] {}); if (methodInfo == null) { throw new ProxyServiceException(string.Format("no find Do() method in proxyType:{0},{1}", proxyType.FullName, proxyType.AssemblyName)); } object result = methodInfo.Invoke(proxyBase, null); ReturnMessage <string> ret = new ReturnMessage <string>(); ret.IsSuccess = true; ret.Result = result == null ? string.Empty : ProxyJsonHelper.ProxyResultToJsonString(result, proxyType.UseDataMemberTransData, proxyType.OutMaxExpandDepth); return(ret); }
/// <summary> /// 重新加载代理对象 /// </summary> /// <param name="proxy"></param> /// <returns></returns> public ReturnMessage <Proxy> ReLoadProxy(Proxy proxy) { if (proxy == null) { throw new ProxyServiceException("proxy is null"); } if (proxy.ProxyType == null) { throw new ProxyServiceException("proxy.ProxyType is null"); } if (string.IsNullOrEmpty(proxy.ProxyJsonString)) { throw new ProxyServiceException("proxy.ProxyJsonString is empty"); } ProxyType proxyType = proxy.ProxyType; if (proxyType.InMaxExpandDepth <= 0) { proxyType.InMaxExpandDepth = ProxyJsonHelper.DefaultInMaxWritingDepth; } if (proxyType.InMaxExpandDepth > ProxyJsonHelper.MaxInMaxWritingDepth) { throw new ProxyServiceException(string.Format("inMaxExpandDepth max value is {0}", ProxyJsonHelper.MaxInMaxWritingDepth)); } Type loadType = ProxyHelper.GetType(proxyType); if (loadType == null) { throw new ProxyServiceException(string.Format("proxyType {0},{1} is not exist", proxyType.FullName, proxyType.AssemblyName)); } ProxyBase proxyBase = ProxyJsonHelper.ProxyObjectFromJsonString(proxy.ProxyJsonString, loadType, proxyType.UseDataMemberTransData) as ProxyBase; if (proxyBase == null) { throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not proxy base object", proxyType.FullName, proxyType.AssemblyName)); } ReturnMessage <Proxy> ret = new ReturnMessage <Proxy>(); proxy.ProxyJsonString = ProxyJsonHelper.ProxyObjectToJsonString(proxyBase, true, proxyType.UseDataMemberTransData, proxyType.InMaxExpandDepth); ret.Result = proxy; return(ret); }
static void Main(string[] args) { // make sure to wrap the call into a using statement or else the proxy will not be returned to pool using (var client = new ProxyBase<IMyService>()) { Console.WriteLine(client.ExecuteProxyFunction(() => client.Proxy.GetData("Dude", 34))); } Console.ReadLine(); using (var client = new ProxyBase<IMyService>()) { Console.WriteLine(client.ExecuteProxyFunction(() => client.Proxy.GetData("Joe", 45))); } Console.ReadLine(); }
public List <MetricSerie> PerformQuery(string db, string query) { List <MetricSerie> metricSeries; ParamterUtil.CheckEmptyString("db", db); ParamterUtil.CheckEmptyString("query", query); List <MetricSerie> metricSeries1 = new List <MetricSerie>(); try { DebugUtil.Log(string.Format("MeasurementHost: performing query '{0}' on db '{1}'.", query, db)); string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.MeasurementApi); if (string.IsNullOrEmpty(appUri)) { DebugUtil.Log("MeasurementHost: failed to fetch measurementServerInfo.Uri from location."); } else { string str = string.Format("{0}api/measurement/run", appUri); Command command = new Command() { Type = CommandType.Read }; command.Parameters.Add("dbname", db); command.Parameters.Add("query", query); FoundationResponse <string> result = ProxyBase.Call <FoundationResponse <string>, Command>(str, command, ApiHttpMethod.POST, 180000, null).Result; if ((result == null ? true : string.IsNullOrEmpty(result.Data))) { DebugUtil.Log(string.Format("MeasurementHost: query '{0}' on db '{1}' return empty.", query, db)); } else { metricSeries1 = JsonSerializerUtil.Deserialize <List <MetricSerie> >(result.Data); } metricSeries = metricSeries1; return(metricSeries); } } catch (Exception exception) { DebugUtil.LogException(exception); } metricSeries = metricSeries1; return(metricSeries); }
private static FoundationResponse <string> PushToServer(List <MetricPoint> points, string db, string rp) { string str; FoundationResponse <string> foundationResponse = null; if ((points == null ? false : points.Count > 0)) { try { string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.MeasurementApi); if (string.IsNullOrEmpty(appUri)) { DebugUtil.Log("MeasurementHost: failed to fetch measurementServerInfo.Uri from location."); foundationResponse = new FoundationResponse <string>() { IsSuccess = false }; } else { str = (!appUri.EndsWith("/") ? string.Format("{0}/api/measurement/write/", appUri) : string.Format("{0}api/measurement/write/", appUri)); MeasurementRequest measurementRequest = new MeasurementRequest(); measurementRequest.MetricPoints.AddRange(points); measurementRequest.DBName = db; measurementRequest.RetentionPolicy = rp; DebugUtil.Log(string.Format("MeasurementHost: Sending {0} points to db '{1}' via {2}.", points.Count, measurementRequest.DBName, str)); foundationResponse = ProxyBase.Call <FoundationResponse <string>, object>(str, measurementRequest, ApiHttpMethod.POST, 180000, null).Result; if (foundationResponse == null) { foundationResponse = new FoundationResponse <string>(); } foundationResponse.IsSuccess = true; } } catch (Exception exception1) { Exception exception = exception1; foundationResponse.IsSuccess = false; foundationResponse.ErrMsg = string.Format("{0}\r\n{1}", exception.Message, exception.StackTrace); DebugUtil.LogException(exception); } } return(foundationResponse); }
/// <summary> /// Unregisters the proxy. /// </summary> /// <param name="proxy">The proxy.</param> internal static void UnregisterProxy(ProxyBase proxy) { if (proxy == null) { ThrowHelper.ThrowArgumentNullException("proxy"); } lock (mContractAndInstancePerSessionAndChannel) { IEnumeratorSpecialized <ContractAndInstanceStruct> iterator = mContractAndInstancePerSessionAndChannel.GetEnumerator(); while (iterator.MoveNext()) { ContractAndInstanceStruct s = iterator.Current; if (s.Instance.Equals(proxy)) { iterator.Remove(); break; } } } }
private void Start() { if (useHookProxy) { proxy = new HookProxy(client); AddHooks(); } else { client.IO.Proxy.AllowIncomingModification = false; client.IO.Proxy.AllowOutgoingModification = false; proxy = client.IO.Proxy; AddHooks(); } if (client.LoggedIn) { currentLocation = GetPlayerLocation(); } uxLog.Clear(); uxStart.Text = "Stop Map Tracking"; tracking = true; }
public static ApiResult <TResult> PostWebApi <TResult, TData>(this string url, TData data, NameValueCollection headers = null, int timeout = 180000) { return(ProxyBase.Call <TResult, TData>(url, data, ApiHttpMethod.POST, timeout, headers)); }
/// <summary> /// Registers the proxy. /// </summary> /// <param name="channel">The channel.</param> /// <param name="contractType">Type of the contract.</param> /// <param name="implType">Type of the impl.</param> /// <param name="sessionId">The session id.</param> /// <param name="proxyId">The proxy id.</param> /// <param name="instance">The instance.</param> internal static void RegisterProxy(Channel channel, Type contractType, Type implType, String sessionId, long proxyId, ProxyBase instance) { lock (mContractAndInstancePerSessionAndChannel) { mContractAndInstancePerSessionAndChannel.Add(new ContractAndInstanceStruct(channel, contractType, implType, sessionId, proxyId, instance)); } }
public Task <T> ProcessResponse <T>(HttpResponseMessage response, T dataResponse, ProxyBase proxy) { throw new NotImplementedException(); }
public ProxyWrapper(Type proxyType, ProxyBase <T> proxyBase) : this(proxyType, proxyBase.InnerChannel) { _proxyBase = proxyBase; }
public override IMessage Invoke(IMessage msg) { IMethodCallMessage methodCall = (IMethodCallMessage)msg; var method = (MethodInfo)methodCall.MethodBase; if (method.DeclaringType.IsGenericType && method.DeclaringType.GetGenericTypeDefinition().FullName.Contains( "System.Runtime.InteropServices.WindowsRuntime")) { Dictionary <string, string> methodMap = new Dictionary <string, string> { // add problematic methods here { "Append", "Add" }, { "GetAt", "get_Item" } }; if (methodMap.ContainsKey(method.Name) == false) { throw new Exception("Unable to resolve '" + method.Name + "'."); } // thanks microsoft string correctMethod = methodMap[method.Name]; method = m_baseInterface.GetInterfaces().Select( i => i.GetMethod(correctMethod)).Where( mi => mi != null).FirstOrDefault(); if (method == null) { throw new Exception("Unable to resolve '" + method.Name + "' to '" + correctMethod + "'."); } } try { if (m_coreInstance == null) { var errorMessage = Resource.CoreInstanceIsNull; WriteLogs(errorMessage, TraceEventType.Error); throw new NullReferenceException(errorMessage); } var args = methodCall.Args.Select(a => { object o; if (RemotingServices.IsTransparentProxy(a)) { o = (RemotingServices.GetRealProxy(a) as ProxyBase).m_coreInstance; } else { o = a; } if (method.Name == "get_Item") { // perform parameter conversions here? if (a.GetType() == typeof(UInt32)) { return(Convert.ToInt32(a)); } return(a); } return(o); }).ToArray(); // this is where it barfs var result = method.Invoke(m_coreInstance, args); // special handling for GetType() if (method.Name == "GetType") { result = m_baseInterface; } else { // special handling for interface return types if (method.ReturnType.IsInterface) { result = ProxyBase.Create(method.ReturnType, result, m_enforce, m_namingSequence); } } return(new ReturnMessage(result, args, args.Length, methodCall.LogicalCallContext, methodCall)); } catch (Exception e) { WriteLogs("Exception: " + e, TraceEventType.Error); if (e is TargetInvocationException && e.InnerException != null) { return(new ReturnMessage(e.InnerException, msg as IMethodCallMessage)); } return(new ReturnMessage(e, msg as IMethodCallMessage)); } }