using System; using System.Windows.Forms; using Xsd2Code.Library; using System.Diagnostics; namespace Xsd2Code.Addin { public partial class FormOption : Form { #region Property : GeneratorParams private GeneratorParams generatorParams; public GeneratorParams GeneratorParams { get { return this.generatorParams; } set { this.generatorParams = value; } } #endregion #region Property public string InputFile { get; set; } public string OutputFile { get; set; } #endregion #region cTor /// /// Constructor /// public FormOption() { this.InitializeComponent(); } #endregion #region Method /// /// Analyse file to find generation option. /// /// The XSD file path. /// The language identifier. /// The default namespace. public void Init(string xsdFilePath, string languageIdentifier, string defaultNamespace, TargetFramework framework) { string outputFile; this.generatorParams = GeneratorParams.LoadFromFile(xsdFilePath, out outputFile); if (this.generatorParams == null) { this.generatorParams = new GeneratorParams(); switch (languageIdentifier) { case "{B5E9BD33-6D3E-4B5D-925E-8A43B79820B4}": this.generatorParams.Language = GenerationLanguage.VisualBasic; break; case "{B5E9BD36-6D3E-4B5D-925E-8A43B79820B4}": this.generatorParams.Language = GenerationLanguage.VisualCpp; break; default: this.generatorParams.Language = GenerationLanguage.CSharp; break; } this.generatorParams.TargetFramework = framework; this.generatorParams.NameSpace = defaultNamespace; } this.propertyGrid.SelectedObject = this.generatorParams; this.OutputFile = outputFile; } /// /// Cancel the validation /// /// /// private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } /// /// Validate the generation /// /// /// private void btnGenerate_Click(object sender, EventArgs e) { var result = this.generatorParams.Validate(); if(!result.Success) { MessageBox.Show(result.Messages.ToString()); return; } this.DialogResult = DialogResult.OK; this.Close(); } #endregion /// /// Close form if press esc. /// /// Object sender /// EventArgs param private void FormOption_KeyPress(object sender, KeyPressEventArgs e) { int ascii = Convert.ToInt16(e.KeyChar); if (ascii == 27) this.Close(); } private void linkToCodePlex_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start(new ProcessStartInfo(linkToCodePlex.Text)); } } }