Example #1
0
        private void btnLoadData_Click(object sender, EventArgs e)
        {
            frmLoadHistory frm    = new frmLoadHistory();
            logLoadFilter  filter = frm.ShowDialog(txtLogPath.Text);    // filter dialog

            if (filter.res == System.Windows.Forms.DialogResult.OK)
            {
                olvLog.ClearObjects();                                          // clear logs
                List <logData> list      = ReadFolder(txtLogPath.Text, filter); // read logs from dir
                ArrayList      classList = new ArrayList();
                foreach (logData x in list)
                {
                    classList.Add(new LogItem(x));                      // create class from list -> fastListView
                }
                olvLog.AddObjects(classList);                           // add logs to fastListView
                RefreshStatus();                                        // refresh status bar
            }
        }
Example #2
0
        public logLoadFilter ShowDialog(string path)
        {
            logLoadFilter filter  = new logLoadFilter();    // filter
            List <string> devList = new List <string>();    // device list

            // ----- IF EXIST LOG DIRECTORY -----
            if (Directory.Exists(path))
            {
                // ----- GET DIR LIST -----
                string[] dirList = Directory.GetDirectories(path);
                for (int i = 0; i < dirList.Length; i++)
                {
                    // ----- SEPARATE DEVICE NAME -----
                    string name = Path.GetFileName(dirList[i]);
                    lvDevices.Items.Add(name);      // add device to deviceListView
                }

                // ----- FILL FILTER -----
                filter.res      = base.ShowDialog();    // <- ShowDialog result
                filter.useFrom  = chbFrom.Checked;
                filter.useTo    = chbTo.Checked;
                filter.fromTime = dtFrom.Value.Date;
                filter.toTime   = dtTo.Value.Date;
                for (int j = 0; j < lvDevices.Items.Count; j++) // get selected devices
                {
                    if (lvDevices.Items[j].Checked)
                    {
                        devList.Add(lvDevices.Items[j].Text);
                    }
                }
                filter.deviceList = devList.ToArray(); // <- selected devices list
            }
            else
            {
                // ----- IF NOT EXIST LOG DIRECTORY -----
                Dialogs.ShowErr("Path not exist!", "Error");
                filter.res = System.Windows.Forms.DialogResult.Cancel;
            }
            return(filter);
        }
Example #3
0
        /// <summary>
        /// Read log folder with filter
        /// </summary>
        /// <param name="path">Log folder</param>
        /// <param name="filter">Filter</param>
        /// <returns></returns>
        private List <logData> ReadFolder(string path, logLoadFilter filter)
        {
            List <logData> list = new List <logData>();

            if (path != "")
            {
                // ----- READ LOG DIRECTORIES -----
                string[] dirList = Directory.GetDirectories(path);
                for (int i = 0; i < dirList.Length; i++)
                {
                    string        name    = Path.GetFileName(dirList[i]);
                    List <string> devList = filter.deviceList.ToList();
                    // ----- USE DEVICE FILTER -----
                    if (devList.Contains(name))
                    {
                        string[] fileList = Directory.GetFiles(dirList[i]);
                        for (int j = 0; j < fileList.Length; j++)
                        {
                            string x = Path.GetExtension(fileList[j]);
                            // ----- USE EXTENSION FILTER -----
                            if (Path.GetExtension(fileList[j]) == ".log")
                            {
                                // ----- USE DATE FILTER -----
                                string fileName = Path.GetFileNameWithoutExtension(fileList[j]);
                                try
                                {
                                    int year, month, day;
                                    year  = int.Parse(fileName.Substring(fileName.Length - 6, 2)) + 2000;
                                    month = int.Parse(fileName.Substring(fileName.Length - 4, 2));
                                    day   = int.Parse(fileName.Substring(fileName.Length - 2, 2));
                                    DateTime fileDate = new DateTime(year, month, day);
                                    string   process  = "";
                                    int      pos      = fileName.IndexOf('_');
                                    if (pos >= 0)
                                    {
                                        process = fileName.Substring(0, pos);
                                    }

                                    bool add = false;
                                    if (filter.useFrom && filter.useTo)
                                    {
                                        if (fileDate >= filter.fromTime && fileDate <= filter.toTime)
                                        {
                                            add = true;
                                        }
                                    }
                                    else if (filter.useFrom)
                                    {
                                        if (fileDate >= filter.fromTime)
                                        {
                                            add = true;
                                        }
                                    }
                                    else if (filter.useTo)
                                    {
                                        if (fileDate <= filter.toTime)
                                        {
                                            add = true;
                                        }
                                    }
                                    else
                                    {
                                        add = true;
                                    }

                                    if (add == true)
                                    {
                                        // ----- ADD FILE TO LOG LIST -----
                                        string text = Files.LoadFile(fileList[j], Encoding.UTF8);
                                        list = AddLog(text, "", name, process, false, list);
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
            }


            return(list);
        }