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);
     }
 }
        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);
            }
        }
Exemple #3
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));
        }
 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 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;
                }
            }
        }
 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);
 }
Exemple #8
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;
        }
        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());
            }
        }
        /// <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;
        }
Exemple #11
0
 public static object Deserialize(string value)
 {
     if (String.IsNullOrWhiteSpace(value))
     {
         return null;
     }
     else
     {
         using (var m = new MemoryStream(Encoding.Unicode.GetBytes(value)))
         {
             var r = XmlDictionaryReader.CreateTextReader(m, Encoding.Unicode, XmlDictionaryReaderQuotas.Max, null);
             var s = new NetDataContractSerializer();
             return s.ReadObject(r);
         }
     }
 }
        object DeserializeInstance(object serializedInstance, bool isText)
        {
            object instance;

            NetDataContractSerializer serializer = new NetDataContractSerializer();
            if (isText)
            {
                StringReader stringReader = new StringReader((string)serializedInstance);
                XmlReader xmlReader = XmlReader.Create(stringReader);

                instance = serializer.ReadObject(xmlReader);

                xmlReader.Close();
                stringReader.Close();
            }
            else
            {
                XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateBinaryReader((byte[])serializedInstance, XmlDictionaryReaderQuotas.Max);

                instance = serializer.ReadObject(dictionaryReader);

                dictionaryReader.Close();
            }

            return instance;
        }
		internal static ScheduledJobDefinition LoadDefFromStore(string definitionName, string definitionPath)
		{
			ScheduledJobDefinition scheduledJobDefinition = null;
			FileStream fileForJobDefinition = null;
			try
			{
				if (definitionPath != null)
				{
					fileForJobDefinition = ScheduledJobStore.GetFileForJobDefinition(definitionName, definitionPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				}
				else
				{
					fileForJobDefinition = ScheduledJobStore.GetFileForJobDefinition(definitionName, FileMode.Open, FileAccess.Read, FileShare.Read);
				}
				XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
				scheduledJobDefinition = netDataContractSerializer.ReadObject(fileForJobDefinition) as ScheduledJobDefinition;
			}
			finally
			{
				if (fileForJobDefinition != null)
				{
					fileForJobDefinition.Close();
				}
			}
			return scheduledJobDefinition;
		}
 public override void Uninstall(IDictionary savedState)
 {
     this.PrintStartText(System.Configuration.Install.Res.GetString("InstallActivityUninstalling"));
     if (!this.initialized)
     {
         this.InitializeFromAssembly();
     }
     string installStatePath = this.GetInstallStatePath(this.Path);
     if ((installStatePath != null) && File.Exists(installStatePath))
     {
         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);
             }
         }
         catch
         {
             base.Context.LogMessage(System.Configuration.Install.Res.GetString("InstallSavedStateFileCorruptedWarning", new object[] { this.Path, installStatePath }));
             savedState = null;
         }
         finally
         {
             if (reader != null)
             {
                 reader.Close();
             }
             if (input != null)
             {
                 input.Close();
             }
         }
     }
     else
     {
         savedState = null;
     }
     base.Uninstall(savedState);
     if ((installStatePath != null) && (installStatePath.Length != 0))
     {
         try
         {
             File.Delete(installStatePath);
         }
         catch
         {
             throw new InvalidOperationException(System.Configuration.Install.Res.GetString("InstallUnableDeleteFile", new object[] { installStatePath }));
         }
     }
 }
 /// <summary>
 /// Loads a pinball machine from an input stream.
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public static PinballMachine FromStream(Stream input)
 {
     NetDataContractSerializer serializer = new NetDataContractSerializer();
     return (PinballMachine)serializer.ReadObject(input);
 }
