Exemplo n.º 1
0
        //Reads data from xml file and creates a dictionary based off of that.
        static IDictionary<XName, InstanceValue> LoadInstanceDataFromFile(Stream inputStream)
        {
            IDictionary<XName, InstanceValue> data = new Dictionary<XName, InstanceValue>();

            var serializer = new NetDataContractSerializer();

            using (var xmlReader = XmlReader.Create(inputStream))
            {
                var doc = new XmlDocument();
                doc.Load(xmlReader);

                var instances = doc.GetElementsByTagName("InstanceValue");
                foreach (XmlElement instanceElement in instances)
                {
                    var keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key");
                    var key = (XName)DeserializeObject(serializer, keyElement);

                    var valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value");
                    var value = DeserializeObject(serializer, valueElement);
                    var instVal = new InstanceValue(value);

                    data.Add(key, instVal);
                }
            }

            return data;
        }
Exemplo n.º 2
0
 internal XmlObjectSerializerContext(NetDataContractSerializer serializer)
     : this(serializer,
     serializer.MaxItemsInObjectGraph,
     serializer.Context,
     serializer.IgnoreExtensionDataObject)
 {
 }
Exemplo n.º 3
0
		protected override object DeserializeObject(ArraySegment<byte> value)
		{
			var ds = new NetDataContractSerializer();

			using (var ms = new MemoryStream(value.Array, value.Offset, value.Count))
				return ds.Deserialize(ms);
		}
        /// <summary>
        /// Saves all instance data.
        /// </summary>
        /// <param name="instanceId">The instance id.</param>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        /// <exception cref="System.Runtime.DurableInstancing.InstancePersistenceException"></exception>
        public Boolean SaveAllInstanceData(Guid instanceId, SaveWorkflowCommand command)
        {
            Boolean isExistingInstance;
            try
            {
                String fileName = String.Format("{0}.xml", instanceId);
                String fullPath = Path.Combine(_dataDirectory, fileName);
                isExistingInstance = File.Exists(fullPath);

                XElement root = new XElement("Instance");
                root.Add(new XAttribute("WorkflowInstanceId", instanceId));
                XDocument xml = new XDocument(root);

                NetDataContractSerializer serializer = new NetDataContractSerializer();

                XElement section = new XElement("InstanceData");
                root.Add(section);
                foreach(var entry in command.InstanceData)
                {
                    SaveSingleEntry(serializer, section, entry);
                }
                SaveInstanceDocument(fullPath, xml);
            }
            catch(Exception exception)
            {
                Dev2Logger.Log.Error(exception);
                throw new InstancePersistenceException(exception.Message, exception);
            }
            return isExistingInstance;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Writes the job (which implements ISerializable) to the provided
        /// file stream.
        /// </summary>
        /// <param name="job">ScheduledJob job to save</param>
        /// <param name="fs">FileStream</param>
        private static void SaveResultsToFile(ScheduledJob job, FileStream fs)
        {
            XmlObjectSerializer serializer = new System.Runtime.Serialization.NetDataContractSerializer();

            serializer.WriteObject(fs, job);
            fs.Flush();
        }
 internal XmlObjectSerializerReadContextComplex(NetDataContractSerializer serializer) : base(serializer)
 {
     this.mode = SerializationMode.SharedType;
     this.preserveObjectReferences = true;
     this.binder = serializer.Binder;
     this.surrogateSelector = serializer.SurrogateSelector;
     this.assemblyFormat = serializer.AssemblyFormat;
 }
Exemplo n.º 7
0
 // Deserializes a stream to a graph using the NetDataContractSerializer (binary mode)
 private static object DeserializeGraph(Stream rawBytes)
 {
     using (XmlDictionaryReader dr = XmlDictionaryReader.CreateBinaryReader(rawBytes, XmlDictionaryReaderQuotas.Max))
     {
         object deserialized = new NetDataContractSerializer().ReadObject(dr);
         return deserialized;
     }
 }
 public override object Deserialize(Type type, byte[] data)
 {
     var formatter = new NetDataContractSerializer();
     using (var ms = new MemoryStream(data))
     {
         return formatter.Deserialize(ms);
     }
 }
Exemplo n.º 9
0
 internal XmlObjectSerializerReadContextComplex(NetDataContractSerializer serializer)
     : base(serializer)
 {
     this.mode = SerializationMode.SharedType;
     this.preserveObjectReferences = true;
     this.binder            = serializer.Binder;
     this.surrogateSelector = serializer.SurrogateSelector;
     this.assemblyFormat    = serializer.AssemblyFormat;
 }
 public override byte[] Serialize(object obj)
 {
     var formatter = new NetDataContractSerializer();
     using (var ms = new MemoryStream())
     {
         formatter.Serialize(ms, obj);
         return ms.ToArray();
     }
 }
 internal override bool WriteClrTypeInfo(XmlWriterDelegator xmlWriter, Type dataContractType, SerializationInfo serInfo)
 {
     if (this.mode == SerializationMode.SharedType)
     {
         NetDataContractSerializer.WriteClrTypeInfo(xmlWriter, dataContractType, this.binder, serInfo);
         return(true);
     }
     return(false);
 }
 internal XmlObjectSerializerWriteContextComplex(NetDataContractSerializer serializer, Hashtable surrogateDataContracts) : base(serializer)
 {
     this.mode = SerializationMode.SharedType;
     base.preserveObjectReferences = true;
     this.streamingContext         = serializer.Context;
     this.binder                 = serializer.Binder;
     this.surrogateSelector      = serializer.SurrogateSelector;
     this.surrogateDataContracts = surrogateDataContracts;
 }
Exemplo n.º 13
0
        public BinaryStateSerializer(ILogger logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");

            this.logger = logger;
            netDataContractSerializer = new NetDataContractSerializer();
            load();
        }
 public static object Deserialize(byte[] buffer)
 {
     using (MemoryStream memStream = new MemoryStream(buffer))
     using (GZipStream zipStream = new GZipStream(memStream, CompressionMode.Decompress))
     using (XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateBinaryReader(zipStream, XmlDictionaryReaderQuotas.Max))
     {
         NetDataContractSerializer serializer = new NetDataContractSerializer();
         return serializer.ReadObject(xmlDictionaryReader);
     }
 }
			public XElement ToElement(object val, Func<Type, XNamespace> getNamespace)
			{
				var serializer = new NetDataContractSerializer();
				using (var ms = new MemoryStream())
				{
					serializer.WriteObject(ms, val);
					ms.Seek(0, SeekOrigin.Begin);
					return XElement.Load(new XmlTextReader(ms));
				}
			}
 internal XmlObjectSerializerWriteContextComplex(NetDataContractSerializer serializer, Hashtable surrogateDataContracts)
     : base(serializer)
 {
     this.mode = SerializationMode.SharedType;
     this.preserveObjectReferences = true;
     this.streamingContext = serializer.Context;
     this.binder = serializer.Binder;
     this.surrogateSelector = serializer.SurrogateSelector;
     this.surrogateDataContracts = surrogateDataContracts;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Creates a new instance of the class with the same value as instance.
 /// </summary>
 /// <returns>Returns cloned object.</returns>
 public virtual object Clone()
 {
     IFormatter formatter = new NetDataContractSerializer();
     using(Stream stream = new MemoryStream())
     {
         formatter.Serialize(stream, this);
         stream.Seek(0, SeekOrigin.Begin);
         return formatter.Deserialize(stream);
     }
 }
        private object Deserialize(string value, Type type)
        {
            using (var m = new MemoryStream(Encoding.Unicode.GetBytes(value)))
            {
                var r = XmlDictionaryReader.CreateTextReader(m, Encoding.Unicode, XmlDictionaryReaderQuotas.Max, null);

                //var s = new DataContractSerializer(type, null, Int32.MaxValue, false, false, null, new PluginDataContractResolver());
                var s = new NetDataContractSerializer();

                return s.ReadObject(r);
            }
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            var ns = new NetDataContractSerializer();
            // NetDataContractSerializer is otherwise the same to use
            // as DataContractSerializer.
            Person p = new Person { Name = "Stacey", Age = 30 };
            var ds = new DataContractSerializer(typeof(Person));
            XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
            using (XmlWriter w = XmlWriter.Create("person.xml", settings))
                ds.WriteObject(w, p);

            System.Diagnostics.Process.Start("person.xml");
        }
Exemplo n.º 20
0
        static KeyValuePair<string, MethodBase> DeserializeMethodBase(XmlReader reader)
        {
            var sb = new StringBuilder();
            sb.Append(reader.ReadOuterXml());

            var s = sb.ToString();
            var ndcs = new NetDataContractSerializer();
            using (var sr = new StringReader(s))
            using (var xr = new XmlTextReader(sr))
            {
                return new KeyValuePair<string, MethodBase>(s, (MethodBase)ndcs.ReadObject(xr));
            }
        }
        public void SholdSerializeOperator()
        {
            // Given
            var entity = new FilterTestEntity { StringField = "Abc", IntField = 5 };

            // Какое-то сложное логическое выражение
            var specification = new FilterSpecification<FilterTestEntity>(
                b => b.Or(
                    c => c
                             .And(a => a.Or(o => o
                                                     .Null(i => i.StringField)
                                                     .Equal(i => i.StringField, string.Empty))
                                           .Equal(i => i.IntField, 0))
                             .And(a => a
                                           .NotNull(i => i.StringField)
                                           .NotEqual(i => i.StringField, string.Empty)
                                           .Or(o => o
                                                        .In(i => i.StringField.ToLower(), new[] { "a", "b", "c" })
                                                        .Contains(i => i.StringField.ToLower(), "abc")
                                                        .StartsWith(i => i.StringField, "1")
                                                        .EndsWith(i => i.StringField, "5"))
                                           .Or(o => o
                                                        .And(a2 => a2
                                                                       .GreaterOrEqual(i => i.IntField, 0)
                                                                       .LessOrEqual(i => i.IntField, 10))
                                                        .And(a2 => a2
                                                                       .Greater(i => i.IntField, 10)
                                                                       .Less(i => i.IntField, 20))
                                                        .Between(i => i.IntField, 20, 30)))));

            IFilterOperator operatorFromStream;
            IFilterOperator operatorToStream = specification.Operator;

            // When
            using (var stream = new MemoryStream())
            {
                // Сериализация
                var serializer = new NetDataContractSerializer();
                serializer.Serialize(stream, operatorToStream);
                stream.Position = 0;

                // Десериализация
                operatorFromStream = (IFilterOperator)serializer.ReadObject(stream);
            }

            // Then
            Assert.IsNotNull(operatorFromStream);
            Assert.AreEqual(operatorToStream.IsSatisfiedBy(entity), operatorFromStream.IsSatisfiedBy(entity));
        }
 public static byte[] Serialize(object graph)
 {
     using (MemoryStream memStream = new MemoryStream())
     using (GZipStream zipStream = new GZipStream(memStream, CompressionMode.Compress))
     {
         using (XmlDictionaryWriter xmlDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(zipStream))
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             serializer.WriteObject(xmlDictionaryWriter, graph);
             xmlDictionaryWriter.Close();
         }
         zipStream.Close();
         return memStream.ToArray();
     }
 }
Exemplo n.º 23
0
        public async Task SerializingTaskTest()
        {
            var count = 10;
            var action = new Action(() => count=count+5);
            Assert.AreEqual(count, 10);

            var sr = new NetDataContractSerializer();
            //v//ar actionString = sr.S
            //var actionString = JsonConvert.SerializeObject(action);
            //var newAction = JsonConvert.DeserializeObject<Action>(actionString);


            //newAction.Invoke();
            Assert.AreEqual(count, 15);
        }
 private static WorkflowCompilerResults DeserializeWrapperOutput(string fileName)
 {
     WorkflowCompilerResults results;
     using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         using (XmlReader reader = XmlReader.Create(stream))
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             SurrogateSelector selector = new SurrogateSelector();
             selector.AddSurrogate(typeof(MemberAttributes), serializer.Context, new CompilerResultsSurrogate());
             serializer.SurrogateSelector = selector;
             results = (WorkflowCompilerResults) serializer.ReadObject(reader);
         }
     }
     return results;
 }
        private string Serialize(object value, Type type)
        {
            using (var m = new MemoryStream())
            {
                var w = XmlDictionaryWriter.CreateTextWriter(m, Encoding.Unicode);

                //var s = new DataContractSerializer(type, null, Int32.MaxValue, false, false, null, new PluginDataContractResolver());
                var s = new NetDataContractSerializer();

                s.WriteObject(w, value);
                w.Flush();
                w.Close();

                return System.Text.Encoding.Unicode.GetString(m.ToArray());
            }
        }
 private static Response GetSerializedVersion(object response)
 {
     try
     {
         using (var stream = new MemoryStream())
         {
             var serializer = new NetDataContractSerializer();
             serializer.WriteObject(stream, response);
             stream.Position = 0;
             return (Response)serializer.ReadObject(stream);
         }
     }
     catch (Exception ex)
     {
         throw new ColomboSerializationException(string.Format("{0} could not be serialized.", response), ex);
     }
 }
 private static void WriteCompilerOutput(string path, WorkflowCompilerResults results)
 {
     using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         XmlWriterSettings settings = new XmlWriterSettings {
             Indent = true
         };
         using (XmlWriter writer = XmlWriter.Create(stream, settings))
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             SurrogateSelector selector = new SurrogateSelector();
             selector.AddSurrogate(typeof(MemberAttributes), serializer.Context, new CompilerResultsSurrogate());
             serializer.SurrogateSelector = selector;
             serializer.WriteObject(writer, results);
         }
     }
 }
        private static object ReadFaultDetail(Message reply)
        {
            const string DetailElementName = "Detail";

            using (XmlDictionaryReader reader = reply.GetReaderAtBodyContents())
            {
                // Find <soap:Detail>
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.LocalName == DetailElementName)
                    {
                        break;
                    }
                }

                // Did we find it?
                if (reader.NodeType != XmlNodeType.Element || reader.LocalName != DetailElementName)
                {
                    return null;
                }

                // Move to the contents of <soap:Detail>
                if (!reader.Read())
                {
                    return null;
                }

                // Deserialize the fault
                NetDataContractSerializer serializer = new NetDataContractSerializer();
                try
                {
                    return serializer.ReadObject(reader);
                }
                catch (FileNotFoundException)
                {
                    // Serializer was unable to find assembly where exception is defined
                    return null;
                }
                catch (SerializationException)
                {
                    // Error during deserialization
                    return null;
                }
            }
        }
        internal override DataContract GetDataContract(int id, RuntimeTypeHandle typeHandle)
        {
            DataContract contract = null;

            if ((this.mode == SerializationMode.SharedType) && (this.surrogateSelector != null))
            {
                contract = NetDataContractSerializer.GetDataContractFromSurrogateSelector(this.surrogateSelector, base.GetStreamingContext(), typeHandle, null, ref this.surrogateDataContracts);
            }
            if (contract == null)
            {
                return(base.GetDataContract(id, typeHandle));
            }
            if (this.IsGetOnlyCollection && (contract is SurrogateDataContract))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser", new object[] { DataContract.GetClrTypeFullName(contract.UnderlyingType) })));
            }
            return(contract);
        }
 public override void Commit(IDictionary savedState)
 {
     this.PrintStartText(System.Configuration.Install.Res.GetString("InstallActivityCommitting"));
     if (!this.initialized)
     {
         this.InitializeFromAssembly();
     }
     string installStatePath = this.GetInstallStatePath(this.Path);
     FileStream input = new FileStream(installStatePath, FileMode.Open, FileAccess.Read);
     XmlReaderSettings settings = new XmlReaderSettings {
         CheckCharacters = false,
         CloseInput = false
     };
     XmlReader reader = null;
     if (input != null)
     {
         reader = XmlReader.Create(input, settings);
     }
     try
     {
         if (reader != null)
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             savedState = (Hashtable) serializer.ReadObject(reader);
         }
     }
     finally
     {
         if (reader != null)
         {
             reader.Close();
         }
         if (input != null)
         {
             input.Close();
         }
         if (base.Installers.Count == 0)
         {
             base.Context.LogMessage(System.Configuration.Install.Res.GetString("RemovingInstallState"));
             File.Delete(installStatePath);
         }
     }
     base.Commit(savedState);
 }
