public IceClientTransportSink(string url) { IceChannelUtils.ParseIceURL(url, out _host, out _port, out _objectUri); Ice.TcpEndpoint te = new Ice.TcpEndpoint(_host, _port); _e = Ice.Manager.GetManager().GetEndpoint(te); }
public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { IMessage call; MessageType mtype = (Ice.MessageType)requestHeaders["__iceMessageType"]; bool isBatched = (mtype == Ice.MessageType.BatchRequest); try { if (requestMsg == null) { requestMsg = IceChannelUtils.ProtocolRequestToMessage(requestStream, isBatched); } else { call = requestMsg; } Trace.WriteLine("IceServerFormatterSink: passing upstream"); _next.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); Trace.WriteLine("IceServerFormatterSink: returned"); responseStream = new MemoryStream(); IceChannelUtils.MessageToProtocolReply(requestMsg, responseMsg, responseStream); } catch (Exception e) { Console.WriteLine(e.ToString()); throw e; } return(ServerProcessing.Complete); }
public IMessage SyncProcessMessage(IMessage msg) { IMethodCallMessage mcall = msg as IMethodCallMessage; Trace.WriteLine("IceClientFormatterSink: ProcessMessage: " + mcall.MethodBase); try { Stream msgStream; FormatMessage(msg, out msgStream); // send downstream for processing TransportHeaders reqHeaders = new TransportHeaders(); ITransportHeaders respHeaders; Stream respStream; _next.ProcessMessage(msg, reqHeaders, msgStream, out respHeaders, out respStream); // convert back into a response message IMessage result = (IMessage)IceChannelUtils.ProtocolReplyToMessage(respStream, msg); respStream.Close(); return(result); } catch (Exception e) { return(new ReturnMessage(e, mcall)); } }
public virtual void WriteProxy(object o, Type ot) { if (!RemotingServices.IsTransparentProxy(o)) { Console.WriteLine("o {0} ot {1} is not transparent proxy!", o, ot); throw new InvalidOperationException("object which is not a transparent proxy passed to WriteProxy, type " + ot); } ObjRef or = RemotingServices.GetObjRefForProxy((System.MarshalByRefObject)o); Ice.Identity proxy_ident = new Ice.Identity(or.URI.StartsWith("/") ? or.URI.Substring(1) : or.URI); Ice.Endpoint proxy_ep = null; foreach (object cdo in or.ChannelInfo.ChannelData) { ChannelDataStore cd = cdo as ChannelDataStore; if (cd == null) { continue; } foreach (string ch_uri in cd.ChannelUris) { string host; int port; string uri; if (IceChannelUtils.ParseIceURL(ch_uri, out host, out port, out uri)) { proxy_ep = new Ice.TcpEndpoint(host, port); proxy_ep.Incoming = true; break; } } } if (proxy_ep == null) { throw new InvalidOperationException("Couldn't find valid Ice endpoint/channel for " + o); } Ice.ProxyData pd = new Ice.ProxyData(); pd.id = proxy_ident; pd.facet = new string[0]; pd.mode = ProxyMode.Twoway; // FIXME -- do I need to send multiple proxy things here? pd.secure = false; WriteStruct(pd); WriteSize(1); // one endpoint follows // tcp endpoint encapsulation WriteObject((short)1); // it's a TCP endpoint BeginEncapsulation(); Ice.TcpEndpoint te = proxy_ep as Ice.TcpEndpoint; Write(te.host); WriteObject(te.port); WriteObject(te.timeout); WriteObject(te.compress); EndEncapsulation(); }
public string Parse(string url, out string objectURI) { string host; int port; string rest; IceChannelUtils.ParseIceURL(url, out host, out port, out rest); objectURI = rest; return("ice://" + host + ":" + port); }
public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, Stream stream) { IMessage reqMessage = (IMessage)state; IMessage replyMessage = (IMessage)IceChannelUtils.ProtocolReplyToMessage(stream, reqMessage); stream.Close(); sinkStack.DispatchReplyMessage(replyMessage); }
public string Parse(string url, out string objectURI) { int port; string host; string uri; objectURI = null; if (!IceChannelUtils.ParseIceURL(url, out host, out port, out uri)) { return(null); } objectURI = uri; return("ice://" + host + ":" + port); }
private void FormatMessage(IMessage msg, out Stream msgStream) { IMethodCallMessage mcall = msg as IMethodCallMessage; // if the identity wasn't set by the custom proxy, then we // extract it from the uri if (mcall.LogicalCallContext.GetData("__iceIdentity") == null) { // extract the Identity from the URI // FIXME FIXME FIXME -- this is supposed to be a Uri, why's it look like a Url?? Trace.WriteLine("IceClientFormatterSink: using identity from " + mcall.Uri); if (mcall.Uri == null) { throw new Exception("__iceIdentity property not set by IceClientFormatterSink upstream, and mcall.Uri == null!"); } string h, r; int p; IceChannelUtils.ParseIceURL(mcall.Uri, out h, out p, out r); mcall.LogicalCallContext.SetData("__iceIdentity", new Ice.Identity(r)); } mcall.LogicalCallContext.SetData("__iceFacetPath", new string[0]); mcall.LogicalCallContext.SetData("__iceContext", new Ice.Context()); OperationMode opmode = OperationMode.Normal; Ice.OperationModeAttribute opmodeattr = (Ice.OperationModeAttribute)Attribute.GetCustomAttribute(mcall.MethodBase, typeof(Ice.OperationModeAttribute)); if (opmodeattr != null) { opmode = opmodeattr.mode; } mcall.LogicalCallContext.SetData("__iceOperationMode", opmode); if (Attribute.GetCustomAttribute(mcall.MethodBase, typeof(OneWayAttribute)) != null) { mcall.LogicalCallContext.SetData("__iceOneWay", true); } else { mcall.LogicalCallContext.SetData("__iceOneWay", false); } msgStream = new MemoryStream(); IceChannelUtils.MessageToProtocolRequest(msgStream, msg); }
public IClientChannelSink CreateSink(IChannelSender channel, string url, object remoteChannelData) { string host; int port; string rest; IceChannelUtils.ParseIceURL(url, out host, out port, out rest); string key = host + ":" + port; if (!_uriMap.Contains(key)) { IClientChannelSink cs = new IceClientTransportSink(url); _uriMap[key] = cs; } return((IClientChannelSink)_uriMap[key]); }
public Proxy(Type rootType, string url) : base(rootType) { string host; int port; string rest; IceChannelUtils.ParseIceURL(url, out host, out port, out rest); _url = url; _identity = new Ice.Identity(rest); _facetPath = new string[0]; _secure = false; _typeIds = null; _realObject = null; FindChannel(); }
// read an object of type t from the stream // does NOT handle reading classes, since these // have to be read by ref and patched public object ReadObject(Type t) { if (t.IsPrimitive) { if (t == typeof(bool)) { return(ReadBoolean()); } if (t == typeof(byte)) { return(ReadByte()); } if (t == typeof(short)) { return(ReadInt16()); } if (t == typeof(int)) { return(ReadInt32()); } if (t == typeof(long)) { return(ReadInt64()); } if (t == typeof(float)) { return(ReadSingle()); } if (t == typeof(double)) { return(ReadDouble()); } throw new NotImplementedException("ReadObject can't read primitive type " + t); } if (t == typeof(string)) { return(ReadString()); } if (t.IsEnum) { Type ue = Enum.GetUnderlyingType(t); if (ue == typeof(byte)) { byte i = ReadByte(); return(Enum.ToObject(t, i)); } if (ue == typeof(short)) { short i = ReadInt16(); return(Enum.ToObject(t, i)); } if (ue == typeof(int)) { int i = ReadInt32(); return(Enum.ToObject(t, i)); } throw new NotSupportedException("ReadObject can't read enum with underlying type " + ue); } if (t.IsSubclassOf(typeof(Ice.Dictionary))) { object o = Activator.CreateInstance(t); Ice.Dictionary dict = o as Ice.Dictionary; return(ReadDictionary(dict)); } if (t.IsArray) { int sz = ReadSize(); Type eltype = t.GetElementType(); // System.Console.WriteLine ("Reading Array: {0} {1}", sz, eltype); Array ao = Array.CreateInstance(eltype, sz); if (IceChannelUtils.IceByValue(eltype)) { for (int i = 0; i < sz; i++) { object elem = ReadObject(eltype); ao.SetValue(elem, i); // System.Console.WriteLine (" {0}: {1}", i, elem); } } else { // this is a class type (and isn't a string or dictionary) for (int i = 0; i < sz; i++) { int r = ReadClassInstanceRef(); if (r == 0) { ao.SetValue(null, i); } else { _instancePatchList.Add(new ArrayPatchInfo(r, ao, i)); } } } return(ao); } if (t.IsValueType) { object o = Activator.CreateInstance(t); MethodInfo unmarshal = t.GetMethod("ice_unmarshal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); if (unmarshal != null) { object[] args = new object[1]; args[0] = this; try { unmarshal.Invoke(o, args); } catch (TargetInvocationException te) { throw te.InnerException; } } else { foreach (FieldInfo field in t.GetFields()) { if (IceChannelUtils.IceByValue(field.FieldType)) { object elem = ReadObject(field.FieldType); field.SetValue(o, elem); } else { // this is a class type int r = ReadClassInstanceRef(); if (r == 0) { field.SetValue(o, null); } else { _instancePatchList.Add(new FieldPatchInfo(r, o, field)); } } } } return(o); } Console.WriteLine("ReadObject: can't read type " + t); throw new NotSupportedException("ReadObject: can't read type " + t); }
public object ReadDictionary(Ice.Dictionary dict) { Ice.DictionaryInfo dinfo = dict.IceDictInfo; int count = ReadSize(); for (int i = 0; i < count; i++) { object k, v; bool haveKey, haveValue; if (IceChannelUtils.IceByValue(dinfo.keyType)) { k = ReadObject(dinfo.keyType); haveKey = true; } else { k = ReadClassInstanceRef(); if ((int)k == 0) { throw new InvalidOperationException("Got NULL dictionary key, expected class ref for type " + dinfo.keyType); } else { haveKey = false; } } if (IceChannelUtils.IceByValue(dinfo.valueType)) { v = ReadObject(dinfo.valueType); haveValue = true; } else { v = ReadClassInstanceRef(); if ((int)v == 0) { v = null; haveValue = true; } else { haveValue = false; } } // if we have both the key and value, we put them in. // otherwise, we have to create a patch based on what // bits we have. if (haveKey && haveValue) { dict.Add(k, v); } else { if (haveKey) { _instancePatchList.Add(new DictionaryValuePatchInfo((int)v, dict, k)); } else if (haveValue) { _instancePatchList.Add(new DictionaryKeyPatchInfo((int)k, dict, v)); } else { _instancePatchList.Add(new DictionaryEntryPatchInfo((int)k, dict, (int)v)); } } } return(dict); }
public object ReadSlice(object inst) { string sliceName = ReadSliceName(); int sliceDataSize = ReadInt32(); sliceDataSize -= 4; // size includes the 4 bytes of the size itself Type sliceType = IceUtil.IceNameToType(sliceName); if (sliceType == null) { // this means we have no local definition of this slice; // we keep going. Eventually we will hit an Ice.Object, // which is the terminating condition of this recursion, // since we know we have Ice.Object defined. ReadBytes(sliceDataSize); return(ReadSlice(inst)); } if (inst == null) { // if it's null, it has yet to be created, and this is // the first (i.e. most derived) slice that we // understand. inst = Activator.CreateInstance(sliceType); } MethodInfo unmarshal = sliceType.GetMethod("ice_unmarshal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); if (unmarshal != null) { object[] args = new object[1]; args[0] = this; try { unmarshal.Invoke(inst, args); } catch (TargetInvocationException te) { throw te.InnerException; } } else { FieldInfo[] fields = sliceType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); foreach (FieldInfo field in fields) { if (IceChannelUtils.IceByValue(field.FieldType)) { object elem = ReadObject(field.FieldType); field.SetValue(inst, elem); } else { // this is a class type int r = ReadClassInstanceRef(); if (r == 0) { field.SetValue(inst, null); } else { _instancePatchList.Add(new FieldPatchInfo(r, inst, field)); } } } } if (sliceType == typeof(Ice.Object)) { return(inst); } else { return(ReadSlice(inst)); } }