LogAnalyzeManager.cs 5.1 KB
using LineSoldering.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using System.Windows.Forms;

namespace LineSoldering.DeviceLibrary
{
    public class LogAnalyzeManager
    {

        public static List<TempLog> getWeldLog(DateTime startTime, DateTime endTime)
        {
            //查找文件夹
            string dic = Application.StartupPath + @"\logs\temp\";

            string[] files = Directory.GetFiles(dic);
            List<TempLog> tempList = new List<TempLog>();
            List<string> lines = new List<string>();
            foreach (string f in files)
            {
                DateTime time = LogUtil.GetFileTime(f);
                DateTime logEndTime = time.AddDays(1);
                if (time != null && ((startTime <= time && time <= endTime) || (time <= startTime && startTime <= logEndTime)))
                {
                    //读取文件内容
                    string[] fileValue = File.ReadAllLines(f);
                    foreach (string s in fileValue)
                    {
                        TempLog log = TempLog.GetLog(s);
                        if (log != null)
                        {
                            if (log.LogTime >= startTime && log.LogTime <= endTime)
                            {
                                tempList.Add(log);
                                lines.Add(s);
                            }
                        }
                    }
                }
            }
            LogUtil.info("查询结果:共【" + tempList.Count + "】条记录");
            int i = 1;
            return tempList;
        }

        public static List<BoardLog> getBoardLogList(DateTime startTime, DateTime endTime, BoardInfo board, out List<string> lines)
        {
            if (board.boardId <= 0)
            {
                board = null;
            }
            //查找文件夹
            string dic = Application.StartupPath + @"\logs\soldering\";

            List<BoardLog> boardLogList = new List<BoardLog>();
            string[] files = Directory.GetFiles(dic);
            lines = new List<string>();
            foreach (string f in files)
            {
                DateTime time = LogUtil.GetFileTime(f);
                DateTime logEndTime = time.AddDays(1);
                if (time != null && ((startTime <= time && time <= endTime)||(time<=startTime&&startTime<=logEndTime)))
                {
                    //读取文件内容
                    string[] fileValue = File.ReadAllLines(f);
                    foreach (string s in fileValue)
                    {
                        BoardLog log = BoardLog.GetLog(s);

                        if (log != null)
                        {
                            if (log.LogTime >= startTime && log.LogTime <= endTime && (board == null || board.boardId <= 0 || log.BoardName.Equals(board.boardName)))
                            {
                                List<WeldPointInfo> list = new List<WeldPointInfo>();
                                if (board == null || board.boardId <= 0)
                                {
                                    BoardInfo theBorad = BoardManager.getBoardByName(log.BoardName);
                                    if (theBorad != null)
                                    {
                                        list = (from m in theBorad.pointList where m.pointName.Equals(log.BoardPoint) select m).ToList<WeldPointInfo>();
                                    }
                                }
                                else
                                {
                                    list = (from m in board.pointList where m.pointName.Equals(log.BoardPoint) select m).ToList<WeldPointInfo>();
                                }
                                if (list != null && list.Count > 0)
                                {
                                    WeldPointInfo point = list[0];
                                    if (log.PreTemp <= 0)
                                    {
                                        log.PreTemp = point.preheatTemperature;
                                    } if (log.WeldTemp <= 0)
                                    {
                                        log.WeldTemp = point.weldTemperature;
                                    }
                                    if (log.PreSendWire <= 0)
                                    {
                                        log.PreSendWire = point.startSendWireSpeed * point.startSendWireTime;
                                    } if (log.SendWire <= 0)
                                    {
                                        log.SendWire = point.sendWireSpeed * point.sendWireTime;
                                    }
                                    boardLogList.Add(log);
                                    lines.Add(log.ToCSVString());
                                }
                            }
                        }
                    }
                }
            }
            lines.Insert(0, BoardLog.CSVTitleString());
            return boardLogList;
        }
    }
}