private void Execute(ICommandInteraction writer, LiteralToken cpuToken, String functionName, bool traceReturn, int?numberOfParameters) { var cpu = (Arm)monitor.ConvertValueOrThrowRecoverable(cpuToken.Value, typeof(Arm)); var cpuTracer = EnsureTracer(cpu); Type handlerType; IFunctionHandler handler; if (!handlers.TryGetValue(functionName, out handlerType)) { if (numberOfParameters.HasValue) { var paramList = new List <FunctionCallParameter>(); for (var i = 0; i < numberOfParameters; ++i) { paramList.Add(new FunctionCallParameter { Type = FunctionCallParameterType.UInt32 }); } FunctionCallParameter?returnParameter = null; if (traceReturn) { returnParameter = new FunctionCallParameter { Type = FunctionCallParameterType.UInt32 }; } var defHandler = new DefaultFunctionHandler(cpu); defHandler.CallParameters = paramList; defHandler.ReturnParameter = returnParameter; handler = defHandler; } else { throw new RecoverableException("Handler for {0} not register. You must provide numberOfParameters to use default handler.".FormatWith(functionName)); } } else { handler = Dynamic.InvokeConstructor(handlerType, cpu); } if (traceReturn) { cpuTracer.TraceFunction(functionName, handler.CallParameters, handler.CallHandler, handler.ReturnParameter, handler.ReturnHandler); } else { cpuTracer.TraceFunction(functionName, handler.CallParameters, handler.CallHandler); } }
/// <summary> /// Determines if the parameter accepts the value specified /// </summary> /// <param name="parameter">The function parameter</param> /// <param name="parameterValue">The parameter value</param> /// <returns>True, if it accepts the value; otherwise false</returns> internal static bool Accepts ( this FunctionParameter parameter, FunctionCallParameter parameterValue ) { Validate.IsNotNull(parameter); Validate.IsNotNull(parameterValue); switch (parameterValue.Type) { case NettleValueType.ModelBinding: case NettleValueType.Variable: // We assume the value is valid because we can't resolve the // values until the template is executed with a model return(true); } if (parameter.DataType == typeof(string)) { return ( parameterValue.Type == NettleValueType.String ); } else if (parameter.DataType.IsNumeric()) { return ( parameterValue.Type == NettleValueType.Number ); } else if (parameter.DataType == typeof(bool)) { return ( parameterValue.Type == NettleValueType.Boolean ); } else { // NOTE: // If we can't resolve the type then assume valid return(true); } }
static FunctionCallParameter() { IgnoredParameter = new FunctionCallParameter { Type = FunctionCallParameterType.Ignore }; }
static FunctionCallParameter() { IgnoredParameter = new FunctionCallParameter { Type = FunctionCallParameterType.Ignore }; }
public override void Run() { if (!(Owner is ISelectableEditor)) { return; } try { XmlEditor editor = Owner as XmlEditor; if (editor == null) { return; } _xpath = editor.SingleDirectionData.SelectedXPath.XPath; _elementName = ExtractElementName(editor.SingleDirectionData.SelectedText); _value = ExtractElementValue(editor.SingleDirectionData.SelectedText); var selectableEditor = Owner as ISelectableEditor; if (selectableEditor.Selected == null) { return; } var stepService = ServiceManager.Instance.GetService <IStepService>(); if (stepService == null) { return; } var currentStep = stepService.CurrentStep; var parserStatus = stepService.GetParserStatus(currentStep.FunctionCall.Location.FilePath); if (parserStatus == false) { MessageService.ShowMessage("Cannot add step"); return; } var functionCall = new FunctionCall(); var signature = new FunctionCallSignature { Name = this.Name }; string currentParameterName = GetCurrentStepResponseParameter(); if (!string.IsNullOrEmpty(currentParameterName)) { signature.Parameters.Add(new FunctionCallParameter(String.Format("XML={0}", currentParameterName), ParameterType.ArgtypeString)); } FillParameters(signature); functionCall.Signature = signature; functionCall.Location = new FunctionCallLocation(currentStep.FunctionCall.Location.FilePath, null, null); IStepModel stepModel = stepService.GenerateStep(functionCall); stepModel.ShowArguments(asyncResult => { var result = (ShowArgumentsResult)asyncResult.AsyncState; if (result.IsModified) { //set the last parameter to False, so it will not move cursor to the newly added step stepService.AddStep(ref stepModel, currentStep, Relative, false); if (string.IsNullOrEmpty(currentParameterName)) { FunctionCallParameter userParameter = stepModel.FunctionCall.Signature.Parameters.Find(p => { return(p.Value.StartsWith("XML=", StringComparison.InvariantCultureIgnoreCase)); }); if (userParameter != null) { SetCurrentStepResponseParameter(stepModel.ScriptItem.Script as IVuGenScript, userParameter.Value.Remove(0, 4)); } } stepService.CurrentStep = currentStep; } }); } catch (Exception ex) { Log.VuGen.Error(string.Format("Error occurred when adding the {2} step. (Type: '{0}', Exception: '{1}')", Owner.GetType(), ex, Name)); } }