/// <exception cref="InvalidOperationException">Handler is already enabled.</exception> public static IDisposable Enable(UpgradeHint hint) { if (isEnabled) { throw new InvalidOperationException(); } isEnabled = true; columnHint = hint; return(new Disposable(_ => { isEnabled = false; columnHint = null; })); }
private void LoadLibraryMigrations(string library) { string fullLibraryName = library; if (!pathManager.ResolveLibraryPath(ref fullLibraryName)) { return; } string migrationsXMLFile = Path.Combine(Path.GetDirectoryName(fullLibraryName), Path.GetFileNameWithoutExtension(fullLibraryName) + ".Migrations.xml"); if (!File.Exists(migrationsXMLFile)) { return; } var foundPriorNameHints = new Dictionary <string, UpgradeHint>(); try { using (var reader = XmlReader.Create(migrationsXMLFile)) { var doc = new XmlDocument(); doc.Load(reader); XmlElement migrationsElement = doc.DocumentElement; var names = new List <string>(); foreach (XmlNode subNode in migrationsElement.ChildNodes) { if (subNode.Name != "priorNameHint") { throw new Exception("Invalid XML"); } names.Add(subNode.Name); var upgradeHint = new UpgradeHint(); string oldName = null; foreach (XmlNode hintSubNode in subNode.ChildNodes) { names.Add(hintSubNode.Name); switch (hintSubNode.Name) { case "oldName": oldName = hintSubNode.InnerText; break; case "newName": upgradeHint.UpgradeName = hintSubNode.InnerText; break; case "additionalAttributes": foreach (XmlNode attributesSubNode in hintSubNode.ChildNodes) { string attributeName = null; string attributeValue = null; switch (attributesSubNode.Name) { case "attribute": foreach (XmlNode attributeSubNode in attributesSubNode.ChildNodes) { switch (attributeSubNode.Name) { case "name": attributeName = attributeSubNode.InnerText; break; case "value": attributeValue = attributeSubNode.InnerText; break; } } break; } upgradeHint.AdditionalAttributes[attributeName] = attributeValue; } break; case "additionalElements": foreach (XmlNode elementsSubnode in hintSubNode.ChildNodes) { XmlElement elem = elementsSubnode as XmlElement; if (elem != null) { upgradeHint.AdditionalElements.Add(elem); } } break; } } foundPriorNameHints[oldName] = upgradeHint; } } } catch (Exception exception) { return; // if the XML file is badly formatted, return like it doesn't exist } // if everything parsed correctly, then add these names to the priorNameHints foreach (string key in foundPriorNameHints.Keys) { priorNameHints[key] = foundPriorNameHints[key]; } }
private static InvalidOperationException HintConflict(UpgradeHint hintOne, UpgradeHint hintTwo) { return(new InvalidOperationException(string.Format(Strings.ExHintXIsConflictingWithHintY, hintOne, hintTwo))); }
///GENMHASH:D5C9144F34CDE74E76FA4B029FD4C6BF:C0C35E00AF4E17F141675A2C05C7067B internal UpgradeHintImpl(UpgradeHint innerObject) : base(innerObject) { }