private ParameterDataBuilder BuildInputParamsCommand(MethodInfo methodCall, object[] args) { ParameterDataBuilder builder = new ParameterDataBuilder(methodCall); builder.Build(args); // Bind to the out-arguments data if (builder.HasOutArg) { int index = 0; foreach (DataRow row in builder.OutArgDataTable.Rows) { if (index == 0) // skip add Return Value { continue; } Type type = (Type)row[2]; if (type.IsByRef) { type = type.GetElementType(); } paraCommands.Add(new ParaCommandInfo() { Title = string.Format("Please enter value for {0} ({1})", row[0].ToString(), type.Name), IsExecute = false, Content = string.Empty, ParameterName = row[0].ToString(), ParameterIndex = index, Type = type.ToString(), Value = null }); index++; } } return(builder); }
private ParameterDataBuilder BindGridToDataTable( IMethodCallMessage methodCall, DataGridView paramterView) { ParameterDataBuilder builder = new ParameterDataBuilder(methodCall); builder.Build(); // Bind to the in-arguments data if (builder.HasInArg) { paramterView.AutoGenerateColumns = false; paramterView.DataSource = builder.InArgDataTable; } // Bind to the out-arguments data if (builder.HasOutArg || builder.HasReturnVal) { int rowIndex = 0; tableActionResult.RowCount = builder.OutArgDataTable.Rows.Count; foreach (DataRow row in builder.OutArgDataTable.Rows) { Type type = (Type)row[2]; if (type.IsByRef) type = type.GetElementType(); if (tableActionResult.RowStyles.Count == rowIndex) tableActionResult.RowStyles.Add(new RowStyle()); tableActionResult.RowStyles[rowIndex].SizeType = SizeType.Absolute; tableActionResult.RowStyles[rowIndex].Height = 25; tableActionResult.Controls.Add(new TextBox() { Text = string.Format("{0} ({1})", row[0].ToString(), type.Name), Dock = DockStyle.Fill, ReadOnly = true, BorderStyle = BorderStyle.None }, 0, rowIndex); if (type.IsEnum) { tableActionResult.Controls.Add(new BindingEnumCombobox(builder.OutArgDataTable, rowIndex, type) { Dock = DockStyle.Fill, DropDownStyle= ComboBoxStyle.DropDownList, FlatStyle = FlatStyle.Flat }, 1, rowIndex); } else { tableActionResult.Controls.Add(new BindingTextBox(builder.OutArgDataTable, rowIndex) { Dock = DockStyle.Fill, BorderStyle = BorderStyle.None }, 1, rowIndex); } rowIndex++; } tableActionResult.Height = rowIndex * 27; } return builder; }
/// <summary> /// Proxy method for substitution of executing methods in adapter interface. /// </summary> /// <param name="mcall">The IMethodCallMessage containing method invoking data.</param> /// <returns>The IMessage containing method return data.</returns> protected override IMessage Invoke(IMethodCallMessage mcall) { // set to compat Mode to allow running of Initialize.cmd or Reset.cmd if call from IAdapter context compatMode = ((mcall.MethodName == "Initialize" || mcall.MethodName == "Reset") && AdapterType.IsAdapterTypeFullName(mcall.MethodBase.DeclaringType.FullName) ); if (compatMode) return InvokeCompat(mcall); // Build parameter on each invoke builder = new ParameterDataBuilder(mcall); builder.Build(); // Initial error message on each invoke ptfAdFailureMessage = null; object retVal = null; outArgs = mcall.Args; string methodhelp = AdapterProxyHelpers.GetHelpMessage(mcall); string arguments = BuildScriptArguments(methodhelp); // Check if this is a method from IAdapter. Any IAdapter methods should be ignored. if (!AdapterType.IsAdapterTypeFullName(mcall.MethodBase.DeclaringType.FullName) && (mcall.MethodBase.DeclaringType.FullName != typeof(IDisposable).FullName) ) { TestSite.Log.Add(LogEntryKind.EnterAdapter, "Script adapter: {0}, method: {1}", ProxyType.Name, mcall.MethodName); try { string path = LookupScript(mcall.MethodName); if (path == null) { TestSite.Assume.Fail( "The invoking script file ({0}.cmd) can not be found.", mcall.MethodName); } else { int scriptRet = InvokeScript(path, arguments); if (scriptRet != 0) { TestSite.Assume.Fail( "Script {0}.cmd exited with non-zero code. Error code: {1}. Failure message: {2}", mcall.MethodName, scriptRet, ptfAdFailureMessage); } retVal = GetReturnValue(); GetOutArgumentsValues(); } } catch (Exception ex) { TestSite.Log.Add(LogEntryKind.Debug, ex.ToString()); throw; } finally { TestSite.Log.Add(LogEntryKind.ExitAdapter, "Script adapter: {0}, method: {1}", ProxyType.Name, mcall.MethodName); } } ReturnMessage mret = new ReturnMessage( retVal, (outArgs != null && outArgs.Length > 0) ? outArgs : null, (outArgs != null) ? outArgs.Length : 0, mcall.LogicalCallContext, mcall); return mret; }
private ParameterDataBuilder BindGridToDataTable( IMethodCallMessage methodCall, DataGridView paramterView) { ParameterDataBuilder builder = new ParameterDataBuilder(methodCall); builder.Build(); // Bind to the in-arguments data if (builder.HasInArg) { paramterView.AutoGenerateColumns = false; paramterView.DataSource = builder.InArgDataTable; } // Bind to the out-arguments data if (builder.HasOutArg || builder.HasReturnVal) { int rowIndex = 0; tableActionResult.RowCount = builder.OutArgDataTable.Rows.Count; foreach (DataRow row in builder.OutArgDataTable.Rows) { Type type = (Type)row[2]; if (type.IsByRef) { type = type.GetElementType(); } if (tableActionResult.RowStyles.Count == rowIndex) { tableActionResult.RowStyles.Add(new RowStyle()); } tableActionResult.RowStyles[rowIndex].SizeType = SizeType.Absolute; tableActionResult.RowStyles[rowIndex].Height = 25; tableActionResult.Controls.Add(new TextBox() { Text = string.Format("{0} ({1})", row[0].ToString(), type.Name), Dock = DockStyle.Fill, ReadOnly = true, BorderStyle = BorderStyle.None }, 0, rowIndex); if (type.IsEnum) { tableActionResult.Controls.Add(new BindingEnumCombobox(builder.OutArgDataTable, rowIndex, type) { Dock = DockStyle.Fill, DropDownStyle = ComboBoxStyle.DropDownList, FlatStyle = FlatStyle.Flat }, 1, rowIndex); } else { tableActionResult.Controls.Add(new BindingTextBox(builder.OutArgDataTable, rowIndex) { Dock = DockStyle.Fill, BorderStyle = BorderStyle.None }, 1, rowIndex); } rowIndex++; } tableActionResult.Height = rowIndex * 27; } return(builder); }
/// <summary> /// Proxy method for substitution of executing methods in adapter interface. /// </summary> /// <param name="mcall">The IMethodCallMessage containing method invoking data.</param> /// <returns>The IMessage containing method return data.</returns> protected override IMessage Invoke(IMethodCallMessage mcall) { // set to compat Mode to allow running of Initialize.cmd or Reset.cmd if call from IAdapter context compatMode = ((mcall.MethodName == "Initialize" || mcall.MethodName == "Reset") && AdapterType.IsAdapterTypeFullName(mcall.MethodBase.DeclaringType.FullName) ); if (compatMode) { return(InvokeCompat(mcall)); } // Build parameter on each invoke builder = new ParameterDataBuilder(mcall); builder.Build(); // Initial error message on each invoke ptfAdFailureMessage = null; object retVal = null; outArgs = mcall.Args; string methodhelp = AdapterProxyHelpers.GetHelpMessage(mcall); string arguments = BuildScriptArguments(methodhelp); // Check if this is a method from IAdapter. Any IAdapter methods should be ignored. if (!AdapterType.IsAdapterTypeFullName(mcall.MethodBase.DeclaringType.FullName) && (mcall.MethodBase.DeclaringType.FullName != typeof(IDisposable).FullName) ) { TestSite.Log.Add(LogEntryKind.EnterAdapter, "Script adapter: {0}, method: {1}", ProxyType.Name, mcall.MethodName); try { string path = LookupScript(mcall.MethodName); if (path == null) { TestSite.Assume.Fail( "The invoking script file ({0}.cmd) can not be found.", mcall.MethodName); } else { int scriptRet = InvokeScript(path, arguments); if (scriptRet != 0) { TestSite.Assume.Fail( "Script {0}.cmd exited with non-zero code. Error code: {1}. Failure message: {2}", mcall.MethodName, scriptRet, ptfAdFailureMessage); } retVal = GetReturnValue(); GetOutArgumentsValues(); } } catch (Exception ex) { TestSite.Log.Add(LogEntryKind.Debug, ex.ToString()); throw; } finally { TestSite.Log.Add(LogEntryKind.ExitAdapter, "Script adapter: {0}, method: {1}", ProxyType.Name, mcall.MethodName); } } ReturnMessage mret = new ReturnMessage( retVal, (outArgs != null && outArgs.Length > 0) ? outArgs : null, (outArgs != null) ? outArgs.Length : 0, mcall.LogicalCallContext, mcall); return(mret); }
/// <summary> /// Proxy method for substitution of executing methods in adapter interface. /// </summary> /// <param name="mcall">The IMethodCallMessage containing method invoking data.</param> /// <returns>The IMessage containing method return data.</returns> protected override IMessage Invoke(IMethodCallMessage mcall) { // set to compat Mode to allow running of Initialize.sh or Reset.sh if call from IAdapter context compatMode = ((mcall.MethodName == "Initialize" || mcall.MethodName == "Reset") && AdapterType.IsAdapterTypeFullName(mcall.MethodBase.DeclaringType.FullName) ); if (compatMode) { return(InvokeCompat(mcall)); } // Build parameter on each invoke builder = new ParameterDataBuilder(mcall); builder.Build(); outArgs = mcall.Args; lastOutput = null; errorMsg = new StringBuilder(); object retVal = null; string arguments = BuildScriptArguments(); // Check if this is a method from IAdapter. Any IAdapter methods should be ignored. if (!AdapterType.IsAdapterTypeFullName(mcall.MethodBase.DeclaringType.FullName) && (mcall.MethodBase.DeclaringType.FullName != typeof(IDisposable).FullName) ) { TestSite.Log.Add(LogEntryKind.EnterAdapter, "Shell adapter: {0}, method: {1}", ProxyType.Name, mcall.MethodName); try { string path = LookupScript(mcall.MethodName); if (path == null) { TestSite.Assume.Fail( "Shell script file ({0}.sh) can not be found.", mcall.MethodName); } else { int scriptRet = InvokeScript(path, arguments); if (scriptRet != 0) { string exceptionMessage = string.Format("Exception thrown when executing {0}.sh.\nExit code: {1}\nError message: {2}\n", mcall.MethodName, scriptRet, errorMsg); throw new InvalidOperationException(exceptionMessage); } if (builder.HasReturnVal) { retVal = AdapterProxyHelpers.ParseResult(builder.RetValType, lastOutput); } } } catch (Exception ex) { TestSite.Log.Add(LogEntryKind.Debug, ex.ToString()); throw; } finally { TestSite.Log.Add(LogEntryKind.ExitAdapter, "Shell adapter: {0}, method: {1}", ProxyType.Name, mcall.MethodName); } } ReturnMessage mret = new ReturnMessage( retVal, (outArgs != null && outArgs.Length > 0) ? outArgs : null, (outArgs != null) ? outArgs.Length : 0, mcall.LogicalCallContext, mcall); return(mret); }
/// <summary> /// Proxy method for substitution of executing methods in adapter interface. /// </summary> /// <param name="targetMethod">The method the caller invoked.</param> /// <param name="args">The arguments the caller passed to the method.</param> /// <returns>The return value of the ExecuteMethod implementation.</returns> protected override object ExecuteMethod(MethodInfo targetMethod, object[] args) { //get help message from attribute string methodhelp = AdapterProxyHelpers.GetHelpMessage(targetMethod); bool compactMode = ((targetMethod.Name == "Initialize" || targetMethod.Name == "Reset") && AdapterType.IsAdapterTypeFullName(targetMethod.DeclaringType.FullName) ); if (compactMode) { return(ExecuteMethodCompact(targetMethod, methodhelp)); } // Build parameter on each invoke builder = new ParameterDataBuilder(targetMethod); builder.Build(args); lastOutput = null; errorMsg = new StringBuilder(); object retVal = null; string arguments = BuildScriptArguments(); // Check if this is a method from IAdapter. Any IAdapter methods should be ignored. if (!AdapterType.IsAdapterTypeFullName(targetMethod.DeclaringType.FullName) && (targetMethod.DeclaringType.FullName != typeof(IDisposable).FullName) ) { TestSite.Log.Add(LogEntryKind.EnterAdapter, "Shell adapter: {0}, method: {1}", ProxyType.Name, targetMethod.Name); try { string path = LookupScript(targetMethod.Name); if (path == null) { TestSite.Assume.Fail( "Shell script file ({0}.sh) can not be found.", targetMethod.Name); } else { int timeout = AdapterProxyHelpers.GetTimeout(targetMethod, int.Parse(TestSite.Properties["AdapterInvokeTimeout"])); Task <int> invokeTask = Task.Run <int>(() => { TestSite.Log.Add(LogEntryKind.Debug, $"Start to invoke shell {targetMethod.Name}.sh, timeout: {timeout}"); int invokeResult = InvokeScript(path, arguments); TestSite.Log.Add(LogEntryKind.Debug, $"Complete execute shell {targetMethod.Name}.sh"); return(invokeResult); }); TimeSpan waiter = TimeSpan.FromMinutes(timeout); if (invokeTask.Wait(waiter)) { if (invokeTask.Result != 0) { string exceptionMessage = string.Format("Exception thrown when executing {0}.sh.\nExit code: {1}\nError message: {2}\n", targetMethod.Name, invokeTask.Result, errorMsg); throw new InvalidOperationException(exceptionMessage); } if (builder.HasReturnVal) { retVal = AdapterProxyHelpers.ParseResult(builder.RetValType, lastOutput); } } else { throw new TimeoutException($"Invoke adapater method timeout after wait {timeout} minutes."); } } } catch (Exception ex) { TestSite.Log.Add(LogEntryKind.Debug, ex.ToString()); throw; } finally { TestSite.Log.Add(LogEntryKind.ExitAdapter, "Shell adapter: {0}, method: {1}", ProxyType.Name, targetMethod.Name); } } return(retVal); }