public ComputationCommand Get(string archetype, string mode = "singleton") { if (mode != "singleton" && mode != "prototype") { return(null); } ComputationCommand temp = null; if (commands.TryGetValue(archetype, out temp)) { return((mode == "singleton")?temp: temp.DeepClone <ComputationCommand>()); } string classname = plugins[archetype]; if (classname == null) { return(null); } string fullpackage = classname; Type t = Type.GetType(fullpackage); if (t == null) { return(null); } commands[archetype] = (ComputationCommand)Activator.CreateInstance(t); return(commands[archetype]); }
public static bool Dispatch(string archetype, COMPUTATION_CONTEXT ctx) { ComputationCommand cmd = obj.Get(archetype); if (cmd == null) { return(false); } if (cmd.PreExecute(ctx)) { bool rs = cmd.Execute(ctx); cmd.PostExecute(ctx); return(rs); } return(false); }
public ComputationCommand Get(string archetype, string mode = "singleton") { //---- We can create a new instance, when a //---- prototype is asked, otherwise we will //---- return the same instance stored in the dictionary if (mode != "singleton" && mode != "prototype") { return(null); } ComputationCommand temp = null; //--- if an instance is already found, return // it (singleton) or clone (prototype if (commands.TryGetValue(archetype, out temp)) { return((mode == "singleton") ? temp : temp.DeepClone <ComputationCommand>()); } //---- retreive the commandclass name string classname = plugins[archetype]; if (classname == null) { return(null); } //------ retreieve the classname, if it //------ is available with CLR Type t = Type.GetType(classname); if (t == null) { return(null); } //---- Create a new Instance and store it //---- in commandclass instance dictionary commands[archetype] = (ComputationCommand)Activator.CreateInstance(t); return(commands[archetype]); }
public static bool Dispatch(string archetype, COMPUTATION_CONTEXT ctx) { ComputationCommand cmd = obj.Get(archetype); return((cmd == null) ? false : cmd.Execute(ctx)); }