private void DownTrCams(int idata) { System.GC.Collect(); this.UseWaitCursor = true; string strText = "Trafikverket - " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string url = "http://trafikinfo.trafikverket.se/lit/orion/orionproxy.ashx"; string[] data = new string[] {"<ORIONML version='1.0'><REQUEST plugin='CameraInfo' version='' locale='SE_sv' authenticationkey='7fd72d2a-4746-482c-b856-15a64f85a205'><PLUGINML table=\"Cameras\" filter=\"TypeValue='RoadConditionCamera' or TypeValue = 'atk' or TypeValue = 'TrafficCamera'\" /></REQUEST></ORIONML>" ,"<ORIONML version='1.0'><REQUEST plugin='TrissData2' version='' locale='SE_sv' authenticationkey='7fd72d2a-4746-482c-b856-15a64f85a205'><PLUGINML table=\"Weather\" filter=\"(EW IS NOT NULL) AND (NS IS NOT NULL)\" columns=\"Id,WindIconId,AmountOfPrecipitation,PrecipitationIconId,PrecipitationAmountName,EW,NS,MeasurePoint,Active,ZoomLevel,StationIconId,RoadTempIconId,AirTempIconId,AirTemp,RoadTemp,WindForce,MaxWindIconId,MaxWindForce,AverageWindIconId,AverageWindForce,CountyNo,MeasureTime,Moisture\" /></REQUEST></ORIONML>" ,"<ORIONML version='1.0'><REQUEST plugin='TrissData2' version='' locale='SE_sv' authenticationkey='7fd72d2a-4746-482c-b856-15a64f85a205'><PLUGINML table=\"Weather\" filter=\"(EW IS NOT NULL) AND (NS IS NOT NULL)\" columns=\"Id,Active,MeasurePoint\" /></REQUEST></ORIONML>" ,"<ORIONML version='1.0'><REQUEST plugin='ATK' version='' locale='SE_sv' authenticationkey='7fd72d2a-4746-482c-b856-15a64f85a205'><PLUGINML table=\"Cameras\" /></REQUEST></ORIONML>"}; try { HttpWebResponse resp; if (cookies != null && cookies.Count == 0) { string s = MyWebClient.DownloadString("http://trafikinfo.trafikverket.se/lit/", out resp); cookies = resp.Cookies; } HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.ContentType = "text/xml"; request.Referer = "http://trafikinfo.trafikverket.se/LIT/"; request.Accept = "application/json, text/javascript, */*; q=0.01"; request.KeepAlive = true; string json = MyWebClient.UploadString(request, data[idata], cookies); XmlDocument xd = new XmlDocument(); json = json.ToString().Replace(".", ",").Replace("{ \"MeasurePoint\": [", "{ \"Mps\": ["); xd = (XmlDocument)JsonConvert.DeserializeXmlNode(json, "Weather"); DataSet ds = new DataSet(); ds.ReadXml(new XmlNodeReader(xd)); string strCols = ""; List<Weather> jsonlist = new List<Weather>(); using (DataTable dt1 = ds.Tables[1]) { if (dtn.TableName.Equals("")) { dtn = new DataTable(dt1.TableName); foreach (DataColumn dc in dt1.Columns) if (!dc.ColumnName.EndsWith("_Id", StringComparison.InvariantCultureIgnoreCase) && !dc.ColumnName.EndsWith("_Id_0", StringComparison.InvariantCultureIgnoreCase)) { dtn.Columns.Add(dc.ColumnName, GetDataType(dt1.Select("Active=true and " + dc.ColumnName + "<>''")[0][dc]), dc.Expression); } } foreach (DataRow dr in dt1.Select("Active=true")) { if (bAbort) return; /* this.Invoke((MethodInvoker)delegate { thisText = strText + " " + countAll(); //list.Count + "/" + dt1.Rows.Count + " - " + this.dataRowBuffer.Count ; }); */ Weather weather = GetWeather(dr); jsonlist.Add(weather); continue; if (weather.EW < 1) { string ssdfdfffff = ""; if (!string.IsNullOrEmpty(ssdfdfffff)) { } } if (!list.Any(w => w.Id.Equals(weather.Id))) { list.Add(weather); dtn.ImportRow(dr); } else { DataRow[] rows = dtn.Select("Id='" + dr["Id"].ToString() + "'"); if (rows.Length < 1) dtn.ImportRow(dr); else { if (areDifferent(rows[0], dr)) { rows[0].BeginEdit(); //rows[0].SetColumnError(0, DateTime.Now.ToString("HH:mm:ss")); mergeRows(rows[0], dr); rows[0].EndEdit(); } else rows[0].ClearErrors(); } } #if !DEBUG try { ThreadPool.QueueUserWorkItem(insertDataRowToMySql, new object[] { dr, weather }); } catch (Exception ex) { string sasdasd = ex.Message; System.GC.Collect(); } #endif } if (showDataToolStripMenuItem.Checked) { this.Invoke((MethodInvoker)delegate { thisText += "-" + countAll(); if (dataGridView1.DataSource == null) dataGridView1.DataSource = dtn; else dataGridView1.Refresh(); if (tabPage3.Controls.Count == 0) { Map map = new Map(list.ToList()); map.Dock = DockStyle.Fill; tabPage3.Controls.Add(map); map.Show(); } }); } if (!bFirstHistoryRun) { bFirstHistoryRun = true; timer2_Tick(this, EventArgs.Empty); } } string njson = JsonConvert.SerializeObject(jsonlist); uploadJson(njson); } catch (System.OutOfMemoryException ex) { GC.Collect(); } catch (Exception ex) { string ssdf = ex.Message; if (string.IsNullOrEmpty(ssdf)) { } } this.UseWaitCursor = false; System.GC.Collect(); return; /* dynamic obj = JObject.Parse(json); foreach (var ev in obj.Weather.MeasurePoint) { string id = ev.Id; int icnt = list.Count(x => x.Id.Equals(id)); Weather w = icnt > 0 ? list.FirstOrDefault(x => x.Id.Equals(id)) : new Weather(); w=AddProperties(w, ev); w.PropertyChanged += w_PropertyChanged; if (w.Active && icnt == 0) list.Add(w); if (icnt == 1) { string sdfölksdöflksöösöld = ""; } } if (dataGridView1.DataSource == null) { dataGridView1.DataSource = GetList(icol, bDesc); } */ }
private void GetLatestMeasure(object state) { if (!CanConnect) return; using (DataSet ds = ExecuteSql("select * from trafikverket.LatestMeasures")) { using (DataTable dt1 = ds.Tables[0]) { if (dtn.TableName.Equals("")) { dtn = new DataTable(dt1.TableName); foreach (DataColumn dc in dt1.Columns) if (!dc.ColumnName.EndsWith("idweather", StringComparison.InvariantCultureIgnoreCase) && !dc.ColumnName.EndsWith("_Id", StringComparison.InvariantCultureIgnoreCase) && !dc.ColumnName.EndsWith("_Id_0", StringComparison.InvariantCultureIgnoreCase)) { dtn.Columns.Add(dc.ColumnName, dc.DataType); } } foreach (DataRow dr in dt1.Select("Active=true")) { if (bAbort) return; Weather weather = GetWeather(dr); if (!list.Any(w => w.Id.Equals(weather.Id))) { list.Add(weather); dtn.ImportRow(dr); } } if (showDataToolStripMenuItem.Checked) { this.Invoke((MethodInvoker)delegate { if (dataGridView1.DataSource == null) dataGridView1.DataSource = dtn; else dataGridView1.Refresh(); if (tabPage3.Controls.Count == 0) { Map map = new Map(list.ToList()); map.Dock = DockStyle.Fill; tabPage3.Controls.Add(map); map.Show(); } }); } } } }