Exemple #1
0
        public void TranspileElementsTest(string xml)
        {
            XPathNodeIterator nodes = XmlLoader.Load(xml);

            var commands = Transpilator.TranspileElements(nodes);

            Assert.IsType <List <Command> >(commands);
            Assert.NotNull(commands);
            Assert.True(commands.Count > 0);
        }
Exemple #2
0
        public IList <Action> GenerateActionsForPrinter(string text)
        {
            var actions = new List <Action>();

            var elements = XmlLoader.Load(text);
            var commands = Transpilator.TranspileElements(elements);

            actions.Add(() => Printer.WakeUp());

            foreach (var command in commands)
            {
                if (!string.IsNullOrEmpty(command.Tag))
                {
                    switch (command.Tag)
                    {
                    case "ad":
                        actions.Add(() => Printer.SetAlignRight());
                        actions.Add(() => Printer.WriteLine(command.Value));
                        break;

                    case "/ad":
                        actions.Add(() => Printer.SetAlignLeft());
                        break;

                    case "s":
                        actions.Add(() => Printer.SetUnderline(2));
                        actions.Add(() => Printer.WriteToBuffer(command.Value));
                        break;

                    case "/s":
                        actions.Add(() => Printer.SetUnderline(0));
                        break;

                    case "b":
                        actions.Add(() => Printer.BoldOn());
                        actions.Add(() => Printer.WriteToBuffer(" " + command.Value));
                        break;

                    case "/b":
                        actions.Add(() => Printer.BoldOff());
                        break;

                    case "c":
                        actions.Add(() => Printer.WriteToBuffer(command.Value + " "));
                        break;

                    case "/c":
                        break;

                    case "ce":
                        actions.Add(() => Printer.SetAlignCenter());
                        actions.Add(() => Printer.WriteToBuffer(command.Value));
                        break;

                    case "/ce":
                        actions.Add(() => Printer.SetAlignLeft());
                        break;

                    case "l":
                        actions.Add(() => Printer.LineFeed());
                        break;

                    case "/l":
                        break;

                    case "sl":
                        actions.Add(() => Printer.LineFeed(byte.Parse(command.Value)));
                        break;

                    case "/sl":
                        break;

                    case "gui":
                        actions.Add(() => Printer.Guillotine());
                        break;

                    case "/gui":
                        break;

                    default:
                        actions.Add(() => Printer.WriteToBuffer(command.Value));
                        break;
                    }
                }
                else
                {
                    actions.Add(() => Printer.WriteToBuffer(command.Value));
                }

                actions.Add(() => Printer.SetAlignLeft());
            }

            return(actions);
        }
Exemple #3
0
        public IList <Action> GenerateActionsForPrinter(string text)
        {
            var actions = new List <Action>();

            try
            {
                var elements = XmlLoader.Load(text);
                var commands = Transpilator.TranspileElements(elements);

                actions.Add(() => Printer.WakeUp());
                actions.Add(() => Printer.Reset());
                actions.Add(() => Printer.SetLineSpacing(2));
                actions.Add(() => Printer.SetLetterSpacing(2));
                actions.Add(() => Printer.SetMarginLeft(20)); // if elgin

                foreach (var command in commands)
                {
                    if (!string.IsNullOrEmpty(command.Tag))
                    {
                        switch (command.Tag)
                        {
                        case "ad":
                            actions.Add(() => Printer.SetAlignRight());
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/ad":
                            actions.Add(() => Printer.SetAlignLeft());
                            break;

                        case "b":
                            actions.Add(() => Printer.BoldOn());
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/b":
                            actions.Add(() => Printer.BoldOff());
                            break;

                        case "c":
                            actions.Add(() => Printer.SetLineSpacing(0));
                            actions.Add(() => Printer.SetLetterSpacing(0));
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/c":
                            actions.Add(() => Printer.SetLineSpacing(2));
                            actions.Add(() => Printer.SetLetterSpacing(2));
                            break;

                        case "ce":
                            actions.Add(() => Printer.SetAlignCenter());
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/ce":
                            actions.Add(() => Printer.SetAlignLeft());
                            break;

                        case "l":
                            actions.Add(() => Printer.LineFeed());
                            break;

                        case "/l":
                            break;

                        case "sl":
                            actions.Add(() => Printer.LineFeed(byte.Parse(command.Value)));
                            break;

                        case "/sl":
                            break;

                        case "gui":
                            actions.Add(() => Printer.Guillotine());
                            break;

                        case "/gui":
                            break;

                        default:
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;
                        }
                    }
                    else
                    {
                        actions.Add(() => Printer.WriteLine(command.Value));
                    }
                }

                return(actions);
            }
            catch
            {
                return(null);
            }
        }