private void UpdateSelectedBundle(object sender, EventArgs e)
        {
            try
            {
                var file = ProjectHelpers.GetSelectedItemPaths().FirstOrDefault();

                if (string.IsNullOrEmpty(file)) // Project
                {
                    var project = ProjectHelpers.GetActiveProject();

                    if (project != null)
                    {
                        file = project.GetConfigFile();
                    }
                }

                if (!string.IsNullOrEmpty(file))
                {
                    BundleService.Process(file);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Exemple #2
0
        async void IService.HelloWorld()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); //воротаемся в UI поток.


            vproject = ProjectHelpers.GetActiveProject();
            string rootfolder  = vproject.GetRootFolder(); //корневая папка проекта с csproj открытым в студии
            string vsixdllpath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "");
            string vsixfolder  = Path.GetDirectoryName(vsixdllpath);

            string filename     = "tmp1.cs";
            string path2addfile = Path.Combine(vsixfolder, "Templates", filename);
            var    filetoadd    = new FileInfo(path2addfile);

            ProjectItem projectItem  = null;
            string      fileprojpath = Path.Combine(rootfolder, filename);

            var filedest = new FileInfo(Path.Combine(fileprojpath));

            if (1 == 1)
            {
                if (1 == 1) //добавить файл в проект из VSIX папки
                {
                    ProjectHelpers.CopyTmpToProjectFile(vproject, filetoadd.FullName, filedest.FullName);
                }
                projectItem = vproject.AddFileToProject(filedest);

                vproject.DTE.ItemOperations.OpenFile(fileprojpath); //открыть редактор с новым файлом

                if (true)                                           //добавить текст
                {
                    Microsoft.VisualStudio.Text.Editor.IWpfTextView view = ProjectHelpers.GetCurentTextView();

                    if (view != null)
                    {
                        try
                        {
                            ITextEdit edit = view.TextBuffer.CreateEdit();
                            edit.Insert(0, Environment.NewLine);
                            edit.Apply();
                        }
                        catch (Exception e)
                        {
                        }
                    }
                }
                if (true) //добавление абсолютной ссылки в проект
                {
                    VSProject refproject;
                    refproject = (VSProject)vproject.Object;
                    try
                    {
                        refproject.References.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Microsoft.Build.dll");
                    }
                    catch (Exception ddd)
                    {
                    }
                }
            }
        }
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var files  = ProjectHelpers.GetSelectedItemPaths();

            button.Visible = button.Enabled = false;

            int count = files.Count();

            if (count == 0) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project == null)
                {
                    return;
                }

                string config = project.GetConfigFile();

                if (!string.IsNullOrEmpty(config) && File.Exists(config))
                {
                    button.Visible = button.Enabled = true;
                }
            }
            else
            {
                button.Visible = button.Enabled = files.Count() == 1 && Path.GetFileName(files.First()) == Constants.CONFIG_FILENAME;
            }
        }
Exemple #4
0
        private ProvisioningTemplateToolsConfiguration GetConfig(bool createIfNotExists)
        {
            var    project     = ProjectHelpers.GetActiveProject();
            string projectPath = ProjectHelpers.GetProjectFolder(project);

            return(GetConfig(projectPath, createIfNotExists));
        }
        private void Execute(object sender, EventArgs e)
        {
            var question = $"This will generate {GULP_FILE_NAME} and install the npm packages needed (it will take a minute or two).\r\nNo files will be deleted.\r\n\r\nDo you wish to continue?";
            var answer   = MessageBox.Show(question, Vsix.Name, MessageBoxButton.OKCancel, MessageBoxImage.Question);

            if (answer == MessageBoxResult.Cancel)
            {
                return;
            }

            var project = ProjectHelpers.GetActiveProject();
            var root    = project.GetRootFolder();

            var bundleConfigFile = Path.Combine(root, Constants.CONFIG_FILENAME);

            StripCommentsFromJsonFile(bundleConfigFile);

            var packageFile = Path.Combine(root, "package.json");
            var gulpFile    = Path.Combine(root, GULP_FILE_NAME);

            CreateFileAndIncludeInProject(project, packageFile);
            CreateFileAndIncludeInProject(project, gulpFile);

            BundlerMinifierPackage._dte.StatusBar.Text = "Installing node modules...";
            InstallNodeModules(Dispatcher.CurrentDispatcher, root, "del", "gulp", "gulp-concat", "gulp-cssmin", "gulp-htmlmin", "gulp-uglify", "merge-stream");
            BundleService.ToggleOutputProduction(project.GetConfigFile(), false);
        }
