Meta.TemplateProfiler.Execute C# (CSharp) Method

Execute() private method

private Execute ( ) : void
return void
        private void Execute()
        {
            try
            {
                if (cancelProfile)
                    return;

                profilePane.Clear();
                profilePane.OutputStringThreadSafe("Profiling Instantiations on " + filename + ":" + Environment.NewLine + Environment.NewLine);
                profilePane.Activate();
                VCFile file = clTool.GetVCFile(filename);
                string preprocessorArgs = clTool.GenerateCLCmdArgs(filename, false);
                string profileArgs = clTool.GenerateCLCmdArgs(filename, true);
                string clWithEnv = clTool.CompilerExecutableWithEnvAsCmdArgs;

                if (!System.IO.File.Exists(file.FullPath))
                    return;

                string workingDirectory = clTool.Project.ProjectDirectory;
                VCFileConfiguration fileConfig = clTool.GetActiveFileConfiguration(filename);
                if (fileConfig != null)
                {
                    VCCLCompilerTool tool = (VCCLCompilerTool)fileConfig.Tool;
                    if (tool != null)
                    {
                        //var originalOption = tool.GeneratePreprocessedFile;
                        string intermediateDir = clTool.Project.ProjectDirectory + @"\" + fileConfig.Evaluate(VCCompilerHelper.ProjectMacros.IntDir);
                        string outputPreprocessed = intermediateDir + @"\" + Path.GetFileNameWithoutExtension(filename) + ".instrumented";
                        string outputPreprocessedCpp = workingDirectory + @"\" + Path.GetFileNameWithoutExtension(filename) + ".instrumented.cpp";
                        string outputProfile = intermediateDir + "\\" + Path.GetFileNameWithoutExtension(filename) + ".template.profile";

                        //! Preprocess the file.
                        try
                        {
                            profilePane.OutputStringThreadSafe("Instrumenting Code..." + Environment.NewLine);
                            Instrument(clWithEnv, preprocessorArgs, workingDirectory, file.RelativePath, outputPreprocessed);
                            if (cancelProfile)
                            {
                                profilePane.OutputStringThreadSafe(Environment.NewLine + "User canceled profile." + Environment.NewLine);
                                return;
                            }
                            if (!File.Exists(outputPreprocessed))
                                throw new FileNotFoundException(outputPreprocessed);

                            //profilePane.OutputStringThreadSafe("Processing Instrumented Code..." + Environment.NewLine);
                            NativeMethods.TemplateProfilePreprocess(outputPreprocessed, outputPreprocessedCpp);
                        }
                        catch( FileNotFoundException /*ex*/ )
                        {
                            profilePane.OutputStringThreadSafe("Unable to preprocess " + filename + ". Please check that the file compiles and try again." + Environment.NewLine );
                            return;
                        }
                        catch (System.Exception ex)
                        {
                            profilePane.OutputStringThreadSafe(ex.Message);
                            return;
                        }
                        finally
                        {
                            File.Delete(outputPreprocessed);
                        }

                        //! Now compile the output and put the output into another file to be input to the postprocessor.
                        try
                        {
                            profilePane.OutputStringThreadSafe("Running Profile..." + Environment.NewLine);
                            Profile(clWithEnv, profileArgs, workingDirectory, outputPreprocessedCpp, outputProfile);
                            if (cancelProfile)
                            {
                                profilePane.OutputStringThreadSafe(Environment.NewLine + "User canceled profile." + Environment.NewLine);
                                return;
                            }
                        }
                        catch (System.Exception ex)
                        {
                            profilePane.OutputStringThreadSafe(ex.Message);
                            return;
                        }
                        finally
                        {
                            File.Delete(outputPreprocessedCpp);
                            File.Delete(outputPreprocessed + ".obj");
                        }

                        try
                        {
                            profilePane.OutputStringThreadSafe("Finalizing Data..." + Environment.NewLine);
                            IntStringDelegate log = new IntStringDelegate(profilePane.OutputStringThreadSafe);
                            NativeMethods.TemplateProfilePostProcess(outputProfile, log);
                            if (cancelProfile)
                            {
                                profilePane.OutputStringThreadSafe(Environment.NewLine + "User canceled profile." + Environment.NewLine);
                                return;
                            }
                        }
                        catch (System.Exception ex)
                        {
                            profilePane.OutputStringThreadSafe(ex.Message);
                        }
                        finally
                        {
                            File.Delete(outputProfile);
                        }
                    }
                }
            }
            finally
            {
                signalFinished();
            }
        }