Exemple #1
0
        /// <summary>
        /// Compiles Ruby script to Abstract Syntax Tree
        /// </summary>
        private void Compile()
        {
            // Clear view
            lstErrors.Items.Clear();
            tvAstNodes.Nodes.Clear();
            txtSprintPs1.DocumentText     = String.Empty;
            txtResourcesPsm1.DocumentText = String.Empty;

            Sprint sprint = new Sprint {
                Mode = cmbSprintMode.Text
            };

            if (cmbSprintMode.Text == "Script")
            {
                sprint.RubyStack = txtRuby.Text;
                sprint.Compile();
            }
            else
            {
                sprint.Build();
                txtRuby.Text = sprint.RubyStack;
            }

            const string style = "<STYLE type=\"text/css\">body, div { background-color: #252526 !important; color: #CCC !important; font-size:16px;} </STYLE>";

            if (sprint.SprintPs1Content != null)
            {
                string sprintPs1ContentHighlight =
                    style
                    + ReStyle(new CodeColorizer().Colorize(sprint.SprintPs1Content,
                                                           Languages.PowerShell));
                Application.DoEvents();
                txtSprintPs1.DocumentText = sprintPs1ContentHighlight;
            }


            if (sprint.ResourcesPs1Content != null)
            {
                string resourcesPs1ContentHighlight =
                    style +
                    ReStyle(new CodeColorizer().Colorize(sprint.ResourcesPs1Content,
                                                         Languages.PowerShell));
                Application.DoEvents();
                txtResourcesPsm1.DocumentText = resourcesPs1ContentHighlight;
            }

            if (sprint.SyntaxErrors.Count > 0)
            {
                foreach (SyntaxError err in sprint.SyntaxErrors)
                {
                    lstErrors.Items.Add(err);
                }
            }
            ShowAstNodes(sprint.AstRootNode);
            tvAstNodes.ExpandAll();
            jvCompiledJson.Json = sprint.CompiledJson;
        }
Exemple #2
0
        public void ExecuteSprint()
        {
            ReturnType rt;
            Sprint     sprint = new Sprint();

            //  ══════════════════════════
            //   Starting Blu
            //  ══════════════════════════
            Host.UI.Write(ConsoleColor.DarkGray, Host.UI.RawUI.BackgroundColor, ChefConfig.BluLogo);
            Console.WriteLine();
            Console.WriteLine();

            // Set Mode
            if (string.IsNullOrEmpty(Mode))
            {
                Mode = "StandAlone";
            }
            sprint.Mode = Mode;

            // Check and save NodeObject
            if (Mode.ToUpper() == "LWRP")
            {
                if (string.IsNullOrEmpty(NodeObject))
                {
                    Terminate("NodeObject can not be empty when using LWRP mode.");
                }
                else
                {
                    try
                    {
                        File.WriteAllText(NodeObject, SprintData.NodeObject);
                    }
                    catch (Exception ex)
                    {
                        Terminate("Error writing node_object.json: " + ex.Message);
                    }
                }
            }

            // Delete the compiled script if exists
            if (File.Exists(SprintData.CompiledSprint))
            {
                File.Delete(SprintData.CompiledSprint);
            }

            // Delete the compiled resources if exists
            if (File.Exists(SprintData.CompiledResources))
            {
                File.Delete(SprintData.CompiledResources);
            }


            sprint.Build();

            string compiledScript = String.Empty;

            if (File.Exists(SprintData.CompiledSprint))
            {
                compiledScript = File.ReadAllText(SprintData.CompiledSprint);
            }
            else
            {
                Terminate("Compiled script (Spring.ps1) does not exist or is not readable.");
            }

            _pipeline = Runspace.DefaultRunspace.CreateNestedPipeline("New-Pipeline", true);
            _pipeline.Commands.AddScript(compiledScript);
            _pipeline.Output.DataReady += outputHandler;
            _pipeline.Invoke();
        }
Exemple #3
0
        public Sprint Load(string sprintId)
        {
            var events = this.eventStore.Replay(sprintId);

            return(Sprint.Build(events));
        }