Esempio n. 1
0
        internal void foo(string virtualDir, HttpContext context)
        {
            _context = context;

            Hashtable compilableFiles = new Hashtable(SymbolHashCodeProvider.Default, SymbolEqualComparer.Default);

            string directory = _context.Request.MapPath(virtualDir) + "\\";

            UnsafeNativeMethods.WIN32_FIND_DATA wfd;
            IntPtr hFindFile = UnsafeNativeMethods.FindFirstFile(directory + "*.*", out wfd);

            // No files: do nothing
            if (hFindFile == new IntPtr(-1))
            {
                return;
            }

            try {
                // Go through all the files in the codegen dir. We use the Win32 native API's
                // directly for perf and memory usage reason (ASURT 97791)
                for (bool more = true; more; more = UnsafeNativeMethods.FindNextFile(hFindFile, out wfd))
                {
                    // Skip directories
                    if ((wfd.dwFileAttributes & UnsafeNativeMethods.FILE_ATTRIBUTE_DIRECTORY) != 0)
                    {
                        continue;
                    }

                    string         filename = directory + wfd.cFileName;
                    CompilableFile cf       = GetCompilableFileFromExtension(filename);

                    // Ignore unknown extensions
                    if (cf == null)
                    {
                        continue;
                    }

                    compilableFiles[filename] = cf;
                }
            }
            finally {
                UnsafeNativeMethods.FindClose(hFindFile);
            }

            foreach (CompilableFile cf in compilableFiles.Values)
            {
                ICollection references = cf.FileNameReferences;

                foreach (string reference in references)
                {
                    CompilableFile dependentCf = (CompilableFile)compilableFiles[reference];

                    if (dependentCf != null)
                    {
                        cf.AddDependentCompilableFile(dependentCf);
                    }
                }
            }

            CompilableFile[][] buckets = Split(compilableFiles);

#if DBG
            for (int i = 0; i < buckets.Length; i++)
            {
                CompilableFile[] bucket = buckets[i];
                Debug.Trace("Batching", "");
                Debug.Trace("Batching", "Bucket " + i + " contains " + bucket.Length + " files");

                for (int j = 0; j < bucket.Length; j++)
                {
                    Debug.Trace("Batching", bucket[j].FileName);
                }
            }
#endif
        }