コード例 #1
0
        void SerializeCall(IMessage call)
        {
            RemotingSurrogateSelector rss = new RemotingSurrogateSelector();
            var fmt = new BinaryFormatter(rss, new StreamingContext(StreamingContextStates.Remoting));

            fmt.Serialize(_stream, call, GetHeaders());
        }
コード例 #2
0
        public static T DeepClone <T>(this T obj, bool ignoreCustomSerialization = false)
        {
            ISurrogateSelector surrogate = null;
            var formatter = new BinarySerializationFormatter(BinarySerializationOptions.RecursiveSerializationAsFallback | BinarySerializationOptions.CompactSerializationOfStructures | BinarySerializationOptions.IgnoreTypeForwardedFromAttribute);

#if NETFRAMEWORK
            if (RemotingServices.IsTransparentProxy(obj))
            {
                surrogate = new RemotingSurrogateSelector();
            }
            else
#endif
            if (ignoreCustomSerialization)
            {
                formatter.Options |= BinarySerializationOptions.IgnoreSerializationMethods | BinarySerializationOptions.IgnoreIObjectReference | BinarySerializationOptions.IgnoreIBinarySerializable;
                surrogate          = new CustomSerializerSurrogateSelector {
                    IgnoreISerializable = true, IgnoreNonSerializedAttribute = true
                };
            }

            formatter.SurrogateSelector = surrogate;
            using (var stream = new MemoryStream())
            {
                formatter.SerializeToStream(stream, obj);
                stream.Position = 0L;
#if NETFRAMEWORK
                if (surrogate is RemotingSurrogateSelector)
                {
                    formatter.SurrogateSelector = null;
                }
#endif
                return((T)formatter.DeserializeFromStream(stream));
            }
        }
コード例 #3
0
ファイル: BinaryCore.cs プロジェクト: raj581/Marvin
        public void Init()
        {
            RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector();
            StreamingContext          context           = new StreamingContext(StreamingContextStates.Remoting, null);

#if !TARGET_JVM
            _serializationFormatter   = new BinaryFormatter(surrogateSelector, context);
            _deserializationFormatter = new BinaryFormatter(null, context);
#else
            _serializationFormatter   = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter(surrogateSelector, context, false);
            _deserializationFormatter = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter(null, context, false);
#endif

#if NET_1_1
            _serializationFormatter.FilterLevel   = _filterLevel;
            _deserializationFormatter.FilterLevel = _filterLevel;
#endif

            if (!_includeVersions)
            {
                _serializationFormatter.AssemblyFormat   = FormatterAssemblyStyle.Simple;
                _deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
            }

            if (!_strictBinding)
            {
                _serializationFormatter.Binder   = ChannelCore.SimpleBinder;
                _deserializationFormatter.Binder = ChannelCore.SimpleBinder;
            }
        }
コード例 #4
0
        void SerializeResponse(IMessage resp)
        {
            RemotingSurrogateSelector rss = new RemotingSurrogateSelector();
            IRemotingFormatter        fmt = new SoapFormatter(rss, new StreamingContext(StreamingContextStates.Remoting));

            fmt.Serialize(_stream, resp, GetHeaders());
        }
コード例 #5
0
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                Throw.ArgumentNullException(Argument.info);
            }
            BinarySerializationFormatter serializer = new BinarySerializationFormatter();
            ISurrogateSelector           surrogate  = null;

#if NETFRAMEWORK
            // ReSharper disable once LocalVariableHidesMember - intended, in non-Framework platforms the field is used.
            bool byFields = this.byFields;
            if (RemotingServices.IsTransparentProxy(obj))
            {
                surrogate = new RemotingSurrogateSelector();
                byFields  = false;
            }
            else
