public void Test_ExcecuteHelloScript()
        {
            var executor = new PowershellScriptExecutor();

            var output = executor.ExecuteScript("hello.ps1");

            Assert.AreEqual("Hello world!", output);
        }
        public void Test_ExecuteTwoStringsScript()
        {
            var executor = new PowershellScriptExecutor();

            var output = executor.ExecuteScript("two_strings.ps1");

            Assert.AreEqual("Hello world!", output);
        }
Ejemplo n.º 3
0
        public void Execute_PS_script_and_get_result()
        {
            var outputs = new PowershellScriptExecutor(null).Execute(
                "param([string]$param1) $param1",
                ("param1", "ok"));

            Assert.AreEqual("ok", outputs.First());
        }
        public void Test_ExecuteScriptWithVariable()
        {
            var executor = new PowershellScriptExecutor();

            IDictionary <string, object> variables = new Dictionary <string, object>();

            variables.Add("testVar", "Hello world!");
            var output = executor.ExecuteScript("variable.ps1", variables);

            Assert.AreEqual("Hello world!", output);
        }
Ejemplo n.º 5
0
        protected override void EndProcessing()
        {
            PatternActionsRegistry <XmlMessage, XmlMessagePattern> registry = new PatternActionsRegistry <XmlMessage, XmlMessagePattern>();

            if (MessagePatterns != null && MessagePatterns.Any())
            {
                foreach (var messagePattern in MessagePatterns)
                {
                    string processingUnitId = (string)messagePattern.Properties["Id"].Value;
                    var    pattern          = ((object[])messagePattern.Properties["Pattern"].Value).Select(o => (string)o).ToArray();
                    var    script           = (ScriptBlock)messagePattern.Properties["Script"].Value;
                    var    sec               = messagePattern.Properties["Secondary"];
                    bool   secondary         = sec != null ? (bool)sec.Value : false;
                    var    xmlMessagePattern = new XmlMessagePattern(secondary, pattern);
                    registry.AddPowershellScript(xmlMessagePattern, script, processingUnitId);
                }
            }
            if (Resources != null && Resources.Any())
            {
                foreach (var resource in Resources)
                {
                    string      processingUnitId    = (string)resource.Properties["Id"].Value;
                    ScriptBlock resourceConstructor = (ScriptBlock)resource.Properties["Constructor"].Value;
                    ScriptBlock resourceDestructor  = (ScriptBlock)resource.Properties["Destructor"]?.Value;
                    registry.SetProcessingUnitResourceFactory(
                        processingUnitId,
                        logger => new Lazy <IDisposable>(() =>
                    {
                        var outputs = new PowershellScriptExecutor(logger).Execute(resourceConstructor.ToString());
                        if (outputs == null || !outputs.Any())
                        {
                            return(null);
                        }
                        System.Collections.Hashtable resources = outputs.First() as System.Collections.Hashtable;
                        if (resources == null)
                        {
                            return(null);
                        }
                        return(new PSResources(resources, logger, resourceDestructor));
                    })
                        );
                }
            }
            var config = Hexagon.NodeConfig.FromFile <AkkaNodeConfig>(NodeConfig);

            using (MessageSystem <XmlMessage, XmlMessagePattern> xmlMessageSystem = CreateSystem(config))
            {
                xmlMessageSystem.Start(config, registry);
                Console.WriteLine("Press Control-C to exit, Enter to clear screen.");
                Console.CancelKeyPress += (sender, e) =>
                {
                    _quitEvent.Set();
                    e.Cancel = true;
                };
                bool exit = false;
                do
                {
                    if (Console.KeyAvailable)
                    {
                        var key = Console.ReadKey(true);
                        if (key.Key == ConsoleKey.Enter)
                        {
                            Console.Clear();
                        }
                    }
                    exit = _quitEvent.WaitOne(100);
                } while (!exit);
            }
        }