Skip to content

Commit

Permalink
Update SvgToPngConverter.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Nov 11, 2019
1 parent 7f3cfc0 commit 66ddfcf
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions tests/SvgToPng/SvgToPngConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,34 +183,38 @@ public static async Task Convert(List<string> inputFiles, IList<Item> items, str
foreach (var inputFile in inputFiles)
{
string inputName = Path.GetFileNameWithoutExtension(inputFile);
string svg = string.Empty;
string extension = System.IO.Path.GetExtension(inputFile);

await Task.Factory.StartNew(async () =>
string svg = await Task.Factory.StartNew<string>(() =>
{
switch (extension.ToLower())
try
{
default:
case ".svg":
{
#if NET461
svg = File.ReadAllText(inputFile);
#else
svg = await File.ReadAllTextAsync(inputFile);
#endif
}
break;
case ".svgz":
{
using (var fileStream = File.OpenRead(inputFile))
using (var gzipStream = new GZipStream(fileStream, System.IO.Compression.CompressionMode.Decompress))
using (var sr = new StreamReader(gzipStream))
string extension = Path.GetExtension(inputFile);
switch (extension.ToLower())
{
default:
case ".svg":
{
svg = sr.ReadToEnd();
return File.ReadAllText(inputFile);
}
}
break;
case ".svgz":
{
using (var fileStream = File.OpenRead(inputFile))
using (var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress))
using (var sr = new StreamReader(gzipStream))
{
return sr.ReadToEnd();
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to read svg file: {inputFile}");
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
return string.Empty;
});

var item = new Item()
Expand All @@ -221,7 +225,7 @@ await Task.Factory.StartNew(async () =>
};
items.Add(item);
}

// Svg.Skia
#if true
await convertProgress.ConvertStatus("Converting svg using Svg.Skia...");
Expand All @@ -242,6 +246,7 @@ await Task.Factory.StartNew(() =>
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to load svg file: {item.Path}");
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
Expand Down Expand Up @@ -272,6 +277,7 @@ await Task.Factory.StartNew(() =>
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to load reference image: {referenceImagePath}");
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
Expand Down Expand Up @@ -306,6 +312,7 @@ await Task.Factory.StartNew(() =>
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to capture: {item.Path}");
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
Expand Down

0 comments on commit 66ddfcf

Please sign in to comment.