-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeocodeCache.cs
More file actions
102 lines (89 loc) · 2.86 KB
/
Copy pathGeocodeCache.cs
File metadata and controls
102 lines (89 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Data;
using Exceptionless;
namespace TeslaLogger
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Literale nicht als lokalisierte Parameter übergeben", Justification = "<Pending>")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Keine allgemeinen Ausnahmetypen abfangen", Justification = "<Pending>")]
internal class GeocodeCache
{
private DataTable dt = new DataTable("cache");
private static GeocodeCache _instance;
static readonly string FilenameGeocodeCache = "GeocodeCache.xml";
public static GeocodeCache Instance
{
get
{
if (_instance == null)
{
_instance = new GeocodeCache();
}
return _instance;
}
}
public GeocodeCache()
{
DataColumn lat = dt.Columns.Add("lat", typeof(double));
DataColumn lng = dt.Columns.Add("lng", typeof(double));
dt.Columns.Add("Value");
dt.PrimaryKey = new DataColumn[] { lat, lng };
try
{
if (System.IO.File.Exists(FilenameGeocodeCache))
{
#pragma warning disable CA3075 // Unsichere DTD-Verarbeitung in XML
_ = dt.ReadXml(FilenameGeocodeCache);
#pragma warning restore CA3075 // Unsichere DTD-Verarbeitung in XML
Logfile.Log("GeocodeCache Items: " + dt.Rows.Count);
}
else
{
Logfile.Log(FilenameGeocodeCache + " Not found!");
}
}
catch (Exception ex)
{
ex.ToExceptionless().Submit();
Logfile.ExceptionWriter(ex, "");
}
}
public string Search(double lat, double lng)
{
DataRow dr = dt.Rows.Find(new object[] { lat, lng });
return dr?["Value"].ToString();
}
public void Insert(double lat, double lng, string value)
{
try
{
DataRow dr = dt.NewRow();
dr["lat"] = lat;
dr["lng"] = lng;
dr["value"] = value;
dt.Rows.Add(dr);
Logfile.Log("GeocodeCache:Insert");
}
catch (Exception ex)
{
ex.ToExceptionless().Submit();
Logfile.Log(ex.Message);
}
}
public void Write()
{
try
{
dt.WriteXml(FilenameGeocodeCache);
}
catch (Exception ex)
{
ex.ToExceptionless().Submit();
Logfile.Log(ex.Message);
}
}
internal void ClearCache()
{
dt.Clear();
}
}
}