Exemple #6
0
        private async void MenuItemCallback(object sender, EventArgs e)
        {
            string currentFilePath = GetCurrentFilePath();

            if (string.IsNullOrEmpty(currentFilePath) || !File.Exists(currentFilePath))
            {
                return;
            }

            Project project = ProjectHelpers.GetActiveProject();

            if (project == null)
            {
                return;
            }

            var currentFileRelativePathFromCurrentProject = GetPathFromProjectFolder(project, currentFilePath);
            var testProjectData = FindMatchingTestProject(project);
            var testProject     = GetTestProject(testProjectData);

            string file = Path.Combine(Path.GetDirectoryName(testProject.FullName) + testProjectData.Path) + currentFileRelativePathFromCurrentProject;
            string dir  = Path.GetDirectoryName(file);

            PackageUtilities.EnsureOutputPath(dir);

            if (!File.Exists(file))
            {
                int position = await WriteFile(testProject, file);

                try
                {
                    testProject.AddFileToProject(file);
                    var window = (Window2)_dte.ItemOperations.OpenFile(file);

                    // Move cursor into position
                    if (position > 0)
                    {
                        var view = ProjectHelpers.GetCurentTextView();

                        if (view != null)
                        {
                            view.Caret.MoveTo(new SnapshotPoint(view.TextBuffer.CurrentSnapshot, position));
                        }
                    }

                    _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
                    _dte.ActiveDocument.Activate();
                    _dte.ExecuteCommand("File.SaveAll");
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show($"Don't worry KAPARA, already got tests for this file ({0})");
            }
        }
Exemple #7
0
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var item   = ProjectHelpers.GetSelectedItems().FirstOrDefault();

            if (item == null) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project != null)
                {
                    string config = project.GetConfigFile();

                    if (!string.IsNullOrEmpty(config) && File.Exists(config))
                    {
                        _isInstalled   = IsPackageInstalled(project);
                        _project       = project;
                        button.Checked = _isInstalled;
                        button.Visible = true;

                        DisableUnsupportProjectType(project, button);

                        return;
                    }
                }
            }

            // Config file
            if (item == null || item.ContainingProject == null || item.Properties == null)
            {
                button.Visible = false;
                return;
            }

            var  sourceFile   = item.Properties.Item("FullPath").Value.ToString();
            bool isConfigFile = Path.GetFileName(sourceFile).Equals(Constants.CONFIG_FILENAME, StringComparison.OrdinalIgnoreCase);

            if (!isConfigFile)
            {
                button.Visible = false;
                return;
            }

            if (!DisableUnsupportProjectType(item.ContainingProject, button))
            {
                return;
            }

            button.Visible = isConfigFile;

            if (button.Visible)
            {
                _isInstalled   = IsPackageInstalled(item.ContainingProject);
                _project       = item.ContainingProject;
                button.Checked = _isInstalled;
            }
        }
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var item   = ProjectHelpers.GetSelectedItems().FirstOrDefault();

            if (item == null) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project != null)
                {
                    string config = project.GetConfigFile();

                    if (!string.IsNullOrEmpty(config) && File.Exists(config))
                    {
                        _isInstalled   = IsPackageInstalled(project);
                        _project       = project;
                        button.Checked = _isInstalled;
                        button.Visible = true;

                        DisableUnsupportProjectType(project, button);

                        return;
                    }
                }
            }

            // Config file
            if (item == null || item.ContainingProject == null || item.Properties == null)
            {
                button.Visible = false;
                return;
            }

            bool isConfigFile = item.IsConfigFile();

            if (!isConfigFile)
            {
                button.Visible = false;
                return;
            }

            if (!DisableUnsupportProjectType(item.ContainingProject, button))
            {
                return;
            }

            button.Visible = isConfigFile;

            if (button.Visible)
            {
                _isInstalled   = IsPackageInstalled(item.ContainingProject);
                _project       = item.ContainingProject;
                button.Checked = _isInstalled;
            }
        }
