private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            string itemText   = null;
            string tagText    = null;
            var    senderItem = sender as MenuItem;

            if (sender is MenuItem)
            {
                itemText = (sender as MenuItem).Header as string;
            }
            tagText = senderItem.Tag as string;

            if (itemText == "Telnet")
            {
                var devName  = "STEVE26";
                var termType = "IBM-3477-FC"; // IBM-3477-FC, IBM-3179-2
                TelnetInitialConnect(
                    this.Model.SystemName, this.Model.AutoConnect, this.Model.DeviceName, this.Model.TerminalType);
            }

            else if (itemText == "Printer")
            {
                TelnetPrinterConnect(this.Model.SystemName);
            }

            else if (itemText == "Exit")
            {
                this.canAutoClose = true;
                this.Close();
            }

            else if (itemText == "Test")
            {
                var s2 = this.Model.ScreenDefnPath;
                Debug.Print("ScreenDefnPath:" + s2);
            }

            else if (itemText == "Read xml")
            {
                string    xmlPath = "c:\\skydrive\\c#\\TextCanvasLib\\xmlfile1.xml";
                var       items   = ScreenDocReader.ReadDoc(xmlPath);
                OneRowCol caret   = null;
                this.Model.TelnetCanvas.PaintScreen(items, caret);
            }

            else if (itemText == "Print log")
            {
                LinePrinter.PrintLines(this.Model.RunLog);
            }
            else if (itemText == "Clear log")
            {
                MainWindow.LogFile.ClearFile();
                this.Model.RunLog.Clear();
                this.PaintThread.PostInputMessage(ThreadMessageCode.ClearLog);
                this.MasterThread.PostInputMessage(ThreadMessageCode.ClearLog);
                this.ToThread.PostInputMessage(ThreadMessageCode.ClearLog);
                this.FromThread.PostInputMessage(ThreadMessageCode.ClearLog);
            }
            else if (itemText == "view special")
            {
                var    specialPath = "c:\\downloads\\specialLog.txt";
                string exePath     =
                    Environment.ExpandEnvironmentVariables(@"%windir%\system32\notepad.exe");
                Process.Start(exePath, specialPath);
            }

            else if (itemText == "Report canvas items")
            {
                MasterThread.PostInputMessage(ThreadMessageCode.ReportVisualItems);
                var visualItems = this.Model.TelnetCanvas.VisualItems;
                var report      = wtdReportExt.PrintVisualItems(visualItems);
                this.Model.RunLog.AddRange(report);
            }

            else if (itemText == "Send data")
            {
                var dataBytes = new byte[] { 0x00, 0x0a, 0x12, 0xa0, 0x01, 0x02,
                                             0x04, 0x00, 0x00, 0x01, 0xff, 0xef };

                dataBytes = new byte[] { 0x00, 0x0A, 0x12, 0xA0, 0x01, 0x02,
                                         0x04, 0x00, 0x00, 0x01, 0xFF, 0xEF };

                var dataMessage = new SendDataMessage(dataBytes);
                this.ToThread.PostInputMessage(dataMessage);
            }

            // capture the currently matched screen.
            else if (tagText == "Capture")
            {
                if (this.Model.MatchScreenDefn == null)
                {
                    MessageBox.Show("no matched screen to capture");
                }
                else
                {
                    // send message to master thread to get the current screen content.
                    var msg = new ExchangeMessage(ThreadMessageCode.GetScreenContent);
                    this.MasterThread.PostInputMessage(msg);
                    msg.WaitReplyEvent();
                    var content = msg.ReplyMessage as ScreenContent;

                    // send message to capture thread telling it to capture the current
                    // screen.
                    var captureMessage = new CaptureContentMessage(
                        this.Model.CaptureFolderPath, this.Model.CaptureAuto,
                        this.Model.MatchScreenDefn, content);
                    this.CaptureThread.PostInputMessage(captureMessage);
                }
            }

            else if (tagText == "CaptureViewer")
            {
                var window = new CaptureViewerWindow();
                window.CaptureFolderPath = this.Model.CaptureFolderPath;
                window.Show();
            }
        }
        /// <summary>
        /// import the ContentItems of the current ScreenContent. Use the MasterThread
        /// property to send a message to the MasterThread asking for a copy of the
        /// current screenContent. That sent message waits for a response and receives
        /// the screenContent as the reply. With the screenContent, then list the
        /// ScreenContent items and import into ScreenDefn.
        ///
        /// Necessary for this to work, the telnetClient which is the parent of the
        /// ScreenDefnListControl must bind to the MasterThread property.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void butImport_Click(object sender, RoutedEventArgs e)
        {
            // send a message to the master thread asking for a copy of the current
            // screenContent.
            ScreenContent content = null;
            {
                var msg = new ExchangeMessage(ThreadMessageCode.GetScreenContent);
                this.MasterThread.PostInputMessage(msg);
                msg.WaitReplyEvent();
                content = msg.ReplyMessage as ScreenContent;
            }

            // create screen section. type body.
            var section = new ScreenSectionModel()
            {
                ScreenLoc   = new OneScreenLoc(1, 1),
                ItemName    = "Body",
                ItemType    = ShowItemType.Section,
                PurposeCode = ScreenPurposeCode.Body
            };

            this.Model.AddItem(section);

            int fieldNum = 0;
            int litNum   = 0;

            foreach (var citem in content.ContentItems( ))
            {
                if (citem is ContentField)
                {
                    var fld = citem as ContentField;

                    {
                        fieldNum += 1;
                        var xx   = fld.IsBypass;
                        var item = new ScreenFieldModel()
                        {
                            ScreenLoc = new OneScreenLoc(fld.RowCol.ToOneBased()),
                            ItemName  = "Field" + fieldNum,
                            Length    = fld.LL_Length,
                            ItemType  = ShowItemType.Field,
                            Usage     = fld.Usage,
                            DsplyAttr = fld.AttrByte.ToDsplyAttr()
                        };
                        section.AddItem(item);
                    }
                }
                else if (citem is ContentText)
                {
                    var contentText = citem as ContentText;
                    {
                        litNum += 1;
                        var item = new ScreenLiteralModel()
                        {
                            ScreenLoc  = new OneScreenLoc(contentText.RowCol.ToOneBased()),
                            ItemName   = "Lit" + litNum,
                            ListValues = contentText.GetShowText(content).ToListString().ToObservableCollection( ),
                            Length     = contentText.GetShowText(content).Length,
                            ItemType   = ShowItemType.Literal,
                            DsplyAttr  = contentText.GetAttrByte(content).ToDsplyAttr()
                        };

#if skip
                        // adjust screenLoc to account for neutral dsply attr.
                        if (item.DsplyAttr.IsEqual(DsplyAttr.NU))
                        {
                            item.ScreenLoc = item.ScreenLoc.Advance(1, new AutoCoder.Telnet.Common.ScreenDm.ScreenDim(24, 80)) as OneScreenLoc;
                        }
#endif

                        section.AddItem(item);
                    }
                }
            }
        }