Ejemplo n.º 1
0
		/*
		 * LoadConfig
		 */

		/// <summary>
		/// Loads state from the specified <see cref="T:Stream"/>.
		/// </summary>
		/// <param name="stream">Specifies the <see cref="T:Stream"/> to load state from.</param>
		/// <exception cref="T:System.ArgumentNullException"><paramref name="stream"/> is <see langword="null"/>.</exception>
		public void LoadConfig(Stream stream)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}

			NuGenXmlTextReader xmlTextReader = new NuGenXmlTextReader(stream);
			this.LoadConfig(xmlTextReader);
			xmlTextReader.Close();
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Deserializes the specified <see cref="Object"/> from the specified path.
		/// </summary>
		/// <param name="obj">Specifies the <see cref="Object"/> to deserialize. Can be <see langword="null"/>.</param>
		/// <param name="stream">Specifies the <see cref="Stream"/> to deserialize from.</param>
		/// <param name="application">Specifies the name of the application that serialized the specified <see cref="T:Object"/>.</param>
		/// <exception cref="T:System.ArgumentNullException">
		/// <paramref name="stream"/> is <see langword="null"/>.
		/// </exception>
		public void Deserialize(object obj, Stream stream, string application)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}

			CultureInfo currentCulture = Application.CurrentCulture;
			NuGenXmlTextReader xmlTextReader = null;

			try
			{
				Application.CurrentCulture = NuGenCulture.enUS;
				xmlTextReader = new NuGenXmlTextReader(stream);

				while (xmlTextReader.Read())
				{
					if (xmlTextReader.IsStartElement() && xmlTextReader.Name == this.Name)
					{
						_graph = new NuGenGraph();
						_references = new NuGenReferenceCollection();

						_graph.Add(obj);

						string applicationName = xmlTextReader.GetAttribute(Resources.XmlAttribute_Application);

						if (applicationName.Equals(application))
						{
							this.DeserializeObject(obj, this.DeserializeObject(xmlTextReader));
							this.SetReferenceDeserializing();
						}

						return;
					}

					xmlTextReader.Read();
				}
			}
			catch
			{
				throw;
			}
			finally
			{
				Application.CurrentCulture = currentCulture;

				if (xmlTextReader != null)
				{
					xmlTextReader.Close();
				}
			}
		}