Example #1
0
        /// <summary>
        /// 現在の位置から最後まで読み込む
        /// </summary>
        /// <returns></returns>
        public ReadData ReadDiff()
        {
            var	result	= new ReadData();

            try
            {
                var	fileInfo	= new FileInfo( FilePath );
                if( m_readedPosition == fileInfo.Length )
                {
                    // 既に最後まで読み込んでいた場合は終了
                    return	null;
                }

                using( var fileStream = File.Open( FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ) )
                {
                    // 既に読み込んでいる場所まで移動する
                    if( m_readedPosition != 0 )
                    {
                        if( fileStream.Length < m_readedPosition )
                        {
                            // 前回読み込んだ位置よりもファイルが小さい
                            _Reset();
                        }
                        else
                        {
                            fileStream.Seek( m_readedPosition, SeekOrigin.Begin );
                        }
                    }

                    result.StartPosition	= m_readedPosition;
                    result.StartLineNum		= m_readedLineNum;

                    using( var textReader = new StreamReader( fileStream, Encoding ) )
                    {
                        string	line;
                        while( ( line = textReader.ReadLine() ) != null )
                        {
                            result.Lines.Add( line );
                        }

                        // 読み込んだ最後の位置を覚えておく。ファイルサイズと同義
                        // m_readedPosition	= fileStream.Length;
                        m_readedPosition = fileStream.Position;

                        result.EndPosition	= m_readedPosition;
                    }

                    m_readedLineNum	+= result.Lines.Count;
                }
            }
            catch
            {
                return	result;
            }

            return	result;
        }
        /// <summary>
        /// 行テキストブロックの追加
        /// </summary>
        /// <param name="readData"></param>
        /// <param name="lineDesigns"></param>
        void _AddLineListBoxItem( ReadData readData, List<TextDesign> lineDesigns )
        {
            // ログのローテートの可能性
            {
                if( readData.EndPosition < m_lastPosition )
                {
                    _NewLogFile();
                }
                m_lastPosition	= readData.EndPosition;
            }

            var	startIndex	= 0;
            var	lineNum	= readData.StartLineNum;
            {
                var	maxLine	= Tailer.MaxLine;
                if( m_first )
                {
                    // 一度に大量のログを追加すると固まってしまうので、初回は数行のみ
                    maxLine	= m_firstMaxLine;
                }

                if( readData.Lines.Count > maxLine )
                {
                    startIndex	= readData.Lines.Count - maxLine;
                    lineNum		+= startIndex;
                }
            }

            // 初回時のみアニメーションしない
            var	animation	= !m_first;

            // LineListBoxItem の作成
            var	active	= false;
            foreach( var textLayout in lineDesigns )
            {
            #if true
                var	item	= new LineListBoxItem( textLayout )
                {
                    LineNum		= lineNum ++,
                    FontFamily	= m_logFontFamily,
                    FontSize	= m_logFontSize,
                };

                // フェードインアニメーション
                if( animation )
                {
                    item.FadeinAnimation();
                }
                if( item.IsActiveLine )
                {
                    active	= true;
                }
                m_data.Add( item );
            #else
                var	item	= new LineListBoxItem( textLayout )
                {
                    LineNum	= lineNum ++,
                    FontFamily	= m_logFontFamily,
                    FontStyle	= m_logFontStyle,
                    FontWeight	= m_logFontWeight,
                    FontStretch	= m_logFontStretch,
                    FontSize	= m_logFontSize,
                    Foreground	= m_logForeground,
                };
                // フェードインアニメーション
                if( animation )
                {
                    item.FadeinAnimation();
                }
                if( item.IsActiveLine )
                {
                    active	= true;
                }

                m_data.Add( item );
            #endif
            }

            // 最大行数を超えた分は削除する
            _DeleteLine();

            // スクロール
            _ScrollIntoViewLastItem();

            // アクティブ
            if( m_first == false && active )
            {
                _Active();
            }

            m_first	= false;
        }