public static string FormatMethod(ModelActionInfo info) { //Format: // Command cmd = conn.createcommand(); StringBuilder buffer = new StringBuilder(100); //Return if (info.RetVal != null) { Model output = info.RetVal as Model; if (output != null) { //Type if (info.Created) { buffer.Append(output.GetType().Name); buffer.Append(" "); } //Variable buffer.Append(output.Name); buffer.Append(output.Id); buffer.Append(" = "); } } //Call buffer.Append(info.Action.Model.Name); if (!info.Action.Method.IsStatic) { buffer.Append(info.Action.Model.Id); } buffer.Append("."); buffer.Append(info.Action.Name); //Parameters buffer.Append("("); if (info.Parameters != null) { int ordinal = 0; foreach (ModelParameter parameter in info.Parameters) { if (ordinal++ > 0) { buffer.Append(", "); } FormatValue(buffer, parameter.Type, parameter.Value.Value); } } buffer.Append(")"); buffer.Append(";"); //Output return(buffer.ToString()); }
private void ExecuteActionInfo(ModelActionInfo actioninfo) { ModelAction action = actioninfo.Action; ModelParameters parameters = actioninfo.Parameters; Model model = action.Model; //Pre-Execute, events //Note: If CallBefore returns false, we simply don't execute the method if (model.OnCallBefore(action, parameters)) { //Adding the selected action (and its param values) to the trace. if (this.Options.Tracing) { _actionstrace.Add(actioninfo); } //Execute the method (delegate) actioninfo.RetVal = action.Execute(parameters); _actionscalled++; //Add the returned model to the system Model output = actioninfo.RetVal as Model; if (output != null) { //If it doesn't already exist, and the model type is part of the set if (this.Models.FindInstance(output) == null) { actioninfo.Created = true; //Add returned models, if requested if (this.Options.AddReturnedModels) { //Note: We always obey the maxinstance count Models found = (Models)this.Models.FindType(output.GetType()).FindFlag((int)ModelItemFlags.Disabled, false); if (found.Count < output.MaxInstances) { output.Enabled = true; //Enabled by default if (output.ParentModel == null) //Hook up the creator, if not already specified { output.ParentModel = action.Model; } this.Models.Add(output); } } } } //Trace if (this.Options.Tracing) { ModelTrace.WriteLine(ModelTrace.FormatMethod(actioninfo)); } //Post-Execute, events model.OnCallAfter(action, parameters, actioninfo.RetVal); } //Reset cached variables foreach (ModelVariable variable in this.Models.Variables) { variable.CachedValue = null; } }