Ejemplo n.º 1
0
        private static EnvDTE.UIHierarchyItem?FindFirstItemRecursively(
            EnvDTE.UIHierarchyItems currentItems,
            string itemName)
        {
            if (currentItems == null)
            {
                return(null);
            }

            foreach (var item in currentItems.Cast <EnvDTE.UIHierarchyItem>())
            {
                if (item.Name == itemName)
                {
                    return(item);
                }

                var result = FindFirstItemRecursively(item.UIHierarchyItems, itemName);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private static EnvDTE.UIHierarchyItem?FindItemAtPath(
            EnvDTE.UIHierarchyItems currentItems,
            string[] path)
        {
            EnvDTE.UIHierarchyItem?item = null;
            foreach (var name in path)
            {
                item = currentItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(i => i.Name == name);

                if (item == null)
                {
                    return(null);
                }

                currentItems = item.UIHierarchyItems;
            }

            return(item);
        }
Ejemplo n.º 3
0
        private void GenerateClick(object sender, RoutedEventArgs e)
        {
            var originalCursor = Cursor;

            try
            {
                Cursor = Cursors.Wait;
                _packageInstaller.InstallPackage(_project, "WAQS.Server", _packageInstallerServices);

                var edmxPath   = edmx.SelectedValue as string;
                var appKind    = _project.Properties.Cast <EnvDTE.Property>().Any(p => p.Name.StartsWith("WebApplication")) ? "Web" : "App";
                var netVersion = _project.GetNetVersion();
                var kind       = (GenerationOptions.KindViewModel)generationOptions.SelectedItem;

                var                projectDirectoryPath = Path.GetDirectoryName(_project.FullName);
                string             waqsDirectory;
                string             edmxName        = null;
                EnvDTE.ProjectItem edmxProjectItem = null;
                string             edmxProjectPath = null;
                if (kind.Kind == GenerationOptions.Kind.FrameworkOnly)
                {
                    waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS.Framework");
                }
                else
                {
                    if (!(edmxPath.EndsWith(".edmx") && File.Exists(edmxPath)))
                    {
                        ShowError("Edmx path is not correct");
                        return;
                    }
                    edmxName        = Path.GetFileNameWithoutExtension(edmxPath);
                    waqsDirectory   = Path.Combine(projectDirectoryPath, "WAQS." + edmxName);
                    edmxProjectItem = _dte.Solution.FindProjectItem(edmxPath);
                    edmxProjectPath = edmxProjectItem.ContainingProject.FullName;
                }
                if (Directory.Exists(waqsDirectory))
                {
                    ShowError(waqsDirectory + "already exists");
                    return;
                }

                var projectUIHierarchyItems    = _dte.GetProjectsUIHierarchyItems().First(uihi => ((EnvDTE.Project)uihi.Object).FullName == _project.FullName).UIHierarchyItems;
                var referencesUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "References").UIHierarchyItems;
                var referencesExpanded         = referencesUIHierarchyItems.Expanded;

                var            toolsPath        = Path.Combine(_packageInstallerServices.GetPackageLocation("WAQS.Server"), "tools");
                var            toolsPathServer  = Path.Combine(toolsPath, "Server");
                var            defaultNamespace = _project.GetDefaultNamespace();
                EnvDTE.Project fxProject;
                if (kind.Kind == GenerationOptions.Kind.GlobalOnly || kind.Kind == GenerationOptions.Kind.WithoutGlobalWithoutFramework)
                {
                    fxProject = _dte.Solution.FindProjectItem("ExpressionExtension.cs").ContainingProject;
                }
                else
                {
                    fxProject = _project;
                }
                var assemblyName    = (string)fxProject.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "AssemblyName").Value;
                var assemblyVersion = (string)fxProject.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "AssemblyVersion").Value;
                var references      = ((VSProject)_project.Object).References;
                references.Add("System");
                references.Add("System.Configuration");
                references.Add("System.Core");
                references.Add("System.Data");
                references.Add("System.Runtime.Serialization");
                references.Add("System.ServiceModel");
                references.Add("System.ServiceModel.Activation");
                references.Add("System.ServiceModel.Channels");
                references.Add("System.Transactions");
                references.Add("System.Web");
                references.Add("System.Xml");
                _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Unity", "3.5.1404", false);
                _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "CommonServiceLocator", "1.3.0", false);
                _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "EntityFramework", "6.1.3", false);
                try
                {
                    referencesUIHierarchyItems.Expanded = referencesExpanded;
                }
                catch
                {
                }
                bool   withGlobal       = (kind.Kind & GenerationOptions.Kind.GlobalOnly) != 0;
                var    globalDirectory  = Path.Combine(projectDirectoryPath, "Global");
                string webConfigPath    = null;
                string globalAsaxPath   = null;
                string globalAsaxCsPath = null;
                string globalWCFService = null;
                if (withGlobal)
                {
                    webConfigPath = Path.Combine(projectDirectoryPath, "Web.config");
                    if (File.Exists(webConfigPath))
                    {
                        try
                        {
                            _dte.SourceControl.CheckOutItem(webConfigPath);
                        }
                        catch
                        {
                        }
                    }
                    globalAsaxPath = Path.Combine(projectDirectoryPath, "Global.asax");
                    if (File.Exists(globalAsaxPath))
                    {
                        try
                        {
                            _dte.SourceControl.CheckOutItem(globalAsaxPath);
                        }
                        catch
                        {
                        }
                    }
                    globalAsaxCsPath = Path.Combine(projectDirectoryPath, "Global.asax.cs");
                    if (File.Exists(globalAsaxCsPath))
                    {
                        try
                        {
                            _dte.SourceControl.CheckOutItem(globalAsaxCsPath);
                        }
                        catch
                        {
                        }
                    }
                    globalWCFService = Path.Combine(projectDirectoryPath, "GlobalWCFService.cs");
                    if (File.Exists(globalWCFService))
                    {
                        try
                        {
                            _dte.SourceControl.CheckOutItem(globalWCFService);
                        }
                        catch
                        {
                        }
                    }
                }
                string vsVersion;
                switch (_dte.Version)
                {
                case "12.0":
                    vsVersion = "VS12";
                    break;

                case "14.0":
                default:
                    vsVersion = "VS14";
                    break;
                }
                var    exePath = Path.Combine(toolsPathServer, "InitWAQSServer.exe");
                string specificationsFolder = null;
                string dtoFolder            = null;
                var    exeArgs = new StringBuilder("\"" + edmxPath + "\" \"" + edmxProjectPath + "\" \"" + projectDirectoryPath + "\" \"" + toolsPathServer + "\" \"" + defaultNamespace + "\" \"" + assemblyName + "\" \"" + assemblyVersion + "\" \"" + netVersion + "\" \"" + vsVersion + "\" \"" + kind.Key + "\" \"" + appKind + "\" \"" + waqsDirectory + "\" \"" + (edmxPath == null ? "" : _dte.Solution.FindProjectItem(edmxPath).ContainingProject.ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == "App.Config")?.GetFilePath()) + "\" " + (copyTemplates.IsChecked == true ? "WithSourceControl" : "WithoutSourceControl") + " \"" + _dte.Solution.FullName + "\" WCF");
                if (kind.Kind == GenerationOptions.Kind.GlobalOnly)
                {
                    exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + ".Server.DAL.Interfaces.tt").GetFirstCsFilePath() + "\"");
                    exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + ".Server.DAL.tt").GetFirstCsFilePath() + "\"");
                    exeArgs.Append(" \"" + _dte.Solution.FindProjectItem("I" + edmxName + "Service.cs").GetFilePath() + "\"");
                    exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + "Service.cs").GetFilePath() + "\"");
                    exeArgs.Append(" \"" + _dte.Solution.FindProjectItem("I" + edmxName + "WCFService.cs").GetFilePath() + "\"");
                    exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + "WCFService.cs").GetFilePath() + "\"");
                    exeArgs.Append(" \"" + edmxProjectPath + "\"");
                    var edmxProjectFolderPath = Path.GetDirectoryName(edmxProjectPath);
                    exeArgs.Append(" \"" + Path.Combine(edmxProjectFolderPath, "Specifications") + "\"");
                    exeArgs.Append(" \"" + Path.Combine(edmxProjectFolderPath, "DTO") + "\"");
                }
                else if (kind.Kind != GenerationOptions.Kind.FrameworkOnly)
                {
                    exeArgs.Append(" \"" + _project.FullName + "\"");
                    specificationsFolder = Path.Combine(projectDirectoryPath, "Specifications");
                    exeArgs.Append(" \"" + specificationsFolder + "\"");
                    dtoFolder = Path.Combine(projectDirectoryPath, "DTO");
                    exeArgs.Append(" \"" + dtoFolder + "\"");
                }
                var process = new Process();
                process.StartInfo.FileName    = exePath;
                process.StartInfo.Arguments   = exeArgs.ToString();
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.Start();
                process.WaitForExit();

                if (copyTemplates.IsChecked == true)
                {
                    string              templatesFolder;
                    HashSet <string>    existingTTIncludes;
                    EnvDTE.ProjectItems templatesProjectItems;
                    TemplatesCopying.CopyTemplates(_dte, "ServerTemplates", netVersion, toolsPath, vsVersion, out templatesFolder, out existingTTIncludes, out templatesProjectItems);
                    var ttInclude     = @"%AppData%\WAQS\Templates\Includes\WAQS.Roslyn.Assemblies.ttinclude";
                    var ttIncludeName = Path.GetFileName(ttInclude);
                    TemplatesCopying.AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems);
                }

                if ((kind.Kind & GenerationOptions.Kind.WithoutGlobalWithoutFramework) != 0)
                {
                    var edmxFileProperties = edmxProjectItem.Properties;
                    edmxFileProperties.Item("CustomTool").Value  = "";
                    edmxFileProperties.Item("BuildAction").Value = 0;
                    foreach (var ttPath in edmxProjectItem.ProjectItems.Cast <EnvDTE.ProjectItem>().Where(pi => pi.Name.EndsWith(".tt")).Select(pi => pi.GetFilePath()))
                    {
                        _dte.Solution.FindProjectItem(ttPath).Delete();
                    }
                }
                if (kind.Kind == GenerationOptions.Kind.FrameworkOnly)
                {
                    edmxName = "Framework";
                }
                _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Server.waqs"));
                _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Server.tt"));
                var dalItem = _dte.Solution.FindProjectItem(Path.Combine(waqsDirectory, edmxName + ".Server.DAL.tt"));
                if (dalItem != null && dalItem.ProjectItems.Count < 2) // strange bug: sometimes code is not generated for this T4 only
                {
                    ((VSProjectItem)dalItem.Object).RunCustomTool();
                }
                try
                {
                    projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "WAQS." + edmxName).UIHierarchyItems.Expanded = false;
                }
                catch
                {
                }
                if (withGlobal && appKind == "Web")
                {
                    _project.ProjectItems.AddFromFile(webConfigPath);
                    _project.ProjectItems.AddFromFile(globalAsaxPath);
                    _project.ProjectItems.AddFromFile(globalAsaxCsPath);
                    _project.ProjectItems.AddFromFile(Path.Combine(projectDirectoryPath, edmxName + ".svc"));
                    if (kind.Kind == GenerationOptions.Kind.GlobalOnly)
                    {
                        var globalUIHierarchyItem = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "Global");
                        EnvDTE.UIHierarchyItems globalUIHierarchyItems = null;
                        bool globalUIHierarchyItemsExpanded            = false;
                        if (globalUIHierarchyItem != null)
                        {
                            globalUIHierarchyItems         = globalUIHierarchyItem.UIHierarchyItems;
                            globalUIHierarchyItemsExpanded = globalUIHierarchyItems.Expanded;
                        }
                        _project.ProjectItems.AddFromFile(Path.Combine(globalDirectory, "GlobalWCFServiceContract.tt"));
                        _project.ProjectItems.AddFromFile(Path.Combine(globalDirectory, "GlobalWCFService.cs"));
                        _project.ProjectItems.AddFromFile(Path.Combine(projectDirectoryPath, "Global.svc"));
                        if (globalUIHierarchyItem == null)
                        {
                            try
                            {
                                globalUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "Global")?.UIHierarchyItems;
                            }
                            catch
                            {
                            }
                        }
                        if (globalUIHierarchyItems != null)
                        {
                            globalUIHierarchyItems.Expanded = globalUIHierarchyItemsExpanded;
                        }
                    }
                }
                if (specificationsFolder != null)
                {
                    _project.ProjectItems.AddFromDirectory(specificationsFolder);
                }
                if (dtoFolder != null)
                {
                    _project.ProjectItems.AddFromDirectory(dtoFolder);
                }
                try
                {
                    _dte.ExecuteCommand("File.TfsRefreshStatus");
                }
                catch
                {
                }
                _dte.ItemOperations.Navigate("https://github.com/MatthieuMEZIL/waqs/blob/master/README.md");
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetType().ToString() + "\r\n" + ex.Message + "\r\n" + ex.StackTrace);
            }
            finally
            {
                Cursor = originalCursor;
            }
        }
