diff --git a/PixaiBot/App.xaml.cs b/PixaiBot/App.xaml.cs index e50d686..dbbeda2 100644 --- a/PixaiBot/App.xaml.cs +++ b/PixaiBot/App.xaml.cs @@ -22,7 +22,7 @@ public partial class App : Application public App() { - _logger = new Logger() ; + _logger = new Logger(); IServiceCollection services = new ServiceCollection(); services.AddSingleton(provider => new MainWindowView() { DataContext = provider.GetService() }); @@ -42,14 +42,14 @@ public App() services.AddSingleton>(serviceProvider => viewModelType => (BaseViewModel)serviceProvider.GetRequiredService(viewModelType)); _serviceProvider = services.BuildServiceProvider(); - Application.Current.DispatcherUnhandledException += HandleUnhandledApplicationException; + Current.DispatcherUnhandledException += HandleUnhandledApplicationException; } protected override void OnStartup(StartupEventArgs e) { InitialConfiguration.CreateConfigFile(); InitialConfiguration.CreateStatisticsFile(); - _logger.Log("=====Application Started=====",_logger.ApplicationLogFilePath); + _logger.Log("=====Application Started=====", _logger.ApplicationLogFilePath); base.OnStartup(e); var mainWindow = _serviceProvider.GetRequiredService(); mainWindow.Show(); @@ -57,14 +57,13 @@ protected override void OnStartup(StartupEventArgs e) protected override void OnExit(ExitEventArgs e) { - _logger.Log("=====Application Closed=====",_logger.ApplicationLogFilePath); + _logger.Log("=====Application Closed=====", _logger.ApplicationLogFilePath); base.OnExit(e); } private void HandleUnhandledApplicationException(object sender, DispatcherUnhandledExceptionEventArgs e) { - _logger.Log($"{e.Exception} | {e.Exception.Message}",_logger.ApplicationLogFilePath); + _logger.Log($"{e.Exception} | {e.Exception.Message}", _logger.ApplicationLogFilePath); e.Handled = true; } - } \ No newline at end of file diff --git a/PixaiBot/Bussines Logic/Data Management/AccountsManager.cs b/PixaiBot/Bussines Logic/Data Management/AccountsManager.cs index 674f91b..f9ffadc 100644 --- a/PixaiBot/Bussines Logic/Data Management/AccountsManager.cs +++ b/PixaiBot/Bussines Logic/Data Management/AccountsManager.cs @@ -23,7 +23,7 @@ public class AccountsManager : IAccountsManager private readonly ILogger _logger; - public AccountsManager(IBotStatisticsManager botStatisticsManager,ILogger logger) + public AccountsManager(IBotStatisticsManager botStatisticsManager, ILogger logger) { _logger = logger; AccountsFilePath = InitialConfiguration.AccountsFilePath; @@ -33,7 +33,6 @@ public AccountsManager(IBotStatisticsManager botStatisticsManager,ILogger logger public void AddAccount(UserAccount account) { - if (!File.Exists(AccountsFilePath)) { var accountsList = new List(); @@ -43,7 +42,7 @@ public void AddAccount(UserAccount account) UpdateAccountManagerProperties(); _logger.Log("Added account ", _logger.ApplicationLogFilePath); - return; + return; } var accountList = _jsonReader.ReadAccountFile(AccountsFilePath); @@ -52,7 +51,6 @@ public void AddAccount(UserAccount account) _botStatisticsManager.IncreaseAccountsCount(1); _logger.Log("Added account", _logger.ApplicationLogFilePath); UpdateAccountManagerProperties(); - } public void RemoveAccount(IList accountList, UserAccount userAccount) @@ -63,7 +61,6 @@ public void RemoveAccount(IList accountList, UserAccount userAccoun _botStatisticsManager.IncreaseAccountsCount(-1); UpdateAccountManagerProperties(); _logger.Log("Removed account", _logger.ApplicationLogFilePath); - } public IEnumerable GetAllAccounts() @@ -87,7 +84,7 @@ public void AddManyAccounts() var result = dialog.ShowDialog(); if (result == false) return; - + var importedUserAccounts = GetUserAccountsFromTxt(dialog.FileName); _logger.Log("Adding accounts in batch", _logger.ApplicationLogFilePath); diff --git a/PixaiBot/Bussines Logic/Data Management/BotStatisticsManager.cs b/PixaiBot/Bussines Logic/Data Management/BotStatisticsManager.cs index 57b9e60..0c49c14 100644 --- a/PixaiBot/Bussines Logic/Data Management/BotStatisticsManager.cs +++ b/PixaiBot/Bussines Logic/Data Management/BotStatisticsManager.cs @@ -10,7 +10,6 @@ namespace PixaiBot.Bussines_Logic; public class BotStatisticsManager : IBotStatisticsManager { - private string AccountsStatisticsFilePath { get; } private BotStatistics _botStatistics; @@ -40,7 +39,6 @@ public void RefreshStatistics() AccountsNumber = _botStatistics.AccountsCount; LastCreditClaimDateTime = _botStatistics.LastCreditClaimDateTime; BotVersion = _botStatistics.BotVersion; - } public void IncreaseAccountsCount(int number) @@ -76,6 +74,5 @@ public void ResetNumberOfAccounts() { _botStatistics.AccountsCount = 0; _logger.Log("Account count rested", _logger.ApplicationLogFilePath); - } } \ No newline at end of file diff --git a/PixaiBot/Bussines Logic/Data Management/ConfigManager.cs b/PixaiBot/Bussines Logic/Data Management/ConfigManager.cs index 0e3ac19..61c41cd 100644 --- a/PixaiBot/Bussines Logic/Data Management/ConfigManager.cs +++ b/PixaiBot/Bussines Logic/Data Management/ConfigManager.cs @@ -25,13 +25,13 @@ public ConfigManager(ILogger logger) public UserConfig GetConfig() { - _logger.Log("Readed Config File",_logger.ApplicationLogFilePath); + _logger.Log("Readed Config File", _logger.ApplicationLogFilePath); return _jsonReader.ReadConfigFile(ConfigFilePath); } public void SaveConfig(UserConfig config) { - _logger.Log("Writed Config File",_logger.ApplicationLogFilePath); + _logger.Log("Writed Config File", _logger.ApplicationLogFilePath); JsonWriter.WriteJson(config, ConfigFilePath); } } \ No newline at end of file diff --git a/PixaiBot/Bussines Logic/Data Management/InitialConfiguration.cs b/PixaiBot/Bussines Logic/Data Management/InitialConfiguration.cs index 83237aa..b4a5838 100644 --- a/PixaiBot/Bussines Logic/Data Management/InitialConfiguration.cs +++ b/PixaiBot/Bussines Logic/Data Management/InitialConfiguration.cs @@ -26,7 +26,6 @@ public static class InitialConfiguration static InitialConfiguration() { - ApplicationDataPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\PixaiAutoClaimer"; UserConfigPath = @@ -50,7 +49,7 @@ public static void CreateDirectories() public static void CreateConfigFile() { if (File.Exists(UserConfigPath)) return; - + var userConfig = new UserConfig() { StartWithSystem = false, @@ -63,13 +62,13 @@ public static void CreateConfigFile() public static void CreateStatisticsFile() { if (File.Exists(StatisticsFilePath)) return; - - var statistics = new BotStatistics() - { - AccountsCount = 0, - BotVersion = BotVersion, - LastCreditClaimDateTime = DateTime.Now, - }; - JsonWriter.WriteJson(statistics, StatisticsFilePath); + + var statistics = new BotStatistics() + { + AccountsCount = 0, + BotVersion = BotVersion, + LastCreditClaimDateTime = DateTime.Now + }; + JsonWriter.WriteJson(statistics, StatisticsFilePath); } } \ No newline at end of file diff --git a/PixaiBot/Bussines Logic/Driver and Browser Management/AccountLoginChecker.cs b/PixaiBot/Bussines Logic/Driver and Browser Management/AccountLoginChecker.cs index ecbe2ae..f688b3c 100644 --- a/PixaiBot/Bussines Logic/Driver and Browser Management/AccountLoginChecker.cs +++ b/PixaiBot/Bussines Logic/Driver and Browser Management/AccountLoginChecker.cs @@ -41,16 +41,16 @@ public bool CheckAccountLogin(UserAccount userAccount) { _driver.Close(); _driver.Dispose(); - _logger.Log($"Valid Account {userAccount.Email}",_logger.CreditClaimerLogFilePath); - _logger.Log($"=====Chrome Drive Disposed=====\n",_logger.CreditClaimerLogFilePath); + _logger.Log($"Valid Account {userAccount.Email}", _logger.CreditClaimerLogFilePath); + _logger.Log($"=====Chrome Drive Disposed=====\n", _logger.CreditClaimerLogFilePath); return true; } _driver.Close(); _driver.Dispose(); - _logger.Log("Invalid Account",_logger.CreditClaimerLogFilePath); - _logger.Log("=====Chrome Drive Disposed=====\n", _logger.CreditClaimerLogFilePath); - return false; + _logger.Log("Invalid Account", _logger.CreditClaimerLogFilePath); + _logger.Log("=====Chrome Drive Disposed=====\n", _logger.CreditClaimerLogFilePath); + return false; } public int CheckAllAccountsLogin(IList accountsList) diff --git a/PixaiBot/Bussines Logic/Driver and Browser Management/ChromeDriverFactory.cs b/PixaiBot/Bussines Logic/Driver and Browser Management/ChromeDriverFactory.cs index 928d61c..4ad135b 100644 --- a/PixaiBot/Bussines Logic/Driver and Browser Management/ChromeDriverFactory.cs +++ b/PixaiBot/Bussines Logic/Driver and Browser Management/ChromeDriverFactory.cs @@ -5,24 +5,22 @@ using System.Threading.Tasks; using OpenQA.Selenium.Chrome; -namespace PixaiBot.Bussines_Logic +namespace PixaiBot.Bussines_Logic; + +public static class ChromeDriverFactory { - public static class ChromeDriverFactory + /// + /// Creates a ChromeDriver with the default settings. + /// + /// Chrome Driver Instance + public static ChromeDriver CreateDriver() { - /// - /// Creates a ChromeDriver with the default settings. - /// - /// Chrome Driver Instance - public static ChromeDriver CreateDriver() - { - ChromeOptions options = new ChromeOptions(); - options.AddArgument("--window-position=-32000,-32000"); + var options = new ChromeOptions(); + options.AddArgument("--window-position=-32000,-32000"); - ChromeDriverService service = ChromeDriverService.CreateDefaultService(); - service.HideCommandPromptWindow = true; + var service = ChromeDriverService.CreateDefaultService(); + service.HideCommandPromptWindow = true; - return new ChromeDriver(service, options); - } + return new ChromeDriver(service, options); } - -} +} \ No newline at end of file diff --git a/PixaiBot/Bussines Logic/Driver and Browser Management/CreditClaimer.cs b/PixaiBot/Bussines Logic/Driver and Browser Management/CreditClaimer.cs index 79d56fa..95987e2 100644 --- a/PixaiBot/Bussines Logic/Driver and Browser Management/CreditClaimer.cs +++ b/PixaiBot/Bussines Logic/Driver and Browser Management/CreditClaimer.cs @@ -33,7 +33,7 @@ public CreditClaimer(ILogger logger) _logger = logger; } - + /// /// Claims credits on the given account /// @@ -42,16 +42,16 @@ public CreditClaimer(ILogger logger) public void ClaimCredits(UserAccount account, IToastNotificationSender toastNotificationSender = null) { _driver = ChromeDriverFactory.CreateDriver(); - + _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(MaxWaitTime); - + _driver.Manage().Window.Minimize(); - LoginModule.Login(_driver, account,_logger); + LoginModule.Login(_driver, account, _logger); if (_driver.Url == LoginUrl) { toastNotificationSender?.SendNotification("Login failed", $"Login failed for {account.Email}", NotificationType.Error); - _logger.Log("Login failed",_logger.CreditClaimerLogFilePath); + _logger.Log("Login failed", _logger.CreditClaimerLogFilePath); _driver.Quit(); _logger.Log("=====Chrome Drive Disposed=====\n", _logger.CreditClaimerLogFilePath); return; @@ -84,8 +84,8 @@ public void ClaimCredits(UserAccount account, IToastNotificationSender toastNoti _logger.Log($"Claiming credits completed successfully for {account.Email}", _logger.CreditClaimerLogFilePath); _driver.Quit(); _logger.Log("=====Chrome Drive Disposed=====\n", _logger.CreditClaimerLogFilePath); - } + /// /// Navigates to profile page /// @@ -111,6 +111,7 @@ private bool GoToProfile() return false; } } + /// /// Claims credits on the account /// diff --git a/PixaiBot/Bussines Logic/Driver and Browser Management/LoginModule.cs b/PixaiBot/Bussines Logic/Driver and Browser Management/LoginModule.cs index 831a788..f5c3038 100644 --- a/PixaiBot/Bussines Logic/Driver and Browser Management/LoginModule.cs +++ b/PixaiBot/Bussines Logic/Driver and Browser Management/LoginModule.cs @@ -18,7 +18,6 @@ public static class LoginModule private const int StartWaitTime = 1000; - /// /// Logs user to pixai.art /// This method is used by CreditClaimer and AccountChecker @@ -29,7 +28,7 @@ public static class LoginModule public static void Login(ChromeDriver driver, UserAccount userAccount, ILogger logger) { logger.Log("=====Launched Chrome Driver=====", logger.CreditClaimerLogFilePath); - + driver.Navigate().GoToUrl(LoginUrl); Thread.Sleep(StartWaitTime); @@ -53,6 +52,7 @@ public static void Login(ChromeDriver driver, UserAccount userAccount, ILogger l return; } + logger.Log($"Sending user credentials to textboxes", logger.CreditClaimerLogFilePath); textInputs.ElementAt(0).Click(); @@ -71,7 +71,7 @@ public static void Login(ChromeDriver driver, UserAccount userAccount, ILogger l } buttons.FirstOrDefault(x => x.Text == "Login")?.Click(); - + logger.Log($"Login Button Clicked", logger.CreditClaimerLogFilePath); } } \ No newline at end of file diff --git a/PixaiBot/Bussines Logic/Logging/Logger.cs b/PixaiBot/Bussines Logic/Logging/Logger.cs index 0205cd8..168a7af 100644 --- a/PixaiBot/Bussines Logic/Logging/Logger.cs +++ b/PixaiBot/Bussines Logic/Logging/Logger.cs @@ -1,5 +1,4 @@ - -using PixaiBot.Data.Interfaces; +using PixaiBot.Data.Interfaces; using System.IO; using System; @@ -13,11 +12,14 @@ public class Logger : ILogger public Logger() { - CreditClaimerLogFilePath = $@"{InitialConfiguration.BotLogsPath}\CreditClaimer Log {DateTime.Now:yyyy-MM-dd}.txt"; + CreditClaimerLogFilePath = + $@"{InitialConfiguration.BotLogsPath}\CreditClaimer Log {DateTime.Now:yyyy-MM-dd}.txt"; ApplicationLogFilePath = $@"{InitialConfiguration.BotLogsPath}\Application Log {DateTime.Now:yyyy-MM-dd}.txt"; - - if (!File.Exists(CreditClaimerLogFilePath)) File.Create(CreditClaimerLogFilePath); ; - if (!File.Exists(ApplicationLogFilePath)) File.Create(ApplicationLogFilePath); ; + + if (!File.Exists(CreditClaimerLogFilePath)) File.Create(CreditClaimerLogFilePath); + ; + if (!File.Exists(ApplicationLogFilePath)) File.Create(ApplicationLogFilePath); + ; } public void Log(string message, string filePath) diff --git a/PixaiBot/Bussines Logic/Notifications/ToastNotificationSender.cs b/PixaiBot/Bussines Logic/Notifications/ToastNotificationSender.cs index b62e0c6..6261197 100644 --- a/PixaiBot/Bussines Logic/Notifications/ToastNotificationSender.cs +++ b/PixaiBot/Bussines Logic/Notifications/ToastNotificationSender.cs @@ -21,7 +21,6 @@ public ToastNotificationSender(ILogger logger) } - public void SendNotification(string title, string message, NotificationType notificationType) { _logger.Log($"Notification Sent, NotificationType{notificationType}", _logger.ApplicationLogFilePath); diff --git a/PixaiBot/Data/Interfaces/ILogger.cs b/PixaiBot/Data/Interfaces/ILogger.cs index dce1aaa..1154734 100644 --- a/PixaiBot/Data/Interfaces/ILogger.cs +++ b/PixaiBot/Data/Interfaces/ILogger.cs @@ -12,5 +12,5 @@ public interface ILogger public string ApplicationLogFilePath { get; } - public void Log(string message,string filePath); + public void Log(string message, string filePath); } \ No newline at end of file diff --git a/PixaiBot/Data/Interfaces/IWindowHelper.cs b/PixaiBot/Data/Interfaces/IWindowHelper.cs index d1f1542..daf6e27 100644 --- a/PixaiBot/Data/Interfaces/IWindowHelper.cs +++ b/PixaiBot/Data/Interfaces/IWindowHelper.cs @@ -8,7 +8,7 @@ namespace PixaiBot.Data.Interfaces; public interface IWindowHelper { - public Action Close { get; set; } + public Action Close { get; set; } - public bool CanCloseWindow(); + public bool CanCloseWindow(); } \ No newline at end of file diff --git a/PixaiBot/UI/Helpers/TrayIconHelper.cs b/PixaiBot/UI/Helpers/TrayIconHelper.cs index c670377..6dd12a3 100644 --- a/PixaiBot/UI/Helpers/TrayIconHelper.cs +++ b/PixaiBot/UI/Helpers/TrayIconHelper.cs @@ -37,7 +37,7 @@ private static void HideToTray(DependencyObject d, DependencyPropertyChangedEven if (trayIconHelper.CanHideToTray()) { window.Hide(); - + var notifyIcon = new NotifyIcon() { Icon = new Icon("Resources/images/PixaiAutoClaimerIcon.ico"), diff --git a/PixaiBot/UI/View/AddAccountWindowView.xaml.cs b/PixaiBot/UI/View/AddAccountWindowView.xaml.cs index cf91d6b..7733ab7 100644 --- a/PixaiBot/UI/View/AddAccountWindowView.xaml.cs +++ b/PixaiBot/UI/View/AddAccountWindowView.xaml.cs @@ -22,7 +22,7 @@ public partial class AddAccountWindowView : Window public AddAccountWindowView(IAccountsManager accountsManager, IDataValidator dataValidator) { InitializeComponent(); - DataContext = new AddAccountWindowViewModel(accountsManager, dataValidator,new Logger()); + DataContext = new AddAccountWindowViewModel(accountsManager, dataValidator, new Logger()); } private void Border_OnMouseDown(object sender, MouseButtonEventArgs e) diff --git a/PixaiBot/UI/View/DashboardControlView.xaml b/PixaiBot/UI/View/DashboardControlView.xaml index e4eff16..a185bee 100644 --- a/PixaiBot/UI/View/DashboardControlView.xaml +++ b/PixaiBot/UI/View/DashboardControlView.xaml @@ -28,7 +28,8 @@ HorizontalAlignment="Center" />