LogMessage() public static method

public static LogMessage ( string message ) : void
message string
return void
Ejemplo n.º 1
0
        /// <summary>
        ///      Implements the QueryStatus method of the IDTCommandTarget interface.
        ///      This is called when the command's availability is updated
        /// </summary>
        /// <param term='commandName'>
        ///		The name of the command to determine state for.
        /// </param>
        /// <param term='neededText'>
        ///		Text that is needed for the command.
        /// </param>
        /// <param term='status'>
        ///		The state of the command in the user interface.
        /// </param>
        /// <param term='commandText'>
        ///		Text requested by the neededText parameter.
        /// </param>
        /// <seealso class='Exec' />
        public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
        {
            AppLog.LogMessage("Entering QueryStatus method.");

            try
            {
                status = vsCommandStatus.vsCommandStatusInvisible;
                if (commandName == MenuBuilder.MenuEditWsdl)
                {
                    status = QueryStatusForEditWsdl();
                }

                if (commandName == MenuBuilder.MenuWscfContextMenu)
                {
                    status = QueryStatusForContextMenu();
                }

                if (commandName == MenuBuilder.MenuCreateWsdl)
                {
                    status = QueryStatusForCreateWsdl();
                }

                if (commandName == MenuBuilder.MenuGenerateDataContracts)
                {
                    status = QueryStatusForGenDC();
                }

                if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
                {
                    if (commandName == MenuBuilder.MenuWscfContextMenu2)
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusEnabled |
                                 vsCommandStatus.vsCommandStatusSupported;
                        AppLog.LogMessage("WSCF menu 2 command is enabled");
                    }
                    if (commandName == MenuBuilder.MenuWscf)
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported |
                                 vsCommandStatus.vsCommandStatusEnabled;
                        AppLog.LogMessage("Contract first command is enabled");
                    }
                    if (commandName == MenuBuilder.MenuPasteXmlAsSchema)
                    {
                        status = vsCommandStatus.vsCommandStatusSupported;
                        if (visualStudio.SelectedProject != null)
                        {
                            status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                            AppLog.LogMessage("Paste Schema command is enabled");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AppLog.LogMessage(ex.Message);
                throw;
            }

            AppLog.LogMessage("Leaving QueryStatus method.");
        }
Ejemplo n.º 2
0
        public bool ExecuteCommand(WscfCommand command)
        {
            try
            {
                AppLog.LogMessage($"Entering {nameof(this.ExecuteCommand)} method.");

                switch (command)
                {
                case WscfCommand.CreateWsdl:
                    return(ProcessWsdlWizardRequest(false));

                case WscfCommand.EditWsdl:
                    return(ProcessWsdlWizardRequest(true));

                case WscfCommand.GenerateDataContractCode:
                    return(ProcessXsdCodeGenerationRequest());

                case WscfCommand.GenerateWebServiceCode:
                    return(ProcessCodeGenerationRequest());

                case WscfCommand.PasteXmlAsSchema:
                    return(ProcessPasteSchemaRequest());

                default:
                    return(false);
                }
            }
            finally
            {
                AppLog.LogMessage($"Leaving {nameof(this.ExecuteCommand)} method.");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 ///		Implements the constructor for the Add-in object.
 ///		Place your initialization code within this method.
 /// </summary>
 public Connect()
 {
     if (fileCounters == null)
     {
         fileCounters = new Hashtable();
     }
     AppLog.LogMessage("A new instance of WSCF Connect class is created.");
 }
Ejemplo n.º 4
0
        public ServiceFacade(DTE2 application)
        {
            VisualStudio = new VisualStudio(application);

            OutputWindowWriter = new OutputWindowWriter(application);

            AppLog.LogMessage($"Created new instance of {nameof(ServiceFacade)}.");
        }
Ejemplo n.º 5
0
        /// <summary>
        ///      Implements the OnConnection method of the IDTExtensibility2 interface.
        ///      Receives notification that the Add-in is being loaded.
        /// </summary>
        /// <param term='application'>
        ///      Root object of the host application.
        /// </param>
        /// <param term='connectMode'>
        ///      Describes how the Add-in is being loaded.
        /// </param>
        /// <param term='addInInst'>
        ///      Object representing this Add-in.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            AppLog.LogMessage("Entering OnConnection method.");

            this.applicationObject = (DTE2)application;
            // Initialize VsHelper.
            this.visualStudio = new VisualStudio(this.applicationObject);

            this.addInInstance = (AddIn)addInInst;
            object[] contextGUIDS = new object[] { };
            //CommandBar cmdBar;
            //Command cmdObj;

            if (connectMode == ext_ConnectMode.ext_cm_Startup ||
                connectMode == ext_ConnectMode.ext_cm_AfterStartup ||
                connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                AppLog.LogMessage("Creating commands.");

                Commands2   commands    = (Commands2)applicationObject.Commands;
                CommandBars commandBars = (CommandBars)applicationObject.CommandBars;

                try
                {
                    menuBuilder = new MenuBuilder(visualStudio);

                    // Add command bar to tools menu
                    contextGUIDS = menuBuilder.AddCommandBarToToolsMenu(addInInstance, applicationObject, commands, contextGUIDS, commandBars);
                    // Create the 'Generate Web Service Code...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForWSCodeGen(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Edit WSDL Interface Description...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForEditWsdl(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Create WSDL Interface Description...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForCreateWsdl(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Choose WSDL to implement...' context-menu entry
                    contextGUIDS = menuBuilder.GenerateMenuItemForChooseWsdlToImplement(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Generate code...' context-menu entry
                    //GenerateMenuItemForDCCodeGen(commands, contextGUIDS);
                    contextGUIDS = menuBuilder.GenerateMenuItemForDCCodeGen(addInInstance, applicationObject, commands, contextGUIDS);
                    // Create the 'Paste XML as Schema' Edit menu entry.
                    menuBuilder.GenerateMenuItemForPasteXmlAsSchema(addInInstance, applicationObject, commands, commandBars, contextGUIDS);
                }
                catch (ArgumentException e)
                {
                    AppLog.LogMessage(e.Message);
                }
                catch (Exception e)
                {
                    AppLog.LogMessage(e.Message);
                }
            }

            AppLog.LogMessage("Leaving OnConnection method.");
        }
Ejemplo n.º 6
0
        /// <summary>
        ///      Implements the Exec method of the IDTCommandTarget interface.
        ///      This is called when the command is invoked.
        /// </summary>
        /// <param term='commandName'>
        ///		The name of the command to execute.
        /// </param>
        /// <param term='executeOption'>
        ///		Describes how the command should be run.
        /// </param>
        /// <param term='varIn'>
        ///		Parameters passed from the caller to the command handler.
        /// </param>
        /// <param term='varOut'>
        ///		Parameters passed from the command handler to the caller.
        /// </param>
        /// <param term='handled'>
        ///		Informs the caller if the command was handled or not.
        /// </param>
        /// <seealso class='Exec' />
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            AppLog.LogMessage("Entering Exec method.");
            ServiceFacade facade = new ServiceFacade(this.visualStudio);

            handled = facade.ProcessServiceRequest(commandName);

            AppLog.LogMessage("Leaving Exec method");

            return;
        }
Ejemplo n.º 7
0
        public object[] AddCommandBarToToolsMenu(AddIn addInInstance, DTE2 applicationObject, Commands2 commands, object[] contextGUIDS, CommandBars commandBars)
        {
            Command command = commands.AddNamedCommand2(
                addInInstance,
                "WsContractFirst",
                "Web Services Contract-First...",
                "Executes the command for WsContractFirstAddin",
                true,
                190,
                ref contextGUIDS,
                (int)vsCommandStatus.vsCommandStatusUnsupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                (int)vsCommandStyle.vsCommandStylePictAndText,
                vsCommandControlType.vsCommandControlTypeButton);

            command.AddControl(toolsSubMenuCommandBar, 1);

            AppLog.LogMessage("Command bar is added to the Tools menu.");
            return(contextGUIDS);
        }
Ejemplo n.º 8
0
        private vsCommandStatus QueryStatusForEditWsdl()
        {
            vsCommandStatus status      = vsCommandStatus.vsCommandStatusInvisible;
            UIHierarchy     uiHierarchy = (UIHierarchy)applicationObject.Windows.Item(
                DteConstants.vsWindowKindSolutionExplorer).Object;

            foreach (UIHierarchyItem item in (Array)uiHierarchy.SelectedItems)
            {
                string itemName = item.Name;

                if (itemName.IndexOf(".wsdl") > -1)
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusEnabled |
                             vsCommandStatus.vsCommandStatusSupported;
                    AppLog.LogMessage("Edit WSDL command is enabled.");
                    break;
                }
            }
            return(status);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Implements the OnDisconnection method of the IDTExtensibility2 interface.
        ///     Receives notification that the Add-in is being unloaded.
        /// </summary>
        /// <param term='disconnectMode'>
        ///      Describes how the Add-in is being unloaded.
        /// </param>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
        {
            AppLog.LogMessage("Entering OnDisconnection method.");

            try
            {
                if (disconnectMode == ext_DisconnectMode.ext_dm_HostShutdown |
                    disconnectMode == ext_DisconnectMode.ext_dm_UserClosed)
                {
                    menuBuilder.CleanUp();
                }
            }
            catch (Exception ex)
            {
                AppLog.LogMessage(ex.Message);
                throw;
            }

            AppLog.LogMessage("Leaving OnDisconnection method.");
        }
Ejemplo n.º 10
0
        public MenuBuilder(VisualStudio visualStudio)
        {
            this.visualStudio = visualStudio;

            try
            {
                CommandBars commandBars          = (CommandBars)visualStudio.ApplicationObject.CommandBars;
                CommandBar  itemCommandBar       = commandBars["Item"];
                CommandBar  webItemCommandBar    = commandBars["Web Item"];
                CommandBar  projectCommandBar    = commandBars["Project"];
                CommandBar  webProjectCommandBar = commandBars["Web Project Folder"];
                CommandBar  toolsCommandBar      = commandBars["Tools"];

                subMenuPopup         = (CommandBarPopup)itemCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true);
                subMenuPopup.Caption = "WSCF.blue";
                subMenuCommandBar    = subMenuPopup.CommandBar;

                webSubMenuPopup         = (CommandBarPopup)webItemCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true);
                webSubMenuPopup.Caption = "WSCF.blue";
                webSubMenuCommandBar    = webSubMenuPopup.CommandBar;

                projectSubMenuPopup         = (CommandBarPopup)projectCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true);
                projectSubMenuPopup.Caption = "WSCF.blue";
                projectSubMenuCommandBar    = projectSubMenuPopup.CommandBar;

                webProjectSubMenuPopup         = (CommandBarPopup)webProjectCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true);
                webProjectSubMenuPopup.Caption = "WSCF.blue";
                webProjectSubMenuCommandBar    = webProjectSubMenuPopup.CommandBar;

                toolsSubMenuPopup         = (CommandBarPopup)toolsCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true);
                toolsSubMenuPopup.Caption = "WSCF.blue";
                toolsSubMenuCommandBar    = toolsSubMenuPopup.CommandBar;

                selectionEvents           = visualStudio.ApplicationObject.Events.SelectionEvents;
                selectionEvents.OnChange += OnSelectionChanged;
            }
            catch (Exception ex)
            {
                AppLog.LogMessage(ex.ToString());
            }
        }