Ejemplo n.º 4
0
        private void GenerateClick(object sender, RoutedEventArgs e)
        {
            var originalCursor = Cursor;

            try
            {
                Cursor = Cursors.Wait;
                _packageInstaller.InstallPackage(_project, "WAQS.Client." + _clientKind, _packageInstallerServices);

                var edmxPath    = edmx.SelectedValue as string;
                var servicePath = service.SelectedValue as string;
                var appKind     = _project.Properties.Cast <EnvDTE.Property>().Any(p => p.Name.StartsWith("WebApplication")) ? "Web" : "App";
                var netVersion  = _project.GetNetVersion();
                var kind        = (GenerationOptions.KindViewModel)generationOptions.SelectedItem;

                var    projectDirectoryPath = Path.GetDirectoryName(_project.FullName);
                string waqsDirectory;
                string edmxName             = null;
                string waqsGeneralDirectory = null;
                string contextsPath         = null;
                bool   servicePathIsUrl     = false;
                if (kind.Kind == GenerationOptions.Kind.FrameworkOnly)
                {
                    waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS.Framework");
                }
                else
                {
                    if (!(edmxPath.EndsWith(".edmx") && File.Exists(edmxPath)))
                    {
                        ShowError("Edmx path is not correct");
                        return;
                    }
                    if (!((servicePathIsUrl = Regex.IsMatch(servicePath, "^http(s)?://")) || servicePath.EndsWith(".svc") && File.Exists(servicePath)))
                    {
                        ShowError("Service path is not correct");
                        return;
                    }
                    edmxName      = Path.GetFileNameWithoutExtension(edmxPath);
                    waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS." + edmxName);
                }
                if (Directory.Exists(waqsDirectory))
                {
                    ShowError(waqsDirectory + "already exists");
                    return;
                }

                var projectUIHierarchyItems    = _dte.GetProjectsUIHierarchyItems().First(uihi => ((EnvDTE.Project)uihi.Object).FullName == _project.FullName).UIHierarchyItems;
                var referencesUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "References")?.UIHierarchyItems;
                var referencesExpanded         = referencesUIHierarchyItems?.Expanded ?? false;

                var toolsPath        = Path.Combine(_packageInstallerServices.GetPackageLocation("WAQS.Client." + _clientKind), "tools");
                var clientToolsPath  = Path.Combine(toolsPath, "Client." + _clientKind);
                var defaultNamespace = _project.GetDefaultNamespace();
                var references       = ((VSProject)_project.Object).References;
                references.Add("System");
                references.Add("System.Core");
                references.Add("System.Runtime.Serialization");
                references.Add("System.ServiceModel");
                if (_clientKind == GenerationOptions.WPF)
                {
                    references.Add("System.ComponentModel.DataAnnotations");
                    references.Add("System.Drawing");
                    references.Add("PresentationCore");
                    references.Add("PresentationFramework");
                    references.Add("System.Xaml");
                    references.Add("System.Xml");
                    _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "System.Windows.Interactivity.WPF", "2.0.20525", false);
                    _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Unity", "3.5.1404", false);
                    _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Rx-WPF", "2.2.5", false);
                }
                else if (_clientKind == GenerationOptions.PCL)
                {
                    _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Microsoft.Bcl.Async", "1.0.168", false);
                }

                try
                {
                    referencesUIHierarchyItems.Expanded = referencesExpanded;
                }
                catch
                {
                }
                bool   withGlobal    = (kind.Kind & GenerationOptions.Kind.GlobalOnly) != 0;
                string appConfigPath = null;
                string appXamlPath   = null;
                string appXamlCsPath = null;
                if (withGlobal)
                {
                    appConfigPath = Path.Combine(projectDirectoryPath, "app.config");
                    if (File.Exists(appConfigPath))
                    {
                        try
                        {
                            _dte.SourceControl.CheckOutItem(appConfigPath);
                        }
                        catch
                        {
                        }
                    }
                    appXamlPath = Path.Combine(projectDirectoryPath, "App.xaml");
                    if (File.Exists(appXamlPath))
                    {
                        try
                        {
                            _dte.SourceControl.CheckOutItem(appXamlPath);
                        }
                        catch
                        {
                        }
                    }
                    appXamlCsPath = Path.Combine(projectDirectoryPath, "App.xaml.cs");
                    if (File.Exists(appXamlCsPath))
                    {
                        try
                        {
                            _dte.SourceControl.CheckOutItem(appXamlCsPath);
                        }
                        catch
                        {
                        }
                    }
                    if (kind.Kind == GenerationOptions.Kind.GlobalOnly)
                    {
                        waqsGeneralDirectory = Path.Combine(projectDirectoryPath, "WAQS");
                        contextsPath         = Path.Combine(waqsGeneralDirectory, "Contexts.xml");
                        if (File.Exists(contextsPath))
                        {
                            try
                            {
                                _dte.SourceControl.CheckOutItem(contextsPath);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                var    entitiesProjectPath  = _dte.Solution.FindProjectItem(edmxName + ".Server.Entities.tt")?.ContainingProject.FullName;
                string entitiesSolutionPath = null;
                if (!string.IsNullOrEmpty(entitiesProjectPath))
                {
                    entitiesSolutionPath = _dte.Solution.FileName;
                }
                string vsVersion = _dte.GetVsVersion();

                string svcUrl = null;
                if (servicePathIsUrl)
                {
                    svcUrl = servicePath;
                }
                else if (!string.IsNullOrEmpty(servicePath))
                {
                    var svcProjectProperties = _dte.Solution.FindProjectItem(servicePath)?.ContainingProject.Properties.Cast <EnvDTE.Property>();
                    if (svcProjectProperties != null && (kind.Kind != GenerationOptions.Kind.FrameworkOnly))
                    {
                        svcUrl = StartService(servicePath, vsVersion, svcProjectProperties);
                    }
                }

                var exePath = Path.Combine(clientToolsPath, "InitWAQSClient" + _clientKind + ".exe");
                var exeArgs = new StringBuilder("\"" + edmxPath + "\" \"" + (_clientKind == GenerationOptions.WPF ? projectDirectoryPath + "\" \"" : "") + clientToolsPath + "\" \"" + defaultNamespace + "\" \"" + svcUrl + "\" \"" + waqsDirectory + "\" \"" + waqsGeneralDirectory + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ClientContext.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == edmxName + "ExpressionTransformer.cs")?.GetFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ServiceProxy.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == "I" + edmxName + "Service.cs")?.GetFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".Entities.tt")?.GetFirstCsFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ClientContext.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == edmxName + "ClientContext.cs")?.GetFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ClientContext.Interfaces.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == "I" + edmxName + "ClientContext.cs")?.GetFilePath() : "") + "\" \"" + entitiesSolutionPath + "\" \"" + entitiesProjectPath + "\" \"" + netVersion + "\" \"" + vsVersion + "\" \"" + kind.Key + "\" " + (copyTemplates.IsChecked == true ? "WithSourceControl" : "WithoutSourceControl") + " \"" + _dte.Solution.FullName + "\"");
                if ((kind.Kind & GenerationOptions.Kind.WithoutGlobalWithoutFramework) != 0)
                {
                    var projectsItems             = _dte.GetProjects().SelectMany(p => p.GetAllProjectItems());
                    var specificationsProjectItem = projectsItems.FirstOrDefault(pi => ((string)pi.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "FullPath").Value).EndsWith("\\Specifications\\"));
                    exeArgs.Append(" \"" + specificationsProjectItem.ContainingProject.FullName + "\"");
                    exeArgs.Append(" \"" + Path.GetDirectoryName(specificationsProjectItem.GetFilePath()) + "\"");
                    var dtoProjectItem = projectsItems.FirstOrDefault(pi => ((string)pi.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "FullPath").Value).EndsWith("\\DTO\\"));
                    exeArgs.Append(" \"" + dtoProjectItem.ContainingProject.FullName + "\"");
                    exeArgs.Append(" \"" + Path.GetDirectoryName(dtoProjectItem.GetFilePath()) + "\"");
                    exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + ".Server.Entities.tt")?.GetFirstCsFilePath() + "\"");
                }
                var process = new Process();
                process.StartInfo.FileName    = exePath;
                process.StartInfo.Arguments   = exeArgs.ToString();
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.Start();
                process.WaitForExit();

                if (copyTemplates.IsChecked == true)
                {
                    string              templatesFolder;
                    HashSet <string>    existingTTIncludes;
                    EnvDTE.ProjectItems templatesProjectItems;
                    TemplatesCopying.CopyTemplates(_dte, _clientKind + "ClientTemplates", netVersion, toolsPath, vsVersion, out templatesFolder, out existingTTIncludes, out templatesProjectItems);
                    var ttInclude     = @"%AppData%\WAQS\Templates\Includes\WAQS.Roslyn.Assemblies.ttinclude";
                    var ttIncludeName = Path.GetFileName(ttInclude);
                    TemplatesCopying.AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems);
                }

                if (kind.Kind == GenerationOptions.Kind.FrameworkOnly)
                {
                    edmxName = "Framework";
                }
                _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Client." + _clientKind + ".waqs"));
                if (kind.Kind != GenerationOptions.Kind.GlobalOnly)
                {
                    _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Client." + _clientKind + ".tt"));
                }
                try
                {
                    projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "WAQS." + edmxName).UIHierarchyItems.Expanded = false;
                }
                catch
                {
                }
                if (withGlobal)
                {
                    if (_clientKind == GenerationOptions.WPF)
                    {
                        _project.ProjectItems.AddFromFile(appConfigPath);
                    }
                    if (kind.Kind == GenerationOptions.Kind.GlobalOnly)
                    {
                        EnvDTE.UIHierarchyItems waqsGeneralUIHierarchyItems = null;
                        Action setWAQSGeneralUIHierarchyItems = () => waqsGeneralUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "WAQS")?.UIHierarchyItems;
                        setWAQSGeneralUIHierarchyItems();
                        bool waqsGeneralUIHierarchyItemsExpanded = false;
                        if (waqsGeneralUIHierarchyItems != null)
                        {
                            waqsGeneralUIHierarchyItemsExpanded = waqsGeneralUIHierarchyItems.Expanded;
                        }
                        _project.ProjectItems.AddFromFile(contextsPath);
                        if (waqsGeneralUIHierarchyItems == null)
                        {
                            try
                            {
                                setWAQSGeneralUIHierarchyItems();
                                waqsGeneralUIHierarchyItems.Expanded = false;
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            try
                            {
                                waqsGeneralUIHierarchyItems.Expanded = waqsGeneralUIHierarchyItemsExpanded;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                try
                {
                    _dte.ExecuteCommand("File.TfsRefreshStatus");
                }
                catch
                {
                }
                _dte.ItemOperations.Navigate("https://github.com/MatthieuMEZIL/waqs/blob/master/README.md");
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetType().ToString() + "\r\n" + ex.Message + "\r\n" + ex.StackTrace);
            }
            finally
            {
                Cursor = originalCursor;
            }
        }