コード例 #1
0
        public Project Load(string filePath)
        {
            var basicProject = XmlSerializationHelper.LoadFromFile <BasicProject>(filePath);

            var projectSchemaVersion = string.IsNullOrEmpty(basicProject.SchemaVersion) ? new Version("0.0.0.0") : new Version(basicProject.SchemaVersion);

            if (projectSchemaVersion > schemaVersion)
            {
                throw new InvalidOperationException("This project has a newer schema version than is currently supported.");
            }

            var project = XmlSerializationHelper.LoadFromFile <Project>(filePath);

            if (projectSchemaVersion < schemaVersion)
            {
                var upgradeTasks = CreateUpgradeTasks();

                foreach (var projectUpgradeTask in upgradeTasks)
                {
                    if (projectUpgradeTask.SchemaVersion < projectSchemaVersion)
                    {
                        continue;
                    }

                    project = projectUpgradeTask.Upgrade(project);
                }

                project.SchemaVersion  = schemaVersion.ToString();
                project.ProgramVersion = GetProgramVersion().ToString();
            }

            return(project);
        }