Writes message to a 'WSCF.blue' pane in the Output window.
Exemple #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);
        }
Exemple #3
0
        public ServiceFacade(DTE2 application)
        {
            VisualStudio = new VisualStudio(application);

            OutputWindowWriter = new OutputWindowWriter(application);

            AppLog.LogMessage($"Created new instance of {nameof(ServiceFacade)}.");
        }
        /// <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.");

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

        	outputWindowWriter = new OutputWindowWriter(applicationObject);

        	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;

            	CommandBar subMenuCommandBar = null;
            	CommandBar webSubMenuCommandBar = null;
            	CommandBar projectSubMenuCommandBar = null;
				CommandBar webProjectSubMenuCommandBar = null;
            	CommandBar toolsSubMenuCommandBar = null;

            	try
            	{
					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 = applicationObject.Events.SelectionEvents;
					selectionEvents.OnChange += OnSelectionChanged;
            	}
            	catch (Exception ex)
            	{
            		AppLog.LogMessage(ex.ToString());
            	}

				// Create the 'Web Services Contract-First...' Tools entry
				try
				{
					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.");
				}
				catch (ArgumentException)
				{
				}
				catch (Exception e)
				{
					AppLog.LogMessage(e.Message);
				}

            	// Create the 'Generate Web Service Code...' context-menu entry
                try
                {
                    // Create the add-in 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.");
                }
                catch (ArgumentException e)
                {
                    AppLog.LogMessage(e.Message);
                }
                catch (Exception ex)
                {
                    AppLog.LogMessage(ex.Message);
                }

                // Create the 'Edit WSDL Interface Description...' context-menu entry
                try
                {
                    // Create the add-in command
                    cmdObj = commands.AddNamedCommand2(
                        addInInstance,
                        "EditWsdlContextMenu",
                        "Edit WSDL Interface Description...",
                        "Executes the command for WsContractFirstAddin ContextMenu",
                        true,
                        190,
                        ref contextGUIDS,
                        (int)vsCommandStatus.vsCommandStatusUnsupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                        (int)vsCommandStyle.vsCommandStylePictAndText,
                        vsCommandControlType.vsCommandControlTypeButton);

					cmdObj.AddControl(subMenuCommandBar, 2);

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

                    AppLog.LogMessage("Edit WSDL menu item is added");
                }
                catch (ArgumentException e)
                {
                    AppLog.LogMessage(e.Message);
                }
                catch (Exception ex)
                {
                    AppLog.LogMessage(ex.Message);
                }

                // Create the 'Create WSDL Interface Description...' context-menu entry
                try
                {
                    // Create the add-in command
                    cmdObj = commands.AddNamedCommand2(
                        addInInstance,
                        "CreateWsdlContextMenu",
                        "Create WSDL Interface Description...",
                        "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("Create WSDL interface desc menu item is added");
                }
                catch (ArgumentException e)
                {
                    AppLog.LogMessage(e.Message);
                }
                catch (Exception ex)
                {
                    AppLog.LogMessage(ex.Message);
                }


                // Create the 'Choose WSDL to implement...' context-menu entry
                try
                {
                    // Create the add-in command
                    cmdObj = commands.AddNamedCommand2(
                        addInInstance,
                        "WsContractFirstContextMenu2",
                        "Choose WSDL to Implement...",
                        "Executes the command for WsContractFirstAddin ContextMenu",
                        true,
                        190,
                        ref contextGUIDS,
                        (int)vsCommandStatus.vsCommandStatusUnsupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                        (int)vsCommandStyle.vsCommandStylePictAndText,
                        vsCommandControlType.vsCommandControlTypeButton);

					cmdObj.AddControl(projectSubMenuCommandBar, 1);

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

                    AppLog.LogMessage("Choose WSDL menu item is added");
                }
                catch (ArgumentException e)
                {
                    AppLog.LogMessage(e.Message);
                }
                catch (Exception ex)
                {
                    AppLog.LogMessage(ex.Message);
                }

				// Create the 'Generate code...' context-menu entry
				try
				{
					// Create the add-in command
					cmdObj = commands.AddNamedCommand2(
						addInInstance,
						"GenerateCodeMenu",
						"Generate Data Contract 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, 2);

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

					AppLog.LogMessage("Generate code menu item is added");
				}
				catch (ArgumentException e)
				{
					AppLog.LogMessage(e.Message);
				}

				// Create the 'Paste XML as Schema' Edit menu entry.
				try
				{
					// Create the add-in 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");
				}
				catch (Exception ex)
				{
					AppLog.LogMessage(ex.Message);
				}
            }

            AppLog.LogMessage("Leaving OnConnection method.");
        }
Exemple #5
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);
        }