2009-12-07 Rolf Bjarne Kvinge <RKvinge@novell.com>
[moon.git] / tools / svg2xaml / svg2xaml.cs
blobf72fd6ecede7ed88c0790a1b0e2c5cdf21396839
1 using System;
2 using System.IO;
3 using System.Xml;
4 using System.Xml.Xsl;
5 using System.Reflection;
8 namespace svg2xaml
10 class MainClass
12 public static void Main(string[] args)
14 if (args.Length == 0)
16 Console.WriteLine ("Usage: svg2xaml input.svg [output.xaml].\n");
17 Console.WriteLine (" If you don't specify an output file, it will be created");
18 Console.WriteLine (" as 'input.svg.xaml' in the location of the svg file.");
19 return;
22 string input = args[0];
23 if (!File.Exists (input))
25 Console.WriteLine ("Error: file {0} does not exist.");
26 Console.WriteLine ("This might work better if you try and convert an svg that actually exists.");
27 return;
30 string output = input + ".xaml";
31 if (args.Length > 1)
32 output = args[1];
34 Console.WriteLine ("Converting file {0} into {1}...", input, output);
36 XmlDocument xsltdoc = new XmlDocument();
37 try
39 Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("svg2xaml.xslt");
40 xsltdoc.Load (s);
42 catch (FileNotFoundException e)
44 Console.WriteLine ("Ooops, can't find the transformation stylesheet. That won't work :p");
45 return;
47 catch (Exception ex)
49 Console.WriteLine (ex.Message);
50 return;
53 try
55 XslTransform t = new XslTransform();
56 t.Load (xsltdoc);
57 t.Transform (input, output);
59 catch (Exception ex)
61 Console.WriteLine ("Houston, we have a problem!");
62 Exception a = ex;
63 Console.WriteLine (a.Message);
64 Console.WriteLine (a.StackTrace);
65 while (a != null)
67 Console.WriteLine (a.Message);
68 a = ex.InnerException;
72 Console.WriteLine ("Conversion done, file {0} created. Have a nice day :)", output);