-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from SwagLyrics/dev
V0.3
- Loading branch information
Showing
12 changed files
with
211 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Windows.Input; | ||
|
||
namespace SwagLyricsGUI.Models | ||
{ | ||
public class Command : ICommand | ||
{ | ||
private Action<object>? _execute; | ||
private Predicate<object>? _canExecute; | ||
|
||
public event EventHandler CanExecuteChanged; | ||
|
||
#pragma warning disable CS8618 | ||
public Command(Action<object>? execute = null, Predicate<object>? canExecute = null) | ||
#pragma warning restore CS8618 | ||
{ | ||
_execute = execute; | ||
_canExecute = canExecute; | ||
} | ||
|
||
public virtual void NotifyCanExecuteChanged() | ||
{ | ||
CanExecuteChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
public bool CanExecute(object parameter) | ||
{ | ||
return _canExecute?.Invoke(parameter) ?? true; | ||
} | ||
|
||
public void Execute(object parameter) | ||
{ | ||
_execute?.Invoke(parameter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SwagLyricsGUI.Models | ||
{ | ||
public class Fact | ||
{ | ||
[JsonPropertyName("text")] | ||
public string Text { get; set; } | ||
[JsonPropertyName("source_url")] | ||
public string SourceUrl { get; set; } | ||
|
||
public Fact(string text, string source) | ||
{ | ||
Text = text; | ||
SourceUrl = source; | ||
} | ||
|
||
public Fact() | ||
{ | ||
|
||
} | ||
|
||
public override string ToString() => $"{Text}\n\n\nSource: {SourceUrl}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace SwagLyricsGUI.Models | ||
{ | ||
public static class RandomFactsFetcher | ||
{ | ||
public const string FactsUrl = @"https://uselessfacts.jsph.pl/random.json?language=en"; | ||
public static Fact GetRandomFact() | ||
{ | ||
WebRequest request = WebRequest.Create(FactsUrl); | ||
var response = request.GetResponse(); | ||
Fact result; | ||
|
||
using (Stream dataStream = response.GetResponseStream()) | ||
{ | ||
// Open the stream using a StreamReader for easy access. | ||
StreamReader reader = new StreamReader(dataStream); | ||
// Read the content. | ||
result = JsonSerializer.Deserialize<Fact>(reader.ReadToEnd()); | ||
} | ||
|
||
// Close the response. | ||
response.Close(); | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.