Deserialize() private method

/// The save format is corrupt and could not be loaded. ///
private Deserialize ( XmlElement node ) : void
node System.Xml.XmlElement
return void
示例#1
0
        /// <exception cref="IOException">
        /// Could not load the project.
        /// </exception>
        /// <exception cref="InvalidDataException">
        /// The save file is corrupt and could not be loaded.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="fileName"/> is empty string.
        /// </exception>
        public static Project Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(Strings.ErrorBlankFilename, "fileName");
            }

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(Strings.ErrorFileNotFound);
            }

            XmlDocument document = new XmlDocument();

            try
            {
                document.Load(fileName);
            }
            catch (Exception ex)
            {
                throw new IOException(Strings.ErrorCouldNotLoadFile, ex);
            }

            XmlElement root = document["Project"];

            if (root == null)
            {
                root = document["ClassProject"];                 // Old file format
                if (root == null)
                {
                    throw new InvalidDataException(Strings.ErrorCorruptSaveFile);
                }
                else
                {
                    Project oldProject = LoadWithPreviousFormat(root);
                    oldProject.FilePath   = fileName;
                    oldProject.name       = Path.GetFileNameWithoutExtension(fileName);
                    oldProject.isUntitled = false;
                    return(oldProject);
                }
            }

            Project project = new Project();

            project.loading = true;
            try
            {
                project.Deserialize(root);
            }
            catch (Exception ex)
            {
                throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex);
            }
            project.loading    = false;
            project.FilePath   = fileName;
            project.isReadOnly = project.projectFile.IsReadOnly;

            return(project);
        }
示例#2
0
文件: Project.cs 项目: koenmd/nERD
        /// <exception cref="IOException">
        /// Could not load the project.
        /// </exception>
        /// <exception cref="InvalidDataException">
        /// The save file is corrupt and could not be loaded.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="fileName"/> is empty string.
        /// </exception>
        public static Project Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(Strings.ErrorBlankFilename, "fileName");
            }

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(Strings.ErrorFileNotFound);
            }

            XmlDocument document = new XmlDocument();

            try
            {
                document.Load(fileName);
            }
            catch (Exception ex)
            {
                throw new IOException(Strings.ErrorCouldNotLoadFile, ex);
            }

            XmlElement root    = document["Project"];
            Project    project = new Project();

            project.Loading = true;
            try
            {
                project.Deserialize(root);
            }
            catch (Exception ex)
            {
                throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex);
            }
            project.Loading    = false;
            project.FilePath   = fileName;
            project.IsReadOnly = project._projectFile.IsReadOnly;

            return(project);
        }
示例#3
0
		/// <exception cref="IOException">
		/// Could not load the project.
		/// </exception>
		/// <exception cref="InvalidDataException">
		/// The save file is corrupt and could not be loaded.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="fileName"/> is empty string.
		/// </exception>
		public static Project Load(string fileName)
		{
			if (string.IsNullOrEmpty(fileName))
				throw new ArgumentException(Strings.ErrorBlankFilename, "fileName");

			if (!File.Exists(fileName))
				throw new FileNotFoundException(Strings.ErrorFileNotFound);

			XmlDocument document = new XmlDocument();
			try
			{
				document.Load(fileName);
			}
			catch (Exception ex)
			{
				throw new IOException(Strings.ErrorCouldNotLoadFile, ex);
			}

			XmlElement root = document["Project"];
			if (root == null)
			{
				root = document["ClassProject"]; // Old file format
				if (root == null)
				{
					throw new InvalidDataException(Strings.ErrorCorruptSaveFile);
				}
				else
				{
					Project oldProject = LoadWithPreviousFormat(root);
					oldProject.FilePath = fileName;
					oldProject.name = Path.GetFileNameWithoutExtension(fileName);
					oldProject.isUntitled = false;
					return oldProject;
				}
			}

			Project project = new Project();
			project.loading = true;
			try
			{
				project.Deserialize(root);
			}
			catch (Exception ex)
			{
				throw new InvalidDataException(Strings.ErrorCorruptSaveFile, ex);
			}
			project.loading = false;
			project.FilePath = fileName;
			project.isReadOnly = project.projectFile.IsReadOnly;

			return project;
		}