示例#1
0
        public static ParserTask GetTask(PPather ppather, NodeTask node)
        {
            //		string s = "";

            //		foreach (string key in registeredTasks.Keys)
            //			s += key + ",";

            //		PPather.WriteLine("Types: " + s);

            if (!registeredTasks.ContainsKey(node.type))
            {
                PPather.WriteLine("No registered task for " + node.type);
                return(null);
            }

            //PPather.WriteLine("Attempting to instantiate " + registeredTasks[node.type]);
            // (In some big task files, the above line can crash Glider)

            ConstructorInfo ci = null;
            Object          o  = null;

            try
            {
                ci = registeredTasks[node.type].GetConstructor(new Type[] { ppather.GetType(), node.GetType() });
                o  = ci.Invoke(new object[] { ppather, node });
            }
            catch (Exception e)
            {
                // an exception here is fatal, popup a dialog
                // to give some feedback and rethrow the error
                string s = "Error instantiating \"" + node.type + "\" task\n\n" + e.GetType().FullName + "\n" + e.Message;

                if (null != e.InnerException)
                {
                    s += "\n\nInner exception:" + e.InnerException.GetType().FullName + "\n" + e.InnerException.Message;
                }

                System.Windows.Forms.MessageBox.Show(s);
                throw e;
            }

            if (null == o)
            {
                PPather.WriteLine("Created null");
            }

            return((ParserTask)o);
        }