// take a config and convert to runtime public ScriptRuntime(IScriptConfig scriptConfig, IGlobalVariables variables) { // copy basic infos ScriptID = scriptConfig.ScriptID; ScreenshotPath = scriptConfig.ScreenshotPath; StartingUrl = scriptConfig.StartingUrl; ScriptName = scriptConfig.ScriptName; Steps = new List <StepRuntime>(); Variables = variables; foreach (var variable in scriptConfig.Variables) { Variables.Set(variable.Name, variable.Value); } // convert each step from config to runtime foreach (var step in scriptConfig.Steps) { var newStep = new StepRuntime(); if (step.EmbeddedScript != null) { newStep.EmbeddedScript = new ScriptRuntime(step.EmbeddedScript, Variables); } configureActions(step, newStep); configureExpectations(step, newStep); configureGetters(step, newStep); configureLoggers(step, newStep); Steps.Add(newStep); } }
// Methods // ======= /// <exception cref="InvalidDataException"></exception> public IScriptConfig Generate(IScriptStorageModel script, MenuLocation menuLocation) { if (!IsValidRegistryKeyName(script.Name, out RegistryName registryName)) { throw new InvalidDataException($"The given registry key's name [{script.Name}] must be [RRC_XX_YYY] where [XX] is a number and [YYY] is of any length greater than 0"); } IScriptConfig newConfig = null; try { newConfig = TryCastToBatScriptConfig(script, registryName, menuLocation); if (newConfig == null) { newConfig = TryCastToPowershellScriptConfig(script, registryName, menuLocation); } if (newConfig == null) { throw new InvalidDataException($"The right-click command [{registryName.Name}] appears to be corrupt. Please delete and re-create it"); } } catch (UnauthorizedAccessException) { //Nothing needed } return(newConfig); }
/// <exception cref="ObjectDisposedException"></exception> /// <exception cref="System.Security.SecurityException"></exception> /// <exception cref="UnauthorizedAccessException"></exception> /// <exception cref="IOException"></exception> private void ReadScriptLocation(KeyValuePair <MenuLocation, string> location, ref List <IScriptConfig> results) { using (RegistryKey scriptLocation = Registry.CurrentUser.OpenSubKey(location.Value, true)) { foreach (string subkeyName in scriptLocation.GetSubKeyNames()) { try { if (!HasRCCPrefix(subkeyName)) { continue; } RegistryScriptStorageModel script = MapRegistryScriptStorageModel(scriptLocation.OpenSubKey(subkeyName)); IScriptConfig newConfig = scriptFactory.Generate(script, location.Key); IScriptConfig original = results.FirstOrDefault(r => r.Name == newConfig.Name); if (original == default(IScriptConfig)) { results.Add(newConfig); } else { original.ModifyLocation(location.Key, true); } } catch (InvalidDataException e) { messagePrompt.PromptOK(e.Message, "Invalid Data", MessageType.Error); } } } }
public UserConfig(IScriptConfig cfg) { if (cfg == null) { throw new ArgumentNullException("Script configuration cannot be null."); } script = cfg; }
public Executor(IScriptConfig cfg) { ddns = new DDNS(Encoding.UTF8); config = new UserConfig(cfg) { nsBuffer = ddns.NSBuffer }; project = new Project(config.script.ProjectDTE, config.script.ProjectsMBE); }
public void Test_MoveSelectedDown_MovesScriptsWithAValidIndex(int index) { IScriptConfig configAtIndex = subject.ScriptConfigs[index]; Given_SelectedScriptConfigIndex_Equals(index); subject.MoveSelectedDown.DoExecute(null); Assert.AreSame(configAtIndex, subject.ScriptConfigs[index + 1]); }
/// <exception cref="ObjectDisposedException"/> /// <exception cref="System.Security.SecurityException"/> /// <exception cref="UnauthorizedAccessException"/> /// <exception cref="IOException"/> private void CreateScriptConfig(string location, IScriptConfig scriptConfig) { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(location, true)) { using (RegistryKey childKey = key.CreateSubKey($"RCC_{scriptConfig.ID}_{scriptConfig.Name}", true)) { childKey.SetValue(MUIVerb, scriptConfig.Label, RegistryValueKind.String); childKey.SetValue(Icon, scriptConfig.Icon?.ToString() ?? string.Empty); using (RegistryKey commandKey = childKey.CreateSubKey(command)) { commandKey.SetValue(string.Empty, $"\"{RCCLocation}\" run {scriptConfig.ScriptArgs}"); } } } }
public object LoadScript(string scriptPath) { if (!scriptPath.Contains(":")) { string folder = AppDomain.CurrentDomain.GetData("DataDirectory") + scriptsSubFolder; scriptPath = String.Format(@"{0}\{1}", folder, scriptPath); } var curTime = File.GetLastWriteTime(scriptPath).ToString(); if (loadedScripts.Any(script => script.Path.Equals(scriptPath, StringComparison.InvariantCultureIgnoreCase) && curTime == script.Id)) { return(null); } Log.WriteInfo("Loading script {0}...", scriptPath); DisposeScriptAssembly(scriptPath); var assemblyPath = Path.Combine(Path.GetDirectoryName(scriptPath), Path.GetFileNameWithoutExtension(scriptPath) + ".dll"); AsmHelper asmHelper = new AsmHelper(CSScript.LoadCodeFrom(scriptPath, null, false, null)); var obj = asmHelper.CreateObject("*"); IScriptConfig configObj = obj as IScriptConfig; if (configObj != null) { configObj.Config = GetScriptConfig(scriptPath, obj); } loadedScripts.Add(new ScriptItem( scriptPath, File.GetLastWriteTime(scriptPath).ToString(), asmHelper, obj )); return(obj); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; } if (editorService != null) { IScriptConfig s = context.Instance is IScriptConfig ? (IScriptConfig)context.Instance : null; using (FScriptForm f = new FScriptForm(s == null ? null : s.Options)) { f.Value = value.ToString(); if (f.ShowDialog() == DialogResult.OK) { value = f.Value; } } } return(value); }
public ScriptRunner(IWebDriver webDriver, IScriptConfig script, IGlobalVariables variables, ILogger logger) { // save to module variables WebDriver = webDriver; Script = new ScriptRuntime(script, variables) { Logger = logger }; Variables = variables; // setup results Results = new ScriptRunResults(); Results.Started = DateTime.Now; Results.ScriptName = script.ScriptName; // message types to log setDefaultLoggerMessageTypes(Script.Logger); // start logging Script.Logger.Log($"Log initialized: {DateTime.Now}", MessageTypes.General); Script.Logger.Log($"Starting script named: {Script.ScriptName} ({Script.ScriptID})", MessageTypes.General); }