/// <summary> /// pso2のWebサイトからDLする /// </summary> /// <returns></returns> internal BaseMessage GetPSO2WebSiteData() { BaseMessage result = new BaseMessage(); try { WebRequest webRequest = WebRequest.CreateHttp(ParsePso2WebData.PSO2ScheduleWebSiteAddress); WebResponse response = webRequest.GetResponse(); string text; using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) { text = streamReader.ReadToEnd(); this.HTMLData = text; } result.SetResponceData(text); } catch (WebException ex) { result.SetResponceData(null, ResponceStatus.NetworkError, ex, "GetPSO2WebSiteData Error"); } return result; }
/// <summary> /// ResultDataに結果を格納する /// </summary> /// <param name="InformationNode"></param> /// <param name="BaseEmergencyData"></param> /// <param name="ResultData"></param> internal BaseMessage SetInformation(HtmlNode InformationNode, EmergencyDataFormat BaseEmergencyData, EmergencyDataFormatCollection ResultData) { BaseMessage result = new BaseMessage(); foreach (HtmlNode current in InformationNode.ChildNodes) { for (HtmlNode htmlNode = current.FirstChild; htmlNode != null; htmlNode = htmlNode.NextSibling) { //ヘッダーは無視 if (htmlNode == current.FirstChild) { continue; } EmergencyDataFormat emergencyData = (EmergencyDataFormat)BaseEmergencyData.Clone(); for (int columnCount = 0; columnCount < 3; columnCount++) { if (htmlNode.ChildNodes.Count != 3) { //unknown format result.SetResponceData(null, ResponceStatus.FormatChanged, new Exception(), "SetInfomation:TableNode Not 3"); continue; } switch (columnCount) { case 0: //時間 string eventTimeText = htmlNode.ChildNodes[columnCount].InnerText; KeyValuePair<TimeSpan, TimeSpan> time = this.GetTime(eventTimeText); emergencyData.StartTime = emergencyData.StartTime.Add(time.Key); emergencyData.EndTime = emergencyData.EndTime.Add(time.Value); break; case 1: //種類 string eventTypeText = htmlNode.ChildNodes[columnCount].FirstChild.Attributes["alt"].Value; emergencyData.EventType = this.GetEventType(eventTypeText); break; case 2: //イベント内容 string eventInfoText = htmlNode.ChildNodes[columnCount].InnerText; emergencyData.EventInformation = eventInfoText; break; } } ResultData.Add(emergencyData); } } return result; }
public void SetResponceData(BaseMessage Data) { this.SetResponceData(Data.GetData, Data.Status, Data._exception, Data._errorMessage); }