Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions EasyRCP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<PackageReference Include="Selenium.Support" Version="4.31.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.31.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="135.0.7049.11400" />
<PackageReference Include="Sentry" Version="5.13.0" />
<PackageReference Include="System.Drawing.Common" Version="9.0.4" />
</ItemGroup>

Expand Down
27 changes: 25 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ static async Task Main()
{
try
{
#if DEBUG
string environment = "Development";
#else
string environment = "Production";
#endif
SentrySdk.Init(o =>
{
o.Dsn = "https://fc312c602b39fe2f9c974049fa40bc6f@o4509757627367424.ingest.de.sentry.io/4509768557068368";
#if DEBUG
o.Debug = true;
#else
o.Debug = false;
#endif
o.Environment = environment;
o.TracesSampleRate = 1.0;
});

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);

// Ensure the application is running from the correct location on the PC
SelfRelocationService.EnsureRunningFromCorrectLocation();

Expand Down Expand Up @@ -104,14 +123,18 @@ static async Task Main()
}
catch (Exception ex)
{
// TODO: tutaj może mail jeszcze do mnie z informacją że coś poszło komuś nie tak - komu i co poszło nie tak
File.AppendAllText("output.txt", $"[{DateTime.Now}] {ex}\nMetoda: Program.cs -> Main()\n\n");
SentrySdk.CaptureException(ex);
File.AppendAllText("output.txt", $"[{DateTime.Now}] {ex}\n\n");
MessageBox.Show(
"Wystąpił nieoczekiwany błąd. Szczegóły zapisano w pliku output.txt, proszę skonsultować się z administratorem.",
"EasyRCP - Błąd",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
SentrySdk.Close();
}
}

