Exemplo n.º 1
0
        public static CSharpClassAst Parse(string text)
        {
            var storage = new StringStorage();
            PsScriptAst = storage.Open(String.Format("$someName = '{0}'", text));
            var statementAst = PsScriptAst.ScriptBlockAst.GetLastAssignmentStatementAst("someName", null);

            return statementAst.GetCSharpClasses().First();
        }
Exemplo n.º 2
0
        private void menuAddMethodMulToClass_Click(object sender, EventArgs e)
        {
            var sharpClassAst = (CSharpClassAst) classeNamesComboBox.SelectedItem;

            sharpClassAst.AddMethod("public int Mul(int a, int b){return a* b;}");
            psScriptAst.PatchCSharpCode(sharpClassAst.GetText(), sharpClassAst.Ast);

            psScriptAst = stringStorage.Open(psScriptAst.GetText());
            var psParseResult = PSFileParser.Parse(psScriptAst);

            RefreshWindow(psParseResult);
        }
Exemplo n.º 3
0
        public static PSParseResult Parse(PSScriptAst psScriptAst)
        {
            var addTypeAsts = psScriptAst.ScriptBlockAst.GetAddTypeAsts();

            var varsWithCode = addTypeAsts
                .Select(ast => new Tuple<string, CommandAst>(ast.GetTypeDefinitionVarNames(), ast))
                .Where(x => x.Item1 != null).ToList();

            var defineVarAsts = varsWithCode
                .Select(x => psScriptAst.ScriptBlockAst.GetLastAssignmentStatementAst(x.Item1, x.Item2))
                .Where(x => x != null).ToList();

            var csharpClassAsts = defineVarAsts.SelectMany(x => x.GetCSharpClasses()).ToList();

            var invokeMembers = psScriptAst.GetInvokeMemberExpressionAst();

            return new PSParseResult(csharpClassAsts, invokeMembers, new List<string>());
        }
Exemplo n.º 4
0
        private void menuChangeCallingMethod_Click(object sender, EventArgs e)
        {
            var invokeMember = (InvokeMember) invokedMembersComboBox.SelectedItem;
            var newMethodName = (string) classesMethodsComboBox.SelectedItem;

            psScriptAst.PatchInvokeMethod(newMethodName, invokeMember.Ast);

            psScriptAst = stringStorage.Open(psScriptAst.GetText());
            var psParseResult = PSFileParser.Parse(psScriptAst);

            RefreshWindow(psParseResult);
        }
Exemplo n.º 5
0
 private void AddPSNode(PSScriptAst psAst)
 {
     var node = new TreeNode("PowerShell");
     treeView.Nodes.Add(node);
     node.Nodes.AddRange(psAst.GetTree());
 }
Exemplo n.º 6
0
        private void menuOpen_Click(object sender, System.EventArgs e)
        {
            openPSFileDialog.FileName = "TestingChallenge.ps1";
            openPSFileDialog.Filter = "powershell script|*.ps1";
            openPSFileDialog.FilterIndex = 0;
            openPSFileDialog.RestoreDirectory = true;

            if (openPSFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    psScriptAst = fileStorage.Open(openPSFileDialog.FileName);
                    var psParseResult = PSFileParser.Parse(psScriptAst);

                    RefreshWindow(psParseResult);

                    fileStatusLabel.Text = openPSFileDialog.FileName;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Error: Could not open file. Original error: {0}", ex.Message));
                }
            }
        }