Skip to content

Commit

Permalink
Added JW Limited Online Services
Browse files Browse the repository at this point in the history
  • Loading branch information
JWLMT88 committed May 15, 2023
1 parent ed6bab9 commit 74c7c6d
Show file tree
Hide file tree
Showing 118 changed files with 7,688 additions and 428 deletions.
22 changes: 22 additions & 0 deletions api.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

155 changes: 155 additions & 0 deletions srvlocal_gui/AppMananger/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace srvlocal_gui.AppMananger
{
public class Helper
{
public static async Task<bool> VerifyEmailAsync(string email)
{
const string apiKey = "YOUR_RAPIDAPI_KEY_HERE";
const string apiUrl = "https://email-verifier1.p.rapidapi.com/v1/";

var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-RapidAPI-Key", apiKey);

var query = HttpUtility.ParseQueryString(string.Empty);
query["email"] = email;

var url = $"{apiUrl}verify?{query}";

var response = await client.GetAsync(url);

if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<EmailVerificationResult>(json);
return result.Status == "valid";
}
else
{
throw new Exception($"Failed to verify email address: {response.StatusCode} - {response.ReasonPhrase}");
}
}

public static async Task<string> TranslateTextAsync(string text, string targetLanguage)
{
// Set up the request URL and parameters
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://google-translate1.p.rapidapi.com/language/translate/v2"),
Headers =
{
{ "X-RapidAPI-Key", "7facbca935msh0800aea598dca8ap19cf02jsn17a04c128f7c" },
{ "X-RapidAPI-Host", "google-translate1.p.rapidapi.com" },
},
Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "q", text },
{ "target", "de" },
{ "source", "en" },
}),
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
dynamic result = JsonConvert.DeserializeObject(json);
string translation = result.data.translations[0].translatedText;

return translation;
}
else
{
return "Failed to translate text";
}

}

}
private static string BuildQueryString(Dictionary<string, string> parameters)
{
var queryParameters = new List<string>();
foreach (var kvp in parameters)
{
queryParameters.Add($"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}");
}
return string.Join("&", queryParameters);
}

public static async Task<string> GetQuoteOfTheDayAsync()
{
// Create an HttpClient with the required headers
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("x-rapidapi-host", "quotes15.p.rapidapi.com");
client.DefaultRequestHeaders.Add("x-rapidapi-key", "7facbca935msh0800aea598dca8ap19cf02jsn17a04c128f7c");

// Make a GET request to the Quotes Free API
HttpResponseMessage response = await client.GetAsync("https://quotes15.p.rapidapi.com/quotes/random/");
if (response.IsSuccessStatusCode)
{
// Parse the JSON response and extract the quote of the day
string json = await response.Content.ReadAsStringAsync();
dynamic result = JsonConvert.DeserializeObject(json);
string quote = result.content;
string author = result.originator.name;

// Return the quote of the day
return $"{quote} - {author}";
}
else
{
// Return an error message if the request failed
return "Failed to get quote of the day";
}
}
public static string ComputeHash(string input)
{
using (SHA256 sha256Hash = SHA256.Create())
{
// Compute hash from the input string
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

// Convert the byte array to a string
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}

}

public class EmailVerificationResult
{
public string Email { get; set; }
public string Status { get; set; }
public string Reason { get; set; }
public string Role { get; set; }
public string Disposable { get; set; }
public string Free { get; set; }
public string AcceptAll { get; set; }
public string VerifiedAt { get; set; }
public string Source { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public string Location { get; set; }
}

}
48 changes: 29 additions & 19 deletions srvlocal_gui/AppMananger/ReadMeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ private void ReadMeDialog_Load(object sender, EventArgs e)
lblVersion.Text = version;
}

public void del(string latestVersion)
public async void del(string latestVersion)
{
var targetFile = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "//JW Limited//LAB//srvlocal_gui.exe";
CreateShortcut("LAB", targetFile);
Updater.RegisterProduct("LAB", latestVersion, targetFile);
Process.Start(targetFile);
Application.ExitThread();
}

public static void CreateShortcut(string shortcutName, string targetFile)
Expand All @@ -80,7 +79,7 @@ public static void CreateShortcut(string shortcutName, string targetFile)
shortcut.Save();
}

private void bntUpdate_Click(object sender, EventArgs e)
private async void bntUpdate_Click(object sender, EventArgs e)
{
var updater = Updater.Instance();

Expand All @@ -96,27 +95,37 @@ private void bntUpdate_Click(object sender, EventArgs e)
updating = true;
Text = "Installing Update...";

Task.Run(() =>
await Task.Run(() =>
{
//taskDialog1.ShowDialog();
updater.VerifyAndExtractZip(zipPath, "8a3a0cecf50f9e4a7387b23d4a4c4e4b3d2bbd8e91edc5729c15f9f1f10c8aaf", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "JW Limited"), progress =>
try
{
progessbar.Value = progress;
taskDialog1.ProgressBarValue = progress;
if (progress == 100)
// Call the API to verify and extract the ZIP file
updater.VerifyAndExtractZip(zipPath, "8a3a0cecf50f9e4a7387b23d4a4c4e4b3d2bbd8e91edc5729c15f9f1f10c8aaf", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "JW Limited"),
progress =>
{
del(latestVersion: version);
}
},
error =>
progessbar.Value = progress;
taskDialog1.ProgressBarValue = progress;
if (progress == 100)
{
Task.Run(() => { del(latestVersion: version);
Application.ExitThread();
});
Application.ExitThread();
}
},
error =>
{
MessageBox.Show($"Error: {error}", "Install Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
catch (Exception ex)
{
MessageBox.Show($"Error: {error}", "Install Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
MessageBox.Show($"Error: {ex.Message}", "Install Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
});

//MessageBox.Show("Installed Updates","Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
MessageBox.Show("Installed Updates", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
Expand All @@ -127,7 +136,7 @@ private void bntUpdate_Click(object sender, EventArgs e)
bntCancel.Enabled = false;
updating = true;

Task.Run(() =>
await Task.Run(() =>
{
updater.DownloadLatestRelease(owner, repo, UpdateProgress);
Expand All @@ -151,6 +160,7 @@ private void bntUpdate_Click(object sender, EventArgs e)
this.ControlBox = true;
}


}

private void UpdateProgress(object sender, DownloadProgressChangedEventArgs e)
Expand Down
1 change: 0 additions & 1 deletion srvlocal_gui/AppMananger/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private SettingsManager()

public T GetSetting<T>(Func<Settings, T> settingSelector, T defaultValue = default)
{
_settings = LoadSettings();

T value = settingSelector(_settings);
if (value != null)
Expand Down
Loading

0 comments on commit 74c7c6d

Please sign in to comment.