Exemplo n.º 31
0
        /// <summary>
        /// Writes the job status information to the provided
        /// file stream.
        /// </summary>
        /// <param name="job">ScheduledJob job to save</param>
        /// <param name="fs">FileStream</param>
        private static void SaveStatusToFile(ScheduledJob job, FileStream fs)
        {
            StatusInfo statusInfo = new StatusInfo(
                job.InstanceId,
                job.Name,
                job.Location,
                job.Command,
                job.StatusMessage,
                job.JobStateInfo.State,
                job.HasMoreData,
                job.PSBeginTime,
                job.PSEndTime,
                job.Definition);

            XmlObjectSerializer serializer = new System.Runtime.Serialization.NetDataContractSerializer();

            serializer.WriteObject(fs, statusInfo);
            fs.Flush();
        }
Exemplo n.º 32
0
        public static object DeserializeUsingNetDataContract(string filename)
        {
            object theObject = null;
            int maxDepth = 10000;
            bool maxDepthExceeded = true;

            while (maxDepthExceeded)
            {
                try
                {
                    using (FileStream fs = new FileStream(filename, FileMode.Open))
                    {
                        XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
                        quotas.MaxDepth = maxDepth;

                        using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, quotas))
                        {
                            NetDataContractSerializer ser = new NetDataContractSerializer();
                            //ser.Binder = new Version2SerializationBinder();
                            theObject = (List<ArchAngel.Providers.Database.Model.Database>)ser.ReadObject(reader, true);
                        }
                        fs.Close();
                        maxDepthExceeded = false;
                    }
                }
                catch (SerializationException ex)
                {
                    if (ex.Message.IndexOf("more levels of nesting than is allowed by the quota") >= 0)
                    {
                        // We need to increase the maxDepth
                        maxDepth += 1000;
                        maxDepthExceeded = true;
                    }
                    else
                    {
                        // We have another kind of error
                        throw;
                    }
                }
            }
            return theObject;
        }
        internal override DataContract GetDataContract(RuntimeTypeHandle typeHandle, Type type)
        {
            DataContract dataContract = null;

            if (mode == SerializationMode.SharedType && surrogateSelector != null)
            {
                dataContract = NetDataContractSerializer.GetDataContractFromSurrogateSelector(surrogateSelector, GetStreamingContext(), typeHandle, type, ref surrogateDataContracts);
            }

            if (dataContract != null)
            {
                if (this.IsGetOnlyCollection && dataContract is SurrogateDataContract)
                {
                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser,
                                                                                                                                                         DataContract.GetClrTypeFullName(dataContract.UnderlyingType))));
                }
                return(dataContract);
            }

            return(base.GetDataContract(typeHandle, type));
        }
        // Update the overloads whenever you are changing this method
        internal static void WriteClrTypeInfo(XmlWriterDelegator writer, Type dataContractType, SerializationBinder binder, SerializationInfo serInfo)
        {
            TypeInformation typeInformation = null;
            string          clrTypeName     = null;
            string          clrAssemblyName = null;

            if (binder != null)
            {
                binder.BindToName(dataContractType, out clrAssemblyName, out clrTypeName);
            }

            if (clrTypeName == null)
            {
                if (serInfo.IsFullTypeNameSetExplicit)
                {
                    clrTypeName = serInfo.FullTypeName;
                }
                else
                {
                    typeInformation = NetDataContractSerializer.GetTypeInformation(serInfo.ObjectType);
                    clrTypeName     = typeInformation.FullTypeName;
                }
            }

            if (clrAssemblyName == null)
            {
                if (serInfo.IsAssemblyNameSetExplicit)
                {
                    clrAssemblyName = serInfo.AssemblyName;
                }
                else
                {
                    clrAssemblyName = (typeInformation == null) ?
                                      NetDataContractSerializer.GetTypeInformation(serInfo.ObjectType).AssemblyString :
                                      typeInformation.AssemblyString;
                }
            }

            WriteClrTypeInfo(writer, clrTypeName, clrAssemblyName);
        }
        public void Net_data_contract_serialization_will_not_change_the_type_of_a_collection()
        {
            using (var session = DataAccess.OpenSession())
            {
                var forum = session.Get<ForumModel>(1);

                //company.EmployeesList made public for the purpose of
                //this demo
                Assert.AreEqual(typeof(NHibernate.Collection.Generic.PersistentGenericBag<TopicModel>), forum.Topics.GetType());

                var serializer = new NetDataContractSerializer();

                //serialize company to a memory stream
                Stream stream = new MemoryStream();
                serializer.WriteObject(stream, forum);
                Console.WriteLine();
                //deserialize the memory stream back to a company
                stream.Position = 0;
                forum = (ForumModel)serializer.ReadObject(stream);

                Assert.AreEqual(typeof(NHibernate.Collection.Generic.PersistentGenericBag<TopicModel>), forum.Topics.GetType());
            }
        }
