Пример #1
0
        ProjectItem _FindItem(string path)
        {
            int  iFound = 0;
            uint itemId = 0;

            EnvDTE.ProjectItem item;
            Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[] pdwPriority = new Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[1];
            for (var i = 0; i < _projects.Length; i++)
            {
                Microsoft.VisualStudio.Shell.Interop.IVsProject vsProject = VSUtility.ToVsProject(_projects.GetValue(i) as EnvDTE.Project);
                vsProject.IsDocumentInProject(path, out iFound, pdwPriority, out itemId);
                if (iFound != 0 && itemId != 0)
                {
                    Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp = null;
                    vsProject.GetItemContext(itemId, out oleSp);
                    if (null != oleSp)
                    {
                        ServiceProvider sp = new ServiceProvider(oleSp);
                        // convert our handle to a ProjectItem
                        item = sp.GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem;
                        return(item);
                    }
                }
            }
            return(null);
        }
        public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            this._pGenerateProgress    = pGenerateProgress;
            this.bstrInputFileContents = bstrInputFileContents;
            this.wszInputFilePath      = wszInputFilePath;
            this.newFileNames.Clear();

            int  iFound = 0;
            uint itemId = 0;

            EnvDTE.ProjectItem item;
            Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[] pdwPriority = new Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[1];

            // obtain a reference to the current project as an IVsProject type
            Microsoft.VisualStudio.Shell.Interop.IVsProject VsProject = VsHelper.ToVsProject(GetProject());
            // this locates, and returns a handle to our source file, as a ProjectItem
            VsProject.IsDocumentInProject(InputFilePath, out iFound, pdwPriority, out itemId);


            // if our source file was found in the project (which it should have been)
            if (iFound != 0 && itemId != 0)
            {
                Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp = null;
                VsProject.GetItemContext(itemId, out oleSp);
                if (oleSp != null)
                {
                    ServiceProvider sp = new ServiceProvider(oleSp);
                    // convert our handle to a ProjectItem
                    item = sp.GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem;
                }
                else
                {
                    throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
                }
            }
            else
            {
                throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
            }

            // now we can start our work, iterate across all the 'elements' in our source file
            foreach (IterativeElementType element in this)
            {
                try
                {
                    // obtain a name for this target file
                    string fileName = GetFileName(element);
                    // add it to the tracking cache
                    newFileNames.Add(fileName);
                    // fully qualify the file on the filesystem
                    string strFile = Path.Combine(wszInputFilePath.Substring(0, wszInputFilePath.LastIndexOf(Path.DirectorySeparatorChar)), fileName);
                    // create the file
                    FileStream fs = File.Create(strFile);

                    try
                    {
                        // generate our target file content
                        byte[] data = GenerateContent(element);

                        // write it out to the stream
                        fs.Write(data, 0, data.Length);

                        fs.Close();

                        // add the newly generated file to the solution, as a child of the source file...
                        EnvDTE.ProjectItem itm = item.ProjectItems.AddFromFile(strFile);

                        /*
                         * Here you may wish to perform some addition logic
                         * such as, setting a custom tool for the target file if it
                         * is intented to perform its own generation process.
                         * Or, set the target file as an 'Embedded Resource' so that
                         * it is embedded into the final Assembly.
                         *
                         * EnvDTE.Property prop = itm.Properties.Item("CustomTool");
                         */

                        //// set to embedded resource
                        itm.Properties.Item("BuildAction").Value = 3;

                        /*
                         * if (String.IsNullOrEmpty((string)prop.Value) || !String.Equals((string)prop.Value, typeof(AnotherCustomTool).Name))
                         * {
                         *  prop.Value = typeof(AnotherCustomTool).Name;
                         * }
                         */
                    }
                    catch (Exception)
                    {
                        fs.Close();
                        if (File.Exists(strFile))
                        {
                            File.Delete(strFile);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            // perform some clean-up, making sure we delete any old (stale) target-files
            foreach (EnvDTE.ProjectItem childItem in item.ProjectItems)
            {
                if (!(childItem.Name.EndsWith(GetMultiExtension()) || newFileNames.Contains(childItem.Name)))
                {
                    // then delete it
                    childItem.Delete();
                }
            }

            // generate our summary content for our 'single' file
            byte[] summaryData = GenerateSummaryContent();

            if (summaryData == null)
            {
                rgbOutputFileContents[0] = IntPtr.Zero;

                pcbOutput = 0;
            }
            else
            {
                // return our summary data, so that Visual Studio may write it to disk.
                rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(summaryData.Length);
                Marshal.Copy(summaryData, 0, rgbOutputFileContents[0], summaryData.Length);

                pcbOutput = (uint)summaryData.Length;
            }

            return(VSConstants.S_OK);
        }
        public int Generate(string inputFilePath, string inputFileContents, string defaultNamespace,
                            IntPtr[] rgbOutputFileContents,
                            out uint output,
                            IVsGeneratorProgress generateProgress)
        {
            try
            {
                if (cancelGenerating)
                {
                    byte[] fileData = File.ReadAllBytes(Path.ChangeExtension(inputFilePath, GetDefaultExtension()));

                    // Return our summary data, so that Visual Studio may write it to disk.
                    //outputFileContents = Marshal.AllocCoTaskMem(fileData.Length);
                    rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(fileData.Length);

                    //Marshal.Copy(fileData, 0, outputFileContents, fileData.Length);
                    Marshal.Copy(fileData, 0, rgbOutputFileContents[0], fileData.Length);


                    //output = fileData.Length;
                    output = (uint)fileData.Length;

                    //return 0;
                    return(VSConstants.E_ABORT); // ??????
                }

                this.inputFileContents = inputFileContents;
                this.inputFilePath     = inputFilePath;
                this.defaultNamespace  = defaultNamespace;

                int         iFound = 0;
                uint        itemId = 0;
                ProjectItem projectItem;

                Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[] pdwPriority = new Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[1];

                // Obtain a reference to the current project as an IVsProject type
                Microsoft.VisualStudio.Shell.Interop.IVsProject VsProject = VsHelper.ToVsProject(project);

                // This locates, and returns a handle to our source file, as a ProjectItem
                VsProject.IsDocumentInProject(InputFilePath, out iFound, pdwPriority, out itemId);

                // If our source file was found in the project (which it should have been)
                if (iFound != 0 && itemId != 0)
                {
                    Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp = null;

                    VsProject.GetItemContext(itemId, out oleSp);

                    if (oleSp != null)
                    {
                        ServiceProvider sp = new ServiceProvider(oleSp);

                        // Convert our handle to a ProjectItem
                        projectItem = sp.GetService(typeof(ProjectItem)) as ProjectItem;
                    }
                    else
                    {
                        throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
                    }
                }
                else
                {
                    throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
                }

                oldFileNames.Clear();
                newFileNames.Clear();

                foreach (ProjectItem childItem in projectItem.ProjectItems)
                {
                    oldFileNames.Add(childItem.Name);

                    if (!childItem.Name.EndsWith(".cs"))
                    {
                        childItem.Properties.Item("BuildAction").Value = 0;
                    }
                }

                // Now we can start our work, iterate across all the 'items' in our source file
                foreach (T item in this)
                {
                    // Obtain a name for this target file
                    string fileName = GetFileName(item);
                    // Add it to the tracking cache
                    newFileNames.Add(fileName);
                    // Fully qualify the file on the filesystem
                    string filePath = Path.Combine(Path.GetDirectoryName(inputFilePath), fileName);

                    if (!(item as IChangable).IsChanged && File.Exists(filePath))
                    {
                        continue;
                    }

                    try
                    {
                        bool isNewAdded = !oldFileNames.Contains(fileName);

                        if (!isNewAdded)
                        {
                            // Check out this file.
                            if (project.DTE.SourceControl.IsItemUnderSCC(filePath) &&
                                !project.DTE.SourceControl.IsItemCheckedOut(filePath))
                            {
                                project.DTE.SourceControl.CheckOutItem(filePath);
                            }
                        }

                        // Create the file
                        FileStream fs = File.Create(filePath);

                        try
                        {
                            // Generate our target file content
                            byte[] data = GenerateContent(item);

                            // Write it out to the stream
                            fs.Write(data, 0, data.Length);

                            fs.Close();

                            OnFileGenerated(filePath, isNewAdded);

                            /*
                             * Here you may wish to perform some addition logic
                             * such as, setting a custom tool for the target file if it
                             * is intented to perform its own generation process.
                             * Or, set the target file as an 'Embedded Resource' so that
                             * it is embedded into the final Assembly.
                             *
                             * EnvDTE.Property prop = itm.Properties.Item("CustomTool");
                             *
                             * if (String.IsNullOrEmpty((string)prop.Value) || !String.Equals((string)prop.Value, typeof(AnotherCustomTool).Name))
                             * {
                             *  prop.Value = typeof(AnotherCustomTool).Name;
                             * }
                             */
                        }
                        catch (Exception ex) // An error generating the content and writing to file. Not fatal?
                        {
                            fs.Close();

                            OnError(ex);

                            LogException(ex);
                        }
                    }
                    catch (Exception ex) // An error during core SS and/or file system operations. This is thrown to parent.
                    {
                        throw ex;
                    }
                }

                // Perform some clean-up, making sure we delete any old (stale) target-files
                foreach (ProjectItem childItem in projectItem.ProjectItems)
                {
                    if (!(childItem.Name.EndsWith(GetDefaultExtension()) || newFileNames.Contains(childItem.Name)))
                    {
                        // Then delete it
                        childItem.Delete();
                    }
                }

                foreach (var newFileName in newFileNames)
                {
                    if (!oldFileNames.Contains(newFileName))
                    {
                        string fileName = Path.Combine(inputFilePath.Substring(0, inputFilePath.LastIndexOf(Path.DirectorySeparatorChar)), newFileName);

                        // Add the newly generated file to the solution, as a child of the source file...
                        ProjectItem itm = projectItem.ProjectItems.AddFromFile(fileName);

                        // Set buildaction to none
                        if (!newFileName.EndsWith(".cs"))
                        {
                            itm.Properties.Item("BuildAction").Value = 0;
                        }
                    }
                }

                // Generate our summary content for our 'single' file
                byte[] summaryData = GenerateSummaryContent();


                if (summaryData == null)
                {
                    //outputFileContents = IntPtr.Zero;
                    rgbOutputFileContents[0] = IntPtr.Zero;
                    output = 0;
                }
                else
                {
                    // Return our summary data, so that Visual Studio may write it to disk.
                    //outputFileContents = Marshal.AllocCoTaskMem(summaryData.Length);
                    rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(summaryData.Length);

                    // Marshal.Copy(summaryData, 0, outputFileContents, summaryData.Length);
                    Marshal.Copy(summaryData, 0, rgbOutputFileContents[0], summaryData.Length);

                    output = (uint)summaryData.Length;
                }
            }
            catch (Exception ex)
            {
                OnError(ex);

                LogException(ex);

                //outputFileContents = IntPtr.Zero;
                rgbOutputFileContents[0] = IntPtr.Zero;
                output = 0;
            }


            return(VSConstants.S_OK);
        }
Пример #4
0
        protected override byte[] GenerateCode(string inputFileContent)
        {
            List <string> newFileNames     = new List <string>();
            string        wszInputFilePath = InputFilePath;

            byte[] returnValue = null;

            int  iFound = 0;
            uint itemId = 0;

            EnvDTE.ProjectItem item;
            Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[] pdwPriority = new Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[1];

            // obtain a reference to the current project as an IVsProject type
            Microsoft.VisualStudio.Shell.Interop.IVsProject VsProject = VsHelper.ToVsProject(GetProject());
            // this locates, and returns a handle to our source file, as a ProjectItem
            VsProject.IsDocumentInProject(InputFilePath, out iFound, pdwPriority, out itemId);

            // if our source file was found in the project (which it should have been)
            if (iFound != 0 && itemId != 0)
            {
                Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp = null;
                VsProject.GetItemContext(itemId, out oleSp);
                if (oleSp != null)
                {
                    ServiceProvider sp = new ServiceProvider(oleSp);
                    // convert our handle to a ProjectItem
                    item = sp.GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem;
                }
                else
                {
                    throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
                }
            }
            else
            {
                throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
            }

            foreach (EnvDTE.ProjectItem childItem in item.ProjectItems)
            {
                if ((childItem.Name.EndsWith(GetDefaultExtension()) /*|| newFileNames.Contains(childItem.Name)*/))
                {
                    // then delete it
                    childItem.Delete();
                }
            }

            // now we can start our work, iterate across all the 'elements' in our source file
            IEnumerable <IterativeElementType> elements = GenerateElements(inputFileContent);

            if (elements != null)
            {
                int count = 0;
                if (typeof(System.Collections.ICollection).IsAssignableFrom(elements.GetEnumerator().GetType()))
                {
                    count = (elements.GetEnumerator() as System.Collections.ICollection).Count;
                }
                int    i             = 0;
                string firstFileName = null;
                foreach (IterativeElementType element in elements)
                {
                    // obtain a name for this target file
                    string fileName = GetFileName(element);

                    // generate our target file content
                    byte[] data = GenerateContent(element);

                    if (returnValue == null)
                    {
                        returnValue   = data;
                        firstFileName = fileName;
                        continue;
                    }

                    // add it to the tracking cache
                    newFileNames.Add(fileName);
                    // fully qualify the file on the filesystem
                    string strFile = Path.Combine(
                        wszInputFilePath.Substring(0, wszInputFilePath.LastIndexOf(Path.DirectorySeparatorChar)),
                        fileName);
                    // create the file
                    bool err = true;
                    try
                    {
                        using (FileStream fs = File.Create(strFile))
                        {
                            // write it out to the stream
                            fs.Write(data, 0, data.Length);
                        }

                        // add the newly generated file to the solution, as a child of the source file...
                        EnvDTE.ProjectItem itm = item.ProjectItems.AddFromFile(strFile);

                        /*
                         * Here you may wish to perform some addition logic
                         * such as, setting a custom tool for the target file if it
                         * is intented to perform its own generation process.
                         * Or, set the target file as an 'Embedded Resource' so that
                         * it is embedded into the final Assembly.
                         *
                         * EnvDTE.Property prop = itm.Properties.Item("CustomTool");
                         * //// set to embedded resource
                         * itm.Properties.Item("BuildAction").Value = 3;
                         * if (String.IsNullOrEmpty((string)prop.Value) || !String.Equals((string)prop.Value, typeof(AnotherCustomTool).Name))
                         * {
                         *  prop.Value = typeof(AnotherCustomTool).Name;
                         * }
                         */
                        err = false;
                    }
                    finally
                    {
                        if (err && File.Exists(strFile))
                        {
                            File.Delete(strFile);
                        }
                    }

                    if (this.CodeGeneratorProgress != null)
                    {
                        //Report that we are 1/2 done
                        this.CodeGeneratorProgress.Progress((uint)i, (uint)count);
                    }

                    i++;
                }
            }
            //if (i == 1)
            //    _fileName = firstFileName;
            // perform some clean-up, making sure we delete any old (stale) target-files
            //foreach (EnvDTE.ProjectItem childItem in item.ProjectItems)
            //{
            //    if ((childItem.Name.EndsWith(GetDefaultExtension()) /*|| newFileNames.Contains(childItem.Name)*/))
            //        // then delete it
            //        childItem.Delete();
            //}

            return(returnValue);
        }
Пример #5
0
        public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput,
                            IVsGeneratorProgress pGenerateProgress)
        {
            if (bstrInputFileContents == null)
            {
                throw new ArgumentNullException(bstrInputFileContents);
            }


            codeFilePath = wszInputFilePath;
            codeFileNameSpace = wszDefaultNamespace;
            codeGeneratorProgress = pGenerateProgress;

            int documentFound = 0;
            uint itemId = 0;
            EnvDTE.ProjectItem item = null;
            Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[] pdwPriority = new Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[1];

            // obtain a reference to the current project as an IVsProject type
            Microsoft.VisualStudio.Shell.Interop.IVsProject VsProject = VsHelper.ToVsProject(project);

            // this locates, and returns a handle to our source file, as a ProjectItem
            VsProject.IsDocumentInProject(wszInputFilePath, out documentFound, pdwPriority, out itemId);

            // if our source file was not found in the project (which it should have been)
            if (documentFound == 0 || itemId == 0)
            {
                // Return E_FAIL to inform Visual Studio that the generator has failed (so that no file gets generated)
                pcbOutput = 0;
                return VSConstants.E_FAIL;
            }

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp = null;
            VsProject.GetItemContext(itemId, out oleSp);

            if (oleSp == null)
            {
                // Return E_FAIL to inform Visual Studio that the generator has failed (so that no file gets generated)
                pcbOutput = 0;
                return VSConstants.E_FAIL;
            }

            // convert our handle to a ProjectItem
            item = new ServiceProvider(oleSp).GetService(typeof(EnvDTE.ProjectItem))
                        as EnvDTE.ProjectItem;

            //compile the typeSql
            var compileResult = TypeSqlCompiler.Compile(bstrInputFileContents, Path.GetFileNameWithoutExtension(wszInputFilePath), DetermineTargetLanguage());

            //create the raw-sql file
            //if the original type-sql file was named with a .sql extension, they we'll call the raw sql file {originalFileNameWithoutExtension}_raw.sql
            string sqlFilePath = Path.GetExtension(wszInputFilePath).Equals(".sql", StringComparison.InvariantCultureIgnoreCase) 
                ? Path.Combine(Path.GetDirectoryName(wszInputFilePath), Path.GetFileNameWithoutExtension(wszInputFilePath) + "_raw" + ".sql")
                : Path.Combine(Path.GetDirectoryName(wszInputFilePath), Path.GetFileNameWithoutExtension(wszInputFilePath) + ".sql");

            using (var fileStream = File.CreateText(sqlFilePath))
            {
                fileStream.Write(compileResult.RawSql);
                fileStream.Close();
            }

            EnvDTE.ProjectItem sqlProjectItem = item.ProjectItems.AddFromFile(sqlFilePath);

            //now write the DAO-code to be written, via the normal interface the Generate method expects:
            // The contract between IVsSingleFileGenerator implementors and consumers is that 
            // any output returned from IVsSingleFileGenerator.Generate() is returned through  
            // memory allocated via CoTaskMemAlloc(). Therefore, we have to convert the 
            // byte[] array returned from GenerateCode() into an unmanaged blob.  

            var daoBytes = Encoding.UTF8.GetBytes(compileResult.Dao);
            int outputLength = daoBytes.Length;
            rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength);
            Marshal.Copy(daoBytes, 0, rgbOutputFileContents[0], outputLength);

            pcbOutput = (uint)outputLength;
            return VSConstants.S_OK;



        }
Пример #6
0
        public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            try
            {
                bool oldVsProject = site.GetType().IsCOMObject;
                InputFileContents      = bstrInputFileContents;
                InputFilePath          = wszInputFilePath;
                _codeGeneratorProgress = pGenerateProgress;
                _newFileNames.Clear();

                int  iFound = 0;
                uint itemId = 0;
                EnvDTE.ProjectItem item;
                Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[] pdwPriority = new Microsoft.VisualStudio.Shell.Interop.VSDOCUMENTPRIORITY[1];

                // obtain a reference to the current project as an IVsProject type
                //Microsoft.VisualStudio.Shell.Interop.IVsProject VsProject = VsHelper.ToVsProject(_project);
                Microsoft.VisualStudio.Shell.Interop.IVsProject VsProject;
                if (oldVsProject)
                {
                    VsProject = VsHelper.ToVsProject(_project);
                }
                else
                {
                    VsProject = VsHelper.ToNewVsProject(_project, (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_project.DTE);
                }
                // this locates, and returns a handle to our source file, as a ProjectItem
                VsProject.IsDocumentInProject(InputFilePath, out iFound, pdwPriority, out itemId);


                // if our source file was found in the project (which it should have been)
                if (iFound != 0 && itemId != 0)
                {
                    VsProject.GetItemContext(itemId, out Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp);
                    if (oleSp != null)
                    {
                        var sp = new ServiceProvider(oleSp);
                        // convert our handle to a ProjectItem
                        item = sp.GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem;
                    }
                    else
                    {
                        throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
                    }
                }
                else
                {
                    throw new ApplicationException("Unable to retrieve Visual Studio ProjectItem");
                }

                var generatePath = Path.GetDirectoryName(wszInputFilePath);
                var configPath   = Path.Combine(generatePath, "gen.config");
                var genTypes     = (from line in File.ReadAllLines(configPath)
                                    where !line.StartsWith("//", StringComparison.Ordinal)
                                    where !string.IsNullOrWhiteSpace(line)
                                    select line).ToArray();
                var siFileName = Path.GetFileName(wszInputFilePath);

                Debug.WriteLine("Start Custom Tool.");
                int    lineCount = bstrInputFileContents.Split('\n').Length;
                byte[] bytes     = Encoding.UTF8.GetBytes(lineCount.ToString() + " LOC");
                int    length    = bytes.Length;
                rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(length);
                Marshal.Copy(bytes, 0, rgbOutputFileContents[0], length);
                pcbOutput = (uint)length;
                // Use ProcessStartInfo class.
                var startInfo = new ProcessStartInfo
                {
                    FileName               = "java.exe",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    WorkingDirectory       = Path.GetDirectoryName(_project.FullName)
                };

                bool isfirst = true;
                var  args    = new StringBuilder();
                foreach (var type in genTypes)
                {
                    if (isfirst)
                    {
                        args.Append($"-jar \"{type}\" \"{wszInputFilePath}\"");
                        isfirst = false;
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(type) && !type.StartsWith("//"))
                        {
                            var genComps = type.Split();
                            if (genComps.Length == 1)
                            {
                                args.Append($" -o \"{generatePath}\" {type}");
                            }
                            else
                            {
                                args.Append(" -o \"" + generatePath + type.Substring(type.IndexOf(" ")).Trim() + "\" " + genComps[0]);
                                Directory.CreateDirectory(generatePath + type.Substring(type.IndexOf(" ")).Trim());
                            }
                        }
                    }
                }
                startInfo.Arguments = args.ToString();

                try
                {
                    // Start the process with the info we specified.
                    // Call WaitForExit and then the using-statement will close.
                    using (var exeProcess = Process.Start(startInfo))
                    {
                        exeProcess.WaitForExit();

                        //var output = "";
                        //while (!exeProcess.StandardOutput.EndOfStream)
                        //{
                        //    output += exeProcess.StandardOutput.ReadLine() + "\n";
                        //}
                        var sb = new StringBuilder();
                        while (!exeProcess.StandardOutput.EndOfStream)
                        {
                            sb.AppendLine(exeProcess.StandardOutput.ReadLine());
                        }
                        var output = sb.ToString();

                        bool start = false;
                        foreach (var oline in Regex.Split(output, "\r\n|\r|\n"))
                        {
                            if (genTypes.Contains(oline) || genTypes.Any(x => x.StartsWith(oline)))
                            {
                                start = true;
                            }

                            if (start)
                            {
                                if (!string.IsNullOrEmpty(oline) && !oline.Trim().StartsWith("(") && !genTypes.Contains(oline))
                                {
                                    _newFileNames.Add(oline.Substring(oline.IndexOf(":") + 2).Trim());
                                }
                            }
                        }

                        if (output.Contains("ParseException"))
                        {
                            var exception = output.Substring(output.IndexOf("ParseException"));
                            exception = exception.Substring(0, exception.IndexOf('\n'));

                            uint line   = uint.Parse(exception.Split(new string[] { " line " }, StringSplitOptions.None)[1].Split(',')[0]) - 1;
                            uint column = uint.Parse(exception.Split(new string[] { " column " }, StringSplitOptions.None)[1].Split('.')[0]) - 1;

                            GeneratorError(4, output.Replace("\n", " "), line, column);

                            foreach (EnvDTE.ProjectItem childItem in item.ProjectItems)
                            {
                                childItem.Delete();
                            }
                            return(VSConstants.E_FAIL);
                        }
                        else if (output.Contains("bbd.jportal.TokenMgrError"))
                        {
                            var exception = output.Substring(output.IndexOf("bbd.jportal.TokenMgrError"));
                            exception = exception.Substring(0, exception.IndexOf('\n'));

                            uint line   = uint.Parse(exception.Split(new string[] { " line " }, StringSplitOptions.None)[1].Split(',')[0]) - 1;
                            uint column = uint.Parse(exception.Split(new string[] { " column " }, StringSplitOptions.None)[1].Split('.')[0]) - 1;

                            GeneratorError(4, output.Replace("\n", " "), line, column);

                            foreach (EnvDTE.ProjectItem childItem in item.ProjectItems)
                            {
                                childItem.Delete();
                            }
                            return(VSConstants.E_FAIL);
                        }
                    }
                }
                catch (Exception ex)
                {
                    pcbOutput = 0;
                    GeneratorError(4, ex.ToString(), 0, 0);
                    File.WriteAllText("sifilegenerator.log", "Si file generation failed for: " + Directory.GetCurrentDirectory() + "\r\n");
                    File.AppendAllText("sifilegenerator.log", ex.Message + "\n\n" + ex.StackTrace + "\n\n" + ex.InnerException);
                    File.AppendAllText("sifilegenerator.log", Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                    return(VSConstants.E_FAIL);
                }

                foreach (var pfile in _newFileNames.ToList())
                {
                    try
                    {
                        if (File.Exists(pfile) && Directory.GetParent(pfile).FullName == generatePath)
                        {
                            EnvDTE.ProjectItem itm = item.ProjectItems.AddFromFile(pfile);
                        }
                        else
                        {
                            _newFileNames.Remove(pfile);
                        }
                    }
                    catch (COMException) { }
                }

                /*
                 * Here you may wish to perform some addition logic
                 * such as, setting a custom tool for the target file if it
                 * is intented to perform its own generation process.
                 * Or, set the target file as an 'Embedded Resource' so that
                 * it is embedded into the final Assembly.
                 *
                 * EnvDTE.Property prop = itm.Properties.Item("CustomTool");
                 * //// set to embedded resource
                 * itm.Properties.Item("BuildAction").Value = 3;
                 * if (String.IsNullOrEmpty((string)prop.Value) || !String.Equals((string)prop.Value, typeof(AnotherCustomTool).Name))
                 * {
                 *  prop.Value = typeof(AnotherCustomTool).Name;
                 *          }
                 */

                // perform some clean-up, making sure we delete any old (stale) target-files
                foreach (EnvDTE.ProjectItem childItem in item.ProjectItems)
                {
                    if (!_newFileNames.Select(x => x.Substring(x.LastIndexOf("\\") + 1)).Contains(childItem.Name))
                    {
                        // then delete it
                        childItem.Delete();
                    }
                }

                // generate our summary content for our 'single' file
                byte[] summaryData = GenerateSummaryContent();

                if (summaryData == null)
                {
                    rgbOutputFileContents[0] = IntPtr.Zero;
                    pcbOutput = 0;
                }
                else
                {
                    // return our summary data, so that Visual Studio may write it to disk.
                    rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(summaryData.Length);
                    Marshal.Copy(summaryData, 0, rgbOutputFileContents[0], summaryData.Length);
                    pcbOutput = (uint)summaryData.Length;
                }
            }
            catch (Exception e)
            {
                pcbOutput = 0;
                GeneratorError(4, e.ToString(), 0, 0);
                var errorPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "SiFileGenerator");
                if (!Directory.Exists(errorPath))
                {
                    Directory.CreateDirectory(errorPath);
                }
                var filePath = Path.Combine(errorPath, "Error.txt");

                using (var writer = new StreamWriter(filePath, true))
                {
                    writer.WriteLine(e);
                    writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }

                return(VSConstants.E_FAIL);
            }

            return(VSConstants.S_OK);
        }