private string CreateXaml(ResourceNavigationUtil.ResourceNavigationData data) { try { using (var ms = new MemoryStream()) { Lifetimes.Using( lt => { using (var sourceStream = data.ReaderFactory(lt)) sourceStream.CopyTo(ms); }); ms.Position = 0; var bamlTranslator = new BamlTranslator(ms); return(bamlTranslator.ToString()); } } catch (Exception e) { Logger.LogException(string.Format("Error while decoding {0} from {1}", data.Moniker, data.Assembly.FullAssemblyName), e); } return(null); }
private void BrowserTreeView_AfterSelect(object sender, TreeViewEventArgs e) { this.textBox.Text = string.Empty; if (e.Node != null) { MemoryStream stream = e.Node.Tag as MemoryStream; if (stream != null) { stream.Position = 0; try { BamlTranslator translator = new BamlTranslator(stream); this.textBox.Text = translator.ToString(); this.textBox.Select(0, 0); } catch (Exception exception) { MessageBox.Show(null, exception.Message, "BAML Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
void BrowserTreeView_SaveAs(object sender, EventArgs args) { try { BamlNode node = SelectedNode as BamlNode; if (node != null) { // Construct the file name string[] fileNameParts = node.Text.Split('/', '\\'); string fileName = fileNameParts[fileNameParts.Length - 1].ToLower().Replace(".baml", ".xaml"); // Setup and show the Save File Dialog SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "Save As"; dialog.OverwritePrompt = true; dialog.CheckPathExists = true; dialog.Filter = "XAML files (*.xaml)|*.xaml|All files (*.*)|*.*"; dialog.FilterIndex = 0; dialog.AddExtension = true; dialog.FileName = fileName; if (dialog.ShowDialog() == DialogResult.OK) { using (FileStream stream = new FileStream(dialog.FileName, FileMode.Create)) using (StreamWriter writer = new StreamWriter(stream)) { // // NOTE: Should probably refactor this code to re-use // between AfterSelect in TreeView and this // code but for simplicity this is a copy of // some of that code. // (Shawn Wildermuth - 3/24/2007) // MemoryStream memoryStream = node.Tag as MemoryStream; if (memoryStream != null) { memoryStream.Position = 0; BamlTranslator translator = new BamlTranslator(memoryStream); writer.Write(translator.ToString()); } } } } } catch (Exception exception) { MessageBox.Show(null, exception.Message, "BAML Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadXamlSourcesForAssembly(Assembly assembly) { var names = assembly.GetManifestResourceNames(); foreach (var name in names) { if (name.Contains("PresentationFramework")) { continue; } var stream = assembly.GetManifestResourceStream(name); foreach (Resource resource in new ResourceReader(stream)) { if (resource.Name.EndsWith("baml")) { string xaml = new BamlTranslator((Stream)resource.Value).ToString(); string sourceName = resource.Name.Replace(".baml", ""); ParseXamlSource(sourceName, xaml); } } } }