Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
R: Cache ImgurUploader instance as static var, fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Oct 16, 2017
1 parent 3f7cc5e commit 616b9ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 2 additions & 5 deletions ImgurSniper/Libraries/Start/StartUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static class StartUpload {
/// <param name="files">Path to all upload-queued Images</param>
public static async Task UploadMultiple(IEnumerable<string> files) {
try {
//Logging in
ImgurUploader imgur = new ImgurUploader();
await imgur.Login();
ImgurUploader imgur = await GetUploaderAsync();

//Binary Image
List<MemoryStream> images = new List<MemoryStream>();
Expand Down Expand Up @@ -80,8 +78,7 @@ public static class StartUpload {
/// </summary>
/// <param name="file">Path to Image</param>
public static async Task UploadSingle(string file) {
ImgurUploader imgur = new ImgurUploader();
await imgur.Login();
ImgurUploader imgur = await GetUploaderAsync();

using (MemoryStream stream = new MemoryStream()) {
try {
Expand Down
13 changes: 12 additions & 1 deletion ImgurSniper/Statics.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
using System;
using ImgurSniper.Libraries.Helper;
using System;
using System.Threading.Tasks;

namespace ImgurSniper {
public static class Statics {
private static ImgurUploader _client { get; set; }

public async static Task<ImgurUploader> GetUploaderAsync() {
if (_client == null)
_client = new ImgurUploader();

await _client.Login(); // Will not do anything if token is still valid
return _client;
}

public static NotificationWindow Notification {
get => _notification;
set {
Expand Down

0 comments on commit 616b9ec

Please sign in to comment.