コード例 #1
0
        /// <summary>
        /// Executes when right clicked to a folder item in the project
        /// </summary>
        /// <param name="sender">Owner of the event</param>
        /// <param name="e">Event arguments</param>
        private void menuCommand_BeforeQueryStatus(object sender, EventArgs e)
        {
            // get the menu that fired the event
            var command = sender as OleMenuCommand;

            // Define handles
            IVsHierarchy hierarchy = null;
            uint         itemId    = VSConstants.VSITEMID_NIL;

            // Get services
            IVsSolution solution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            // Set all visibility to false
            command.Visible = false;
            command.Enabled = false;

            // Get selected hierarchy from solution
            // Check if any hierarchy selected or not
            if ((hierarchy = solution.GetSelectedHierarchy(out itemId)) == null)
            {
                return;
            }

            // Get selected project item
            ProjectItem selectedProjectItem = hierarchy.GetSelectedProjectItem(itemId);

            /*
             * Now we have selected project item
             * So check its name and directory location
             */
            uint   commandId                = (uint)command.CommandID.ID;
            string selectionItemName        = selectedProjectItem.Name;
            string projectPathDirectoryName = Path.GetDirectoryName(selectedProjectItem.ContainingProject.FullName);

            // Get WCF services
            IVsWCFReferenceGroupCollection serviceReferences = this.GetWCFServices(hierarchy);

            if (serviceReferences.Count() > 0)
            {
                if (commandId == PkgCmdIDList.configureServiceProxy)
                {
                    IVsWCFReferenceGroup serviceReferenceItem = serviceReferences.GetReferenceGroupByName(selectionItemName, selectionItemName);

                    if (serviceReferenceItem != null)
                    {
                        command.Enabled = true;
                        command.Visible = true;
                    }
                }
                else if (commandId == PkgCmdIDList.addNewServiceProxy && selectionItemName.Equals(ProxyMgrConstants.PackageFolderName))
                {
                    command.Visible = true;
                    command.Enabled = true;
                }
            }
        }
コード例 #2
0
        private void dialog_OnProxyEntered(object sender, ProxyEntryInformation pInfo)
        {
            // Get active project
            DTE     dte           = (DTE)GetService(typeof(DTE));
            Project activeProject = (dte.ActiveSolutionProjects as Array).GetValue(0) as EnvDTE.Project;

            // Get current solution
            IVsSolution solution = GetService(typeof(IVsSolution)) as IVsSolution;
            // Get WCF Service references
            uint itemId = VSConstants.VSITEMID_NIL;

            IVsWCFReferenceGroupCollection serviceReferences = this.GetWCFServices(solution.GetSelectedHierarchy(out itemId));

            // Create project file variables
            string        languageFileExtension = GetLanguageFileExtension(activeProject);
            string        projectFile           = activeProject.FullName;                                                                                                                                         // C:\MySampleApp\MySampleApp\MySampleApp.csproj
            string        generatedCodeFilePath = string.Format(@"{0}\{1}\{2}\{2}.proxy.{3}", Path.GetDirectoryName(projectFile), ProxyMgrConstants.PackageFolderName, pInfo.ServiceName, languageFileExtension); //C:\MySampleApp\MySampleApp\Service Proxies\Input\
            string        svcmapFilePath        = string.Format(@"{0}\{1}{2}", Path.GetDirectoryName(generatedCodeFilePath), pInfo.ServiceName, ProxyMgrConstants.SvcmapFileExtension);
            List <string> itemsToCheckout       = new List <string>(2);
            FileStream    svcMapStream          = null;

            // Log
            LogWriter.WriteLine(@"****************** PROXY GENERATION STARTED: " + pInfo.ServiceAddress + " ******************");
            LogWriter.WriteLine("[ OK ] State: " + (pInfo.IsAddContext ? "Add" : "Configure"));
            LogWriter.WriteLine("[ OK ] CodeFilePath: " + generatedCodeFilePath);
            LogWriter.WriteLine("[ OK ] MapFilePath : " + svcmapFilePath);

            // if intended service not exists
            if (serviceReferences.GetReferenceGroupByName(pInfo.ServiceName, pInfo.ServiceName) == null)
            {
                if (!Directory.Exists(Path.GetDirectoryName(generatedCodeFilePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(generatedCodeFilePath));
                }

                svcMapStream = File.Create(svcmapFilePath);
                this.CheckOutItems(dte, projectFile);
            }
            else
            {
                if (pInfo.IsAddContext)
                {
                    // Service proxy exists
                    ShowError("[ FAIL ] Intended Service Reference name is exists. Please enter another name for proxy!");
                    return;
                }

                if (!File.Exists(svcmapFilePath))
                {
                    // Something went worng error
                    ShowError("[ FAIL ] Service mapping file is missing. Check path: " + svcmapFilePath);
                    return;
                }

                this.CheckOutItems(dte, svcmapFilePath, generatedCodeFilePath);
                svcMapStream = File.Open(svcmapFilePath, FileMode.Truncate, FileAccess.Write);
            }

            using (svcMapStream)
                svcMapStream.Serialize(pInfo);

            // Generate code
            this.GenerateServiceProxy(activeProject, pInfo);

            if (pInfo.IsAddContext)
            {
                this.ManipulateProjectFile(projectFile, (serviceReferences.Count() > 0), languageFileExtension, pInfo.ServiceName);
            }

            // Save the project!!!
            activeProject.Save();

            // Reload project
            this.Reload(activeProject);
        }