Exemplo n.º 36
0
        /// <summary>
        /// Deserialize data.
        /// </summary>
        /// <param name="data">Data to deserialize.</param>
        /// <param name="encoding">The encoding to use.</param>
        /// <returns>The deserialized data.</returns>
        public object Deserialize( string data, Encoding encoding = null )
        {
            if ( encoding == null )
             {
            encoding = DefaultEncoding;
             }

             if ( data == null )
             {
            return null;
             }

             var bytes = encoding.GetBytes( data );

             if ( bytes == null || bytes.Length == 0 )
             {
            return null;
             }

             object result;
             using ( var memoryStream = new MemoryStream( bytes ) )
             {
            using ( var xmlDictionaryReader = XmlDictionaryReader.CreateTextReader( memoryStream, encoding, XmlDictionaryReaderQuotas.Max, null ) )
            {
               var netDataContractSerializer = new NetDataContractSerializer();

               result = netDataContractSerializer.ReadObject( xmlDictionaryReader, true );
            }
             }

             if ( result != null && result.GetType() == typeof( NullObject ) )
             {
            return null;
             }

             return result;
        }
        // Update the overloads whenever you are changing this method
        internal static void WriteClrTypeInfo(XmlWriterDelegator writer, DataContract dataContract, SerializationBinder binder)
        {
            if (!dataContract.IsISerializable && !(dataContract is SurrogateDataContract))
            {
                TypeInformation typeInformation = null;
                Type            clrType         = dataContract.OriginalUnderlyingType;
                string          clrTypeName     = null;
                string          clrAssemblyName = null;

                if (binder != null)
                {
                    binder.BindToName(clrType, out clrAssemblyName, out clrTypeName);
                }

                if (clrTypeName == null)
                {
                    typeInformation = NetDataContractSerializer.GetTypeInformation(clrType);
                    clrTypeName     = typeInformation.FullTypeName;
                }

                if (clrAssemblyName == null)
                {
                    clrAssemblyName = (typeInformation == null) ?
                                      NetDataContractSerializer.GetTypeInformation(clrType).AssemblyString :
                                      typeInformation.AssemblyString;

                    // Throw in the [TypeForwardedFrom] case to prevent a partially trusted assembly from forwarding itself to an assembly with higher privileges
                    if (!UnsafeTypeForwardingEnabled && !clrType.Assembly.IsFullyTrusted && !IsAssemblyNameForwardingSafe(clrType.Assembly.FullName, clrAssemblyName))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.TypeCannotBeForwardedFrom, DataContract.GetClrTypeFullName(clrType), clrType.Assembly.FullName, clrAssemblyName)));
                    }
                }

                WriteClrTypeInfo(writer, clrTypeName, clrAssemblyName);
            }
        }
