Пример #1
0
        private static String MergeXml(params string[] xml)
        {
            string body_temp, numOfRows_str, pageNo_str
            , head = xml[0].Substring(0, xml[0].IndexOf("<msgBody>") + "<msgBody>".Length)
            , body = (body = xml[0].Substring(xml[0].IndexOf("<msgBody>") + "<msgBody>".Length)).Substring(0, body.IndexOf("</msgBody>"))
            , tail = xml[0].Substring(xml[0].IndexOf("</msgBody>"));
            int numOfRows, pageNo;

            numOfRows_str = (numOfRows_str = (head.Substring(head.IndexOf("<numOfRows>") + "<numOfRows>".Length))).Substring(0, numOfRows_str.IndexOf("</numOfRows>"));
            numOfRows     = BusInfo.ConvertStrToNaturalNumber(numOfRows_str);
            pageNo_str    = (pageNo_str = (head.Substring(head.IndexOf("<pageNo>") + "<pageNo>".Length))).Substring(0, pageNo_str.IndexOf("</pageNo>"));
            pageNo        = BusInfo.ConvertStrToNaturalNumber(pageNo_str);


            for (int i = 1; i < xml.Length; i++)
            {
                numOfRows_str = (numOfRows_str = (xml[i].Substring(0, xml[i].IndexOf("<msgBody>") + "<msgBody>".Length).Substring(xml[i].Substring(0, xml[i].IndexOf("<msgBody>") + "<msgBody>".Length).IndexOf("<numOfRows>") + "<numOfRows>".Length))).Substring(0, numOfRows_str.IndexOf("</numOfRows>"));
                numOfRows    += BusInfo.ConvertStrToNaturalNumber(numOfRows_str);
                pageNo_str    = (pageNo_str = (xml[i].Substring(0, xml[i].IndexOf("<msgBody>") + "<msgBody>".Length).Substring(xml[i].Substring(0, xml[i].IndexOf("<msgBody>") + "<msgBody>".Length).IndexOf("<pageNo>") + "<pageNo>".Length))).Substring(0, pageNo_str.IndexOf("</pageNo>"));
                pageNo       += BusInfo.ConvertStrToNaturalNumber(pageNo_str);

                body_temp = (body_temp = xml[i].Substring(xml[i].IndexOf("<msgBody>") + "<msgBody>".Length)).Substring(0, body_temp.IndexOf("</msgBody>"));
                body     += body_temp;
            }

            head = head.Substring(0, head.IndexOf("<numOfRows>") + "<numOfRows>".Length)
                   + numOfRows + head.Substring(head.IndexOf("</numOfRows>"));
            head = head.Substring(0, head.IndexOf("<pageNo>") + "<pageNo>".Length)
                   + pageNo + head.Substring(head.IndexOf("</pageNo>"));

            return(head + body + tail);
        }
Пример #2
0
        static bool checkIntegrity(String fileName)
        {
            fileName = String.Format("{0}\\{1}년 {2}월\\Sorted CSV Files\\{0}", "Bus Information for Big Data", DateTime.Now.Year, DateTime.Now.Month, fileName);
            FileInfo fileInfo = new FileInfo(fileName);

            if (!fileInfo.Exists)
            {
                throw new System.ArgumentException("Called from checkIntegrity(), Message : No Such File(" + fileName + ").", "directory fault");
                return(false);
            }

            System.IO.StreamReader file = new System.IO.StreamReader(fileName);

            string strLine = file.ReadLine();

            string[] column = strLine.Split(','), temp;        // Split() 메서드를 이용하여 ',' 구분하여 잘라냄

            int i;
            int ROUTE_ID = -1, RSTOP = -1, prev_RSTOP = -1, ROUTE_ID_index = -1, RSTOP_index = -1, Line_Hash_index = -1;

            List <int> Line_Hash = new List <int>();

            int ROUTE_NAME, ROUTE_NAME_index = -1;

            for (i = 0; i < column.Length; i++)
            {
                if (column[i] == _getArrInfoByStopID.msgBody.ROUTE_ID)
                {
                    ROUTE_ID_index = i;
                }
                else if (column[i] == _getArrInfoByStopID.msgBody.RSTOP)
                {
                    RSTOP_index = i;
                }
                else if (column[i] == "Line-Hash")
                {
                    Line_Hash_index = i;
                }
                if (RSTOP_index != -1 && ROUTE_ID_index != -1 && Line_Hash_index != -1)
                {
                    break;
                }
            }
            if (RSTOP_index == -1 || ROUTE_ID_index == -1 || Line_Hash_index == -1)
            {
                throw new System.ArgumentException("Called from BusHistory_CSVFile_sort(), Message : Can't find these columns(RSTOP, ROUTE_ID, Line-Hash)", "csv file content fault");
                return(false);
            }

            while ((strLine = file.ReadLine()) != null)
            {
                temp = strLine.Split(',');
                if (temp.Length < 2) // 회차변경
                {
                    ROUTE_ID   = BusInfo.ConvertStrToNaturalNumber(temp[ROUTE_ID_index]);
                    prev_RSTOP = -1;
                    continue;
                }

                if (prev_RSTOP == -1)
                {
                }
                else
                {
                    RSTOP = BusInfo.ConvertStrToNaturalNumber(temp[RSTOP_index]);
                    if (prev_RSTOP - RSTOP != 1)
                    {
                        //throw new Exception("RSTOP간격이 1이 아닙니다 ("+strLine+ ").");
                        Console.WriteLine("RSTOP간격이 1이 아닙니다 (" + strLine + ").");
                    }
                }

                if (Line_Hash.Contains(BusInfo.ConvertStrToNaturalNumber(temp[Line_Hash_index])))
                {
                    throw new Exception("중복된 Line Hash값이 있습니다.");
                }
                else
                {
                    Line_Hash.Add(BusInfo.ConvertStrToNaturalNumber(temp[Line_Hash_index]));
                }


                prev_RSTOP = BusInfo.ConvertStrToNaturalNumber(temp[RSTOP_index]);
            }

            return(true);
        }