BondInEtwLinqpadDriver.BondDynamicDriver.GetSchemaAndBuildAssembly C# (CSharp) Method

GetSchemaAndBuildAssembly() public method

Builds an assembly containing a typed data context, and returns data for the Schema Explorer.
public GetSchemaAndBuildAssembly ( IConnectionInfo cxInfo, AssemblyName assemblyToBuild, string &nameSpace, string &typeName ) : List
cxInfo IConnectionInfo Connection information, as entered by the user
assemblyToBuild System.Reflection.AssemblyName Name and location of the target assembly to build
nameSpace string The suggested namespace of the typed data context. You must update this /// parameter if you don't use the suggested namespace.
typeName string The suggested type name of the typed data context. You must update this /// parameter if you don't use the suggested type name.
return List
        public override List<ExplorerItem> GetSchemaAndBuildAssembly(
            IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            Stopwatch sw = Stopwatch.StartNew();

            nameSpace = @"System.Reactive.Tx";
            typeName = "PlaybackClass";

            var sourceCode = new List<string>();
            var sbContextUsings = new StringBuilder();
            var sbContextProperties = new StringBuilder();

            var dataContext = DataContextTemplate.Replace(@"[usings]", sbContextUsings.ToString())
                                                 .Replace(@"[properties]", sbContextProperties.ToString());

            var bondInEtwProperties = new BondInEtwProperties(cxInfo);
            _typeCache.Initialize(bondInEtwProperties.ContextName, bondInEtwProperties.Files);

            sourceCode.Add(dataContext);

            //Build Assembly - CSharpCodeProvider to compile generated code.

            var outputName = assemblyToBuild.CodeBase;

            using (
                var codeProvider =
                    new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } }))
            {
                string[] assemblies = this.GetAssembliesToAdd(cxInfo).ToArray();

                var compilerOptions = new CompilerParameters(assemblies, outputName, true);

                var results = codeProvider.CompileAssemblyFromSource(compilerOptions, sourceCode.ToArray());

                if (results.Errors.Count > 0)
                {
                    var sbErrors = new StringBuilder();

                    foreach (var error in results.Errors)
                    {
                        sbErrors.Append(error);
                    }

                    MessageBox.Show(sbErrors.ToString(), "Error compiling generated code.");
                }
            }

            var controller = new EventStatisticCache();
            var stat = controller.GetTypeStatistics(_typeCache, bondInEtwProperties.Files);

            sw.Stop();

            Console.WriteLine("Complete operation took {0} milliseconds.", sw.ElapsedMilliseconds);

            return this.CreateEventTree(stat);
        }