Exemple #9
0
        private void EditConnMenuItemCallback(object sender, EventArgs e)
        {
            var project             = ProjectHelpers.GetActiveProject();
            var projectPath         = Helpers.ProjectHelpers.GetProjectFolder(project);
            var configFileCredsPath = Path.Combine(projectPath, Resources.FileNameProvisioningUserCreds);

            var config = GetConfig(projectPath, true);

            GetUserCreds(config, projectPath, configFileCredsPath);
        }
        private void Execute(object sender, EventArgs e)
        {
            var button     = (OleMenuCommand)sender;
            var project    = ProjectHelpers.GetActiveProject();
            var configFile = project?.GetConfigFile();

            if (!string.IsNullOrEmpty(configFile))
            {
                BundleService.ToggleOutputProduction(configFile, !button.Checked);
                ProjectEventCommand.Instance.EnsureProjectIsActive(project);
            }
        }
Exemple #11
0
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var files  = ProjectHelpers.GetSelectedItemPaths();

            button.Visible = button.Enabled = false;

            int count = files.Count();

            if (count == 0) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project == null)
                {
                    return;
                }

                string config = project.GetConfigFile();

                if (!string.IsNullOrEmpty(config) && File.Exists(config))
                {
                    button.Visible = true;
                    var root     = project.GetRootFolder();
                    var gulpFile = Path.Combine(root, "gulpfile.js");
                    button.Enabled = !File.Exists(gulpFile);
                }
            }
            else
            {
                button.Visible = files.Count() == 1 && Path.GetFileName(files.First()) == Constants.CONFIG_FILENAME;

                if (button.Visible)
                {
                    var root     = ProjectHelpers.GetActiveProject()?.GetRootFolder();
                    var gulpFile = Path.Combine(root, "gulpfile.js");
                    button.Enabled = !File.Exists(gulpFile);
                }
            }

            if (button.Enabled)
            {
                button.Text = "Convert To Gulp...";
            }
            else
            {
                button.Text = "Convert To Gulp... (gulpfile.js already exists)";
            }
        }
        /// <summary>
        /// xsd生成wsdl
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void XsdCommandInvoke(object sender, EventArgs e)
        {
            var items = ProjectHelpers.GetSelectedItemPaths(_dte);

            if (items.Count() == 1 &&
                (items.ElementAt(0).ToLower().EndsWith(".xsd", StringComparison.OrdinalIgnoreCase)))
            {
                var _file         = items.ElementAt(0);
                var fileInfo      = new FileInfo(_file);
                var folder        = fileInfo.Directory?.FullName;
                var project       = ProjectHelpers.GetActiveProject().FullName;
                var projectInfo   = new FileInfo(project);
                var folderproject = projectInfo.Directory?.FullName;
                if (!string.IsNullOrEmpty(folder))
                {
                    WsdlWizardForm wizard = null;
                    try
                    {
                        wizard = new WsdlWizardForm(_file);
                        wizard.WsdlLocation          = folder;
                        wizard.DefaultPathForImports = "";
                        wizard.ProjectRootDirectory  = folderproject;
                        wizard.ShowDialog();

                        string wsdlFile = "";
                        if (wizard.DialogResult == DialogResult.OK)
                        {
                            if (wizard.WsdlLocation.Length > 0)
                            {
                                wsdlFile = wizard.WsdlLocation;
                                ProjectHelpers.AddFileToActiveProject(wsdlFile);
                                //ProcessCodeGenerationRequest(wsdlFile);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ProjectHelpers.AddError(_package, ex.ToString());
                        MessageBox.Show(ex.Message, "WSDL Wizard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        if (wizard != null)
                        {
                            wizard.Close();
                        }
                    }
                }
            }
        }
Exemple #13
0
        private void UpdateSelectedConfig(object sender, EventArgs e)
        {
            var file = ProjectHelpers.GetSelectedItemPaths().FirstOrDefault();

            if (string.IsNullOrEmpty(file)) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project != null)
                {
                    file = project.GetConfigFile();
                }
            }

            if (!string.IsNullOrEmpty(file))
            {
                CompilerService.Process(file);
            }
        }
        private void LoadFiles()
        {
            lstFiles.Items.Clear();
            var project = ProjectHelpers.GetActiveProject();

            Projectpath = project.GetFullPath();

            var files        = Directory.GetFiles(Projectpath, "*.cs", SearchOption.AllDirectories).ToList();
            var filteredList = FileHelper.FilterFileList(files);

            var fileList = filteredList.ToList();

            foreach (var file in fileList)
            {
                var model = file.Replace(Projectpath, "").Replace(".cs", "");
                lstFiles.Items.Add(model);
            }

            RawContent = FileHelper.GenerateRawStringAllFiles(fileList);
        }
Exemple #15
0
        private void UpdateSelectedBundle(object sender, EventArgs e)
        {
            var file = ProjectHelpers.GetSelectedItemPaths().FirstOrDefault();

            if (string.IsNullOrEmpty(file)) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project != null)
                {
                    file = project.GetConfigFile();
                }
            }

            if (!string.IsNullOrEmpty(file))
            {
                BundleService.Process(file);
                Telemetry.TrackEvent("VS update bundle");
            }
        }
        private void UpdateSelectedBundle(object sender, EventArgs e)
        {
            var configFile = ProjectHelpers.GetSelectedItemPaths().FirstOrDefault();

            if (string.IsNullOrEmpty(configFile))
            {
                var project = ProjectHelpers.GetActiveProject();
                configFile = project?.GetConfigFile();
            }

            if (string.IsNullOrEmpty(configFile) || !File.Exists(configFile))
            {
                return;
            }

            var bundles = BundleHandler.GetBundles(configFile);

            BundleFileProcessor processor = new BundleFileProcessor();

            processor.Clean(configFile, bundles);
        }