static void AddApplicationToStartup()
Expand Down
13 changes: 9 additions & 4 deletions Services/RcpApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ public async Task<bool> CheckIfWorkAlreadyStarted()
catch (Exception ex)
{
// Sth not right but cannot throw error to Program.cs as this is in Polly retry policy. Needs to be handled here
SentrySdk.CaptureException(ex);
File.AppendAllText("output.txt", $"[{DateTime.Now}] Coś poszło nie tak, nie udało się sprawdzić," +
$"czy użytkownik jest już w pracy.\nMetoda: RcpApiClient -> CheckIfWorkAlreadyStarted()\n ex.Message: {ex.Message}\n" +
$"Możliwe, że zmieniło się coś w zwracanym z /dashboard/getMyStatus/ HTMLu.\n\n");
$"czy użytkownik jest już w pracy.\nMożliwe, że zmieniło się coś w zwracanym z /dashboard/getMyStatus/ HTMLu.\n" +
$"Metoda: RcpApiClient -> CheckIfWorkAlreadyStarted()\n ex.Message: {ex.Message}\n\n");
MessageBox.Show(
"Wystąpił nieoczekiwany błąd. Szczegóły zapisano w pliku output.txt, proszę skonsultować się z administratorem.",
"EasyRCP - Błąd",
Expand Down Expand Up @@ -303,8 +304,10 @@ private async Task<bool> SendPostAndHandleResponseAsync(string requestUri, FormU
if (!resp.IsSuccessStatusCode)
{
// TODO: tu może wystarczy zrobić throw do Program.cs
SentrySdk.CaptureException(new Exception($"[{DateTime.Now}] HTTP {(int)resp.StatusCode}: {resp.ReasonPhrase}\n{json}\n" +
$"Metoda: RcpApiClient -> SendPostAndHandleResponseAsync()\n\n"));
File.AppendAllText("output.txt", $"[{DateTime.Now}] HTTP {(int)resp.StatusCode}: {resp.ReasonPhrase}\n{json}\n" +
$"Metoda: RcpApiClient -> SendPostAndHandleResponseAsync()\n\n");
$"Metoda: RcpApiClient -> SendPostAndHandleResponseAsync()\n\n");
MessageBox.Show(
$"Błąd, szczegóły zostały zapisane w pliku output.txt, proszę skonsultować się z administratorem.",
"EasyRCP - Błąd",
Expand All @@ -318,8 +321,10 @@ private async Task<bool> SendPostAndHandleResponseAsync(string requestUri, FormU
if (!success)
{
// TODO: tu może wystarczy zrobić throw do Program.cs
SentrySdk.CaptureException(new Exception($"[{DateTime.Now}] API zwróciło success = false\n{json}\n" +
$"Metoda: RcpApiClient -> SendPostAndHandleResponseAsync()\n\n"));
File.AppendAllText("output.txt", $"[{DateTime.Now}] API zwróciło success = false\n{json}\n" +
$"Metoda: RcpApiClient -> SendPostAndHandleResponseAsync()\n\n");
$"Metoda: RcpApiClient -> SendPostAndHandleResponseAsync()\n\n");
MessageBox.Show(
$"Błąd, szczegóły zostały zapisane w pliku output.txt, proszę skonsultować się z administratorem.",
"EasyRCP - Błąd",
Expand Down
14 changes: 8 additions & 6 deletions Services/RcpAutomationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public static class RcpAutomationService
sleepDurationProvider: retryAttempt => TimeSpan.FromMinutes(1),
onRetry: (exception, timeSpan, retryCount, _) =>
{
SentrySdk.CaptureException(exception);
File.AppendAllText("output.txt", $"[{DateTime.Now}] [Retry {retryCount}] Błąd: {exception.Message}. Próba ponownie za {timeSpan.TotalSeconds} sek.\n" +
$"Metoda: RcpAutomationService -> CheckIfWorkAlreadyStartedAsync()\n\n");
$"Metoda: RcpAutomationService -> CheckIfWorkAlreadyStartedAsync()\n\n");
});

/// <summary>
Expand All @@ -36,8 +37,9 @@ public static class RcpAutomationService
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
File.AppendAllText("output.txt", $"[{DateTime.Now}] {ex}\n" +
$"Metoda: RcpAutomationService -> CheckIfWorkAlreadyStartedWithRetryAsync()\n\n");
$"Metoda: RcpAutomationService -> CheckIfWorkAlreadyStartedWithRetryAsync()\n\n");
Console.WriteLine($"Wszystkie retry zakończone niepowodzeniem (pewnie brak internetu). Szczegóły błędu zapisano w pliku output.txt");
return null;
}
Expand Down Expand Up @@ -93,9 +95,9 @@ public static async Task StartWorkAsync(RcpApiClient api)
// TODO: error handling jest w PRogram.cs - sprawdzić, czy bez try catcha tutaj będą ładnie szły błędy do
// Program.cs właśnie w każdym przypadku (zarówno z metody wywoływanej w Program.cs, jak i z opcji w tray menu)

// TODO: tutaj może mail jeszcze do mnie z informacją że coś poszło komuś nie tak - komu i co poszło nie tak
SentrySdk.CaptureException(ex);
File.AppendAllText("output.txt", $"[{DateTime.Now}] {ex}\n" +
$"Metoda: RcpAutomationService -> StartWorkAsync()\n\n");
$"Metoda: RcpAutomationService -> StartWorkAsync()\n\n");
MessageBox.Show(
"Wystąpił nieoczekiwany błąd, nie udało się zarejestrować początku pracy. Szczegóły błędu zapisano w pliku output.txt, proszę skonsultować się z administratorem.",
"EasyRCP - Błąd",
Expand Down Expand Up @@ -145,9 +147,9 @@ public static async Task EndWork(RcpApiClient api)
// TODO: error handling jest w PRogram.cs - sprawdzić, czy bez try catcha tutaj będą ładnie szły błędy do
// Program.cs właśnie w każdym przypadku (zarówno z metody wywoływanej w Program.cs, jak i z opcji w tray menu)

// TODO: tutaj może mail jeszcze do mnie z informacją że coś poszło komuś nie tak - komu i co poszło nie tak
SentrySdk.CaptureException(ex);
File.AppendAllText("output.txt", $"[{DateTime.Now}] {ex}\n" +
$"Metoda: RcpAutomationService -> EndWork()\n\n");
$"Metoda: RcpAutomationService -> EndWork()\n\n");
MessageBox.Show(
"Wystąpił nieoczekiwany błąd, nie udało się zarejestrować końca pracy. Szczegóły błędu zapisano w pliku output.txt, proszę skonsultować się z administratorem.",
"EasyRCP - Błąd",
Expand Down