Пример #1
0
 public ServiceFacade(VisualStudio visualStudio)
 {
     vsInstance         = visualStudio;
     selectedItem       = vsInstance.SelectedItem;
     currentProject     = vsInstance.SelectedProject;
     outputWindowWriter = new OutputWindowWriter(visualStudio.ApplicationObject);
 }
        public ServiceFacade(VisualStudio visualStudio)
        {
            vsInstance = visualStudio;
            selectedItem = vsInstance.SelectedItem;
            currentProject = vsInstance.SelectedProject;
			outputWindowWriter = new OutputWindowWriter(visualStudio.ApplicationObject);
        }
Пример #3
0
        private string GetOutputDirectory()
        {
            VisualStudioSelectedItem selectedItem = this.VisualStudio.SelectedItem;
            VisualStudioProject      project      = selectedItem.ParentProject;
            string outputDirectory;

            if (project.IsWebProject)
            {
                string serviceName = Path.GetFileNameWithoutExtension(selectedItem.FileName);
                outputDirectory = project.AddCodeFolderToWebProject(serviceName);
            }
            else
            {
                outputDirectory = selectedItem.Directory;
            }

            return(outputDirectory);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private bool ProcessCodeGenerationRequest()
        {
            if (!CanGenerateCode())
            {
                return(false);
            }

            VisualStudioSelectedItem selectedItem = this.VisualStudio.SelectedItem;

            if (selectedItem.IsProject)
            {
                return(ProcessCodeGenerationRequestCore(string.Empty));
            }
            else
            {
                return(ProcessCodeGenerationRequestCore(selectedItem.FileName));
            }
        }
Пример #5
0
        private bool ProcessWsdlWizardRequest(bool roundtrip)
        {
            VisualStudioSelectedItem selectedItem = this.VisualStudio.SelectedItem;

            if (selectedItem == null)
            {
                MessageBox.Show("No selected item.",
                                "Web Services Contract-First WSDL Wizard", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return(true);
            }

            if (!selectedItem.HasProject)
            {
                MessageBox.Show("Cannot create a WSDL contract for items outside of a project.",
                                "Web Services Contract-First WSDL Wizard", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                return(true);
            }

            string currentDir     = selectedItem.Directory;
            string projectRootDir = selectedItem.ParentProject.ProjectDirectory;
            string metdataFile    = selectedItem.FileName;

            WsdlWizardForm wizard = null;

            try
            {
                wizard = roundtrip ? new WsdlWizardForm(metdataFile, true) : new WsdlWizardForm(metdataFile);
                wizard.WsdlLocation          = currentDir;
                wizard.DefaultPathForImports = "";
                wizard.ProjectRootDirectory  = projectRootDir;
                wizard.ShowDialog();

                if (wizard.DialogResult == DialogResult.OK)
                {
                    if (wizard.WsdlLocation.Length > 0)
                    {
                        var wsdlFile = wizard.WsdlLocation;

                        if (!roundtrip)
                        {
                            AddFileToCurrentProject(wsdlFile);
                        }

                        if (wizard.OpenCodeGenDialog)
                        {
                            ProcessCodeGenerationRequest(wsdlFile);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                wizard?.Close();
                return(false);
            }

            return(true);
        }
Пример #6
0
        private bool ProcessCodeGenerationRequestCore(string wsdlFile)
        {
            try
            {
                VisualStudioProject      project      = this.VisualStudio.SelectedProject;
                VisualStudioSelectedItem selectedItem = this.VisualStudio.SelectedItem;

                // Fist display the UI and get the options.
                WebServiceCodeGenDialogNew dialog = new WebServiceCodeGenDialogNew();
                if (!project.IsWebProject)
                {
                    dialog.DestinationNamespace = project.AssemblyNamespace;
                }
                dialog.DestinationFilename = project.GetDefaultDestinationFilename(wsdlFile);

                if (!selectedItem.IsProject)
                {
                    //dialog.WsdlLocation = selectedItem.FileName;
                    dialog.WsdlLocation = wsdlFile;
                }
                if (dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return(false);
                }

                wsdlFile = dialog.WsdlPath;
                // Try the Rpc2DocumentLiteral translation first.
                // wsdlFile = TryTranslateRpc2DocumentLiteral(wsdlFile);

                CodeGenerationOptions options = new CodeGenerationOptions();
                options.MetadataLocation = wsdlFile;
                options.ClrNamespace     = dialog.DestinationNamespace;
                options.OutputFileName   = dialog.DestinationFilename;
                options.OutputLocation   = GetOutputDirectory();
                options.ProjectDirectory = project.ProjectDirectory;
                options.Language         = project.ProjectLanguage;
                options.ProjectName      = project.ProjectName;
                // TODO: Infer the config file type according to the project type
                // and merge the generated config file with the existing one.
                options.ConfigurationFile         = "output.config";
                options.GenerateService           = dialog.ServiceCode;
                options.GenerateProperties        = dialog.GenerateProperties;
                options.VirtualProperties         = dialog.VirtualProperties;
                options.FormatSoapActions         = dialog.FormatSoapActions;
                options.GenerateCollections       = dialog.Collections;
                options.GenerateTypedLists        = dialog.GenericList;
                options.EnableDataBinding         = dialog.EnableDataBinding;
                options.GenerateOrderIdentifiers  = dialog.OrderIdentifiers;
                options.GenerateAsyncCode         = dialog.AsyncMethods;
                options.GenerateSeparateFiles     = dialog.GenerateMultipleFiles;
                options.AdjustCasing              = dialog.ChangeCasing;
                options.OverwriteExistingFiles    = dialog.Overwrite;
                options.EnableWsdlEndpoint        = dialog.EnabledWsdlEndpoint;
                options.GenerateSvcFile           = dialog.GenerateSvcFile;
                options.ConcurrencyMode           = dialog.ConcurrencyMode;
                options.InstanceContextMode       = dialog.InstanceContextMode;
                options.UseSynchronizationContext = dialog.UseSynchronizationContext;
                options.MethodImplementation      = dialog.MethodImplementation;

                OutputWindowWriter.Clear();

                CodeGenerator    codeGenerator = new CodeGenerator();
                CodeWriterOutput output        = codeGenerator.GenerateCode(options);

                AddGeneratedFilesToProject(output);

                // Finally add the project references.
                AddAssemblyReferences();

                // add custom assembly references if necessary
                if (options.EnableWsdlEndpoint)
                {
                    AddMetadataExtensionsReference();
                }

                MessageBox.Show("Code generation successfully completed.", "WSCF.Blue", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (ClientServiceGenerationException ex)
            {
                AppLog.LogMessage(ex.ToString());

                const string separator = "---------------------------------------------------------------------------------";
                foreach (string message in ex.Messages)
                {
                    OutputWindowWriter.WriteMessage(message + "\r\n" + separator + "\r\n");
                }

                MessageBox.Show("Errors were found while importing the contract. Please check the 'WSCF.blue' pane in the Output window for more information.",
                                "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            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);
        }