#endif
            if (byFields)
            {
                serializer.Options |= BinarySerializationOptions.IgnoreSerializationMethods | BinarySerializationOptions.IgnoreIObjectReference | BinarySerializationOptions.IgnoreIBinarySerializable;
                surrogate           = new CustomSerializerSurrogateSelector {
                    IgnoreISerializable = true, IgnoreNonSerializedAttribute = true
                };
            }

            serializer.SurrogateSelector = surrogate;
            info.AddValue(nameof(isWeak), isWeak);
            info.AddValue(nameof(byFields), byFields);
            info.AddValue("data", serializer.Serialize(obj));
        }
コード例 #6
0
        public void GetReady()
        {
            StreamingContext context = new StreamingContext(StreamingContextStates.All);

            _surrogate                 = new RemotingSurrogateSelector();
            _soapFormatter             = new SoapFormatter(_surrogate, context);
            _soapFormatterDeserializer = new SoapFormatter(null, context);
        }
コード例 #7
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static void SerializeObject(Object obj, MemoryStream stm)
        {
            BinaryFormatter           fmt = new BinaryFormatter();
            RemotingSurrogateSelector ss  = new RemotingSurrogateSelector();

            fmt.SurrogateSelector = ss;
            fmt.Context           = new StreamingContext(StreamingContextStates.CrossAppDomain);
            fmt.Serialize(stm, obj, null, false /* No Security check */);
        } // SerializeMessageParts
コード例 #8
0
        internal static void SerializeObject(object obj, MemoryStream stm)
        {
            BinaryFormatter           formatter = new BinaryFormatter();
            RemotingSurrogateSelector selector  = new RemotingSurrogateSelector();

            formatter.SurrogateSelector = selector;
            formatter.Context           = new StreamingContext(StreamingContextStates.CrossAppDomain);
            formatter.Serialize(stm, obj, null, false);
        }
コード例 #9
0
        public BinaryWireFormatter()
        {
            StreamingContext          context  = new StreamingContext(StreamingContextStates.Other);
            RemotingSurrogateSelector selector = new RemotingSurrogateSelector();

            _serializer = new BinaryFormatter(selector, context);
            _serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;

            _deserializer = new BinaryFormatter(null, context);
            _deserializer.AssemblyFormat = FormatterAssemblyStyle.Simple;
        }
コード例 #10
0
ファイル: SoapCore.cs プロジェクト: pmq20/mono_forked
        public void Init()
        {
            RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector();
            StreamingContext          context           = new StreamingContext(StreamingContextStates.Remoting, null);

            _serializationFormatter   = CreateFormatter(surrogateSelector, context);
            _deserializationFormatter = CreateFormatter(null, context);

            _serializationFormatter.FilterLevel   = _filterLevel;
            _deserializationFormatter.FilterLevel = _filterLevel;
        }
コード例 #11
0
        internal static MemoryStream SerializeMessage(IMessage msg)
        {
            MemoryStream serializationStream   = new MemoryStream();
            RemotingSurrogateSelector selector = new RemotingSurrogateSelector();

            new BinaryFormatter {
                SurrogateSelector = selector, Context = new StreamingContext(StreamingContextStates.CrossAppDomain)
            }.Serialize(serializationStream, msg, null, false);
            serializationStream.Position = 0L;
            return(serializationStream);
        }
コード例 #12
0
        internal static MemoryStream SerializeMessageParts(ArrayList argsToSerialize)
        {
            MemoryStream              serializationStream = new MemoryStream();
            BinaryFormatter           formatter           = new BinaryFormatter();
            RemotingSurrogateSelector selector            = new RemotingSurrogateSelector();

            formatter.SurrogateSelector = selector;
            formatter.Context           = new StreamingContext(StreamingContextStates.CrossAppDomain);
            formatter.Serialize(serializationStream, argsToSerialize, null, false);
            serializationStream.Position = 0L;
            return(serializationStream);
        }
