Esempio n. 1
0
      int IVsSingleFileGenerator.Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
      {
         ProgressReporter reporter = new ProgressReporter(pGenerateProgress);

         bool fail = false;
         string output;
         try
         {
            output = Generate(wszInputFilePath, bstrInputFileContents, wszDefaultNamespace, new ServiceProvider(Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider).GetService(typeof(ProjectItem)) as ProjectItem, reporter);
         }
         catch (Exception ex)
         {
            output = "An unhandled exception occurred during generation; " + ex.Message;
            reporter.GenerateError(ex.Message);
            fail = true;
         }


         byte[] bytes = Encoding.UTF8.GetBytes(output);

         int outputLength = bytes.Length;
         rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength);
         Marshal.Copy(bytes, 0, rgbOutputFileContents[0], outputLength);
         pcbOutput = (uint)outputLength;

         return fail ? VSConstants.E_FAIL : VSConstants.S_OK;
      }
Esempio n. 2
0
        int IVsSingleFileGenerator.Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            ProgressReporter reporter = new ProgressReporter(pGenerateProgress);

            bool   fail = false;
            string output;

            try
            {
                output = Generate(wszInputFilePath, bstrInputFileContents, wszDefaultNamespace, new ServiceProvider(Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider).GetService(typeof(ProjectItem)) as ProjectItem, reporter);
            }
            catch (Exception ex)
            {
                output = "An unhandled exception occurred during generation; " + ex.Message;
                reporter.GenerateError(ex.Message);
                fail = true;
            }


            byte[] bytes = Encoding.UTF8.GetBytes(output);

            int outputLength = bytes.Length;

            rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength);
            Marshal.Copy(bytes, 0, rgbOutputFileContents[0], outputLength);
            pcbOutput = (uint)outputLength;

            return(fail ? VSConstants.E_FAIL : VSConstants.S_OK);
        }