Example #1
0
        public ReadPM(string FileDir, string Filename)
        {
            try
            {
                int a;
                this.FileDir  = FileDir;
                this.Filename = Filename;
                StreamReader  f;
                string        Line;
                NE.Port       newPort     = new NE.Port(1);
                NE.Statistics currentStat = new NE.Statistics(1);
                Ports = new List <NE.Port>();
                string filepath = FileDir + "/" + Filename;
                string PortName;

                if (File.Exists(filepath))
                {
                    currentStat.FilePath = filepath;
                    var tFile = File.ReadAllText(filepath);
                    if (tFile.Contains("15 minutes"))    //read pm15 file
                    {
                        return;
                    }
                    f    = new StreamReader(filepath);
                    Line = f.ReadLine();
                    var ListLine = Line.Split(':');
                    NE_Name  = ListLine[1].Trim().TrimStart('"').TrimEnd('"');
                    Line     = f.ReadLine();
                    ListLine = Line.Split();
                    Date     = DateTime.ParseExact(ListLine[2].TrimStart('"').TrimEnd('"'), "dd:MM:yyyy", CultureInfo.InvariantCulture);

                    while (!f.EndOfStream) //повторять до конца файла
                    {
                        if (Line.Split()[0] == "PP:")
                        {
                            PortName = Line.Split()[1].TrimStart('"').TrimEnd('"'); //PortName
                        }
                        else
                        {
                            Line = f.ReadLine(); // порт
                            continue;
                        }
                        int ind = Ports.FindIndex(p => p.PortName == PortName);  //index of port in Ports
                        if (ind == -1)
                        {
                            currentStat          = new NE.Statistics(1);
                            currentStat.Date     = Date.Date; //Date
                            currentStat.FilePath = filepath;
                        }

                        f.ReadLine(); // next
                        f.ReadLine(); //next
                        Line = f.ReadLine();
                        if (String.IsNullOrEmpty(Line))
                        {
                            continue;
                        }
                        while (Line.Split()[0].Trim() == "ME:")
                        {
                            switch (Line.Split()[1].Trim())
                            {
                            case "FEBBE":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.FEBBE);
                                break;

                            case "BBE":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.BBE);
                                break;

                            case "FEES":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.FEES);
                                break;

                            case "ES":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.ES);
                                break;

                            case "SES":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.SES);
                                break;

                            case "FESES":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.FESES);
                                break;

                            case "FEUAS":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.FEUAS);
                                break;

                            case "NEUAS":
                                int.TryParse(Line.Split()[2].Trim(), out currentStat.NEUAS);
                                break;
                            }
                            Line = f.ReadLine();
                            if (String.IsNullOrEmpty(Line))
                            {
                                break;
                            }
                        }


                        //if (Line.Split()[1].Trim() == "FEBBE")
                        //    int.TryParse(Line.Split()[2].Trim(), out newStat.FEBBE);
                        //else int.TryParse(Line.Split()[2].Trim(),out newStat.BBE);
                        //Line = f.ReadLine(); //ES FEES
                        //if (Line.Split()[1].Trim() == "FEES") int.TryParse(Line.Split()[2].Trim(),out newStat.FESES);
                        //else int.TryParse(Line.Split()[2].Trim(),out newStat.ES);
                        //Line = f.ReadLine(); //SES   FESES
                        //if (Line.Split()[1].Trim() == "FESES") int.TryParse(Line.Split()[2].Trim(), out newStat.FESES);
                        //else int.TryParse(Line.Split()[2].Trim(), out newStat.SES);
                        //Line = f.ReadLine(); //UAS
                        //if (Line.Split()[1].Trim() == "FEUAS") int.TryParse(Line.Split()[2].Trim(),out newStat.FEUAS);
                        //else int.TryParse(Line.Split()[2].Trim(), out newStat.NEUAS);
                        if (ind == -1)
                        {
                            //порт не найден
                            newPort          = new NE.Port(1);
                            newPort.PortName = PortName;
                            newPort.Stat.Add(currentStat);
                            Ports.Add(newPort);  //добавление нового порта
                        }
                        else //порт найден. добавляем stat в существующий
                        {
                            var removeStat = Ports[ind].Stat.FindIndex(s => s.Date.Date == currentStat.Date.Date);
                            if (removeStat == -1)
                            {
                                Ports[ind].Stat.Add(currentStat);                 //нету такой статы
                            }
                            else //удаляем существующую стату чтобы добавить новую
                            {
                                Ports[ind].Stat.Remove(Ports[ind].Stat[removeStat]);
                                Ports[ind].Stat.Add(currentStat);
                            }
                        }
                    } //конец чтения файла

                    f.Close();
                }
                else
                {
                    MessageBox.Show("Ошибка открытия файла" + filepath, "ReadPM Class");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        public PM15(string FilePath)
        {
            try {
                Filename = FilePath.Split('\\').Last();
                Ports    = new List <NE.Port>();
                NE.Port       currentPort    = new NE.Port();
                NE.Statistics currentStat    = new NE.Statistics(1);
                int           currentInteral = 0;
                bool          firstPort      = true;
                string        nS;         // text of NumberInterval
                if (!File.Exists(FilePath))
                {
                    //Ports.Add(new NE.Port("fileNotFound"));
                    NE_Name = FilePath;
                    return;
                }
                currentStat.FilePath = FilePath;
                //all  lines in file
                var Lines = File.ReadAllLines(FilePath);
                for (int i = 0; i < Lines.Length; i++) //проход по всем строкам
                {
                    var segments = Lines[i].Split('\t');

                    switch (segments[0])
                    {
                    case "NE:":
                        NE_Name = segments[1].Trim().TrimStart('"').TrimEnd('"');
                        break;

                    case "PO:":                                                                                           //get all intervals into Intervals[]
                        nS = segments[1];                                                                                 //Номер интервала
                        int      N        = int.Parse(nS);                                                                //Номер интервала
                        string   dt       = segments[2].TrimStart('"').TrimEnd('"');                                      //дата интервала
                        DateTime datetime = DateTime.ParseExact(dt, "dd:MM:yyyy HH:mm:ss", CultureInfo.InvariantCulture); //дата интервала
                        Intervals[N] = datetime;
                        break;

                    case "PP:":             //port name
                        var port_Name = segments[1].Trim('"');
                        //save prev port
                        if (!firstPort)
                        {
                            currentPort.Stat.Add(currentStat);
                            Ports.Add(currentPort);
                            currentPort = new NE.Port(port_Name);
                        }
                        else
                        {
                            currentPort = new NE.Port(port_Name);
                            firstPort   = false;
                        }
                        break;

                    case "BL:":                       //errors interval
                        nS             = segments[1]; //Номер интервала
                        currentInteral = int.Parse(nS);
                        if (currentInteral != 0)
                        {
                            currentPort.Stat.Add(currentStat);
                        }
                        currentStat          = new NE.Statistics(1);
                        currentStat.FilePath = FilePath;
                        currentStat.Date     = Intervals[currentInteral];
                        break;

                    case "ME:":              //ERRORS
                        var erType  = segments[1];
                        int erCount = int.Parse(segments[2].Trim());
                        switch (erType)
                        {
                        case "NEUAS":
                            currentStat.NEUAS = erCount;
                            break;

                        case "SES":
                            currentStat.SES = erCount;
                            break;

                        case "ES":
                            currentStat.ES = erCount;
                            break;

                        case "BBE":
                            currentStat.BBE = erCount;
                            break;

                        case "FEBBE":
                            currentStat.FEBBE = erCount;
                            break;

                        case "FEES":
                            currentStat.FEES = erCount;
                            break;

                        case "FESES":
                            currentStat.FESES = erCount;
                            break;

                        case "FEUAS":
                            currentStat.FEUAS = erCount;
                            break;
                        }
                        break;
                    }

                    if (i == Lines.Length - 1)
                    {
                        currentPort.Stat.Add(currentStat);
                        Ports.Add(currentPort);
                    }
                }
            } catch (Exception Ex) {
                throw new Exception("PM15", Ex);
            }
        }