Exemple #1
0
 public override void Generate(string wszInputFilePath,
                               string bstrInputFileContents,
                               string wszDefaultNamespace,
                               out IntPtr rgbOutputFileContents,
                               out int pcbOutput,
                               IVsGeneratorProgress pGenerateProgress)
 {
     try
     {
         byte[] data = CodeGeneratorCustomTool.GenerateUnitTestCode(wszDefaultNamespace, wszInputFilePath,
                                                                    "CSharp", "NUnit");
         if (data == null)
         {
             rgbOutputFileContents = IntPtr.Zero;
             pcbOutput             = 0;
         }
         else
         {
             rgbOutputFileContents = Marshal.AllocCoTaskMem(data.Length);
             Marshal.Copy(data, 0, rgbOutputFileContents, data.Length);
             pcbOutput = data.Length;
         }
     }
     catch (Exception e)
     {
         var applicationException = new ApplicationException("Unable to generate code", e);
         var messageBox           = new ExceptionMessageBox(applicationException);
         messageBox.Show(null);
         throw;
     }
 }
Exemple #2
0
        public override void Generate(string wszInputFilePath,
                                      string bstrInputFileContents,
                                      string wszDefaultNamespace,
                                      out IntPtr rgbOutputFileContents,
                                      out int pcbOutput,
                                      IVsGeneratorProgress pGenerateProgress)
        {
            try
            {
                var database      = CodeGeneratorCustomTool.GetDatabase(wszDefaultNamespace, wszInputFilePath);
                var codeGenerator = CodeGeneratorFactory.Create <CSharpMangoLinqToSqlCodeGenerator>(database);

                var data = CodeGeneratorCustomTool.GetData(codeGenerator);
                if (data == null)
                {
                    rgbOutputFileContents = IntPtr.Zero;
                    pcbOutput             = 0;
                }
                else
                {
                    rgbOutputFileContents = Marshal.AllocCoTaskMem(data.Length);
                    Marshal.Copy(data, 0, rgbOutputFileContents, data.Length);
                    pcbOutput = data.Length;
                }
            }
            catch (Exception e)
            {
                var applicationException = new ApplicationException("Unable to generate code", e);
                var messageBox           = new ExceptionMessageBox(applicationException);
                messageBox.Show(null);
                throw;
            }
        }
Exemple #3
0
        public override void Generate(string wszInputFilePath,
                                      string bstrInputFileContents,
                                      string wszDefaultNamespace,
                                      out IntPtr rgbOutputFileContents,
                                      out int pcbOutput,
                                      IVsGeneratorProgress pGenerateProgress)
        {
            try
            {
                var database      = CodeGeneratorCustomTool.GetDatabase(wszDefaultNamespace, wszInputFilePath);
                var factory       = new UnitTestCodeGeneratorFactory(database);
                var codeGenerator = factory.Create("xUnit");
                codeGenerator.GenerateEntities();
                codeGenerator.GenerateDataAccessLayer();

                var header = new StringBuilder();
                codeGenerator.WriteHeaderInformation(header);

                var files = new Dictionary <string, StringBuilder>(codeGenerator.CodeFiles.Count);
                foreach (var codeFile in codeGenerator.CodeFiles)
                {
                    files.Add(codeFile.Key + GetDefaultExtension(), codeFile.Value);
                }

                AddOutputToProject(wszInputFilePath, files, header);

                base.Generate(wszInputFilePath,
                              bstrInputFileContents,
                              wszDefaultNamespace,
                              out rgbOutputFileContents,
                              out pcbOutput,
                              pGenerateProgress);
            }
            catch (Exception)
            {
                var codeGen = new SQLCEXUnitCodeGenerator();
                codeGen.Generate(wszInputFilePath, bstrInputFileContents, wszDefaultNamespace, out rgbOutputFileContents,
                                 out pcbOutput, pGenerateProgress);

                //var applicationException = new ApplicationException("Unable to generate code", e);
                //var messageBox = new ExceptionMessageBox(applicationException);
                //messageBox.Show(null);
                //throw;
            }
        }
Exemple #4
0
 protected override string Generate(string wszInputFilePath, string wszDefaultNamespace)
 {
     return(CodeGeneratorCustomTool.GenerateCodeString(wszDefaultNamespace, wszInputFilePath));
 }