/// <include file='doc\BatchParser.uex' path='docs/doc[@for="BatchTemplateParser.GetSourceReferences"]/*' /> /// <devdoc> /// </devdoc> internal SourceReference[] GetSourceReferences() { Hashtable curReferences = new Hashtable(SymbolHashCodeProvider.Default, SymbolEqualComparer.Default); // Create a SourceReference for each source file and add it the the hashtable foreach (string source in _sources) { curReferences[source] = new SourceReference(source); } for (int i = 0; i < _dependencies.Count; i++) { ArrayList deplist = (ArrayList)_dependencies[i]; SourceReference sr = (SourceReference)curReferences[((string)_sources[i])]; // Go through all the dependencies of the current SourceReference foreach (string dep in deplist) { // If the dependency is itself in the hashtable, add it as a // dependency of the SourceReference object. SourceReference srdep = (SourceReference)curReferences[dep]; if (srdep != null) { sr.AddDependency(srdep); } } } SourceReference[] result = new SourceReference[curReferences.Count]; { int k; IDictionaryEnumerator en; for (en = curReferences.GetEnumerator(), k = 0; en.MoveNext(); k++) { result[k] = (SourceReference)en.Value; } } return(result); }
/// <include file='doc\BatchParser.uex' path='docs/doc[@for="SourceReference.AddDependency"]/*' /> /// <devdoc> /// </devdoc> internal void AddDependency(SourceReference dep) { Debug.Trace("Template", "Discovered dependency: " + _filename + " depends on " + dep.Filename); _dependencies[dep] = dep; }
internal static SourceReference[][] Split(SourceReference[] input) { // First phase: compute levels in the dependency tree int totaldepth = 0; Hashtable depth = new Hashtable(); ArrayList stack = new ArrayList(); // compute depths for (int i = 0; i < input.Length; i++) { stack.Add(input[i]); while (stack.Count > 0) { SourceReference curnode = (SourceReference)stack[stack.Count - 1]; bool recurse = false; int maxdepth = 0; for (IEnumerator en = curnode.Dependencies.GetEnumerator(); en.MoveNext();) { SourceReference child = (SourceReference)en.Current; if (depth.ContainsKey(child)) { if (maxdepth <= (int)depth[child]) { maxdepth = (int)depth[child] + 1; } else if ((int)depth[child] == -1) { throw new HttpException(child.Filename + " has a circular reference!"); } } else { recurse = true; stack.Add(child); } } if (recurse) { depth[curnode] = -1; // being computed; } else { stack.RemoveAt(stack.Count - 1); depth[curnode] = maxdepth; if (totaldepth <= maxdepth) { totaldepth = maxdepth + 1; } } } } // drop into buckets by depth ArrayList[] codeLevel = new ArrayList[totaldepth]; for (IDictionaryEnumerator en = (IDictionaryEnumerator)depth.GetEnumerator(); en.MoveNext();) { int level = (int)en.Value; if (codeLevel[level] == null) { codeLevel[level] = new ArrayList(); } codeLevel[level].Add(en.Key); } // return buckets as array of arrays. SourceReference[][] result = new SourceReference[totaldepth][]; for (int i = 0; i < totaldepth; i++) { result[i] = (SourceReference[])codeLevel[i].ToArray(typeof(SourceReference)); } return(result); }