Deserialize() 개인적인 메소드

/// The save format is corrupt and could not be loaded. ///
private Deserialize ( XmlElement node ) : void
node System.Xml.XmlElement
리턴 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
파일: Project.cs 프로젝트: gbaychev/NClass
		/// <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;
		}