public void BuildCache()

in Source/Tx.LinqPad/TypeCache.cs [31:141]


        public void BuildCache(string targetDir, string[] traces, string[] metadaFiles)
        {
            List<string> extraAssembies = new List<string>();

            foreach (string f in metadaFiles.Concat(traces))
            {
                string output = Path.Combine(GetCacheDir(targetDir),
                                             Path.ChangeExtension(
                                                 Path.GetFileName(f),
                                                 ".dll"));

                DateTime metadataTimestamp = File.GetLastWriteTimeUtc(f);
                DateTime outputTimestamp = File.GetLastWriteTimeUtc(output);

                if (outputTimestamp == metadataTimestamp)
                    continue;

                var sources = new Dictionary<string, string>();
                switch (Path.GetExtension(f).ToLower())
                {
                    case ".man":
                    case ".manifest":
                        {
                            string manifest = File.ReadAllText(f);
                            Dictionary<string, string> s = ManifestParser.Parse(manifest);
                            foreach (string type in s.Keys)
                            {
                                if (!sources.ContainsKey(type))
                                {
                                    sources.Add(type, s[type]);
                                }
                            }
                            break;
                        }

                    case ".etl":
                        {
                            string[] manifests = ManifestParser.ExtractFromTrace(f);
                            if (manifests.Length == 0)
                                continue;

                            foreach (string manifest in manifests)
                            {
                                Dictionary<string, string> s;                                
                                try
                                {
                                    s = ManifestParser.Parse(manifest);
                                }
                                catch (XmlException)
                                {
                                    // if one manifest is bad, we should still see the other events
                                    string err = String.Format(
                                        "Malformed manifest found in the file {0}\nThe corresponding events will not be shown in the tree-control. \nHere are the first 1000 characters: \n\n{1}", f, manifest.Substring(0,1000));
                                    MessageBox.Show(err, "Tx LINQPad Driver");
                                    continue; 
                                }
 

                                foreach (string type in s.Keys)
                                {
                                    if (!sources.ContainsKey(type))
                                    {
                                        sources.Add(type, s[type]);
                                    }
                                }
                            }
                        }
                        break;

                    case ".blg":
                    case ".csv":
                    case ".tsv":
                        {
                            Dictionary<string, string> s = PerfCounterParser.Parse(f);
                            foreach (string type in s.Keys)
                            {
                                if (!sources.ContainsKey(type))
                                {
                                    sources.Add(type, s[type]);
                                }
                            }
                        }
                        break;

                    case ".evtx":
                        break;

                    case ".xel":
                        {
                            extraAssembies.Add(typeof(XEventAttribute).Assembly.Location);
                            extraAssembies.Add(typeof(CallStack).Assembly.Location);

                            Dictionary<string, string> s = XeTypeGenerator.Parse(f);
                            foreach (string type in s.Keys)
                            {
                                if (!sources.ContainsKey(type))
                                {
                                    sources.Add(type, s[type]);
                                }
                            }
                        }
                        break;

                    default:
                        throw new Exception("Unknown metadata format " + f);
                }

                AssemblyBuilder.OutputAssembly(sources, extraAssembies, output);
                File.SetLastWriteTimeUtc(output, metadataTimestamp);
            }
        }