public static void SerialiseToXaml(TextWriter textWriter, SettingsSerialisation serialisation) { //var resourceDictionary = new ResourceDictionary(); //foreach (var pair in serialisation.dictionary) // resourceDictionary.Add(pair.Key, pair.Value); // Writes correctly, but in indeterminate order, annoyingly //var xmlWriter = XmlWriter.Create(textWriter, new XmlWriterSettings //{ // Indent = true //}); //XamlWriter.Save(resourceDictionary, xmlWriter); using (var xmlWriter = XmlWriter.Create(textWriter, new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Auto, Indent = true, IndentChars = "\t", NewLineHandling = NewLineHandling.Entitize })) { xmlWriter.WriteStartElement("wpf", "ResourceDictionary", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); xmlWriter.WriteAttributeString("xml", "space", null, "preserve"); xmlWriter.WriteAttributeString("xmlns", "x", null, "http://schemas.microsoft.com/winfx/2006/xaml"); xmlWriter.WriteAttributeString("xmlns", "s", null, "clr-namespace:System;assembly=mscorlib"); xmlWriter.WriteAttributeString("xmlns", "ss", null, "urn:shemas-jetbrains-com:settings-storage-xaml"); foreach (var entry in serialisation.dictionary.OrderBy(p => p.Key).Where(p => p.Value != null)) { xmlWriter.WriteStartElement("s", entry.Value.GetType().Name, "clr-namespace:System;assembly=mscorlib"); xmlWriter.WriteAttributeString("x", "Key", "http://schemas.microsoft.com/winfx/2006/xaml", entry.Key); xmlWriter.WriteValue(entry.Value); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); } }
private static void DoCompile(CompileOptions compileOptions) { var dictionary = new Dictionary <string, object>(); var serialisation = new SettingsSerialisation(dictionary); var store = new TemplateStore(serialisation); var inputFiles = GetInputFiles(compileOptions.InputFiles); var parser = new TemplateParser(); foreach (var inputFile in inputFiles) { if (inputFile.EndsWith("readme.md", StringComparison.InvariantCultureIgnoreCase)) { Console.WriteLine("Ignoring readme.md..."); continue; } var markdown = File.ReadAllText(inputFile); var template = parser.Parse(markdown); template.InputFile = Path.Combine(Directory.GetCurrentDirectory(), inputFile); store.AddTemplate(template); // TODO: Concatenate markdown to a readme.md } var stream = File.Open(compileOptions.OutputFile, FileMode.Create, FileAccess.Write); using (var streamWriter = new StreamWriter(stream)) SettingsSerialisation.SerialiseToXaml(streamWriter, serialisation); stream = File.Open(compileOptions.ReadMeFile, FileMode.Create, FileAccess.Write); using (var streamWriter = new StreamWriter(stream)) { var readme = new ReadmeFormatter(streamWriter, Path.GetDirectoryName(Path.GetFullPath(compileOptions.ReadMeFile))); readme.FormatTemplates(store); } }
private static void DoDecompile(DecompileOptions decompileOptions) { IList <Template> templates; var stream = File.OpenRead(decompileOptions.InputFile); using (var streamReader = new StreamReader(stream)) { var deserialiser = SettingsSerialisation.DeserialiseFromXaml(streamReader); templates = deserialiser.DeserialiseTemplates(); } foreach (var template in templates) { var name = template.Shortcut ?? template.Description.Replace(' ', '_'); var filename = InvalidFileCharsRegex.Replace(name + ".md", string.Empty); var file = File.Open(Path.Combine(decompileOptions.OutDir, filename), FileMode.Create, FileAccess.Write); using (var writer = new StreamWriter(file)) { var formatter = new TemplateFormatter(writer); formatter.FormatTemplate(template); } } }
public TemplateStore(SettingsSerialisation settingsSerialisation) { liveTemplateSettings = settingsSerialisation.GetSettings("Default", "PatternsAndTemplates", "LiveTemplates"); }