public AmlScript(IPackageFile file, IPackage package) { Path = file.Path; var doc = new XDocument(); using (var writer = doc.CreateWriter()) file.WriteAml(package, writer); Script = doc.Root; var item = Script.DescendantsAndSelf("Item").FirstOrDefault(); if (item != null && (item.Parent == null || !item.Parent.Elements("Item").Skip(1).Any())) { Id = (string)item.Attribute("id"); var parts = new[] { ((string)(item.Attribute("id") ?? item.Attribute("where")))?.ToUpperInvariant(), (string)item.Attribute(XmlFlags.Attr_ScriptType), (string)item.Attribute("action") }; if (parts[2] == "add" || parts[2] == "create") { parts[2] = "merge"; } Key = string.Join(".", parts); } }