Exemple #17
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out _document))
            {
                string fileName = Path.GetFileName(_document.FilePath);

                if (fileName.Equals(Constants.CONFIG_FILENAME, StringComparison.OrdinalIgnoreCase))
                {
                    _document.FileActionOccurred += DocumentSaved;
                }
                else if (fileName.Equals(Constants.CONFIG_FILENAME + ".bindings", StringComparison.OrdinalIgnoreCase))
                {
                    var project = ProjectHelpers.GetActiveProject();
                    ProjectEventCommand.Instance.EnsureProjectIsActive(project);
                }
            }

            textView.Closed += TextviewClosed;
        }
Exemple #18
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            string message = string.Format(CultureInfo.CurrentCulture, "Process Completed Successfully", GetType().FullName);
            string title   = "JWT Integrator Tool";

            var project = ProjectHelpers.GetActiveProject();

            var projectpath = project.GetFullPath();

            try
            {
                FileHelper.CreateBackup(projectpath);

                FileHelper.AddtoConfigJson(FileHelper.GetJsonFile(projectpath));

                FileHelper.CreateSigningConfigurationsFile(projectpath);

                FileHelper.CreateTokenConfigurationsFile(projectpath);

                FileHelper.AddInfotoStartup(projectpath);

                FileHelper.CreateTokenController(projectpath);
            }
            catch (Exception ex)
            {
                Logger.Log("Error during the operation: " + ex);
            }

            Logger.Log("Integration completed with success");

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                ServiceProvider,
                message,
                title,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