Exemple #16
0
        /// <summary>
        /// Init WurmServer with optional dir path to where it should store it's data
        /// </summary>
        /// <param name="dataDir">Absolute directory path, default null uses CodeBase</param>
        /// <exception cref="ArgumentException">Directory path was probably invalid</exception>
        /// <exception cref="InvalidOperationException">WurmServer was already initialized</exception>
        public static void InitializeWurmServer(string dataDir = null)
        {
            if (isInitialized) throw new InvalidOperationException("WurmServer is already initialized");

            if (dataDir == null) _dataFilePath = GeneralHelper.PathCombineWithCodeBasePath("WurmServerData.xml");
            else _dataFilePath = Path.Combine(dataDir, "WurmServerData.xml");

            Logger.LogInfo("Initializing", THIS);
            _initTask = new Task(async () =>
                {
                    try
                    {
                        //get the old data so program can init faster
                        var ds = new NetDataContractSerializer();
                        using (Stream s = File.OpenRead(_dataFilePath))
                        {
                            _serverData = (WurmServerData)ds.ReadObject(s);
                        }
                    }
                    catch (Exception _e)
                    {
                        _serverData = new WurmServerData();
                        Logger.LogInfo("problem while loading cached WurmServer state, recaching", THIS, _e);
                    }
                    var webTask = ExtractFromWebAsync();
                    var logsTask = ExtractFromLogsAsync();
                    await webTask;
                    await logsTask;
                    Logger.LogInfo("Init complete", THIS);
                });
            _initTask.Start();
        }
 /// <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);
 }
			public object FromElement(Type type, XElement element)
			{
				var serializer = new NetDataContractSerializer();
				var childElement = element.FirstNode.NextNode;
				return serializer.ReadObject(XmlReader.Create(new StringReader(childElement.ToString())));
			}
        private static object ReadFaultDetail(Message reply)
        {
            const string detailElementName = "Detail";
            const string reasonElementName = "Reason";
            string reason = null;

            using (XmlDictionaryReader reader = reply.GetReaderAtBodyContents())
            {
                // Find <soap:Reason>
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.LocalName == reasonElementName)
                    {
                        // Find <soap:Text>
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "Text")
                            {
                                reader.Read();
                                reason = reader.Value;
                                break;
                            }
                        }
                        break;
                    }
                }

                // 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
                var serializer = new NetDataContractSerializer();
                try
                {
                    return serializer.ReadObject(reader, false);
                }
                catch (SerializationException ex)
                {
                    throw reason != null
                              ? new SerializationException(reason)
                              : ex;
                }
                catch (FileNotFoundException)
                {
                    // Serializer was unable to find assembly where exception is defined
                    return null;
                }
            }
        }
		internal object DeserializeObject2(ArraySegment<byte> source)
		{
			object obj;
			try
			{
				XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
				using (MemoryStream memoryStream = new MemoryStream(source.Array, source.Offset, source.Count))
				{
					object obj1 = netDataContractSerializer.ReadObject(memoryStream);
					obj = obj1;
				}
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				this.Tracer.TraceException(exception);
				throw;
			}
			return obj;
		}
Exemple #21
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));
        }
Exemple #22
0
        /// <summary>
        /// Загрузка данных из файла "data.xml" (десериализация).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Load_Click(object sender, RoutedEventArgs e)
        {
                        System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory();

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                XmlTextReader xmlr = new XmlTextReader(openFileDialog1.FileName);
                NetDataContractSerializer dcs = new NetDataContractSerializer();
                polygons.List = (ObservableCollection<PolygonShell>)dcs.ReadObject(xmlr);
                xmlr.Close();

                list_view.ItemsSource = null;
                list_view.ItemsSource = polygons.List;

                double length = 0;
                for (int i = 0; i < polygons.List.Count; i++)
                {
                    double max_x = double.NegativeInfinity;
                    for (int j = 0; j < polygons.List[i].Count; j++)
                        if (max_x < polygons.List[i][j].X)
                            max_x = polygons.List[i][j].X;
                    if (length < polygons.List[i].Pole.X + max_x)
                        length = polygons.List[i].Pole.X + max_x;
                }
                strip_length.Text = length.ToString();
            }
        }
