Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Harabe-x committed Oct 22, 2023
1 parent a0cda4e commit b0e1ba3
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 9 deletions.
5 changes: 4 additions & 1 deletion PixaiBot/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
)]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
18 changes: 18 additions & 0 deletions PixaiBot/Bussines Logic/Data Handling/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@ namespace PixaiBot.Bussines_Logic;

public static class JsonReader
{

/// <summary>
/// Reads a json file and returns a list of user accounts
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static IList<UserAccount> ReadAccountFile(string filePath)
{
var jsonString = File.ReadAllText(filePath);
var accounts = JsonSerializer.Deserialize<IList<UserAccount>>(jsonString);
return accounts;
}


/// <summary>
/// Reads a json file and returns a user config object
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static UserConfig ReadConfigFile(string filePath)
{
var jsonString = File.ReadAllText(filePath);
Expand All @@ -26,6 +38,12 @@ public static UserConfig ReadConfigFile(string filePath)
return userConfig;
}


/// <summary>
/// Reads a json file and returns a bot statistics object
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static BotStatistics ReadStatisticsFile(string filePath)
{
var jsonString = File.ReadAllText(filePath);
Expand Down
6 changes: 6 additions & 0 deletions PixaiBot/Bussines Logic/Data Handling/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ namespace PixaiBot.Bussines_Logic;

public class JsonWriter
{
/// <summary>
/// Writes a json file with the given object
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="filePath"></param>
public static void WriteJson<T>(T obj, string filePath)
{
var serializedJson = JsonSerializer.Serialize(obj);
Expand Down
20 changes: 20 additions & 0 deletions PixaiBot/Bussines Logic/Data Management/AccountsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public AccountsManager(IBotStatisticsManager botStatisticsManager, ILogger logge
_botStatisticsManager = botStatisticsManager;
}


/// <summary>
/// Add new account to accounts file
/// </summary>
/// <param name="account"></param>
public void AddAccount(UserAccount account)
{
if (!File.Exists(AccountsFilePath))
Expand All @@ -54,6 +59,12 @@ public void AddAccount(UserAccount account)
UpdateAccountManagerProperties();
}


/// <summary>
/// Removes account from accounts file
/// </summary>
/// <param name="accountList"></param>
/// <param name="userAccount"></param>
public void RemoveAccount(IList<UserAccount> accountList, UserAccount userAccount)
{
if (!File.Exists(AccountsFilePath)) return;
Expand All @@ -64,6 +75,11 @@ public void RemoveAccount(IList<UserAccount> accountList, UserAccount userAccoun
_logger.Log("Removed account", _logger.ApplicationLogFilePath);
}


/// <summary>
/// Returns all accounts from accounts file
/// </summary>
/// <returns></returns>
public IEnumerable<UserAccount> GetAllAccounts()
{
_logger.Log("Reading account List", _logger.ApplicationLogFilePath);
Expand All @@ -73,6 +89,10 @@ public IEnumerable<UserAccount> GetAllAccounts()
: new List<UserAccount>();
}


/// <summary>
/// Opens File Dialog and extracts user accounts from txt file
/// </summary>
public void AddManyAccounts()
{
var dialog = new OpenFileDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public BotStatisticsManager(ILogger logger)

private void InitializeData()
{
BotVersion = _botStatistics.BotVersion;
BotVersion = InitialConfiguration.BotVersion;
LastCreditClaimDateTime = _botStatistics.LastCreditClaimDateTime;
AccountsNumber = _botStatistics.AccountsCount;
}
Expand Down
14 changes: 12 additions & 2 deletions PixaiBot/Bussines Logic/Data Management/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,29 @@ public void SaveConfig(UserConfig config)
_logger.Log("Writed Config File", _logger.ApplicationLogFilePath);
JsonWriter.WriteJson(config, ConfigFilePath);
}

/// <summary>
/// Sets <see cref="ShouldStartWithSystem"/> to <paramref name="flag"/>
/// </summary>
/// <param name="flag"></param>
public void SetStartWithSystemFlag(bool flag)
{
ShouldStartWithSystem = flag;
ConfigChanged?.Invoke(this,EventArgs.Empty);
}

/// <summary>
/// Sets <see cref="ShouldSendToastNotifications"/> to <paramref name="flag"/>
/// </summary>
/// <param name="flag"></param>
public void SetToastNotificationsFlag(bool flag)
{
ShouldSendToastNotifications = flag;
ConfigChanged?.Invoke(this,EventArgs.Empty);
}

/// <summary>
/// Sets <see cref="ShouldAutoClaimCredits"/> to <paramref name="flag"/>
/// </summary>
/// <param name="flag"></param>
public void SetCreditsAutoClaimFlag(bool flag)
{
ShouldAutoClaimCredits = flag;
Expand Down
33 changes: 33 additions & 0 deletions PixaiBot/Bussines Logic/Data Management/InitialConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,38 @@ namespace PixaiBot.Bussines_Logic;

public static class InitialConfiguration
{
/// <summary>
/// Current Bot Version
/// </summary>
public static string BotVersion { get; }


/// <summary>
/// Path to the user config file
/// </summary>
public static string UserConfigPath { get; }


/// <summary>
/// Path to the bot logs folder
/// </summary>
public static string BotLogsPath { get; }


/// <summary>
/// Path to the bot statistics file
/// </summary>
public static string StatisticsFilePath { get; }

/// <summary>
/// Path to the accounts file
/// </summary>
public static string AccountsFilePath { get; }


/// <summary>
/// Path to the application data folder
/// </summary>
public static string ApplicationDataPath { get; }

static InitialConfiguration()
Expand All @@ -39,13 +61,20 @@ static InitialConfiguration()
if (!Directory.Exists(ApplicationDataPath)) CreateDirectories();
}


/// <summary>
/// Creates the directories needed for the bot to work
/// </summary>
public static void CreateDirectories()
{
Directory.CreateDirectory(
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\PixaiAutoClaimer\\Logs");
}


/// <summary>
/// Creates the config file if it doesn't exist
/// </summary>
public static void CreateConfigFile()
{
if (File.Exists(UserConfigPath)) return;
Expand All @@ -59,6 +88,10 @@ public static void CreateConfigFile()
JsonWriter.WriteJson(userConfig, UserConfigPath);
}


/// <summary>
/// Creates the statistics file if it doesn't exist
/// </summary>
public static void CreateStatisticsFile()
{
if (File.Exists(StatisticsFilePath)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ public AccountLoginChecker(ILogger logger)
{
_accountsFilePath = InitialConfiguration.AccountsFilePath;
_logger = logger;
}

}
/// <summary>
/// Checks account login credentials
/// </summary>
/// <param name="userAccount"></param>
/// <param name="toastNotificationSender"></param>
/// <returns>True if the account is valid</returns>
public bool CheckAccountLogin(UserAccount userAccount,IToastNotificationSender toastNotificationSender)
{
_driver = ChromeDriverFactory.CreateDriver();
Expand All @@ -55,7 +61,12 @@ public bool CheckAccountLogin(UserAccount userAccount,IToastNotificationSender t
toastNotificationSender?.SendNotification("PixaiBot", $"Invalid Account {userAccount.Email}",NotificationType.Error);
return false;
}

/// <summary>
/// Checks all accounts login credentials
/// </summary>
/// <param name="accountsList"></param>
/// <param name="toastNotificationSender"></param>
/// <returns>Number of valid accounts</returns>
public int CheckAllAccountsLogin(IList<UserAccount> accountsList,IToastNotificationSender toastNotificationSender = null)
{
var validAccounts = accountsList.Where((account) => CheckAccountLogin(account,toastNotificationSender)).ToList();
Expand Down
5 changes: 5 additions & 0 deletions PixaiBot/Bussines Logic/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public Logger()
;
}

/// <summary>
/// Logs a message to the log file
/// </summary>
/// <param name="message"></param>
/// <param name="filePath"></param>
public void Log(string message, string filePath)
{
File.AppendAllText(filePath, $"[{DateTime.Now:HH:mm:ss}] {message}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public ToastNotificationSender(ILogger logger)
_notification = new NotificationManager();
}


/// <summary>
/// Sends a notification to the user
/// </summary>
/// <param name="title"></param>
/// <param name="message"></param>
/// <param name="notificationType"></param>
public void SendNotification(string title, string message, NotificationType notificationType)
{
_logger.Log($"Notification Sent, NotificationType{notificationType}", _logger.ApplicationLogFilePath);
Expand Down
48 changes: 48 additions & 0 deletions PixaiBot/PixaiBot - Backup.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\images\PixaiAutoClaimerIcon.ico</ApplicationIcon>
<AssemblyVersion>1.2,.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<Version>1.0.2</Version>
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\images\PixaiAutoClaimerIcon.ico" />
<None Remove="Resources\images\PixaiAutoClaimerLogo.png" />
<None Remove="Resources\images\PixaiLogo.png" />
<None Remove="UI\View\PixaiAutoClaimerLogo.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FontAwesome" Version="4.7.0" />
<PackageReference Include="FontAwesome.WPF" Version="4.7.0.9" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Notification.Wpf" Version="7.0.0.2" />
<PackageReference Include="Selenium.WebDriver" Version="4.12.2" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Windows.Forms">
<HintPath>..\..\..\..\..\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Content Include="Resources\images\PixaiAutoClaimerIcon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Resource Include="Resources\images\PixaiAutoClaimerLogo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Resources\images\PixaiLogo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="UI\View\PixaiAutoClaimerLogo.png" />
</ItemGroup>

</Project>
13 changes: 11 additions & 2 deletions PixaiBot/PixaiBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\images\PixaiAutoClaimerIcon.ico</ApplicationIcon>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<AssemblyVersion></AssemblyVersion>
<FileVersion></FileVersion>
<Version></Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit b0e1ba3

Please sign in to comment.