annotate FrmXmlExport.cs @ 243:55c94d438a4b

Re #58: Remove LogNotifier from API * Add logging moved from API
author IBBoard <dev@ibboard.co.uk>
date Sat, 17 Mar 2012 21:03:33 +0000
parents 72beddaffb71
children 4d25c42bbe7b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
1 using System;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
2 using System.Collections.Generic;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
3 using System.ComponentModel;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
4 using System.Data;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
5 using System.Drawing;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
6 using System.Text;
214
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
7 using System.IO;
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
8 using System.Windows.Forms;
215
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 214
diff changeset
9 using System.Xml.Xsl;
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
10 using IBBoard.Lang;
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
11 using IBBoard.WarFoundry.API.Objects;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
12 using IBBoard.WarFoundry.API.Exporters;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
13
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
14 namespace IBBoard.WarFoundry.GUI.WinForms
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
15 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
16 public partial class FrmXmlExport : Form
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
17 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
18 Army myArmy = null;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
19 public FrmXmlExport(Army army)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
20 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
21 InitializeComponent();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
22 myArmy = army;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
23 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
24
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
25 private void FrmXmlExport_Load(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
26 {
214
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
27 tbXslPath.Text = Directory.GetCurrentDirectory() + "\\xsl\\default_html.xsl";
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
28 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
29
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
30 private void bttnOutputSelect_Click(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
31 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
32 SaveFileDialog sfd = new SaveFileDialog();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
33 sfd.Filter = "XML File|*.xml|HTML File|*.html|XHTML File|*.xhtml";
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
34 sfd.Title = "Save XML output";
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
35 sfd.ShowDialog();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
36
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
37 if (sfd.FileName != "")
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
38 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
39 tbOutputFile.Text = sfd.FileName;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
40 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
41 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
42
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
43 private void bttnCancel_Click(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
44 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
45 this.DialogResult = DialogResult.Cancel;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
46 this.Hide();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
47 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
48
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
49 private void bttnExport_Click(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
50 {
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
51 string errorMessage = "";
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
52 // Catch potential errors with the file export or XSL compiliation
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
53 try
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
54 {
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
55 if (cbApplyTransform.Checked)
215
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 214
diff changeset
56 {
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 214
diff changeset
57 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(myArmy, tbOutputFile.Text, tbXslPath.Text);
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 214
diff changeset
58 }
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
59 else
215
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 214
diff changeset
60 {
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
61 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(myArmy, tbOutputFile.Text);
215
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 214
diff changeset
62 }
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
63 }
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
64 catch (XsltCompileException ex)
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
65 {
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
66 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") +
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
67 ":\n" + ex.Message;
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
68 }
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
69 catch (XsltException ex)
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
70 {
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
71
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
72 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") +
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
73 ":\n" + ex.Message;
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
74 }
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
75 catch (FileNotFoundException ex)
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
76 {
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
77 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") +
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
78 ":\n" + ex.Message;
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
79 }
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
80 catch (IOException ex)
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
81 {
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
82 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") +
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
83 ":\n" + ex.Message;
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
84 }
219
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
85 catch (Exception ex)
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
86 {
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
87 errorMessage = Translation.GetTranslation("mbErrorFailed", "") +
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
88 ":\n" + ex.Message;
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
89 }
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
90 if (errorMessage != "")
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
91 {
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
92 MessageBox.Show(errorMessage, "Error During Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
a3e62a2c267f Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents: 215
diff changeset
93 }
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
94 this.DialogResult = DialogResult.OK;
214
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
95 this.Hide();
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
96 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
97
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
98 private void tbOutputFile_Change(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
99 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
100 if (tbOutputFile.Text != "")
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
101 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
102 bttnExport.Enabled = true;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
103 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
104 else
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
105 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
106 bttnExport.Enabled = false;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
107 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
108 }
214
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
109
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
110 private void cbApplyTransform_CheckedChanged(object sender, EventArgs e)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
111 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
112 if (cbApplyTransform.Checked)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
113 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
114 tbXslPath.Enabled = true;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
115 bttnXslSelect.Enabled = true;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
116 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
117 else
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
118 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
119 tbXslPath.Enabled = false;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
120 bttnXslSelect.Enabled = false;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
121 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
122 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
123
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
124 private void bttnXslSelect_Click(object sender, EventArgs e)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
125 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
126 OpenFileDialog ofd = new OpenFileDialog();
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
127
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
128 ofd.InitialDirectory = Directory.GetCurrentDirectory() + "\\xsl";
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
129 ofd.Filter = "XSL Files|*.xsl";
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
130 DialogResult result = ofd.ShowDialog();
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
131
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
132 if (result == DialogResult.OK)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
133 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
134 tbXslPath.Text = ofd.FileName;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
135 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
136
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 213
diff changeset
137 }
213
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
138 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
139 }