Exemple #19
0
        private bool IsEnabledForCurrentProject()
        {
            var project = ProjectHelpers.GetActiveProject();

            return(IsEnabledForProject(project));
        }
        /// <summary>
        /// 根据xsd生成model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ModelCommandInvoke(object sender, EventArgs e)
        {
            //可以选多个
            var items = ProjectHelpers.GetSelectedItemPaths(_dte);

            if (items != null && items.Any(r => !r.ToLower().EndsWith(".xsd", StringComparison.OrdinalIgnoreCase)))
            {
                ProjectHelpers.AddError(_package, "select file is not xsd file");
                return;
            }

            var _file           = items.ElementAt(0);
            var project         = ProjectHelpers.GetActiveProject();
            var projectFullName = ProjectHelpers.GetActiveProject().FullName;
            var projectInfo     = new FileInfo(projectFullName);
            var folderproject   = projectInfo.Directory?.FullName;

            try
            {
                string[]         dataContractFiles = items.ToArray();
                XsdCodeGenDialog dialogForm        = new XsdCodeGenDialog(dataContractFiles);
                if (!project.IsWebProject())
                {
                    dialogForm.Namespace = project.GetProjectProperty("DefaultNamespace");
                    if (string.IsNullOrEmpty(dialogForm.Namespace))
                    {
                        dialogForm.Namespace = Path.GetFileNameWithoutExtension(_file);
                    }
                }
                else
                {
                    dialogForm.Namespace = Path.GetFileNameWithoutExtension(_file);
                }
                dialogForm.TargetFileName = ProjectHelpers.GetDefaultDestinationFilename(_file);
                if (dialogForm.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                CodeGenOptions options = new CodeGenOptions();
                options.GenerateDataContractsOnly          = true;
                options.DataContractFiles                  = dataContractFiles;
                options.GenerateSeparateFiles              = dialogForm.GenerateMultipleFiles;
                options.GenerateSeparateFilesEachNamespace = dialogForm.GenerateMultipleFilesEachNamespace;
                options.GenerateSeparateFilesEachXsd       = dialogForm.GenerateSeparateFilesEachXsd;
                options.AscendingClassByName               = dialogForm.AscendingClassByName;
                options.OnlyUseDataContractSerializer      = dialogForm.OnlyUseDataContractSerializer;
                options.OverwriteExistingFiles             = dialogForm.OverwriteFiles;
                options.EnableDataBinding                  = dialogForm.DataBinding;
                options.EnableSummaryComment               = dialogForm.Comment;
                options.GenerateCollections                = dialogForm.Collections;
                options.GenerateTypedLists                 = dialogForm.TypedList;
                options.EnableLazyLoading                  = dialogForm.LazyLoading;
                options.OutputFileName            = dialogForm.TargetFileName;
                options.OutputLocation            = folderproject;
                options.ProjectDirectory          = project.FullName;
                options.Language                  = CodeLanguage.CSharp;
                options.ClrNamespace              = dialogForm.Namespace;
                options.EnableSummaryComment      = dialogForm.Comment;
                options.ProjectName               = project.Name;
                options.EnableBaijiSerialization  = dialogForm.EnableBaijiSerialization;
                options.AddCustomRequestInterface = dialogForm.AddCustomRequestInterface;
                options.CustomRequestInterface    = dialogForm.CustomRequestInterface;
                options.ForceElementName          = dialogForm.ForceElementName;
                options.ForceElementNamespace     = dialogForm.ForceElementNamespace;
                options.GenerateAsyncOperations   = dialogForm.GenerateAsyncOperations;
                options.EnableInitializeFields    = true;



                CodeGenerator    codeGenerator = new CodeGenerator();
                CodeWriterOutput output        = codeGenerator.GenerateCode(options);

                AddGeneratedFilesToProject(output);

                // Finally add the project references.
                ProjectHelpers.AddAssemblyReferences(project);

                MessageBox.Show("Model generation successfully completed.", "Ant.SOA.CodeGen", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                ProjectHelpers.AddError(_package, ex.ToString());
                MessageBox.Show(ex.Message, "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 static void AddProjectFile(string path, string contents)
 {
     File.WriteAllText(path, contents);
     ProjectHelpers.GetActiveProject().ProjectItems.AddFromFile(path);
 }
        /// <summary>
        /// css生成dll
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CsDllCommandInvoke(object sender, EventArgs e)
        {
            var items = ProjectHelpers.GetSelectedItemPaths(_dte);

            if (items.Count() != 1)
            {
                ProjectHelpers.AddError(_package, "no cs was selected");
                return;
            }
            try
            {
                //System.IServiceProvider oServiceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte);
                //EnvDTE.ProjectItem oProjectItem = _dte.SelectedItems.Item(1).ProjectItem;
                //Microsoft.Build.Evaluation.Project oBuildProject = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.GetLoadedProjects(oProjectItem.ContainingProject.FullName).SingleOrDefault();
                //Microsoft.Build.Evaluation.ProjectProperty oGUID = oBuildProject.AllEvaluatedProperties.SingleOrDefault(oProperty => oProperty.Name == "ProjectGuid");
                //Microsoft.VisualStudio.Shell.Interop.IVsHierarchy oVsHierarchy = VsShellUtilities.GetHierarchy(oServiceProvider, new Guid(oGUID.EvaluatedValue));
                //Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage oVsBuildPropertyStorage = (Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage)oVsHierarchy;

                //string szItemPath = (string)oProjectItem.Properties.Item("FullPath").Value;
                string szItemPath = ProjectHelpers.GetActiveProject().FullName;
                var    refDll     = new List <string>();
                var    csprojText = File.ReadAllLines(szItemPath).Where(r => r.Contains(@"<ProjectReference Include=") ||
                                                                        (r.Contains("<HintPath>")));
                var serviceStack = csprojText.Where(r => r.Contains("AntServiceStack"));
                foreach (var s in serviceStack)
                {
                    string folder = new FileInfo(szItemPath).DirectoryName;
                    if (s.Trim().EndsWith(".csproj\">"))
                    {
                        var s1       = s.Split('"')[1];
                        var s2       = s1.Split('\\');
                        var dotCount = s2.Count(r => r.Equals(".."));
                        for (int i = 0; i < dotCount; i++)
                        {
                            folder = Directory.GetParent(folder).FullName;
                        }

                        for (int i = 0; i < s2.Length - 1; i++)
                        {
                            var ss = s2[i];
                            if (ss.Equals(".."))
                            {
                                continue;
                            }
                            folder = Path.Combine(folder, ss);
                        }
                        folder = Path.Combine(folder, "bin", "Debug");
                        if (!Directory.Exists(folder))
                        {
                            ProjectHelpers.AddError(_package, folder + " not found");
                            return;
                        }
                        var dllname = s2[s2.Length - 1].Replace(".csproj", ".dll");
                        var dllPath = Path.Combine(folder, dllname);
                        if (!File.Exists(dllPath))
                        {
                            ProjectHelpers.AddError(_package, dllPath + " not found");
                            return;
                        }
                        refDll.Add("\"" + dllPath + "\"");
                    }
                    else if (s.Trim().Contains("<HintPath>") && s.Trim().Contains("AntServiceStack") && s.Trim().Contains("dll"))
                    {
                        var dllPath = s.Trim().Split('>')[1].Split('<')[0];
                        if (dllPath.StartsWith(".."))
                        {
                            var s2       = dllPath.Split('\\');
                            var dotCount = s2.Count(r => r.Equals(".."));
                            for (int i = 0; i < dotCount; i++)
                            {
                                folder = Directory.GetParent(folder).FullName;
                            }
                            for (int i = 0; i < s2.Length; i++)
                            {
                                var ss = s2[i];
                                if (ss.Equals(".."))
                                {
                                    continue;
                                }
                                folder = Path.Combine(folder, ss);
                            }
                            dllPath = folder;
                        }

                        refDll.Add("\"" + dllPath + "\"");
                    }
                }

                //uint nItemId;
                //oVsHierarchy.ParseCanonicalName(szItemPath, out nItemId);

                //string szOut;
                //oVsBuildPropertyStorage.GetItemAttribute(nItemId, "ClientDllVersion", out szOut);
                //if (string.IsNullOrEmpty(szOut))
                //{
                //    //oVsBuildPropertyStorage.SetItemAttribute(nItemId, "ItemColor", );
                //}


                string   file          = items.ElementAt(0);
                string   baseFileName  = Path.GetFileNameWithoutExtension(file);
                FileInfo fileInfo      = new FileInfo(file);
                var      frameworkPath = RuntimeEnvironment.GetRuntimeDirectory();

                var cscPath = Path.Combine(frameworkPath, "csc.exe");
                //C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe /t:library /out:MyCScode.dll *.cs /debug /r:System.dll /r:System.Web.dll /r:System.Data.dll /r:System.Xml.dll
                System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.UseShellExecute  = true;
                startInfo.WorkingDirectory = fileInfo.DirectoryName;
                startInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName         = cscPath;
                startInfo.Arguments        = "/t:library /out:" + baseFileName + ".dll " + baseFileName + ".cs /r:System.dll /r:System.Configuration.dll /r:System.Core.dll /r:System.Runtime.Serialization.dll /r:System.ServiceModel.dll /r:System.Xml.Linq.dll /r:System.Data.DataSetExtensions.dll /r:Microsoft.CSharp.dll /r:System.Data.dll /r:System.Xml.dll" + (refDll.Count > 0 ? " /r:" + string.Join(" /r:", refDll) : "");
                process.StartInfo          = startInfo;
                process.Start();
                process.WaitForExit(10000);// 10 seconds timeout
                int result = process.ExitCode;
                if (result == -1)
                {
                    ProjectHelpers.AddError(_package, "cs compile err :" + startInfo.Arguments);
                    MessageBox.Show("Error happens",
                                    "Cs Dll Conversion", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    return;
                }
                MessageBox.Show("compile is success",
                                "Cs Dll Conversion", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
                {
                    FileName        = fileInfo.DirectoryName,
                    UseShellExecute = true,
                    Verb            = "open"
                });
            }
            catch (Exception ex)
            {
                ProjectHelpers.AddError(_package, ex.ToString());
                MessageBox.Show("Error happens: " + ex,
                                "Cs Dll Conversion", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }
        }
        private async void ExecuteAsync(object sender, EventArgs e)
        {
            object selectedItem = ProjectHelpers.GetSelectedItem();
            string folder       = FindFolder(selectedItem);

            if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
            {
                return;
            }

            var     selectedProjectItem = selectedItem as ProjectItem;
            var     selectedProject     = selectedItem as Project;
            Project project             = selectedProjectItem?.ContainingProject ?? selectedProject ?? ProjectHelpers.GetActiveProject();

            if (project == null)
            {
                return;
            }

            string input = PromptForFileName(folder).TrimStart('/', '\\').Replace("/", "\\");

            if (string.IsNullOrEmpty(input))
            {
                return;
            }

            string[] parsedInputs = GetParsedInput(input);

            foreach (string inputItem in parsedInputs)
            {
                input = inputItem;

                if (input.EndsWith("\\", StringComparison.Ordinal))
                {
                    input = input + "__dummy__";
                }

                var inputLower = input.ToLower();
                var inputCamel = inputLower.Substring(0, 1).ToUpper() + inputLower.Substring(1);

                //添加父级文件夹
                var rootFolderName = $"{inputCamel}s";
                var appFolder      = Path.Combine(folder, rootFolderName);
                project.ProjectItems.AddFolder(appFolder);


                foreach (ProjectItem childProject in project.ProjectItems)
                {
                    if (childProject.Name == rootFolderName)
                    {
                        //添加dto文件夹
                        var dtoFolder = Path.Combine(appFolder, "Dto");
                        childProject.ProjectItems.AddFolder(dtoFolder);

                        //添加几个dto类及映射类
                        await CreateDtoFile(inputCamel, dtoFolder, selectedItem, childProject, project, TemplateType.DefaultDto);
                        await CreateDtoFile(inputCamel, dtoFolder, selectedItem, childProject, project, TemplateType.CreateDto);
                        await CreateDtoFile(inputCamel, dtoFolder, selectedItem, childProject, project, TemplateType.UpdateDto);
                        await CreateDtoFile(inputCamel, dtoFolder, selectedItem, childProject, project, TemplateType.PagedDto);
                        await CreateDtoFile(inputCamel, dtoFolder, selectedItem, childProject, project, TemplateType.MapProfile);

                        break;
                    }
                }

                //添加接口
                await CreateFile(inputCamel, appFolder, selectedItem, project, TemplateType.Interface);

                //添加业务类
                await CreateFile(inputCamel, appFolder, selectedItem, project, TemplateType.Class);
            }
        }
        /// <summary>
        /// wsdl生成cs
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WsdlCommandInvoke(object sender, EventArgs e)
        {
            var items = ProjectHelpers.GetSelectedItemPaths(_dte);

            if (items.Count() != 1 ||
                !(items.ElementAt(0).ToLower().EndsWith(".wsdl", StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            var _file           = items.ElementAt(0);
            var project         = ProjectHelpers.GetActiveProject();
            var projectFullName = ProjectHelpers.GetActiveProject().FullName;
            var projectInfo     = new FileInfo(projectFullName);
            var folderproject   = projectInfo.Directory?.FullName;

            try
            {
                // Fist display the UI and get the options.
                WebServiceCodeGenDialogNew dialog = new WebServiceCodeGenDialogNew();
                if (!project.IsWebProject())
                {
                    dialog.DestinationNamespace = project.GetProjectProperty("DefaultNamespace");
                    if (string.IsNullOrEmpty(dialog.DestinationNamespace))
                    {
                        dialog.DestinationNamespace = Path.GetFileNameWithoutExtension(_file);
                    }
                }
                else
                {
                    dialog.DestinationNamespace = Path.GetFileNameWithoutExtension(_file);
                }
                dialog.DestinationFilename = ProjectHelpers.GetDefaultDestinationFilename(_file);
                dialog.WsdlLocation        = _file;

                if (dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                var wsdlFile = _file;
                // Try the Rpc2DocumentLiteral translation first.
                // wsdlFile = TryTranslateRpc2DocumentLiteral(wsdlFile);

                CodeGenOptions options = new CodeGenOptions();
                options.MetadataLocation = wsdlFile;
                options.OutputFileName   = dialog.DestinationFilename;
                options.OutputLocation   = folderproject;
                options.ProjectDirectory = project.FullName;
                options.Language         = CodeLanguage.CSharp;
                options.ProjectName      = project.Name;

                options.EnableDataBinding                  = dialog.EnableDataBinding;
                options.EnableSummaryComment               = dialog.Comment;
                options.GenerateCollections                = dialog.Collections;
                options.GenerateTypedLists                 = dialog.TypedList;
                options.EnableLazyLoading                  = dialog.LazyLoading;
                options.GenerateSeparateFiles              = dialog.GenerateMultipleFiles;
                options.OnlyUseDataContractSerializer      = dialog.OnlyUseDataContractSerializer;
                options.GenerateSeparateFilesEachNamespace = dialog.GenerateMultipleFilesEachNamespace;
                options.GenerateSeparateFilesEachXsd       = dialog.GenerateSeparateFilesEachXsd;
                options.AscendingClassByName               = dialog.AscendingClassByName;
                options.OverwriteExistingFiles             = dialog.Overwrite;
                options.ClrNamespace              = dialog.DestinationNamespace;
                options.EnableBaijiSerialization  = dialog.EnableBaijiSerialization;
                options.AddCustomRequestInterface = dialog.AddCustomRequestInterface;
                options.CustomRequestInterface    = dialog.CustomRequestInterface;
                options.ForceElementName          = dialog.ForceElementName;
                options.ForceElementNamespace     = dialog.ForceElementNamespace;
                options.GenerateAsyncOperations   = dialog.GenerateAsyncOperations;

                if (dialog.ServiceCode)
                {
                    options.CodeGeneratorMode = CodeGeneratorMode.Service;
                }
                else if (dialog.ClientCode)
                {
                    options.CodeGeneratorMode = CodeGeneratorMode.Client;
                }
                else
                {
                    options.CodeGeneratorMode = CodeGeneratorMode.ClientForTest;
                }

                options.EnableInitializeFields = true;


                CodeGenerator    codeGenerator = new CodeGenerator();
                CodeWriterOutput output        = codeGenerator.GenerateCode(options);

                AddGeneratedFilesToProject(output);

                // Finally add the project references.
                ProjectHelpers.AddAssemblyReferences(project);

                MessageBox.Show("Code generation successfully completed.", "Ant.SOA.CodeGen", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                ProjectHelpers.AddError(_package, ex.ToString());
                MessageBox.Show(ex.Message, "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }