private void CreateSvgThumbnail(Stream sourceStream, Stream destinationStream, Size size)
{
sourceStream.Seek(0, SeekOrigin.Begin);
var xDocument = XDocument.Load(sourceStream);
var root = xDocument.Root;
if (root == null || root.Name.LocalName != "svg")
{
const string message = "An error has occured while trying to read the file";
throw new ValidationException(() => message, message);
}
var attributes = root.Attributes().ToList();
var widthAttribute = attributes.FirstOrDefault(x => x.Name == "width");
if (widthAttribute == null)
{
widthAttribute = new XAttribute("width", size.Width.ToString());
attributes.Add(widthAttribute);
}
else
{
widthAttribute.Value = size.Width.ToString();
}
var heightAttribute = attributes.FirstOrDefault(x => x.Name == "height");
if (heightAttribute == null)
{
heightAttribute = new XAttribute("height", size.Height.ToString());
attributes.Add(heightAttribute);
}
else
{
heightAttribute.Value = size.Height.ToString();
}
root.ReplaceAttributes(attributes);
xDocument.Save(destinationStream);
}