コード例 #13
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static MemoryStream SerializeMessageParts(ArrayList argsToSerialize)
        {
            MemoryStream stm = new MemoryStream();

            BinaryFormatter           fmt = new BinaryFormatter();
            RemotingSurrogateSelector ss  = new RemotingSurrogateSelector();

            fmt.SurrogateSelector = ss;
            fmt.Context           = new StreamingContext(StreamingContextStates.CrossAppDomain);
            fmt.Serialize(stm, argsToSerialize, null, false /* No Security check */);

            stm.Position = 0;
            return(stm);
        } // SerializeMessageParts
コード例 #14
0
        } // SerializeMessageParts

        // called from MessageSmuggler classes
        internal static MemoryStream SerializeObject(Object obj)
        {
            MemoryStream stm = new MemoryStream();

            BinaryFormatter           fmt = new BinaryFormatter();
            RemotingSurrogateSelector ss  = new RemotingSurrogateSelector();

            fmt.SurrogateSelector = ss;
            fmt.Context           = new StreamingContext(StreamingContextStates.Other);
            fmt.Serialize(stm, obj, null, false /* No Security check */);

            stm.Position = 0;
            return(stm);
        } // SerializeMessageParts
コード例 #15
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static MemoryStream SerializeMessage(IMessage msg)
        {
            MemoryStream stm              = new MemoryStream();
            RemotingSurrogateSelector ss  = new RemotingSurrogateSelector();
            BinaryFormatter           fmt = new BinaryFormatter();

            fmt.SurrogateSelector = ss;
            fmt.Context           = new StreamingContext(StreamingContextStates.CrossAppDomain);
            fmt.Serialize(stm, msg, null, false /* No Security check */);

            // Reset the stream so that Deserialize happens correctly
            stm.Position = 0;

            return(stm);
        }
コード例 #16
0
ファイル: RemotingServices.cs プロジェクト: zhufengGNSS/mono
        static RemotingServices()
        {
            RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector();
            StreamingContext          context           = new StreamingContext(StreamingContextStates.Remoting, null);

            _serializationFormatter   = new BinaryFormatter(surrogateSelector, context);
            _deserializationFormatter = new BinaryFormatter(null, context);
            _serializationFormatter.AssemblyFormat   = FormatterAssemblyStyle.Full;
            _deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Full;

            RegisterInternalChannels();
            CreateWellKnownServerIdentity(typeof(RemoteActivator), "RemoteActivationService.rem", WellKnownObjectMode.Singleton);

            FieldSetterMethod = typeof(object).GetMethod("FieldSetter", BindingFlags.NonPublic | BindingFlags.Instance);
            FieldGetterMethod = typeof(object).GetMethod("FieldGetter", BindingFlags.NonPublic | BindingFlags.Instance);
        }
コード例 #17
0
        public void Init()
        {
            RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector();
            StreamingContext          context           = new StreamingContext(StreamingContextStates.Remoting, null);

            _serializationFormatter               = new BinaryFormatter(surrogateSelector, context).Safe();
            _deserializationFormatter             = new BinaryFormatter(null, context).Safe();
            _serializationFormatter.FilterLevel   = _filterLevel;
            _deserializationFormatter.FilterLevel = _filterLevel;

            if (!_includeVersions || !_strictBinding)
            {
                _serializationFormatter.AssemblyFormat   = FormatterAssemblyStyle.Simple;
                _deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
            }
        }
コード例 #18
0
        internal static BinaryFormatter CreateBinaryFormatter(bool serialize, bool includeVersionsOrStrictBinding)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            if (serialize)
            {
                RemotingSurrogateSelector selector = new RemotingSurrogateSelector();
                formatter.SurrogateSelector = selector;
            }
            else
            {
                formatter.SurrogateSelector = null;
            }
            formatter.Context        = new StreamingContext(StreamingContextStates.Other);
            formatter.AssemblyFormat = includeVersionsOrStrictBinding ? FormatterAssemblyStyle.Full : FormatterAssemblyStyle.Simple;
            return(formatter);
        }
