private bool ProcessXsdCodeGenerationRequest() { try { VisualStudioProject project = currentProject; IEnumerable <VisualStudioSelectedItem> selectedItems = vsInstance.SelectedItems; if (selectedItems.Count() == 0) { MessageBox.Show( "Cannot generate code for items outside of a project.", "Web Services Contract-First code generation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(true); } foreach (VisualStudioSelectedItem selectedItem in selectedItems) { string extension = Path.GetExtension(selectedItem.FileName).ToLower(); if (extension == ".xsd" || extension == ".wsdl") { continue; } MessageBox.Show( "Data Contracts can only be generated for .xsd or .wsdl files.", "Web Services Contract-First code generation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(true); } string[] dataContractFiles = selectedItems.Select(i => i.FileName).ToArray(); XsdCodeGenDialog dialogForm = new XsdCodeGenDialog(dataContractFiles); if (!project.IsWebProject) { dialogForm.Namespace = project.AssemblyNamespace; } dialogForm.TargetFileName = project.GetDefaultDestinationFilename(dataContractFiles[0]); if (dialogForm.ShowDialog() == DialogResult.Cancel) { return(false); } CodeGenerationOptions options = new CodeGenerationOptions(); options.GenerateDataContracts = true; options.DataContractFiles = dataContractFiles; options.GenerateProperties = dialogForm.PublicProperties; options.GenerateCollections = dialogForm.Collections; options.GenerateSeparateFiles = dialogForm.GenerateMultipleFiles; options.OverwriteExistingFiles = dialogForm.OverwriteFiles; options.AdjustCasing = dialogForm.AdjustCasing; options.EnableDataBinding = dialogForm.DataBinding; options.GenerateOrderIdentifiers = dialogForm.OrderIdentifiers; options.GenerateTypedLists = dialogForm.GenericLists; options.ClrNamespace = dialogForm.Namespace; options.OutputFileName = dialogForm.TargetFileName; options.OutputLocation = GetOutputDirectory(); options.ProjectDirectory = project.ProjectDirectory; options.Language = project.ProjectLanguage; CodeGenerator codeGenerator = new CodeGenerator(); CodeWriterOutput output = codeGenerator.GenerateCode(options); AddGeneratedFilesToProject(output); // Finally add the project references. AddAssemblyReferences(); MessageBox.Show("Code generation successfully completed.", "WSCF.Blue", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { AppLog.LogMessage(ex.ToString()); MessageBox.Show(ex.ToString(), "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error); // TODO: Log the exception. //System.Diagnostics.Debugger.Break(); } return(true); } // End of ProcessXsdCodeGenerationRequestFunction.
} // End of ProcessCodeGenerationRequestFunction. // This method is not current being used. private bool ProcessXsdCodeGenerationRequest() { if (!CanGenerateCode()) { return false; } try { VisualStudioProject project = visualStudio.SelectedProject; IEnumerable<VisualStudioSelectedItem> selectedItems = visualStudio.SelectedItems; if (selectedItems.Count() == 0) { MessageBox.Show( "Cannot generate code for items outside of a project.", "Web Services Contract-First code generation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return true; } foreach (VisualStudioSelectedItem selectedItem in selectedItems) { string extension = Path.GetExtension(selectedItem.FileName).ToLower(); if (extension == ".xsd" || extension == ".wsdl") continue; MessageBox.Show( "Data Contracts can only be generated for .xsd or .wsdl files.", "Web Services Contract-First code generation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return true; } string[] dataContractFiles = selectedItems.Select(i => i.FileName).ToArray(); XsdCodeGenDialog dialogForm = new XsdCodeGenDialog(dataContractFiles); if (!project.IsWebProject) { dialogForm.Namespace = project.AssemblyNamespace; } dialogForm.TargetFileName = project.GetDefaultDestinationFilename(dataContractFiles[0]); if (dialogForm.ShowDialog() == DialogResult.Cancel) { return false; } CodeGenerationOptions options = new CodeGenerationOptions(); options.GenerateDataContracts = true; options.DataContractFiles = dataContractFiles; options.GenerateProperties = dialogForm.PublicProperties; options.GenerateCollections = dialogForm.Collections; options.GenerateSeparateFiles = dialogForm.GenerateMultipleFiles; options.OverwriteExistingFiles = dialogForm.OverwriteFiles; options.AdjustCasing = dialogForm.AdjustCasing; options.EnableDataBinding = dialogForm.DataBinding; options.GenerateOrderIdentifiers = dialogForm.OrderIdentifiers; options.GenerateTypedLists = dialogForm.GenericLists; options.ClrNamespace = dialogForm.Namespace; options.OutputFileName = dialogForm.TargetFileName; options.OutputLocation = GetOutputDirectory(); options.ProjectDirectory = project.ProjectDirectory; options.Language = project.ProjectLanguage; CodeGenerator codeGenerator = new CodeGenerator(); CodeWriterOutput output = codeGenerator.GenerateCode(options); AddGeneratedFilesToProject(output); // Finally add the project references. AddAssemblyReferences(); MessageBox.Show("Code generation successfully completed.", "WSCF.Blue", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { AppLog.LogMessage(ex.ToString()); MessageBox.Show(ex.ToString(), "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error); // TODO: Log the exception. //System.Diagnostics.Debugger.Break(); } return true; } // End of ProcessXsdCodeGenerationRequestFunction.