Ejemplo n.º 1
0
 internal void Append(TextHighliter other)
 {
     _bits.AddRange(other._bits);
 }
Ejemplo n.º 2
0
        private void CommandExecute()
        {
#if DEBUG
            // stores the commands being launched
            var fname = Path.Combine(Path.GetTempPath(), "mvdxmlcommands.txt");
            using (var writer = System.IO.File.CreateText(fname))
            {
                writer.Write(TxtCommand.Text);
                writer.Flush();
                writer.Close();
            }
#endif

            TxtOut.Document = new FlowDocument();

            var commandArray = TxtCommand.Text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (TxtCommand.SelectedText != string.Empty)
            {
                commandArray = TxtCommand.SelectedText.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            }

            foreach (var cmdF in commandArray)
            {
                var th = new TextHighliter();

                th.Append("> " + cmdF, Brushes.ForestGreen);
                var cmd = cmdF;
                var i   = cmd.IndexOf("//", StringComparison.Ordinal);
                if (i > 0)
                {
                    cmd = cmd.Substring(0, i);
                }
                if (cmd.TrimStart().StartsWith("//"))
                {
                    continue;
                }

                var commandMatch = Regex.Match(cmd, @"^Check *(?<mode>(all|uuid|variables))?$", RegexOptions.IgnoreCase);
                if (commandMatch.Success)
                {
                    var mode = commandMatch.Groups["mode"].Value.ToLowerInvariant();
                    var some = false;
                    if (mode == "all" || mode == "uuid")
                    {
                        th.Append("== Reporting uuid-issues", Brushes.DarkGreen);
                        int iCnt = 0;
                        foreach (var issue in Doc.Mvd.ReportUuidIssues())
                        {
                            th.Append(issue, Brushes.OrangeRed);
                            iCnt++;
                        }
                        if (iCnt == 0)
                        {
                            th.Append($"== No uuid-issues found.", Brushes.DarkGreen);
                        }
                        else if (iCnt == 1)
                        {
                            th.Append($"== 1 uuid-issue found.", Brushes.Red);
                        }
                        else
                        {
                            th.Append($"== {iCnt} uuid-issues found.", Brushes.Red);
                        }

                        some = true;
                    }
                    if (mode == "all" || mode == "variables")
                    {
                        th.Append("== Reporting variable-issues", Brushes.DarkGreen);
                        int iCnt = 0;
                        foreach (var issue in Doc.Mvd.ReportVariableNameIssues())
                        {
                            th.Append(issue, Brushes.OrangeRed);
                            iCnt++;
                        }
                        if (iCnt == 0)
                        {
                            th.Append($"== No variable-issues found.", Brushes.DarkGreen);
                        }
                        else if (iCnt == 1)
                        {
                            th.Append($"== 1 variable-issues found.", Brushes.Red);
                        }
                        else
                        {
                            th.Append($"== {iCnt} variable-issues found.", Brushes.Red);
                        }

                        some = true;
                    }
                    if (!some)
                    {
                        th.Append($"== Checkm command. Unknown mode \"{mode}\". Nothing done.", Brushes.Red);
                    }

                    th.DropInto(TxtOut.Document);
                    continue;
                }

                commandMatch = Regex.Match(cmd, @"^clear *(?<what>(cache))*$", RegexOptions.IgnoreCase);
                if (commandMatch.Success)
                {
                    var what = commandMatch.Groups["what"].Value.ToLowerInvariant();
                    if (what == "cache")
                    {
                        Doc.ClearCache();
                        th.Append($"== Cache cleared.", Brushes.DarkGreen);
                        th.DropInto(TxtOut.Document);
                        continue;
                    }
                    th.Append($"== Clear command. Unknown item \"{what}\". Nothing done.", Brushes.Red);
                    th.DropInto(TxtOut.Document);
                    continue;
                }

                commandMatch = Regex.Match(cmd, @"^help$", RegexOptions.IgnoreCase);
                if (commandMatch.Success)
                {
                    th.AppendFormat("Commands:");
                    th.AppendFormat("- Check <UUID|Variables|All>");
                    th.AppendFormat("- Clear <Cache>");
                    th.DropInto(TxtOut.Document);
                    continue;
                }

                th.Append($"Commands not understood: \"{cmd}\".", Brushes.Red);
                th.DropInto(TxtOut.Document);
            }
        }