Skip to content

Commit

Permalink
(GH-7) Modifications after review
Browse files Browse the repository at this point in the history
- Use XmlWriter, rather that StreamWriter
- While the file is being created, prevent the Export button from being
pushed again
  • Loading branch information
gep13 committed Mar 24, 2015
1 parent 62f933e commit 82364f1
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace ChocolateyGui.ViewModels.Controls
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Xml;

using ChocolateyGui.Base;
using ChocolateyGui.Models;
using ChocolateyGui.Services;
Expand Down Expand Up @@ -199,6 +201,8 @@ public async void UpdateAll()

public async void ExportAll()
{
this._exportAll = false;

try
{
var fileStream = this._persistenceService.SaveFile("*.config", "Config Files (.config)|*.config");
Expand All @@ -208,24 +212,33 @@ public async void ExportAll()
return;
}

using (StreamWriter sw = new StreamWriter(fileStream, Encoding.ASCII))
XmlWriterSettings settings = new XmlWriterSettings { Indent = true };

using (var xw = XmlWriter.Create(fileStream, settings))
{
sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sw.WriteLine("<packages>");
xw.WriteStartDocument();
xw.WriteStartElement("packages");

foreach (var package in this.Packages)
{
sw.WriteLine("{0}<package id=\"{1}\" version=\"{2}\" />", "\t", package.Id, package.Version);
xw.WriteStartElement("package");
xw.WriteAttributeString("id", package.Id);
xw.WriteAttributeString("version", package.Version.ToString());
xw.WriteEndElement();
}

sw.WriteLine("</packages>");
xw.WriteEndElement();
}
}
catch (Exception ex)
{
this._logService.Fatal("Export all has failed.", ex);
throw;
}
finally
{
this._exportAll = true;
}
}

public async void RefreshPackages()
Expand Down

0 comments on commit 82364f1

Please sign in to comment.