Esempio n. 1
0
        public List <RadioStationItem> read_prev_data()
        {
            List <RadioStationItem> _radiostation_prev = new List <RadioStationItem>();

            using (StreamReader sr = new StreamReader(file_radio_station))
            {
                Console.WriteLine(@"read_prev_data file_radio_station = " + file_radio_station);

                string line;

                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(line);

                    string[] fields = line.Split(',');

                    RadioStationItem logItem = new RadioStationItem()
                    {
                        call_sign       = fields[0],
                        station_type    = fields[1],
                        station_address = fields[2],
                        bool_14mhz      = fields[3],
                        max_power_watt  = fields[4],
                        checked_date    = fields[5]
                    };

                    _radiostation_prev.Add(logItem);

                    //bindingSource.DataSource = _radiostation_prev;
                }
            }
            Console.WriteLine(@"read_prev_data _radiostation_prev.Count() = " + _radiostation_prev.Count());

            return(_radiostation_prev);
        }
        public List <RadioStationItem> Read_Prev_Data()
        {
            List <RadioStationItem> _radiostation_prev = new List <RadioStationItem>();

            string fileName = file_radio_station;

            if (System.IO.File.Exists(fileName))
            {
                using (StreamReader sr = new StreamReader(file_radio_station))
                {
                    Console.WriteLine(@"read_prev_data file_radio_station = " + file_radio_station);

                    string line;
                    int    no_data = 0;

                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);

                        string[] fields = line.Split(',');
                        no_data++;

                        RadioStationItem logItem = new RadioStationItem()
                        {
                            no              = no_data,
                            call_sign       = fields[0],
                            station_type    = fields[1],
                            station_address = fields[2],
                            bool_14mhz      = fields[3],
                            max_power_watt  = fields[4],
                            checked_date    = fields[5]
                        };

                        _radiostation_prev.Add(logItem);

                        //bindingSource.DataSource = _radiostation_prev;
                    }
                }

                //Console.WriteLine(@"read_prev_data _radiostation_prev.Count() = " + _radiostation_prev.Count());
                mainWindow.LabelNumberOfSoumu.Content = _radiostation_prev.Count();
            }
            else
            {
                MessageBox.Show("File not found in Read_Prev_Data:" + fileName);
            }

            return(_radiostation_prev);
        }
        public void CompleteDownloadProcSerial(string result, string call /*, BindingSource bindingSource*/)
        {
            //Console.WriteLine("CompleteDownloadProcSerial: e.Result = " + result);

            MatchCollection zeromatch = Regex.Matches(result, "検索結果が0件です。");

            if (0 < zeromatch.Count)
            {
                //-------------------------------------------------------------------------------------検索結果が0件です。
                string m = "CompleteDownloadProcSerial: zeromatch.Count = " + zeromatch.Count + " " + call;
                mainWindow.LabelStatusBarSoumu.Content = m;

                //-----------------------------------------------------------item data .csv write

                DateTime dt_now       = DateTime.Now;
                string[] aStrings     = { call, dt_now.ToString("yyyy-MM-dd") };
                string   strSeparator = ",";
                string   strLine      = string.Join(strSeparator, aStrings);

                using (StreamWriter sw = new StreamWriter(file_not_found, true))
                {
                    sw.WriteLine(strLine);
                    sw.Close();
                }
            }
            else
            {
                MatchCollection matches = Regex.Matches(result, ".*[都道府県].*<br>");

                foreach (Match m in matches)
                {
                    //Console.WriteLine(m.Value);
                    string address = m.Value.Replace("<br>", "").Trim();
                    Console.WriteLine("CompleteDownloadProcSerial: address = " + address + " " + call);
                }

                //-----------------------------------------------------------
                //<a href="./SearchServlet?pageID=4&IT=A&DFCD=0009844&DD=1&styleNumber=50" target="_blank">XXX(XXXXXX)</a>
                //-----------------------------------------------------------

                string          HRefPattern = "href\\s*=\\s*(?:[\"'](?<1>[^\"']*)[\"']|(?<1>\\S+))";
                MatchCollection mat2        = Regex.Matches(result, HRefPattern);

                foreach (Match m in mat2)
                {
                    if (m.Value.Contains("pageID=4"))
                    {
                        //-------------------------------------------------------------------------------------parse subpage
                        string href = m.Value;

                        Console.WriteLine("CompleteDownloadProcSerial: address = " + href + " " + call);

                        string url              = href.Remove(0, 7);
                        string url2             = "https://www.tele.soumu.go.jp/musen" + url.Remove(url.Length - 1, 1);
                        System.Net.WebClient wc = new System.Net.WebClient();
                        wc.Encoding = System.Text.Encoding.Default;

                        string source = wc.DownloadString(url2);
                        wc.Dispose();

                        //Console.WriteLine(source);

                        //----
                        string[] deli  = { "\n" };
                        string[] lines = source.Split(deli, StringSplitOptions.None);

                        //----------------------------------------------------------識別信号
                        int index0 = Array.FindIndex(lines, ContainsCallsign);
                        Console.WriteLine("CompleteDownloadProcSerial: lines[index + 4] = " + lines[index0 + 4].Trim() + " " + call);
                        string callsign = lines[index0 + 4].Replace("<BR>", "").Trim();

                        //----------------------------------------------------------氏名又は名称
                        int index1 = Array.FindIndex(lines, ContainsKeyword);
                        Console.WriteLine("CompleteDownloadProcSerial: lines[index + 4] = " + lines[index1 + 4].Trim() + " " + call);
                        string op_name = lines[index1 + 4].Trim();

                        //----------------------------------------------------------移動範囲

                        string type_station = "";

                        if (source.Contains("陸上、海上及び上空"))
                        {
                            type_station = "陸上、海上及び上空";
                        }
                        else if (source.Contains("移動しない"))
                        {
                            type_station = "移動しない";
                        }

                        //----------------------------------------------------------無線設備の設置場所/常置場所
                        string sta_place = "";
                        int    index2    = Array.FindIndex(lines, ContainsPlace);
                        for (int i = 0; i < 40; i++)
                        {
                            //Console.WriteLine("CompleteDownloadProc: lines[index + 4] = " + lines[index2 + i].Trim() + " " + call);

                            if (lines[index2 + i].Contains("<br>"))
                            {
                                sta_place = lines[index2 + i].Trim().Replace("<br>", "");
                                Console.WriteLine("CompleteDownloadProcSerial: Contains <br> = " + sta_place + " " + call);
                            }
                        }

                        //----------------------------------------------------------14175 MHz
                        int    index3    = Array.FindIndex(lines, Contains14175);
                        string power     = "";
                        string bool14mhz = "NO";
                        if (0 < index3)
                        {
                            power = lines[index3 + 22].Replace("&nbsp;", "").Replace(@"<td><pre class=""defpre"">", "").Replace(@"</pre></td>", "").Trim();

                            Console.WriteLine("CompleteDownloadProcSerial: power = 14175MHz " + power.Trim() + " " + call);
                            bool14mhz = "YES14MHz";
                        }
                        else
                        {
                            bool14mhz = "NO";
                        }

                        //-----------------------------------------------------------item data Add
                        DateTime dt_now     = DateTime.Now;
                        string   date_today = dt_now.ToString("yyyy-MM-dd");

                        RadioStationItem newItem = new RadioStationItem()
                        {
                            call_sign       = callsign,
                            station_type    = type_station,
                            station_address = sta_place,
                            bool_14mhz      = bool14mhz,
                            max_power_watt  = power,
                            checked_date    = date_today
                        };

                        _radiostation_serial.Add(newItem);

                        mainWindow.DataGridSoumuGoJp.ItemsSource = _radiostation_serial;

                        //bindingSource.DataSource = _radiostation_serial;

                        Console.WriteLine("CompleteDownloadProcSerial: _radiostation_serial.Count() " + _radiostation_serial.Count() + " " + call);

                        //-----------------------------------------------------------item data .csv write

                        string[] aStrings     = { callsign, type_station, sta_place, bool14mhz, power, date_today };
                        string   strSeparator = ",";
                        string   strLine      = string.Join(strSeparator, aStrings);

                        using (StreamWriter sw = new StreamWriter(file_radio_station, true))
                        {
                            sw.WriteLine(strLine);
                            sw.Close();
                        }
                    }
                }
            }
        }