예제 #1
0
        private bool GenerateServiceProxy(Project activeProject, ProxyEntryInformation pInfo)
        {
            string languageFileExtension = this.GetLanguageFileExtension(activeProject);
            string frameworkPath         = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
            string reusableLibraries     = string.Join(" ", ProxyMgrConstants.ReusableLibraries.Select(r => string.Concat("/r:", frameworkPath + r)));
            string generatedCodeFilePath = string.Format(@"{0}\{1}\{2}\{2}.proxy.{3}", Path.GetDirectoryName(activeProject.FullName), ProxyMgrConstants.PackageFolderName, pInfo.ServiceName, languageFileExtension); //C:\MySampleApp\MySampleApp\Service Proxies\Input\
            string arguments             = string.Format(ProxyMgrConstants.SvcutilCommandArgumentTemplate, (pInfo.GenerateClient ? "" : "/serviceContract "), generatedCodeFilePath, pInfo.ServiceAddress, reusableLibraries, activeProject.Name, pInfo.ServiceName);
            string executionWarning      = null;
            bool   operationIsSuccess    = false;

            // Execute external process
            if (this.ExecuteProcessWithArguments(ProxyMgrConstants.SvcUtilPath, arguments, out executionWarning))
            {
                operationIsSuccess = true;
                // Add as warning
                if (!string.IsNullOrWhiteSpace(executionWarning))
                {
                    new ErrorListProvider(this).Tasks.Add(new ErrorTask
                    {
                        Category      = TaskCategory.User,
                        ErrorCategory = TaskErrorCategory.Warning,
                        Text          = executionWarning
                    });
                }

                // Get newly added project file
                // When ProcjectItems.AddFromFile method called it adds Compile tag in project file
                // We need this because we are going to look up to interface is created or not!
                ProjectItem generatedCodeProjectItem = activeProject.ProjectItems.AddFromFile(generatedCodeFilePath);
            }

            return(operationIsSuccess);
        }
예제 #2
0
        private void AcquireServiceProxy(ProxyEntryInformation dataContext)
        {
            System.Threading.Thread.Sleep(10);

            Dispatcher.Invoke(() =>
            {
                System.Windows.Input.Cursor currentCursor = Cursor;

                try
                {
                    Cursor = System.Windows.Input.Cursors.Wait;
                    OnProxyEntered(this, dataContext);

                    container.IsEnabled = true;
                    Cursor = currentCursor;
                    this.Close();
                }
                catch (Exception ex)
                {
                    container.IsEnabled = true;
                    Cursor = currentCursor;
                    MessageBox.Show(ex.Message);
                }
            });
        }
예제 #3
0
        /// <summary>
        /// Shows the input etry window with the given model
        /// </summary>
        /// <param name="model">Model to bind to</param>
        private void ShowProxyEntry(ProxyEntryInformation model)
        {
            ProxyEntry dialog = new ProxyEntry(model);

            // Attach event
            dialog.OnProxyEntered += dialog_OnProxyEntered;
            // Show window
            dialog.ShowModal();
        }
예제 #4
0
        private void btnFile_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ProxyEntryInformation proxyInformation = (this.DataContext as ProxyEntryInformation);
            OpenFileDialog        openFileDialog   = new OpenFileDialog()
            {
                Filter           = "WSDL-XML Files|*.wsdl;*.xml",
                InitialDirectory = GetWSDLPath(proxyInformation.ServiceAddress)
            };

            if (openFileDialog.ShowDialog() == true)
            {
                (this.DataContext as ProxyEntryInformation).ServiceAddress = openFileDialog.FileName;
            }
        }
예제 #5
0
        /// <summary>
        /// This event has fired when Configure Menu Item clicked
        /// </summary>
        private void ConfigureMenuItemClicked(object sender, EventArgs e)
        {
            // Get current solution
            IVsSolution  solution            = GetService(typeof(IVsSolution)) as IVsSolution;
            uint         itemId              = VSConstants.VSITEMID_NIL;
            IVsHierarchy hierarchy           = solution.GetSelectedHierarchy(out itemId);
            ProjectItem  selectedProjectItem = hierarchy.GetSelectedProjectItem(itemId);

            // Get paths and file names...
            string selectedItemName       = selectedProjectItem.Name;
            string fullpath               = Path.GetDirectoryName(selectedProjectItem.Properties.Item("FullPath").Value.ToString());
            string svcMapFilePath         = string.Concat(fullpath, Path.DirectorySeparatorChar, selectedItemName, ProxyMgrConstants.SvcmapFileExtension);
            ProxyEntryInformation context = null;

            // Read svcmap file
            if (File.Exists(svcMapFilePath))
            {
                using (System.IO.FileStream file = File.Open(svcMapFilePath, FileMode.Open, FileAccess.Read))
                {
                    context = file.Deserialize <ProxyEntryInformation>();
                }
            }

            // Check context
            if (context == null)
            {
                LogWriter.WriteLine(string.Format("[ WARNING ] {0} file not found.", svcMapFilePath));
                context = new ProxyEntryInformation()
                {
                    ServiceName = selectedItemName, ShowMissingMap = false
                };
            }

            context.IsAddContext = false;

            // Show input entry window
            this.ShowProxyEntry(context);
        }
예제 #6
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);
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of <see cref="ProxyEntry"/> class with the given model
 /// </summary>
 /// <param name="vModel">View model to bind</param>
 internal ProxyEntry(ProxyEntryInformation vModel)
 {
     InitializeComponent();
     this.DataContext = vModel;
 }