public ActionAnimationScript(IList<ScriptSegment> scriptSegments, string name) { _scriptSegments = scriptSegments; _scriptVariables = new ScriptVariables(); _name = name; _currentIndex = 0; }
static string DeclareLocalVariables(IVariables variables) { var output = new StringBuilder(); foreach (var variableName in variables.GetNames().Where(name => !ScriptVariables.IsLibraryScriptModule(name))) { if (ScriptVariables.IsExcludedFromLocalVariables(variableName)) { continue; } // This is the way we used to fix up the identifiers - people might still rely on this behavior var legacyKey = new string(variableName.Where(char.IsLetterOrDigit).ToArray()); // This is the way we should have done it var smartKey = new string(variableName.Where(IsValidPowerShellIdentifierChar).ToArray()); if (legacyKey != smartKey) { WriteVariableAssignment(output, legacyKey, variableName); } WriteVariableAssignment(output, smartKey, variableName); } return(output.ToString()); }
static string[] WriteScriptModules(IVariables variables, string parentDirectory, StringBuilder output) { var scriptModules = new List <string>(); foreach (var variableName in variables.GetNames().Where(ScriptVariables.IsLibraryScriptModule)) { if (ScriptVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.PowerShell) { var libraryScriptModuleName = ScriptVariables.GetLibraryScriptModuleName(variableName); var name = "Library_" + new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray()) + "_" + DateTime.Now.Ticks; var moduleFileName = $"{name}.psm1"; var moduleFilePath = Path.Combine(parentDirectory, moduleFileName); Log.VerboseFormat("Writing script module '{0}' as PowerShell module {1}. This module will be automatically imported - functions will automatically be in scope.", libraryScriptModuleName, moduleFileName, name); var contents = variables.Get(variableName); if (contents == null) { throw new InvalidOperationException($"Value for variable {variableName} could not be found."); } CalamariFileSystem.OverwriteFile(moduleFilePath, contents, Encoding.UTF8); output.AppendLine($"Import-ScriptModule '{libraryScriptModuleName.EscapeSingleQuotedString()}' '{moduleFilePath.EscapeSingleQuotedString()}'"); output.AppendLine(); scriptModules.Add(moduleFilePath); } } return(scriptModules.ToArray()); }
public void GetScriptVariable(String key, Action <object> callback) { object obj; ScriptVariables.TryGetValue(key, out obj); callback(obj); }
private void uiBtnOk_Click(object sender, EventArgs e) { txtVariableName.Text = txtVariableName.Text.Trim(); if (txtVariableName.Text == string.Empty) { lblVariableNameError.Text = "Variable Name not provided"; return; } string newVariableName = txtVariableName.Text; var existingVariable = ScriptVariables.Where(var => var.VariableName == newVariableName).FirstOrDefault(); var existingArgument = ScriptArguments.Where(arg => arg.ArgumentName == newVariableName).FirstOrDefault(); if (existingVariable != null || existingArgument != null) { if (!_isEditMode || existingVariable.VariableName != _editingVariableName) { lblVariableNameError.Text = "A Variable or Argument with this name already exists"; return; } } if (txtVariableName.Text.StartsWith("{") || txtVariableName.Text.EndsWith("}")) { lblVariableNameError.Text = "Variable markers '{' and '}' should not be included"; return; } DialogResult = DialogResult.OK; }
public void ShouldReturnTheNamesOfTheVariables() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\" bar=\"{$bar}\"/>"); var scriptVariables = new ScriptVariables(document); CollectionAssert.AreEqual(new string[] { "foo", "bar" }, scriptVariables.Names.ToArray()); }
public void ShouldReturnNullWhenElementIsNull() { var document = new XmlDocument(); var scriptVariables = new ScriptVariables(document); var result = scriptVariables.GetSingleArray(null); Assert.IsNull(result); }
public void ShouldThrowExceptionWhenNameIsNull() { var document = new XmlDocument(); var scriptVariables = new ScriptVariables(document); ExceptionAssert.Throws <ArgumentNullException>("name", () => { scriptVariables.Get(null); }); }
public void ShouldThrowExceptionWhenNameIsInvalid() { var document = new XmlDocument(); var scriptVariables = new ScriptVariables(document); ExceptionAssert.Throws <ArgumentException>("name", () => { scriptVariables.Get("invalid"); }, "Invalid variable name: invalid"); }
public void ShouldGetTheVariable() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\"/>"); var scriptVariables = new ScriptVariables(document); Assert.AreEqual(null, scriptVariables.Get("foo")); }
public void ShouldThrowExceptionWhenNameToGetIsInvalid() { var document = new XmlDocument(); var scriptVariables = new ScriptVariables(document); ExceptionAssert.ThrowsArgumentException("name", () => { var test = scriptVariables["invalid"]; }, "Invalid variable name: invalid"); }
/// <summary> /// Clears the stored data. /// </summary> public void ClearSession() { ScriptTextVariables.Clear(); ScriptUsernameVariables.Clear(); ScriptPasswordVariables.Clear(); ScriptMultiLineVariables.Clear(); ScriptCheckboxVariables.Clear(); ScriptRadiobuttonVariables.Clear(); ScriptVariables.Clear(); _scriptDescription = ""; }
public void ShouldSetTheVariable() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\"/>"); var scriptVariables = new ScriptVariables(document); scriptVariables["foo"] = "test"; Assert.AreEqual("test", scriptVariables["foo"]); }
public void BasicScriptVariablesWithScriptTags() { var scriptVars = new ScriptVariables(); scriptVars.Add("name", "Rick"); scriptVars.Add("timestamp", DateTime.UtcNow); var code = scriptVars.ToString(); Console.WriteLine(code); Assert.IsNotNull(code); Assert.IsTrue(code.Contains("new Date(")); }
public void RawValueSerialization() { var value = new { Name = "Rick", Entered = DateTime.UtcNow, Accessed = 10 }; var result = ScriptVariables.Serialize(value); Console.WriteLine(result); }
public static ScriptVariables BuildScriptVariables(List <DataPoint> lines) { var scriptVariables = new ScriptVariables( BuildTimes(lines), BuildCurrencies(lines), BuildIndicators(lines), BuildValues(lines) ); // Return return(scriptVariables); }
public void ParseAndEvaluateTest() { ScriptVariables var = new ScriptVariables() { Round = 5 }; string script = @"1)4/6/10 4)4/8/8"; WeblScript wScript = new WeblScript(); string expected = "4/8/8"; string actual = wScript.ParseAndEvaluate(script, var).Text; Assert.AreEqual(expected, actual); }
/// <summary> /// Adds each of the stored collections of input objects /// to the main collection of input objects. /// </summary> private void AddScriptArgumentsToMainCollection() { if (ScriptTextVariables != null && ScriptTextVariables.Count > 0) { ScriptVariables.Add(new CollectionContainer() { Collection = ScriptTextVariables }); } if (ScriptUsernameVariables != null && ScriptUsernameVariables.Count > 0) { ScriptVariables.Add(new CollectionContainer() { Collection = ScriptUsernameVariables }); } if (ScriptPasswordVariables != null && ScriptPasswordVariables.Count > 0) { ScriptVariables.Add(new CollectionContainer() { Collection = ScriptPasswordVariables }); } if (ScriptMultiLineVariables != null && ScriptMultiLineVariables.Count > 0) { ScriptVariables.Add(new CollectionContainer() { Collection = ScriptMultiLineVariables }); } if (ScriptCheckboxVariables != null && ScriptCheckboxVariables.Count > 0) { ScriptVariables.Add(new CollectionContainer() { Collection = ScriptCheckboxVariables }); } if (ScriptRadiobuttonVariables != null && ScriptRadiobuttonVariables.Count > 0) { ScriptVariables.Add(new CollectionContainer() { Collection = ScriptRadiobuttonVariables }); } }
public static ScriptVariables GetFake_List() { var scriptVariablesResponse = new ScriptVariables(); var now = DateTime.UtcNow.StripSeconds(); var times = new List <DateTime> { now }; var currencies = new List <string> { "BTC", "ETH", "EOS" }; var indicators = new List <string> { "master.PRICE", "master.HYPE" }; var level31 = new Dictionary <string, decimal> { { "master.PRICE", 3200m }, { "master.HYPE", 0.125m } }; var level32 = new Dictionary <string, decimal> { { "master.PRICE", 570m }, { "master.HYPE", 6.5m } }; var level33 = new Dictionary <string, decimal> { { "master.PRICE", 3m }, { "master.HYPE", 0.5m } }; var level2 = new Dictionary <string, Dictionary <string, decimal> > { { "BTC", level31 }, { "ETH", level32 }, { "EOS", level33 } }; var level1 = new Dictionary <DateTime, Dictionary <string, Dictionary <string, decimal> > > { { now, level2 } }; scriptVariablesResponse.Times = times; scriptVariablesResponse.Currencies = currencies; scriptVariablesResponse.Indicators = indicators; scriptVariablesResponse.Values = level1; // Return return(scriptVariablesResponse); }
private FighterRoundPlan EvaluatePlan(FightRoundVariables frv) { if (WeblScript == null) { WeblScript = new WeblScript(); } ScriptVariables variables = frv.ToScriptVariables(); ParseResult res = WeblScript.ParseAndEvaluate(this.FightPlanText, variables); FighterRoundPlan roundPlan = FighterRoundPlan.Parse(res.Text); if (res.Cheat) { roundPlan.Dirty = true; } roundPlan.HitLineNumber = res.LineNumber; return(roundPlan); }
public void ClientScriptVariablesDictionaryWithNumberedIndexesInitializationTest() { var scriptVars = new ScriptVariables("pageVars"); scriptVars.Add("values",new Dictionary<int, object> { { 2, "Rick & Company" }, { 4, DateTime.Now }, { 6, new Item() { Sku = "wwhelp", Description = "Help Builder < test >", Price = 299M }} }); // output as a string string output = scriptVars.ToString(); Console.WriteLine(output); Assert.IsNotNull(output); Assert.IsTrue(output.Contains("Help Builder")); }
public void ClientScriptVariablesDictionaryInitializationTest() { var scriptVars = new ScriptVariables("pageVars"); scriptVars.Add( new Dictionary<string,object>() { { "name", "Rick & Company" }, { "date", DateTime.Now }, { "item", new Item() { Sku = "wwhelp", Description = "Help Builder < test >", Price = 299M }} }); // output as a string string output = scriptVars.ToString(true); Console.WriteLine(output); Assert.IsNotNull(output); Assert.IsTrue(output.Contains("Help Builder")); }
public void ClientScriptVariablesWithItemsTest() { var scriptVars = new ScriptVariables("pageVars"); scriptVars.Add("name", "Rick & Company"); scriptVars.Add("date", DateTime.Now); scriptVars.Add("item", new Item() { Sku = "wwhelp", Description = "Help Builder < test >", Price = 299M }); scriptVars.UpdateMode = AllowUpdateTypes.ItemsOnly; // output as a string string output = scriptVars.ToString(true); Console.WriteLine(output); Assert.IsNotNull(output); Assert.IsTrue(output.Contains("Help Builder")); }
public void ReturnNestedVariableTest() { var scriptVars = new ScriptVariables("app.names"); scriptVars.Add("values", new { name = "Rick", company = "Westwind", entered = DateTime.UtcNow }); // output as a string string output = scriptVars.ToString(); Console.WriteLine(output); Assert.IsNotNull(output); Assert.IsTrue(output.Contains("Westwind")); }
static IEnumerable <string> PrepareScriptModules(IVariables variables, string workingDirectory) { foreach (var variableName in variables.GetNames().Where(ScriptVariables.IsLibraryScriptModule)) { if (ScriptVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.Bash) { var libraryScriptModuleName = ScriptVariables.GetLibraryScriptModuleName(variableName); var name = new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray()); var moduleFileName = $"{name}.sh"; var moduleFilePath = Path.Combine(workingDirectory, moduleFileName); Log.VerboseFormat("Writing script module '{0}' as bash script {1}. Import this via `source {1}`.", libraryScriptModuleName, moduleFileName, name); Encoding utf8WithoutBom = new UTF8Encoding(false); CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), utf8WithoutBom); EnsureValidUnixFile(moduleFilePath); yield return(moduleFilePath); } } }
public void ShouldReturnValue() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\"/>"); var scriptVariables = new ScriptVariables(document); scriptVariables.Set("foo", new float[] { 42 }); var element = document.CreateElement("test"); element.SetAttribute("variable", "{$foo}"); var result = scriptVariables.GetSingleArray(element); Assert.IsNotNull(result); Assert.AreEqual(42.0f, result[0]); }
static (string encrypted, string iv) GetEncryptedVariablesString(IVariables variables) { var sb = new StringBuilder(); foreach (var variableName in variables.GetNames().Where(name => !ScriptVariables.IsLibraryScriptModule(name))) { var value = variables.Get(variableName); var encryptedValue = value == null ? "nul" : EncodeAsBase64(value); // "nul" is not a valid Base64 string sb.Append(EncodeAsBase64(variableName)).Append("$").AppendLine(encryptedValue); } var encrypted = VariableEncryptor.Encrypt(sb.ToString()); var rawEncrypted = AesEncryption.ExtractIV(encrypted, out var iv); return( Convert.ToBase64String(rawEncrypted, Base64FormattingOptions.InsertLineBreaks), Convert.ToBase64String(iv) ); }
private void dgvVariablesArguments_CellEnter(object sender, DataGridViewCellEventArgs e) { try { //creates a list of all existing variable/argument names to check against, prior to creating a new one DataGridView dgv = (DataGridView)sender; _preEditVarArgName = dgv.Rows[e.RowIndex].Cells[0].Value?.ToString(); _existingVarArgSearchList = new List <string>(); _existingVarArgSearchList.AddRange(ScriptArguments.Select(arg => arg.ArgumentName).ToList()); _existingVarArgSearchList.AddRange(ScriptVariables.Select(var => var.VariableName).ToList()); _existingVarArgSearchList.AddRange(CommonMethods.GenerateSystemVariables().Select(var => var.VariableName).ToList()); } catch (Exception ex) { //datagridview event failure Console.WriteLine(ex); } }
private void Initialize(Stream stream) { Throw.IfNull(nameof(stream), stream); using (XmlReader xmlReader = XmlReader.Create(stream, _ReaderSettings)) { _Script = new XmlDocument(); _Script.Load(xmlReader); } Variables = new ScriptVariables(_Script); }