Esempio n. 1
0
        public void Write(Serializer serializer, object value, CustomData customData)
        {
            var message = (Message) customData.Data;

            if (value is IDataObject)
            {
                serializer.WriteByte((byte)DataType.DataObject);
                WriteDataObject(serializer, customData.Type, (IDataObject) value, message);
                return;
            }

            if (value is Delegate)
            {
                serializer.WriteByte((byte)DataType.Delegate);
                var contextId = message.RemotingManager.ContextManager.GetContextId(customData.RequestingAssembly);
                var del = message.RemotingManager.DelegateManager.CreateDelegateImpl(contextId, (Delegate)value);
                serializer.WriteI32(del.LocalId);
                // TODO: Serialize Peer and RemoteId so we can create delegate proxies to other peer's delegates.
                return;
            }

            if (ServiceManager.IsService(customData.Type))
            {
                serializer.WriteByte((byte)DataType.Service);
                var serviceImpl = message.RemotingManager.ServiceManager.GetCreateImplementation(customData.Type, value);
                serializer.WriteI32(serviceImpl.LocalId);
                return;
            }

            throw new NotImplementedException();
        }
Esempio n. 2
0
        public object Read(Serializer serializer, CustomData customData)
        {
            var message = (Message) customData.Data;

            var dataType = (DataType) serializer.ReadByte();
            switch (dataType)
            {
                case DataType.DataObject:
                    if(!typeof(IDataObject).IsAssignableFrom(customData.Type))
                        throw new Exception();

                    return ReadDataObject(serializer, customData.Type, message);

                case DataType.Delegate:
                    var remoteDelegateId = serializer.ReadI32();
                    var contextId = message.RemotingManager.ContextManager.GetContextId(customData.RequestingAssembly);
                    var del = message.RemotingManager.DelegateManager.CreateDelegateProxy(contextId, customData.Type, message.Peer, remoteDelegateId);
                    return del.Delegate;

                case DataType.Service:
                    var remoteId = serializer.ReadI32();
                    return message.RemotingManager.ServiceManager.GetService(customData.Type, message.Peer, remoteId);

                default:
                    throw new NotImplementedException();
            }
        }
Esempio n. 3
0
        public object ReadCustom(CustomData customData)
        {
            if(CustomSerializer != null)
                return CustomSerializer.Read(this, customData);

            Log.Error("No custom serializer available.");

            return null;
        }
Esempio n. 4
0
        public void WriteCustom(object value, CustomData customData)
        {
            if(CustomSerializer != null)
                CustomSerializer.Write(this, value, customData);

            Log.Error("No custom serializer available.");
        }