コード例 #1
0
 public ActionAnimationScript(IList<ScriptSegment> scriptSegments, string name)
 {
     _scriptSegments = scriptSegments;
     _scriptVariables = new ScriptVariables();
     _name = name;
     _currentIndex = 0;
 }
コード例 #2
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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        public void GetScriptVariable(String key, Action <object> callback)
        {
            object obj;

            ScriptVariables.TryGetValue(key, out obj);
            callback(obj);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
            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());
            }
コード例 #7
0
            public void ShouldReturnNullWhenElementIsNull()
            {
                var document        = new XmlDocument();
                var scriptVariables = new ScriptVariables(document);

                var result = scriptVariables.GetSingleArray(null);

                Assert.IsNull(result);
            }
コード例 #8
0
            public void ShouldThrowExceptionWhenNameIsNull()
            {
                var document        = new XmlDocument();
                var scriptVariables = new ScriptVariables(document);

                ExceptionAssert.Throws <ArgumentNullException>("name", () =>
                {
                    scriptVariables.Get(null);
                });
            }
コード例 #9
0
            public void ShouldThrowExceptionWhenNameIsInvalid()
            {
                var document        = new XmlDocument();
                var scriptVariables = new ScriptVariables(document);

                ExceptionAssert.Throws <ArgumentException>("name", () =>
                {
                    scriptVariables.Get("invalid");
                }, "Invalid variable name: invalid");
            }
コード例 #10
0
            public void ShouldGetTheVariable()
            {
                var document = new XmlDocument();

                document.LoadXml("<test foo=\"{$foo}\"/>");

                var scriptVariables = new ScriptVariables(document);

                Assert.AreEqual(null, scriptVariables.Get("foo"));
            }
コード例 #11
0
            public void ShouldThrowExceptionWhenNameToGetIsInvalid()
            {
                var document        = new XmlDocument();
                var scriptVariables = new ScriptVariables(document);

                ExceptionAssert.ThrowsArgumentException("name", () =>
                {
                    var test = scriptVariables["invalid"];
                }, "Invalid variable name: invalid");
            }
コード例 #12
0
 /// <summary>
 /// Clears the stored data.
 /// </summary>
 public void ClearSession()
 {
     ScriptTextVariables.Clear();
     ScriptUsernameVariables.Clear();
     ScriptPasswordVariables.Clear();
     ScriptMultiLineVariables.Clear();
     ScriptCheckboxVariables.Clear();
     ScriptRadiobuttonVariables.Clear();
     ScriptVariables.Clear();
     _scriptDescription = "";
 }
コード例 #13
0
            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"]);
            }
コード例 #14
0
        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("));
        }
コード例 #15
0
        public void RawValueSerialization()
        {
            var value = new
            {
                Name     = "Rick",
                Entered  = DateTime.UtcNow,
                Accessed = 10
            };

            var result = ScriptVariables.Serialize(value);

            Console.WriteLine(result);
        }
コード例 #16
0
        public static ScriptVariables BuildScriptVariables(List <DataPoint> lines)
        {
            var scriptVariables = new ScriptVariables(
                BuildTimes(lines),
                BuildCurrencies(lines),
                BuildIndicators(lines),
                BuildValues(lines)
                );


            // Return
            return(scriptVariables);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        /// <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
                });
            }
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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"));
        }
コード例 #22
0
        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"));
        }
コード例 #23
0
        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"));
        }
コード例 #24
0
        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"));
        }
コード例 #25
0
 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);
         }
     }
 }
コード例 #26
0
            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]);
            }
コード例 #27
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)
                );
        }
コード例 #28
0
        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);
            }
        }
コード例 #29
0
        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"));
            
        }
コード例 #30
0
ファイル: MagickScript.cs プロジェクト: dlemstra/Magick.NET
    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);
    }