Ejemplo n.º 11
0
        public object[] GenerateMenuItemForWSCodeGen(AddIn addInInstance, DTE2 applicationObject, Commands2 commands, object[] contextGUIDS)
        {
            Command cmdObj = commands.AddNamedCommand2(
                addInInstance,
                "WsContractFirstContextMenu",
                "Generate Web Service Code...",
                "Executes the command for WsContractFirstAddin ContextMenu",
                true,
                190,
                ref contextGUIDS,
                (int)vsCommandStatus.vsCommandStatusUnsupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                (int)vsCommandStyle.vsCommandStylePictAndText,
                vsCommandControlType.vsCommandControlTypeButton);

            cmdObj.AddControl(subMenuCommandBar, 1);

            // BDS 11/21/2005: Add this menu item to the web project
            // template.
            cmdObj.AddControl(webSubMenuCommandBar, 1);

            AppLog.LogMessage("Generate Web Serive Code menu item is added.");
            return(contextGUIDS);
        }
Ejemplo n.º 12
0
        public void GenerateMenuItemForPasteXmlAsSchema(AddIn addInInstance, DTE2 applicationObject, Commands2 commands, CommandBars commandBars, object[] contextGUIDS)
        {
            Command cmdObj = commands.AddNamedCommand2(
                addInInstance,
                "PasteSchemaMenu",
                "Paste XML as Schema",
                "Pastes the XML on the clipboard as XSD schema.",
                true,
                239,
                ref contextGUIDS,
                (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                (int)vsCommandStyle.vsCommandStylePictAndText,
                vsCommandControlType.vsCommandControlTypeButton);

            CommandBar menuBarCommandBar = commandBars["MenuBar"];

            CommandBarControl editControl  = menuBarCommandBar.Controls["Edit"];
            CommandBarPopup   editPopup    = (CommandBarPopup)editControl;
            CommandBarControl pasteControl = editPopup.CommandBar.Controls["Paste"];

            cmdObj.AddControl(editPopup.CommandBar, pasteControl != null ? pasteControl.Index + 1 : 1);

            AppLog.LogMessage("Paste Schema code menu item is added");
        }
Ejemplo n.º 13
0
        private bool ProcessPasteSchemaRequest()
        {
            try
            {
                if (currentProject == null)
                {
                    MessageBox.Show(
                        "You cannot paste schema items outside of a project.",
                        "Web Services Contract-First Paste Schema",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    return(true);
                }

                IDataObject dataObject = Clipboard.GetDataObject();
                if (dataObject == null)
                {
                    MessageBox.Show(
                        "There was no data found in the clipboard.",
                        "Web Services Contract-First Paste Schema",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    return(true);
                }

                string xml = (string)dataObject.GetData(typeof(string));
                if (xml == null)
                {
                    MessageBox.Show(
                        "There was no string data found in the clipboard.",
                        "Web Services Contract-First Paste Schema",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    return(true);
                }

                XElement schemaXml;
                try
                {
                    schemaXml = XElement.Parse(xml);
                }
                catch (Exception)
                {
                    MessageBox.Show(
                        "The data found in the clipboard is not valid XML.",
                        "Web Services Contract-First Paste Schema",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);

                    return(true);
                }

                XmlSchemaSet       schemas   = new XmlSchemaSet();
                XmlSchemaInference inference = new XmlSchemaInference();

                using (XmlReader reader = schemaXml.CreateReader())
                {
                    inference.InferSchema(reader, schemas);
                }

                XmlWriterSettings settings = new XmlWriterSettings {
                    Indent = true
                };

                foreach (XmlSchema schema in schemas.Schemas())
                {
                    if (schema.Items.Count == 0)
                    {
                        continue;
                    }

                    string schemaName = ((XmlSchemaElement)(schema.Items[0])).Name;
                    string fileName   = Path.Combine(selectedItem.Directory, Path.ChangeExtension(schemaName, "xsd"));

                    if (File.Exists(fileName))
                    {
                        DialogResult dialogResult = MessageBox.Show(
                            "A file named '" + Path.GetFileName(fileName) + "' already exist in the project. Do you want to overwrite this file?",
                            "Web Services Contract-First Paste Schema",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question);

                        if (dialogResult == DialogResult.No)
                        {
                            continue;
                        }
                    }

                    using (XmlWriter writer = XmlWriter.Create(fileName, settings))
                    {
                        if (writer != null)
                        {
                            schema.Write(writer);
                        }
                    }
                    if (File.Exists(fileName))
                    {
                        currentProject.AddFile(fileName);
                    }
                }
            }
            catch (Exception ex)
            {
                AppLog.LogMessage(ex.ToString());
                MessageBox.Show(ex.ToString(), "Web Services Contract-First Paste Schema", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This overloaded method handles the generation of client or server code
        /// for a supplied WSDL file
        /// </summary>
        /// <param name="wsdlFile"></param>
        /// <returns></returns>
        private bool ProcessStubGenerationRequest(string wsdlFile)
        {
            try
            {
                // Fist display the UI and get the options.
                WebServiceCodeGenDialogNew dialog = new WebServiceCodeGenDialogNew();
                if (!currentProject.IsWebProject)
                {
                    dialog.DestinationNamespace = currentProject.AssemblyNamespace;
                }
                dialog.DestinationFilename = GetDefaultDestinationFilename(wsdlFile);

                if (!selectedItem.IsProject)
                {
                    //dialog.WsdlLocation = selectedItem.FileName;
                    dialog.WsdlLocation = wsdlFile;
                }

                //if we havent passed the wsdl file in, there is still
                // the option for the user to use the BROWSE button and pick
                // the wsdl.

                if (dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return(false);
                }


                //Get the options set in the dialog and add other things
                // that are specific to VS
                CodeGenerationOptions options = dialog.Options;

                options.Language         = currentProject.ProjectLanguage;
                options.ProjectDirectory = currentProject.ProjectDirectory;
                options.OutputLocation   = GetOutputDirectory();
                // 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";

                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(false);
            }
            return(true);
        }
Ejemplo n.º 15
0
        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.
Ejemplo n.º 16
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);
        }