Beispiel #1
0
        private UpgradeResult RunUpgradesAndExecuteAction(string xmlToUpgradeFilePath, Action <XmlFile> documentOperation)
        {
            XmlFile xmlToUpgrade = XmlFile.LoadXml(xmlToUpgradeFilePath);

            if (xmlToUpgrade.Version.Equals(registrations.Max(x => x.Version)))
            {
                return(new UpgradeResult
                {
                    UpgradeNeeded = false
                });
            }

            IEnumerable <Registration> upgradesToApply = registrations
                                                         .OrderBy(x => x.Version)
                                                         .Where(x => x.Version > xmlToUpgrade.Version)
                                                         .ToArray();

            var initialVersion = xmlToUpgrade.Version;

            foreach (var registration in upgradesToApply)
            {
                var upgrader = new OneVersionUpgrader(registration.GetUpgradePlan(), xmlToUpgrade);
                xmlToUpgrade = upgrader.Upgrade();
            }

            if (documentOperation != null)
            {
                documentOperation(xmlToUpgrade); // save or verify
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(new UpgradeResult()
            {
                UpgradeNeeded = true,
                UpgradedFromVersion = initialVersion,
                UpgradedToVersion = xmlToUpgrade.Version
            });
        }
Beispiel #2
0
 public void LoadFile()
 {
     File = XmlFile.LoadXml(FilePath);
 }