Added error handling if cookie retrieval fails
This commit is contained in:
+26
-23
@@ -66,36 +66,38 @@ namespace Test_Merge
|
|||||||
StartCookieRecovering();
|
StartCookieRecovering();
|
||||||
string value = "";
|
string value = "";
|
||||||
List<Cookie> cookies = new List<Cookie>();
|
List<Cookie> cookies = new List<Cookie>();
|
||||||
using (var reader = new StreamReader(COOKIES_CSV_FILENAME))
|
if (File.Exists(COOKIES_CSV_FILENAME))
|
||||||
{
|
{
|
||||||
// Read the header row and validate column order
|
using (var reader = new StreamReader(COOKIES_CSV_FILENAME))
|
||||||
string header = reader.ReadLine();
|
|
||||||
string[] expectedColumns = { "host_key", "name", "value", "path", "expires_utc", "is_secure", "is_httponly" };
|
|
||||||
string[] actualColumns = header.Split(',');
|
|
||||||
for (int i = 0; i < expectedColumns.Length; i++)
|
|
||||||
{
|
{
|
||||||
if (expectedColumns[i] != actualColumns[i])
|
// Read the header row and validate column order
|
||||||
|
string header = reader.ReadLine();
|
||||||
|
string[] expectedColumns = { "host_key", "name", "value", "path", "expires_utc", "is_secure", "is_httponly" };
|
||||||
|
string[] actualColumns = header.Split(',');
|
||||||
|
for (int i = 0; i < expectedColumns.Length; i++)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Expected column '{expectedColumns[i]}' at index {i} but found '{actualColumns[i]}'");
|
if (expectedColumns[i] != actualColumns[i])
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Expected column '{expectedColumns[i]}' at index {i} but found '{actualColumns[i]}'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Read each data row and parse values into a Cookie object
|
// Read each data row and parse values into a Cookie object
|
||||||
while (!reader.EndOfStream)
|
while (!reader.EndOfStream)
|
||||||
{
|
|
||||||
string line = reader.ReadLine();
|
|
||||||
string[] fields = line.Split(',');
|
|
||||||
|
|
||||||
string hostname = fields[0];
|
|
||||||
string cookieName = fields[1];
|
|
||||||
|
|
||||||
if (hostname == host && cookieName == name)
|
|
||||||
{
|
{
|
||||||
value = fields[2];
|
string line = reader.ReadLine();
|
||||||
|
string[] fields = line.Split(',');
|
||||||
|
|
||||||
|
string hostname = fields[0];
|
||||||
|
string cookieName = fields[1];
|
||||||
|
|
||||||
|
if (hostname == host && cookieName == name)
|
||||||
|
{
|
||||||
|
value = fields[2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -111,8 +113,9 @@ namespace Test_Merge
|
|||||||
string loginCookieValue = GetCookie(COOKIE_HOST, loginCookieName);
|
string loginCookieValue = GetCookie(COOKIE_HOST, loginCookieName);
|
||||||
string loginSessionValue = GetCookie(COOKIE_HOST, loginSessionCookieName);
|
string loginSessionValue = GetCookie(COOKIE_HOST, loginSessionCookieName);
|
||||||
|
|
||||||
int windowWidth = 1920;
|
//Cookie retreival has gone wrong (usually its because of python not being installed properly)
|
||||||
int windowHeight = 768;
|
if (loginCookieValue == "" || loginSessionValue == "")
|
||||||
|
return 100;
|
||||||
|
|
||||||
var service = FirefoxDriverService.CreateDefaultService(GECKODRIVER_FILENAME);
|
var service = FirefoxDriverService.CreateDefaultService(GECKODRIVER_FILENAME);
|
||||||
service.Host = "127.0.0.1";
|
service.Host = "127.0.0.1";
|
||||||
|
|||||||
@@ -255,6 +255,9 @@ namespace Test_Merge
|
|||||||
string message = "";
|
string message = "";
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
{
|
{
|
||||||
|
case 100:
|
||||||
|
message = "Error " + errorCode + " Could not recover cookies. It could be because of an improper installation of python or bad cookies in the chrome database. Please try to log on to the F1TV using chrome again";
|
||||||
|
break;
|
||||||
case 101:
|
case 101:
|
||||||
message = "Error " + errorCode + " Could not start the driver. It could be because an other instance is runnin make sure you closed them all before trying again";
|
message = "Error " + errorCode + " Could not start the driver. It could be because an other instance is runnin make sure you closed them all before trying again";
|
||||||
break;
|
break;
|
||||||
|
|||||||
Generated
+4
-1
@@ -226,6 +226,7 @@
|
|||||||
//
|
//
|
||||||
this.btnResetDriver.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
this.btnResetDriver.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.btnResetDriver.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
|
this.btnResetDriver.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
|
||||||
|
this.btnResetDriver.Enabled = false;
|
||||||
this.btnResetDriver.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
this.btnResetDriver.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
||||||
this.btnResetDriver.ForeColor = System.Drawing.Color.White;
|
this.btnResetDriver.ForeColor = System.Drawing.Color.White;
|
||||||
this.btnResetDriver.Location = new System.Drawing.Point(748, 20);
|
this.btnResetDriver.Location = new System.Drawing.Point(748, 20);
|
||||||
@@ -246,7 +247,7 @@
|
|||||||
this.btnRefresh.Name = "btnRefresh";
|
this.btnRefresh.Name = "btnRefresh";
|
||||||
this.btnRefresh.Size = new System.Drawing.Size(193, 33);
|
this.btnRefresh.Size = new System.Drawing.Size(193, 33);
|
||||||
this.btnRefresh.TabIndex = 1;
|
this.btnRefresh.TabIndex = 1;
|
||||||
this.btnRefresh.Text = "Get a newer image";
|
this.btnRefresh.Text = "Start the browser";
|
||||||
this.btnRefresh.UseVisualStyleBackColor = false;
|
this.btnRefresh.UseVisualStyleBackColor = false;
|
||||||
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
|
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
|
||||||
//
|
//
|
||||||
@@ -273,6 +274,7 @@
|
|||||||
// btnCreateWindow
|
// btnCreateWindow
|
||||||
//
|
//
|
||||||
this.btnCreateWindow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
|
this.btnCreateWindow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
|
||||||
|
this.btnCreateWindow.Enabled = false;
|
||||||
this.btnCreateWindow.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
this.btnCreateWindow.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
||||||
this.btnCreateWindow.ForeColor = System.Drawing.Color.White;
|
this.btnCreateWindow.ForeColor = System.Drawing.Color.White;
|
||||||
this.btnCreateWindow.Location = new System.Drawing.Point(213, 23);
|
this.btnCreateWindow.Location = new System.Drawing.Point(213, 23);
|
||||||
@@ -298,6 +300,7 @@
|
|||||||
// btnCreatZone
|
// btnCreatZone
|
||||||
//
|
//
|
||||||
this.btnCreatZone.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
|
this.btnCreatZone.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51)))));
|
||||||
|
this.btnCreatZone.Enabled = false;
|
||||||
this.btnCreatZone.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
this.btnCreatZone.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
||||||
this.btnCreatZone.ForeColor = System.Drawing.Color.White;
|
this.btnCreatZone.ForeColor = System.Drawing.Color.White;
|
||||||
this.btnCreatZone.Location = new System.Drawing.Point(6, 23);
|
this.btnCreatZone.Location = new System.Drawing.Point(6, 23);
|
||||||
|
|||||||
+10
-1
@@ -311,6 +311,9 @@ namespace Test_Merge
|
|||||||
private async void btnRefresh_Click(object sender, EventArgs e)
|
private async void btnRefresh_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
btnRefresh.Enabled = false;
|
btnRefresh.Enabled = false;
|
||||||
|
btnCreatZone.Enabled = false;
|
||||||
|
btnCreateWindow.Enabled = false;
|
||||||
|
btnResetDriver.Enabled = false;
|
||||||
if (Emulator == null || Emulator.GrandPrixUrl != tbxGpUrl.Text)
|
if (Emulator == null || Emulator.GrandPrixUrl != tbxGpUrl.Text)
|
||||||
{
|
{
|
||||||
Emulator = new F1TVEmulator(tbxGpUrl.Text);
|
Emulator = new F1TVEmulator(tbxGpUrl.Text);
|
||||||
@@ -325,6 +328,9 @@ namespace Test_Merge
|
|||||||
string message;
|
string message;
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
{
|
{
|
||||||
|
case 100:
|
||||||
|
message = "Error " + errorCode + " Could not recover cookies. It could be because of an improper installation of python or bad cookies in the chrome database. Please try to log on to the F1TV using chrome again";
|
||||||
|
break;
|
||||||
case 101:
|
case 101:
|
||||||
message = "Error " + errorCode + " Could not start the driver. It could be because an other instance is runnin make sure you closed them all before trying again";
|
message = "Error " + errorCode + " Could not start the driver. It could be because an other instance is runnin make sure you closed them all before trying again";
|
||||||
break;
|
break;
|
||||||
@@ -359,6 +365,10 @@ namespace Test_Merge
|
|||||||
pbxPreview.Image = Emulator.Screenshot();
|
pbxPreview.Image = Emulator.Screenshot();
|
||||||
}
|
}
|
||||||
btnRefresh.Enabled = true;
|
btnRefresh.Enabled = true;
|
||||||
|
btnCreatZone.Enabled = true;
|
||||||
|
btnCreateWindow.Enabled = true;
|
||||||
|
btnResetDriver.Enabled = true;
|
||||||
|
btnRefresh.Text = "Get a newer image";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Settings_FormClosing(object sender, FormClosingEventArgs e)
|
private void Settings_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
@@ -462,6 +472,5 @@ namespace Test_Merge
|
|||||||
e.Graphics.DrawString(gpbx.Text, gpbx.Font, brush, textPosition);
|
e.Graphics.DrawString(gpbx.Text, gpbx.Font, brush, textPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user