コード例 #19
0
        internal static SoapFormatter CreateSoapFormatter(bool serialize, bool includeVersions)
        {
            SoapFormatter formatter = new SoapFormatter();

            if (serialize)
            {
                RemotingSurrogateSelector selector = new RemotingSurrogateSelector();
                formatter.SurrogateSelector = selector;
                selector.UseSoapFormat();
            }
            else
            {
                formatter.SurrogateSelector = null;
            }
            formatter.Context        = new StreamingContext(StreamingContextStates.Other);
            formatter.AssemblyFormat = includeVersions ? FormatterAssemblyStyle.Full : FormatterAssemblyStyle.Simple;
            return(formatter);
        }
コード例 #20
0
        public void Init()
        {
            RemotingSurrogateSelector remotingSurrogateSelector = new RemotingSurrogateSelector();
            StreamingContext          streamingContext          = new StreamingContext(StreamingContextStates.Remoting, null);

            this._serializationFormatter   = new BinaryFormatter(remotingSurrogateSelector, streamingContext);
            this._deserializationFormatter = new BinaryFormatter(null, streamingContext);
            if (!this._includeVersions)
            {
                this._serializationFormatter.AssemblyFormat   = FormatterAssemblyStyle.Simple;
                this._deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
            }
            if (!this._strictBinding)
            {
                this._serializationFormatter.Binder   = SimpleBinder.Instance;
                this._deserializationFormatter.Binder = SimpleBinder.Instance;
            }
        }
コード例 #21
0
        // -------------- ISerializable Interface ------------------------------
        /// <summary>
        /// Serialises the information
        /// </summary>
        /// <param name="info">Standard <c>SerializationInfo</c> object</param>
        /// <param name="context">Standard <c>StreamingContext</c> object</param>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            BinaryFormatter           bf  = new BinaryFormatter();
            RemotingSurrogateSelector rss = new RemotingSurrogateSelector();

            bf.SurrogateSelector = rss;
            bf.Context           = new StreamingContext(StreamingContextStates.Other);
            bf.AssemblyFormat    = FormatterAssemblyStyle.Full;

            MemoryStream ms = new MemoryStream();

            bf.Serialize(ms, msg, null);

            info.AddValue("type", type);
            info.AddValue("stream", ms);
            info.AddValue("source", source);
            info.AddValue("objectUri", objectUri);
        }
コード例 #22
0
        internal static MemoryStream SerializeMessage(IMessage msg)
        {
            MemoryStream memoryStream1 = new MemoryStream();
            RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector();
            BinaryFormatter           binaryFormatter   = new BinaryFormatter();

            binaryFormatter.SurrogateSelector = (ISurrogateSelector)surrogateSelector;
            StreamingContext streamingContext = new StreamingContext(StreamingContextStates.CrossAppDomain);

            binaryFormatter.Context = streamingContext;
            MemoryStream memoryStream2 = memoryStream1;
            IMessage     message       = msg;
            // ISSUE: variable of the null type
            __Null local = null;
            int    num   = 0;

            binaryFormatter.Serialize((Stream)memoryStream2, (object)message, (Header[])local, num != 0);
            memoryStream1.Position = 0L;
            return(memoryStream1);
        }
コード例 #23
0
        private BinaryFormatter CreateFormatter(bool serialize)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Context        = new StreamingContext(StreamingContextStates.Other);
            formatter.AssemblyFormat = FormatterAssemblyStyle.Full;

            if (!serialize)
            {
                formatter.SurrogateSelector = new AdoNetFastSerializerSurrogate();
            }
            else
            {
                ISurrogateSelector surrogateSelector = new RemotingSurrogateSelector();
                surrogateSelector.ChainSelector(new AdoNetFastSerializerSurrogate());
                formatter.SurrogateSelector = surrogateSelector;
            }

            return(formatter);
        }