public static object Unmarshal(ObjRef objectRef, bool fRefine) { Type classToProxy = fRefine ? objectRef.ServerType : typeof(MarshalByRefObject); if (classToProxy == null) { classToProxy = typeof(MarshalByRefObject); } if (objectRef.IsReferenceToWellKnow) { object obj = GetRemoteObject(objectRef, classToProxy); TrackingServices.NotifyUnmarshaledObject(obj, objectRef); return(obj); } else { object obj; if (classToProxy.IsContextful) { // Look for a ProxyAttribute ProxyAttribute att = (ProxyAttribute)Attribute.GetCustomAttribute(classToProxy, typeof(ProxyAttribute), true); if (att != null) { obj = att.CreateProxy(objectRef, classToProxy, null, null).GetTransparentProxy(); TrackingServices.NotifyUnmarshaledObject(obj, objectRef); return(obj); } } obj = GetProxyForRemoteObject(objectRef, classToProxy); TrackingServices.NotifyUnmarshaledObject(obj, objectRef); return(obj); } }
public async Task BeforeRequestAsyncTest() { var context = new ApiActionContext { HttpApiConfig = new HttpApiConfig(), RequestMessage = new HttpApiRequestMessage(), ApiActionDescriptor = ApiDescriptorCache.GetApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync")) }; var attr = new ProxyAttribute("localhost", 5555); await attr.BeforeRequestAsync(context); var handler = context.HttpApiConfig.HttpClient.Handler; Assert.True(handler.UseProxy == true); Assert.True(handler.Proxy != null); Assert.True(handler.Proxy.Credentials == null); Assert.True(handler.Proxy.GetProxy(new Uri("http://www.baidu.com")).Authority == "localhost:5555"); var attr2 = new ProxyAttribute("localhost", 5555, "laojiu", "123456"); await attr2.BeforeRequestAsync(context); handler = context.HttpApiConfig.HttpClient.Handler; Assert.True(handler.UseProxy == true); Assert.True(handler.Proxy != null); Assert.True(handler.Proxy.GetProxy(new Uri("http://www.baidu.com")).Authority == "localhost:5555"); Assert.True(handler.Proxy.Credentials != null); }
internal static ProxyAttribute GetProxyAttribute(Type serverType) { if (!serverType.HasProxyAttribute) { return(DefaultProxyAttribute); } ProxyAttribute attribute = _proxyTable[serverType] as ProxyAttribute; if (attribute == null) { object[] objArray = Attribute.GetCustomAttributes(serverType, proxyAttributeType, true); if ((objArray != null) && (objArray.Length != 0)) { if (!serverType.IsContextful) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_MBR_ProxyAttribute")); } attribute = objArray[0] as ProxyAttribute; } if (_proxyTable.Contains(serverType)) { return(attribute); } lock (_proxyTable) { if (!_proxyTable.Contains(serverType)) { _proxyTable.Add(serverType, attribute); } } } return(attribute); }
internal static ProxyAttribute GetProxyAttribute(Type serverType) { if (!serverType.HasProxyAttribute) { return(ActivationServices.DefaultProxyAttribute); } ProxyAttribute proxyAttribute = ActivationServices._proxyTable[(object)serverType] as ProxyAttribute; if (proxyAttribute == null) { object[] objArray = (object[])Attribute.GetCustomAttributes((MemberInfo)serverType, ActivationServices.proxyAttributeType, true); if (objArray != null && objArray.Length != 0) { if (!serverType.IsContextful) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_MBR_ProxyAttribute")); } proxyAttribute = objArray[0] as ProxyAttribute; } if (!ActivationServices._proxyTable.Contains((object)serverType)) { lock (ActivationServices._proxyTable) { if (!ActivationServices._proxyTable.Contains((object)serverType)) { ActivationServices._proxyTable.Add((object)serverType, (object)proxyAttribute); } } } } return(proxyAttribute); }
internal static ProxyAttribute GetProxyAttribute(Type serverType) { if (!serverType.HasProxyAttribute) { return(ActivationServices.DefaultProxyAttribute); } ProxyAttribute proxyAttribute = ActivationServices._proxyTable[serverType] as ProxyAttribute; if (proxyAttribute == null) { object[] customAttributes = Attribute.GetCustomAttributes(serverType, ActivationServices.proxyAttributeType, true); if (customAttributes != null && customAttributes.Length != 0) { if (!serverType.IsContextful) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_MBR_ProxyAttribute")); } proxyAttribute = (customAttributes[0] as ProxyAttribute); } if (!ActivationServices._proxyTable.Contains(serverType)) { Hashtable proxyTable = ActivationServices._proxyTable; lock (proxyTable) { if (!ActivationServices._proxyTable.Contains(serverType)) { ActivationServices._proxyTable.Add(serverType, proxyAttribute); } } } } return(proxyAttribute); }
internal static MethodCase GetMethodCase(ProxyAttribute proxyAttr) { MethodCase methodCase = MethodCase.Both; if (proxyAttr != null) { methodCase = proxyAttr.MethodCase; } return(methodCase); }
private static MarshalByRefObject CreateObjectForCom(RuntimeType serverType, object[] props, bool bNewObj) { if (ActivationServices.PeekActivationAttributes((Type)serverType) != null) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_ActivForCom")); } ActivationServices.InitActivationServices(); ProxyAttribute proxyAttribute = ActivationServices.GetProxyAttribute((Type)serverType); return(!(proxyAttribute is ICustomFactory) ? (MarshalByRefObject)Activator.CreateInstance((Type)serverType, true) : ((ICustomFactory)proxyAttribute).CreateInstance((Type)serverType)); }
private static string GetVarName(Type type) { string varName = type.Name; ProxyAttribute proxyAttr = null; if (type.HasCustomAttributeOfType <ProxyAttribute>(true, out proxyAttr)) { varName = proxyAttr.VarName; } return(varName); }
internal static object CreateClientProxyForContextBound(Type type, object[] activationAttributes) { if (type.IsContextful) { // Look for a ProxyAttribute ProxyAttribute att = (ProxyAttribute)Attribute.GetCustomAttribute(type, typeof(ProxyAttribute), true); if (att != null) { return(att.CreateInstance(type)); } } RemotingProxy proxy = new RemotingProxy(type, ChannelServices.CrossContextUrl, activationAttributes); return(proxy.GetTransparentProxy()); }
internal static string GetVarName(Type type) { string varName = type.Name; ProxyAttribute proxyAttr = null; if (type.HasCustomAttributeOfType <ProxyAttribute>(true, out proxyAttr)) { if (!string.IsNullOrEmpty(proxyAttr.VarName)) { varName = proxyAttr.VarName; } } return(varName); }
private static MarshalByRefObject IsCurrentContextOK(RuntimeType serverType, object[] props, bool bNewObj) { MarshalByRefObject proxy = null; InitActivationServices(); ProxyAttribute proxyAttribute = GetProxyAttribute(serverType); if (object.ReferenceEquals(proxyAttribute, DefaultProxyAttribute)) { return(proxyAttribute.CreateInstanceInternal(serverType)); } proxy = proxyAttribute.CreateInstance(serverType); if (((proxy != null) && !RemotingServices.IsTransparentProxy(proxy)) && !serverType.IsAssignableFrom(proxy.GetType())) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Activation_BadObject"), new object[] { serverType })); } return(proxy); }
public async Task BeforeRequestAsyncTest() { var context = new TestActionContext( httpApi: null, httpApiConfig: new HttpApiConfig(), apiActionDescriptor: new ApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync"))); var attr = new ProxyAttribute("localhost", 5555); await attr.BeforeRequestAsync(context); var handler = context.HttpApiConfig.HttpHandler; Assert.True(handler.UseProxy == true); Assert.True(handler.Proxy != null); Assert.True(handler.Proxy.Credentials == null); Assert.True(handler.Proxy.GetProxy(new Uri("http://www.baidu.com")).Authority == "localhost:5555"); var attr2 = new ProxyAttribute("localhost", 5555, "laojiu", "123456"); await Assert.ThrowsAsync <HttpApiConfigException>(() => attr2.BeforeRequestAsync(context)); }
private static MarshalByRefObject IsCurrentContextOK(RuntimeType serverType, object[] props, bool bNewObj) { ActivationServices.InitActivationServices(); ProxyAttribute proxyAttribute = ActivationServices.GetProxyAttribute((Type)serverType); MarshalByRefObject marshalByRefObject; if (proxyAttribute == ActivationServices.DefaultProxyAttribute) { marshalByRefObject = proxyAttribute.CreateInstanceInternal(serverType); } else { marshalByRefObject = proxyAttribute.CreateInstance((Type)serverType); if (marshalByRefObject != null && !RemotingServices.IsTransparentProxy((object)marshalByRefObject) && !serverType.IsAssignableFrom(marshalByRefObject.GetType())) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Activation_BadObject"), (object)serverType)); } } return(marshalByRefObject); }
private void ForEachProxiedClass(string searchPattern, DirectoryInfo ctrlrDir, Action <Type> doForEachProxiedType) { if (ctrlrDir.Exists) { FileInfo[] files = ctrlrDir.GetFiles(searchPattern); int ol = files.Length; for (int i = 0; i < ol; i++) { FileInfo file = files[i]; Assembly.LoadFrom(file.FullName) .GetTypes() .Where(type => type.HasCustomAttributeOfType <ProxyAttribute>()) .Each(t => { ProxyAttribute attr = t.GetCustomAttributeOfType <ProxyAttribute>(); if (!string.IsNullOrEmpty(attr.VarName)) { BamConf.AddProxyAlias(attr.VarName, t); } doForEachProxiedType(t); }); } } }
public ONInterceptionAttribute() { ProxyAttribute[] lProxyAttributes = (ProxyAttribute[])typeof(ServicedComponent).GetCustomAttributes(typeof(ProxyAttribute), false); mBase = lProxyAttributes[0]; }