Example #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="FormProcessDisplay" /> class.
        /// </summary>
        /// <param name="windowTitle">The description / form title</param>
        /// <param name="withLoggerDisplay">True if a debug logging windows should be shown</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public FormProcessDisplay(string windowTitle, bool withLoggerDisplay, CancellationToken cancellationToken)
        {
            CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            m_ProcessDisplay        = new ProcessDisplayTime(CancellationTokenSource.Token);
            InitializeComponent();

            m_Title   = windowTitle;
            base.Text = windowTitle;

            Maximum = 0;
            SuspendLayout();
            m_TableLayoutPanel.SuspendLayout();
            if (withLoggerDisplay)
            {
                Height += 100;

                m_LoggerDisplay = new LoggerDisplay {
                    MinLevel = Logger.Level.Debug, Dock = DockStyle.Fill, Multiline = true, TabIndex = 8
                };
                m_TableLayoutPanel.Controls.Add(m_LoggerDisplay, 0, 3);
                m_LoggerDisplay.Dock = DockStyle.Fill;
            }

            m_TableLayoutPanel.ResumeLayout(false);
            m_TableLayoutPanel.PerformLayout();
            ResumeLayout(false);
            PerformLayout();
        }
Example #2
0
        private void UpdateView()
        {
            m_DisplayedAt = ScrollBarVertical.Value;
            if (string.IsNullOrEmpty(m_CsvFile.FileName))
            {
                return;
            }
            try
            {
                using (var procDisp = new ProcessDisplayTime(System.Threading.CancellationToken.None))
                    using (var istream = ImprovedStream.OpenRead(m_CsvFile))
                        using (var sr = new StreamReader(istream.Stream, m_CsvFile.GetEncoding(), m_CsvFile.ByteOrderMark))
                        {
                            // Some stream do not support seek...
                            if (istream.Stream.CanSeek)
                            {
                                istream.Stream.Seek(m_DisplayedAt, SeekOrigin.Begin);
                                if (m_DisplayedAt != 0)
                                {
                                    // find the line start
                                    var read = sr.Read();
                                    while (read != 13 && read != 10 && !sr.EndOfStream)
                                    {
                                        read = sr.Read();
                                    }

                                    var next = sr.Peek();
                                    if (read == 13 && next == 10 || read == 10 && next == 13)
                                    {
                                        sr.Read();
                                    }
                                }
                            }
                            else
                            {
                                ScrollBarVertical.Enabled = false;
                            }

                            var buffer = new char[32000];
                            var len    = sr.Read(buffer, 0, buffer.Length);
                            CSVTextBox.Text = new string(buffer, 0, len);
                        }
            }
            catch (Exception exc)
            {
                CSVTextBox.Text = exc.ExceptionMessages();
            }
        }