public Control CreateDropdownFor(string parameterName, ScriptCommand parent) { var dropdownBox = new ComboBox(); dropdownBox.Font = new Font("Segoe UI", 12, FontStyle.Regular); dropdownBox.DataBindings.Add("Text", parent, parameterName, false, DataSourceUpdateMode.OnPropertyChanged); dropdownBox.Height = 30; dropdownBox.Width = 300; dropdownBox.Name = parameterName; var variableProperties = parent.GetType().GetProperties().Where(f => f.Name == parameterName).FirstOrDefault(); var propertyAttributesAssigned = variableProperties.GetCustomAttributes(typeof(PropertyUISelectionOption), true); foreach (PropertyUISelectionOption option in propertyAttributesAssigned) { dropdownBox.Items.Add(option.UIOption); } dropdownBox.Click += DropdownBox_Click; dropdownBox.KeyDown += DropdownBox_KeyDown; dropdownBox.KeyPress += DropdownBox_KeyPress; dropdownBox.MouseWheel += DropdownBox_MouseWheel; return(dropdownBox); }
public CommandControlValidationContext(string parameterName, ScriptCommand command) { ParameterName = parameterName; Command = command; var variableProperties = Command.GetType().GetProperties().Where(f => f.Name == ParameterName).FirstOrDefault(); var compatibleTypesAttributesAssigned = variableProperties.GetCustomAttributes(typeof(CompatibleTypes), true); var requiredAttributesAssigned = variableProperties.GetCustomAttributes(typeof(RequiredAttribute), true); if (compatibleTypesAttributesAssigned.Length > 0) { var attribute = (CompatibleTypes)compatibleTypesAttributesAssigned[0]; CompatibleTypes = attribute.CompTypes; } else { IsDropDown = true; } if (requiredAttributesAssigned.Length > 0) { IsRequired = true; } if (parameterName == "v_ImageCapture") { IsImageCapture = true; } }
public Control CreateDefaultLabelFor(string parameterName, ScriptCommand parent) { var variableProperties = parent.GetType().GetProperties().Where(f => f.Name == parameterName).FirstOrDefault(); var propertyAttributesAssigned = variableProperties.GetCustomAttributes(typeof(DisplayNameAttribute), true); Label inputLabel = new Label(); if (propertyAttributesAssigned.Length > 0) { var attribute = (DisplayNameAttribute)propertyAttributesAssigned[0]; inputLabel.Text = attribute.DisplayName; } else { inputLabel.Text = parameterName; } inputLabel.AutoSize = true; inputLabel.Font = new Font("Segoe UI Light", 12); inputLabel.ForeColor = Color.White; inputLabel.Name = "lbl_" + parameterName; CreateDefaultToolTipFor(parameterName, parent, inputLabel); return(inputLabel); }
public void Process(List <string> resourceList) { foreach (var res in resourceList) { ScriptLoader loader = new ScriptLoader(); ScriptFile file; file = loader.Parse(res, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); ScriptCommand namespaceCmd = (ScriptCommand)file.Commands[0]; if (namespaceCmd != null && namespaceCmd.GetType().Equals(typeof(NamespaceScriptCommand))) { namespaceCmd.Execute(this); } else { if (namespaceFileDic.ContainsKey("(default)")) { if (namespaceFileDic["(default)"] == null) { namespaceFileDic["(default)"] = new List <ScriptFile>(); } namespaceFileDic["(default)"].Add(file); } else { namespaceFileDic.Add("(default)", new List <ScriptFile>() { file }); } } } }
public static object ConvertUserVariableToObject(this string varArgName, IAutomationEngineInstance engine, string parameterName, ScriptCommand parent) { var variableProperties = parent.GetType().GetProperties().Where(f => f.Name == parameterName).FirstOrDefault(); var compatibleTypesAttribute = variableProperties.GetCustomAttributes(typeof(CompatibleTypes), true); Type[] compatibleTypes = null; if (compatibleTypesAttribute.Length > 0) { compatibleTypes = ((CompatibleTypes[])compatibleTypesAttribute)[0].CompTypes; } ScriptVariable requiredVariable; ScriptArgument requiredArgument; if (varArgName.StartsWith("{") && varArgName.EndsWith("}")) { //reformat and attempt var reformattedVarArg = varArgName.Replace("{", "").Replace("}", ""); requiredVariable = engine.AutomationEngineContext.Variables .Where(var => var.VariableName == reformattedVarArg) .FirstOrDefault(); if (requiredVariable != null && compatibleTypes != null && !compatibleTypes.Any(x => x.IsAssignableFrom(requiredVariable.VariableType) || x == requiredVariable.VariableType)) { throw new ArgumentException($"The type of variable '{requiredVariable.VariableName}' is not compatible."); } requiredArgument = engine.AutomationEngineContext.Arguments .Where(arg => arg.ArgumentName == reformattedVarArg) .FirstOrDefault(); if (requiredArgument != null && compatibleTypes != null && !compatibleTypes.Any(x => x.IsAssignableFrom(requiredArgument.ArgumentType) || x == requiredArgument.ArgumentType)) { throw new ArgumentException($"The type of argument '{requiredArgument.ArgumentName}' is not compatible."); } } else { throw new Exception("Variable/Argument markers '{}' missing. Variable/Argument '" + varArgName + "' could not be found."); } if (requiredVariable != null) { return(requiredVariable.VariableValue); } else if (requiredArgument != null) { return(requiredArgument.ArgumentValue); } else { return(null); } }
/// <summary> /// Stores value of the object to a user-defined variable. /// </summary> /// <param name="sender">The script engine instance (AutomationEngineInstance) which contains session variables.</param> /// <param name="targetVariable">the name of the user-defined variable to override with new value</param> public static void StoreInUserVariable(this object varArgValue, IAutomationEngineInstance engine, string varArgName, string parameterName, ScriptCommand parent) { var variableProperties = parent.GetType().GetProperties().Where(f => f.Name == parameterName).FirstOrDefault(); var compatibleTypesAttribute = variableProperties.GetCustomAttributes(typeof(CompatibleTypes), true); Type[] compatibleTypes = null; if (compatibleTypesAttribute.Length > 0) { compatibleTypes = ((CompatibleTypes[])compatibleTypesAttribute)[0].CompTypes; } if (varArgName.StartsWith("{") && varArgName.EndsWith("}")) { varArgName = varArgName.Replace("{", "").Replace("}", ""); } else { throw new Exception("Variable markers '{}' missing. '" + varArgName + "' is an invalid output variable name."); } var existingVariable = engine.AutomationEngineContext.Variables .Where(var => var.VariableName == varArgName) .FirstOrDefault(); if (existingVariable != null && compatibleTypes != null && !compatibleTypes.Any(x => x.IsAssignableFrom(existingVariable.VariableType) || x == existingVariable.VariableType)) { throw new ArgumentException($"The type of variable '{existingVariable.VariableName}' is not compatible."); } else if (existingVariable != null) { existingVariable.VariableValue = varArgValue; return; } var existingArgument = engine.AutomationEngineContext.Arguments .Where(arg => arg.ArgumentName == varArgName) .FirstOrDefault(); if (existingArgument != null && compatibleTypes != null && !compatibleTypes.Any(x => x.IsAssignableFrom(existingArgument.ArgumentType) || x == existingArgument.ArgumentType)) { throw new ArgumentException($"The type of argument '{existingArgument.ArgumentName}' is not compatible."); } else if (existingArgument != null) { existingArgument.ArgumentValue = varArgValue; return; } throw new ArgumentNullException($"No variable/argument with the name '{varArgName}' was found."); }
private ListViewItem CreateScriptCommandListViewItem(ScriptCommand cmdDetails) { ListViewItem newCommand = new ListViewItem(); newCommand.Text = cmdDetails.GetDisplayValue(); newCommand.SubItems.Add(cmdDetails.GetDisplayValue()); newCommand.SubItems.Add(cmdDetails.GetDisplayValue()); //cmdDetails.RenderedControls = null; newCommand.Tag = cmdDetails; newCommand.ForeColor = cmdDetails.DisplayForeColor; newCommand.BackColor = Color.DimGray; newCommand.ImageIndex = _uiImages.Images.IndexOfKey(cmdDetails.GetType().Name); return(newCommand); }
private ListViewItem CreateScriptCommandListViewItem(ScriptCommand cmdDetails) { ListViewItem newCommand = new ListViewItem(); newCommand.Text = cmdDetails.GetDisplayValue(); newCommand.SubItems.Add(cmdDetails.GetDisplayValue()); newCommand.SubItems.Add(cmdDetails.GetDisplayValue()); newCommand.ToolTipText = cmdDetails.GetDisplayValue(); newCommand.Tag = cmdDetails; newCommand.ForeColor = Color.SteelBlue; newCommand.BackColor = Color.DimGray; if (UiImages != null) { newCommand.ImageIndex = UiImages.Images.IndexOfKey(cmdDetails.GetType().Name); } return(newCommand); }
public void CreateDefaultToolTipFor(string parameterName, ScriptCommand parent, Control label) { var variableProperties = parent.GetType().GetProperties().Where(f => f.Name == parameterName).FirstOrDefault(); var inputSpecificationAttributesAssigned = variableProperties.GetCustomAttributes(typeof(DescriptionAttribute), true); var sampleUsageAttributesAssigned = variableProperties.GetCustomAttributes(typeof(SampleUsage), true); var remarksAttributesAssigned = variableProperties.GetCustomAttributes(typeof(Remarks), true); string toolTipText = ""; if (inputSpecificationAttributesAssigned.Length > 0) { var attribute = (DescriptionAttribute)inputSpecificationAttributesAssigned[0]; toolTipText = attribute.Description; } if (sampleUsageAttributesAssigned.Length > 0) { var attribute = (SampleUsage)sampleUsageAttributesAssigned[0]; if (attribute.Usage.Length > 0) { toolTipText += "\nSample: " + attribute.Usage; } } if (remarksAttributesAssigned.Length > 0) { var attribute = (Remarks)remarksAttributesAssigned[0]; if (attribute.Remark.Length > 0) { toolTipText += "\n" + attribute.Remark; } } ToolTip inputToolTip = new ToolTip(); inputToolTip.ToolTipIcon = ToolTipIcon.Info; inputToolTip.IsBalloon = true; inputToolTip.ShowAlways = true; inputToolTip.ToolTipTitle = label.Text; inputToolTip.AutoPopDelay = 15000; inputToolTip.SetToolTip(label, toolTipText); }
public List <Control> CreateUIHelpersFor(string parameterName, ScriptCommand parent, Control[] targetControls, IfrmCommandEditor editor) { var variableProperties = parent.GetType().GetProperties().Where(f => f.Name == parameterName).FirstOrDefault(); var propertyUIHelpers = variableProperties.GetCustomAttributes(typeof(EditorAttribute), true); var controlList = new List <Control>(); if (propertyUIHelpers.Count() == 0) { return(controlList); } foreach (EditorAttribute attrib in propertyUIHelpers) { CommandItemControl helperControl = new CommandItemControl(); helperControl.Padding = new Padding(10, 0, 0, 0); helperControl.ForeColor = Color.AliceBlue; helperControl.Font = new Font("Segoe UI Semilight", 10); helperControl.Name = parameterName + "_helper"; helperControl.Tag = targetControls.FirstOrDefault(); helperControl.HelperType = (UIAdditionalHelperType)Enum.Parse(typeof(UIAdditionalHelperType), attrib.EditorTypeName, true); switch (helperControl.HelperType) { case UIAdditionalHelperType.ShowVariableHelper: //show variable selector helperControl.CommandImage = Resources.command_parse; helperControl.CommandDisplay = "Insert Variable"; helperControl.Click += (sender, e) => ShowVariableSelector(sender, e); break; case UIAdditionalHelperType.ShowElementHelper: //show element selector helperControl.CommandImage = Resources.command_element; helperControl.CommandDisplay = "Insert Element"; helperControl.Click += (sender, e) => ShowElementSelector(sender, e); break; case UIAdditionalHelperType.ShowFileSelectionHelper: //show file selector helperControl.CommandImage = Resources.command_files; helperControl.CommandDisplay = "Select a File"; helperControl.Click += (sender, e) => ShowFileSelector(sender, e, (frmCommandEditor)editor); break; case UIAdditionalHelperType.ShowFolderSelectionHelper: //show file selector helperControl.CommandImage = Resources.command_folders; helperControl.CommandDisplay = "Select a Folder"; helperControl.Click += (sender, e) => ShowFolderSelector(sender, e, (frmCommandEditor)editor); break; case UIAdditionalHelperType.ShowImageCaptureHelper: //show file selector helperControl.CommandImage = Resources.command_camera; helperControl.CommandDisplay = "Capture Reference Image"; helperControl.Click += (sender, e) => ShowImageCapture(sender, e); CommandItemControl testRun = new CommandItemControl(); testRun.Padding = new Padding(10, 0, 0, 0); testRun.ForeColor = Color.AliceBlue; testRun.CommandImage = Resources.command_camera; testRun.CommandDisplay = "Run Image Recognition Test"; testRun.ForeColor = Color.AliceBlue; testRun.Font = new Font("Segoe UI Semilight", 10); testRun.Tag = targetControls.FirstOrDefault(); testRun.Click += (sender, e) => RunImageCapture(sender, e); controlList.Add(testRun); break; case UIAdditionalHelperType.ShowCodeBuilder: //show variable selector helperControl.CommandImage = Resources.command_script; helperControl.CommandDisplay = "Code Builder"; helperControl.Click += (sender, e) => ShowCodeBuilder(sender, e, (frmCommandEditor)editor); break; case UIAdditionalHelperType.ShowMouseCaptureHelper: helperControl.CommandImage = Resources.command_input; helperControl.CommandDisplay = "Capture Mouse Position"; helperControl.ForeColor = Color.AliceBlue; helperControl.Click += (sender, e) => ShowMouseCaptureForm(sender, e, (frmCommandEditor)editor); break; case UIAdditionalHelperType.ShowElementRecorder: //show variable selector helperControl.CommandImage = Resources.command_camera; helperControl.CommandDisplay = "Element Recorder"; helperControl.Click += (sender, e) => ShowElementRecorder(sender, e, (frmCommandEditor)editor); break; case UIAdditionalHelperType.GenerateDLLParameters: //show variable selector helperControl.CommandImage = Resources.command_run_code; helperControl.CommandDisplay = "Generate Parameters"; helperControl.Click += (sender, e) => GenerateDLLParameters(sender, e); break; case UIAdditionalHelperType.ShowDLLExplorer: //show variable selector helperControl.CommandImage = Resources.command_run_code; helperControl.CommandDisplay = "Launch DLL Explorer"; helperControl.Click += (sender, e) => ShowDLLExplorer(sender, e); break; case UIAdditionalHelperType.AddInputParameter: //show variable selector helperControl.CommandImage = Resources.command_run_code; helperControl.CommandDisplay = "Add Input Parameter"; helperControl.Click += (sender, e) => AddInputParameter(sender, e, (frmCommandEditor)editor); break; case UIAdditionalHelperType.ShowHTMLBuilder: helperControl.CommandImage = Resources.command_web; helperControl.CommandDisplay = "Launch HTML Builder"; helperControl.Click += (sender, e) => ShowHTMLBuilder(sender, e, (frmCommandEditor)editor); break; case UIAdditionalHelperType.ShowIfBuilder: //show variable selector helperControl.CommandImage = Resources.command_begin_if; helperControl.CommandDisplay = "Add New If Statement"; break; case UIAdditionalHelperType.ShowLoopBuilder: //show variable selector helperControl.CommandImage = Resources.command_startloop; helperControl.CommandDisplay = "Add New Loop Statement"; break; case UIAdditionalHelperType.ShowEncryptionHelper: //show variable selector helperControl.CommandImage = Resources.command_password; helperControl.CommandDisplay = "Encrypt Text"; helperControl.Click += (sender, e) => EncryptText(sender, e, (frmCommandEditor)editor); break; //default: // MessageBox.Show("Command Helper does not exist for: " + attrib.additionalHelper.ToString()); // break; } controlList.Add(helperControl); } return(controlList); }
public static string ToDescriptionString(this ScriptCommand val) { DescriptionAttribute[] attributes = (DescriptionAttribute[])val.GetType().GetField(val.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false); return(attributes.Length > 0 ? attributes[0].Description : string.Empty); }