public override void SavePackage(InstalledPackage package)
{
var fileName = Path.Combine(dataFolder, Constants.InstalledPackagesXml);
var packages = FillPackages() ?? new List<InstalledPackage>();
int pkgIndex = -1;
for (int index = 0; index < packages.Count; index++)
{
var p = packages[index];
if (p.PackageId == package.PackageId)
{
pkgIndex = index;
break;
}
}
if(pkgIndex >= 0)
packages.RemoveAt(pkgIndex);
packages.Add(package);
using (var writer = new XmlTextWriter(fileName, Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartDocument(true);
writer.WriteStartElement("InstalledPackages");
foreach (var p in packages)
{
writer.WriteStartElement("item");
writer.WriteAttributeString("id", p.PackageId);
writer.WriteAttributeString("version", p.Version);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
}