From f03952522c89ceba2af049fa02d95ba7bd0d01d4 Mon Sep 17 00:00:00 2001 From: "Serg V. Zhdanovskih" Date: Mon, 26 Dec 2016 21:34:00 +0500 Subject: [PATCH] Minor improvements --- .gitignore | 1 + .../GKCore/Geocoding/GoogleGeocoder.cs | 50 +++--- .../GKCore/Geocoding/YandexGeocoder.cs | 3 +- projects/GEDKeeper2/GKUI/BaseWin.Designer.cs | 159 +++++++++--------- projects/GEDKeeper2/GKUI/BaseWin.cs | 2 +- 5 files changed, 109 insertions(+), 106 deletions(-) diff --git a/.gitignore b/.gitignore index a3f60ddfb..31f084a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ gource-gk.cmd build_coverity.cmd +/projects/GEDKeeper2.mswin-cov.sln sonarqube.cmd /projects/GEDKeeper2/bin/ diff --git a/projects/GEDKeeper2/GKCore/Geocoding/GoogleGeocoder.cs b/projects/GEDKeeper2/GKCore/Geocoding/GoogleGeocoder.cs index 50d4a13b2..6edece4d8 100644 --- a/projects/GEDKeeper2/GKCore/Geocoding/GoogleGeocoder.cs +++ b/projects/GEDKeeper2/GKCore/Geocoding/GoogleGeocoder.cs @@ -56,35 +56,37 @@ private IList ParseXml(string url) request.ContentType = "application/x-www-form-urlencoded"; request.Proxy = fProxy; - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - Stream stream = response.GetResponseStream(); + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { + using (Stream stream = response.GetResponseStream()) { - XmlDocument xmlDocument = new XmlDocument(); - xmlDocument.Load(stream); - XmlNode node = xmlDocument.DocumentElement; + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.Load(stream); + XmlNode node = xmlDocument.DocumentElement; - if (node != null && node.ChildNodes.Count > 0) - { - int num = node.ChildNodes.Count; - for (int i = 0; i < num; i++) - { - XmlNode xNode = node.ChildNodes[i]; - if (xNode.Name == "result") + if (node != null && node.ChildNodes.Count > 0) { - XmlNode addressNode = xNode["formatted_address"]; - XmlNode geometry = xNode["geometry"]; - XmlNode pointNode = geometry["location"]; - - if (addressNode != null && pointNode != null) + int num = node.ChildNodes.Count; + for (int i = 0; i < num; i++) { - string ptHint = addressNode.InnerText; - double ptLongitude = SysUtils.ParseFloat(pointNode["lng"].InnerText, -1.0); - double ptLatitude = SysUtils.ParseFloat(pointNode["lat"].InnerText, -1.0); - - if (ptLatitude != -1.0 && ptLongitude != -1.0) + XmlNode xNode = node.ChildNodes[i]; + if (xNode.Name == "result") { - GeoPoint gpt = new GeoPoint(ptLatitude, ptLongitude, ptHint); - geoObjects.Add(gpt); + XmlNode addressNode = xNode["formatted_address"]; + XmlNode geometry = xNode["geometry"]; + XmlNode pointNode = geometry["location"]; + + if (addressNode != null && pointNode != null) + { + string ptHint = addressNode.InnerText; + double ptLongitude = SysUtils.ParseFloat(pointNode["lng"].InnerText, -1.0); + double ptLatitude = SysUtils.ParseFloat(pointNode["lat"].InnerText, -1.0); + + if (ptLatitude != -1.0 && ptLongitude != -1.0) + { + GeoPoint gpt = new GeoPoint(ptLatitude, ptLongitude, ptHint); + geoObjects.Add(gpt); + } + } } } } diff --git a/projects/GEDKeeper2/GKCore/Geocoding/YandexGeocoder.cs b/projects/GEDKeeper2/GKCore/Geocoding/YandexGeocoder.cs index b76057661..48b350031 100644 --- a/projects/GEDKeeper2/GKCore/Geocoding/YandexGeocoder.cs +++ b/projects/GEDKeeper2/GKCore/Geocoding/YandexGeocoder.cs @@ -70,8 +70,9 @@ private static IList ParseXml(string url) string[] splitted = pointNode.InnerText.Split(new char[] { ' ' }, count: 2); double lng = double.Parse(splitted[0], CultureInfo.InvariantCulture); double lat = double.Parse(splitted[1], CultureInfo.InvariantCulture); + string ptHint = (metaNode == null) ? string.Empty : metaNode["text"].InnerText; - GeoPoint gpt = new GeoPoint(lat, lng, metaNode["text"].InnerText); + GeoPoint gpt = new GeoPoint(lat, lng, ptHint); geoObjects.Add(gpt); } } diff --git a/projects/GEDKeeper2/GKUI/BaseWin.Designer.cs b/projects/GEDKeeper2/GKUI/BaseWin.Designer.cs index f899b6d23..6762d5b54 100644 --- a/projects/GEDKeeper2/GKUI/BaseWin.Designer.cs +++ b/projects/GEDKeeper2/GKUI/BaseWin.Designer.cs @@ -17,86 +17,85 @@ partial class BaseWin private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.tabsRecords = new System.Windows.Forms.TabControl(); - this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); - this.miRecordAdd = new System.Windows.Forms.ToolStripMenuItem(); - this.miRecordEdit = new System.Windows.Forms.ToolStripMenuItem(); - this.miRecordDelete = new System.Windows.Forms.ToolStripMenuItem(); - this.miRecordDuplicate = new System.Windows.Forms.ToolStripMenuItem(); - this.contextMenu.SuspendLayout(); - this.SuspendLayout(); - // - // tabsRecords - // - this.tabsRecords.Dock = System.Windows.Forms.DockStyle.Fill; - this.tabsRecords.Location = new System.Drawing.Point(0, 0); - this.tabsRecords.Margin = new System.Windows.Forms.Padding(2); - this.tabsRecords.Name = "tabsRecords"; - this.tabsRecords.SelectedIndex = 0; - this.tabsRecords.Size = new System.Drawing.Size(781, 370); - this.tabsRecords.TabIndex = 0; - this.tabsRecords.SelectedIndexChanged += new System.EventHandler(this.PageRecords_SelectedIndexChanged); - // - // contextMenu - // - this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.miRecordAdd, - this.miRecordEdit, - this.miRecordDelete, - this.miRecordDuplicate}); - this.contextMenu.Name = "contextMenu"; - this.contextMenu.Size = new System.Drawing.Size(176, 92); - this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenu_Opening); - // - // miRecordAdd - // - this.miRecordAdd.Name = "miRecordAdd"; - this.miRecordAdd.Size = new System.Drawing.Size(175, 22); - this.miRecordAdd.Text = "miRecordAdd"; - this.miRecordAdd.Click += new System.EventHandler(this.miRecordAdd_Click); - // - // miRecordEdit - // - this.miRecordEdit.Name = "miRecordEdit"; - this.miRecordEdit.Size = new System.Drawing.Size(175, 22); - this.miRecordEdit.Text = "miRecordEdit"; - this.miRecordEdit.Click += new System.EventHandler(this.miRecordEdit_Click); - // - // miRecordDelete - // - this.miRecordDelete.Name = "miRecordDelete"; - this.miRecordDelete.Size = new System.Drawing.Size(175, 22); - this.miRecordDelete.Text = "miRecordDelete"; - this.miRecordDelete.Click += new System.EventHandler(this.miRecordDelete_Click); - // - // miRecordDuplicate - // - this.miRecordDuplicate.Name = "miRecordDuplicate"; - this.miRecordDuplicate.Size = new System.Drawing.Size(175, 22); - this.miRecordDuplicate.Text = "miRecordDuplicate"; - this.miRecordDuplicate.Click += new System.EventHandler(this.miRecordDuplicate_Click); - // - // BaseWin - // - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.ClientSize = new System.Drawing.Size(781, 370); - this.Controls.Add(this.tabsRecords); - this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.KeyPreview = true; - this.Margin = new System.Windows.Forms.Padding(2); - this.Name = "BaseWin"; - this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; - this.Text = "BaseWin"; - this.Activated += new System.EventHandler(this.Form_Activated); - this.Closing += new System.ComponentModel.CancelEventHandler(this.Form_Closing); - this.Deactivate += new System.EventHandler(this.Form_Deactivate); - this.Load += new System.EventHandler(this.Form_Load); - this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form_KeyDown); - this.contextMenu.ResumeLayout(false); - this.ResumeLayout(false); - + this.components = new System.ComponentModel.Container(); + this.tabsRecords = new System.Windows.Forms.TabControl(); + this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); + this.miRecordAdd = new System.Windows.Forms.ToolStripMenuItem(); + this.miRecordEdit = new System.Windows.Forms.ToolStripMenuItem(); + this.miRecordDelete = new System.Windows.Forms.ToolStripMenuItem(); + this.miRecordDuplicate = new System.Windows.Forms.ToolStripMenuItem(); + this.contextMenu.SuspendLayout(); + this.SuspendLayout(); + // + // tabsRecords + // + this.tabsRecords.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabsRecords.Location = new System.Drawing.Point(0, 0); + this.tabsRecords.Margin = new System.Windows.Forms.Padding(2); + this.tabsRecords.Name = "tabsRecords"; + this.tabsRecords.SelectedIndex = 0; + this.tabsRecords.Size = new System.Drawing.Size(781, 370); + this.tabsRecords.TabIndex = 0; + this.tabsRecords.SelectedIndexChanged += new System.EventHandler(this.PageRecords_SelectedIndexChanged); + // + // contextMenu + // + this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.miRecordAdd, + this.miRecordEdit, + this.miRecordDelete, + this.miRecordDuplicate}); + this.contextMenu.Name = "contextMenu"; + this.contextMenu.Size = new System.Drawing.Size(176, 92); + this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenu_Opening); + // + // miRecordAdd + // + this.miRecordAdd.Name = "miRecordAdd"; + this.miRecordAdd.Size = new System.Drawing.Size(175, 22); + this.miRecordAdd.Text = "miRecordAdd"; + this.miRecordAdd.Click += new System.EventHandler(this.miRecordAdd_Click); + // + // miRecordEdit + // + this.miRecordEdit.Name = "miRecordEdit"; + this.miRecordEdit.Size = new System.Drawing.Size(175, 22); + this.miRecordEdit.Text = "miRecordEdit"; + this.miRecordEdit.Click += new System.EventHandler(this.miRecordEdit_Click); + // + // miRecordDelete + // + this.miRecordDelete.Name = "miRecordDelete"; + this.miRecordDelete.Size = new System.Drawing.Size(175, 22); + this.miRecordDelete.Text = "miRecordDelete"; + this.miRecordDelete.Click += new System.EventHandler(this.miRecordDelete_Click); + // + // miRecordDuplicate + // + this.miRecordDuplicate.Name = "miRecordDuplicate"; + this.miRecordDuplicate.Size = new System.Drawing.Size(175, 22); + this.miRecordDuplicate.Text = "miRecordDuplicate"; + this.miRecordDuplicate.Click += new System.EventHandler(this.miRecordDuplicate_Click); + // + // BaseWin + // + this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(781, 370); + this.Controls.Add(this.tabsRecords); + this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.KeyPreview = true; + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "BaseWin"; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.Text = "BaseWin"; + this.Activated += new System.EventHandler(this.Form_Activated); + this.Closing += new System.ComponentModel.CancelEventHandler(this.Form_Closing); + this.Deactivate += new System.EventHandler(this.Form_Deactivate); + this.Load += new System.EventHandler(this.Form_Load); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form_KeyDown); + this.contextMenu.ResumeLayout(false); + this.ResumeLayout(false); } } } diff --git a/projects/GEDKeeper2/GKUI/BaseWin.cs b/projects/GEDKeeper2/GKUI/BaseWin.cs index ac81dd608..ab47d385b 100644 --- a/projects/GEDKeeper2/GKUI/BaseWin.cs +++ b/projects/GEDKeeper2/GKUI/BaseWin.cs @@ -249,7 +249,7 @@ private void contextMenu_Opening(object sender, CancelEventArgs e) private void miRecordAdd_Click(object sender, EventArgs e) { - this.RecordAdd(); + this.RecordAdd(); } private void miRecordEdit_Click(object sender, EventArgs e)