-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
97 lines (85 loc) · 3.32 KB
/
Program.cs
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
using Exceptionless;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TeslaLogger;
namespace OVMS
{
class Program
{
static void Main(string[] args)
{
try
{
if (args?.Contains("nodate") == true)
Logfile.noDate = true;
ExceptionlessClient.Default.Startup("WA0Y7kBPrfI4yXwYPzSmB4NQrycRj9ooFh1Y5sKB");
ExceptionlessClient.Default.Configuration.ServerUrl = ApplicationSettings.Default.ExceptionlessServerUrl;
ExceptionlessClient.Default.Configuration.SetVersion(Assembly.GetExecutingAssembly().GetName().Version);
ExceptionlessClient.Default.CreateLog("Start " + Assembly.GetExecutingAssembly().GetName().Version).FirstCarUserID().Submit();
Logfile.WriteToLogfile = true;
Logfile.Logfilepath = new System.IO.FileInfo("../nohup.out").FullName;
Logfile.Log("Start OVMSLogger V" + Assembly.GetExecutingAssembly().GetName().Version);
InitConnectToDB();
var dt = DBHelper.GetAllOVMSCars();
foreach (DataRow dr in dt.Rows)
{
try
{
int dbcarid = (Int32)dr["id"];
string name = dr["tesla_name"].ToString();
string password = dr["tesla_password"].ToString();
string CarId = dr["tesla_token"].ToString().Substring(5);
var c = new Car(dbcarid, name, password, CarId);
}
catch (Exception ex)
{
ex.ToExceptionless().Submit();
}
}
while (true)
{
System.Threading.Thread.Sleep(1000);
}
}
catch (Exception ex)
{
ex.ToExceptionless().FirstCarUserID().Submit();
TeslaLogger.Logfile.Log(ex.ToString());
}
}
private static void InitConnectToDB()
{
for (int x = 1; x <= 30; x++) // try 30 times until DB is up and running
{
try
{
Logfile.Log("DB Version: " + DBHelper.GetVersion());
Logfile.Log("Count Pos: " + DBHelper.CountPos()); // test the DBConnection
break;
}
catch (Exception ex)
{
if (ex.Message.Contains("Connection refused")
|| ex.Message.Contains("Unable to connect to any of the specified MySQL hosts")
|| ex.Message.Contains("Reading from the stream has failed."))
{
Logfile.Log($"Wait for DB ({x}/30): Connection refused.");
}
else
{
ex.ToExceptionless().Submit();
Logfile.Log("DBCONNECTION " + ex.Message);
}
Thread.Sleep(15000);
}
}
}
}
}