Updated documentation

This commit is contained in:
2022-05-03 21:58:44 +03:00
parent f3d0ea426e
commit f5f1827540
26 changed files with 520 additions and 180 deletions

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
@@ -13,6 +9,15 @@ namespace PluginManager.Online.Helpers
{
internal static class OnlineFunctions
{
/// <summary>
/// Downloads a <see cref="Stream"/> and saves it to another <see cref="Stream"/>.
/// </summary>
/// <param name="client">The <see cref="HttpClient"/> that is used to download the file</param>
/// <param name="url">The url to the file</param>
/// <param name="destination">The <see cref="Stream"/> to save the downloaded data</param>
/// <param name="progress">The <see cref="IProgress{T}"/> that is used to track the download progress</param>
/// <param name="cancellation">The cancellation token</param>
/// <returns></returns>
internal static async Task DownloadFileAsync(this HttpClient client, string url, Stream destination, IProgress<float> progress = null, CancellationToken cancellation = default)
{
using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
@@ -39,6 +44,12 @@ namespace PluginManager.Online.Helpers
}
}
/// <summary>
/// Read contents of a file as string from specified URL
/// </summary>
/// <param name="url">The URL to read from</param>
/// <param name="cancellation">The cancellation token</param>
/// <returns></returns>
internal static async Task<string> DownloadStringAsync(string url, CancellationToken cancellation = default)
{
using (var client = new HttpClient())

View File

@@ -11,8 +11,17 @@ namespace PluginManager.Online
public class LanguageManager
{
private string link;
/// <summary>
/// The Language Manager constructor
/// </summary>
/// <param name="link">The link to where all the languages for the bot are stored</param>
public LanguageManager(string link) => this.link = link;
/// <summary>
/// The method to list all languages
/// </summary>
/// <returns></returns>
public async Task ListAllLanguages()
{
@@ -49,6 +58,11 @@ namespace PluginManager.Online
}
/// <summary>
/// A function that gets the download link for specified language
/// </summary>
/// <param name="langName">The name of the language</param>
/// <returns></returns>
public async Task<string[]?> GetDownloadLink(string langName)
{
try

View File

@@ -10,13 +10,24 @@ namespace PluginManager.Online
{
public class PluginsManager
{
/// <summary>
/// The URL of the server
/// </summary>
public string PluginsLink { get; private set; }
/// <summary>
/// The Plugin Manager constructor
/// </summary>
/// <param name="link">The link to the file where all plugins are stored</param>
public PluginsManager(string link)
{
PluginsLink = link;
}
/// <summary>
/// The method to load all plugins
/// </summary>
/// <returns></returns>
public async Task ListAvailablePlugins()
{
try
@@ -77,6 +88,11 @@ namespace PluginManager.Online
}
/// <summary>
/// The method to get plugin information by its name
/// </summary>
/// <param name="name">The plugin name</param>
/// <returns></returns>
public async Task<string[]> GetPluginLinkByName(string name)
{
try

View File

@@ -13,27 +13,26 @@ namespace PluginManager.Online
{
public class ServerCom
{
/// <summary>
/// Read all lines from a file async
/// </summary>
/// <param name="link">The link of the file</param>
/// <returns></returns>
public static async Task<List<string>> ReadTextFromFile(string link)
{
string response = await OnlineFunctions.DownloadStringAsync(link);
string[] lines = response.Split('\n');
return lines.ToList();
//[Obsolete]
#region old code for reading text from link
/*
List<string> s = new List<string>();
WebClient webClient = new WebClient();
var data = await webClient.OpenReadTaskAsync(link);
var response = await new StreamReader(data).ReadToEndAsync();
s.AddRange(from a in response.Split('\n')
where !a.StartsWith("$")
select a);
return s;*/
#endregion
}
/// <summary>
/// Download file from url
/// </summary>
/// <param name="URL">The url to the file</param>
/// <param name="location">The location where to store the downloaded data</param>
/// <param name="progress">The <see cref="IProgress{T}"/> to track the download</param>
/// <returns></returns>
public static async Task DownloadFileAsync(string URL, string location, IProgress<float> progress)
{
using (var client = new System.Net.Http.HttpClient())
@@ -46,50 +45,5 @@ namespace PluginManager.Online
}
}
}
public static async Task DownloadFileAsync(string url, string location, int downloadNumber, int totalToDownload)
{
IProgress<float> progress = new Progress<float>(bytes =>
{
Console.Title = $"Downloading {MathF.Round(bytes, 2)}% ({downloadNumber}/{totalToDownload})";
});
await DownloadFileAsync(url, location, progress);
Console.Title = "ONLINE";
return;
//[Obsolete]
#region old download code
/*
WebClient client = new WebClient();
Spinner spinner = new Spinner();
Console.Write("Downloading ");
spinner.Start();
string oldTitle = Console.Title ?? "";
client.DownloadProgressChanged += (sender, e) =>
{
Console.Title = e.BytesReceived + "/" + e.TotalBytesToReceive + " (" + e.ProgressPercentage + "%) (" + downloadNumber + " / " + totalToDownload + ")";
};
client.DownloadFileCompleted += (sender, e) =>
{
spinner.Stop(); Console.WriteLine();
};
try
{
await client.DownloadFileTaskAsync(new Uri(url), location);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
Console.Title = oldTitle;
}*/
#endregion
}
}
}