public Hierarchy(IList <T> _grp, int rootLevel, GetLevelDelegate delegate1, IsParentDelegate delegate2, TreeNode <T> .GetTreeNodeValue delegate3) { mGetLevelDelegate = delegate1; mIsParentDelegate = delegate2; mEntities = _grp; MaxLevel = 0; MinLevel = 100000; int level = 0; foreach (T ent in mEntities) { level = mGetLevelDelegate(ent); if (level > MaxLevel) { MaxLevel = level; } if (level < MinLevel) { MinLevel = level; } } for (int i = MinLevel; i <= MaxLevel; ++i) { mTreeHierarchy[i] = new List <TreeNode <T> >(); } foreach (T ent in mEntities) { level = mGetLevelDelegate(ent); mTreeHierarchy[level].Add(new TreeNode <T>(ent, delegate3)); } level = MinLevel; while (level < MaxLevel) { if (level == rootLevel) { foreach (TreeNode <T> node in mTreeHierarchy[level]) { node.Root = node; } } foreach (TreeNode <T> node in mTreeHierarchy[level]) { foreach (TreeNode <T> child_node in mTreeHierarchy[level + 1]) { if (mIsParentDelegate(node.DataSource, child_node.DataSource)) { node.AddChild(child_node); } } } level++; } }
/// <summary> /// Let the caller override our delegates with their own functions... /// </summary> /// <param name="a_closedelegate">use this to close the logging session</param> /// <param name="a_getleveldelegate">get the current log level</param> /// <param name="a_opendelegate">open the logging session</param> /// <param name="a_registertwaindelegate">not needed at this time</param> /// <param name="a_setflushdelegate">turn flushing on and off</param> /// <param name="a_setleveldelegate">set the new log level</param> /// <param name="a_writeentrydelegate">the function that actually writes to the log</param> /// <param name="a_getstatedelegate">returns a way to get the current TWAIN state</param> public static void Override ( CloseDelegate a_closedelegate, GetLevelDelegate a_getleveldelegate, OpenDelegate a_opendelegate, RegisterTwainDelegate a_registertwaindelegate, SetFlushDelegate a_setflushdelegate, SetLevelDelegate a_setleveldelegate, WriteEntryDelegate a_writeentrydelegate, out GetStateDelegate a_getstatedelegate ) { Close = (a_closedelegate != null) ? a_closedelegate : CloseLocal; GetLevel = (a_getleveldelegate != null) ? a_getleveldelegate : GetLevelLocal; Open = (a_opendelegate != null) ? a_opendelegate : OpenLocal; RegisterTwain = (a_registertwaindelegate != null) ? a_registertwaindelegate : RegisterTwainLocal; SetFlush = (a_setflushdelegate != null) ? a_setflushdelegate : SetFlushLocal; SetLevel = (a_setleveldelegate != null) ? a_setleveldelegate : SetLevelLocal; WriteEntry = (a_writeentrydelegate != null) ? a_writeentrydelegate : WriteEntryLocal; a_getstatedelegate = GetStateLocal; }