Exemple #23
0
 public override void Rollback(IDictionary savedState)
 {
     this.PrintStartText(Res.GetString("InstallActivityRollingBack"));
     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();
         }
     }
     try
     {
         base.Rollback(savedState);
     }
     finally
     {
         File.Delete(installStatePath);
     }
 }
        public static void LoadSchemas(string schemaXMLFile)
        {
            XDocument schemaDoc = XDocument.Load(schemaXMLFile);

             RemoveAllSchemas();

             var nodes = from n in schemaDoc.Root.Elements()
                     select n;

             foreach ( var node in  nodes)
             {
            NetDataContractSerializer sr = new NetDataContractSerializer();
            StringReader strReader = new StringReader(node.ToString());
            XmlReader xr = XmlReader.Create(strReader);
            EntitySchema schema = (EntitySchema)sr.ReadObject(xr);

            AddSchema(schema);
             }
        }
        /// <summary>
        /// Reads a ScheduledJobDefinition object from file and
        /// returns object.
        /// </summary>
        /// <param name="definitionName">Name of definition to load</param>
        /// <param name="definitionPath">Path to definition file</param>
        /// <returns>ScheduledJobDefinition object</returns>
        internal static ScheduledJobDefinition LoadDefFromStore(
            string definitionName,
            string definitionPath)
        {
            ScheduledJobDefinition definition = null;
            FileStream fs = null;
            try
            {
                fs = GetFileStream(
                    definitionName,
                    definitionPath,
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.Read);

                XmlObjectSerializer serializer = new System.Runtime.Serialization.NetDataContractSerializer();
                definition = serializer.ReadObject(fs) as ScheduledJobDefinition;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            return definition;
        }
Exemple #26
0
        public void ET_WCF_Serialization_List()
        {
            var model = new Book
            {
                ChapterList =
                {
                    new Chapter {
                        Id = 111,
                        Name = "Chapter1",
                    },
                    new Chapter {
                        Id = 222,
                        Name = "Chapter2",
                    },
                }
            };

            //序列化。
            var serializer = new NetDataContractSerializer();
            var stream = new MemoryStream();
            serializer.WriteObject(stream, model);

            //读取 xml
            byte[] bytes = stream.ToArray();
            string xml = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            Assert.IsTrue(xml.Contains("<Book"));
            Assert.IsTrue(xml.Contains("<ChapterList"));
            Assert.IsTrue(xml.Contains("<Chapter"));
            Assert.IsTrue(xml.Contains("111"));
            Assert.IsTrue(xml.Contains("<Name"));
            Assert.IsTrue(xml.Contains("Chapter1"));

            //反序列化
            stream.Seek(0, SeekOrigin.Begin);
            var model2 = (Book)serializer.ReadObject(stream);

            Assert.IsTrue(model2.GetProperty(Book.ChapterListProperty) != null);
            Assert.IsTrue(model2.ChapterList.Count == 2);
            Assert.IsTrue(model2.ChapterList[0].Id == 111);
            Assert.IsTrue(model2.ChapterList[0].Name == "Chapter1");
        }
Exemple #27
0
        public static void ReadObject(string fileName)
        {
            Console.WriteLine("Deserializing an instance of the object.");

            // Creating the serializer
            FileStream fs = new FileStream(fileName, FileMode.Open);
            XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
            NetDataContractSerializer ser = new NetDataContractSerializer();

            // Deserialize the data and read it from the instance
            ComplexNumber deserializedNumber = (ComplexNumber)ser.ReadObject(reader, true);
            fs.Close();
            Console.WriteLine(String.Format("Real: {0}, Imaginary: {1}", deserializedNumber.Real, deserializedNumber.Imaginary));
        }
        public void AfterReceiveReply(ref Message reply, object correlationState)
        {
            if (reply.IsFault)
            {

                const string detailElementName = "Detail";

                using (XmlDictionaryReader reader = reply.GetReaderAtBodyContents())
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.LocalName == detailElementName)
                        {
                            break;
                        }
                    }

                    if (reader.NodeType != XmlNodeType.Element || reader.LocalName != detailElementName)
                    {
                        return;
                    }

                    if (!reader.Read())
                    {
                        return;
                    }
                    var serializer = new NetDataContractSerializer();

                    var detail = serializer.ReadObject(reader);

                    var exception = detail as Exception;
                    if (exception != null)
                    {
                        throw exception;
                    }
                }

            }
        }
 public object Deserialize(System.IO.Stream stream, Type type)
 {
     NetDataContractSerializer serializer = new NetDataContractSerializer();
     return serializer.ReadObject(stream);
 }
		private static Job2 LoadResultsFromFile(FileStream fs)
		{
			XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
			return (Job2)netDataContractSerializer.ReadObject(fs);
		}
		internal object LoadFromFileAndDeserialize(string filePath)
		{
			object obj;
			FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None);
			try
			{
				if (fileStream.Length == (long)0)
				{
					return null;
				}
				else
				{
					GZipStream gZipStream = new GZipStream(fileStream, CompressionMode.Decompress);
					try
					{
						try
						{
							byte[] numArray = new byte[1];
							gZipStream.Read(numArray, 0, 1);
							if (numArray[0] != 84)
							{
								XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
								obj = netDataContractSerializer.ReadObject(gZipStream);
							}
							else
							{
								gZipStream.Close();
								fileStream.Close();
								ArraySegment<byte> nums = this.LoadFromFile2(filePath);
								obj = this.DeserializeObject2(this.Decrypt(nums));
							}
						}
						catch (Exception exception1)
						{
							Exception exception = exception1;
							this.Tracer.TraceException(exception);
							throw;
						}
					}
					finally
					{
						gZipStream.Close();
						gZipStream.Dispose();
					}
				}
			}
			finally
			{
				fileStream.Close();
				fileStream.Dispose();
			}
			return obj;
		}