Exemplo n.º 38
0
		private static void SaveStatusToFile(ScheduledJob job, FileStream fs)
		{
			StatusInfo statusInfo = new StatusInfo(job.InstanceId, job.Name, job.Location, job.Command, job.StatusMessage, job.JobStateInfo.State, job.HasMoreData, job.PSBeginTime, job.PSEndTime, job.Definition);
			XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
			netDataContractSerializer.WriteObject(fs, statusInfo);
			fs.Flush();
		}
Exemplo n.º 39
0
		private static void SaveResultsToFile(ScheduledJob job, FileStream fs)
		{
			XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
			netDataContractSerializer.WriteObject(fs, job);
			fs.Flush();
		}
Exemplo n.º 40
0
        /// <summary>
        /// Loads the Job2 object from provided files stream.
        /// </summary>
        /// <param name="fs">FileStream from which to read job object</param>
        /// <returns>Created Job2 from file stream</returns>
        private static Job2 LoadResultsFromFile(FileStream fs)
        {
            XmlObjectSerializer serializer = new System.Runtime.Serialization.NetDataContractSerializer();

            return((Job2)serializer.ReadObject(fs));
        }
 internal XmlObjectSerializerContext(NetDataContractSerializer serializer) : this(serializer, serializer.MaxItemsInObjectGraph, serializer.Context, serializer.IgnoreExtensionDataObject)
 {
 }
Exemplo n.º 42
0
 protected XmlObjectSerializerWriteContext(NetDataContractSerializer serializer)
     : base(serializer)
 {
     this.unsafeTypeForwardingEnabled = NetDataContractSerializer.UnsafeTypeForwardingEnabled;
 }
Exemplo n.º 43
0
 protected XmlObjectSerializerReadContext(NetDataContractSerializer serializer) : base(serializer)
 {
     this.attributes = new Attributes();
 }
Exemplo n.º 44
0
 internal static XmlObjectSerializerReadContext CreateContext(NetDataContractSerializer serializer)
 {
     return(new XmlObjectSerializerReadContextComplex(serializer));
 }
 protected XmlObjectSerializerWriteContext(NetDataContractSerializer serializer) : base(serializer)
 {
     this.byValObjectsInScope = new ObjectReferenceStack();
 }
 internal static XmlObjectSerializerWriteContext CreateContext(NetDataContractSerializer serializer, Hashtable surrogateDataContracts)
 {
     return(new XmlObjectSerializerWriteContextComplex(serializer, surrogateDataContracts));
 }