|
|
|
@ -4,11 +4,20 @@ using System;
|
|
|
|
|
using static WetPancake.Pancake; |
|
|
|
|
using static System.Environment; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using Microsoft.FSharp.Control; |
|
|
|
|
using Microsoft.FSharp.Core; |
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
namespace WetPancakeCLI |
|
|
|
|
{ |
|
|
|
|
public static class ConsoleCommands |
|
|
|
|
{ |
|
|
|
|
// Pass these in when running an FSharpAsync task. |
|
|
|
|
// Examples are within the command-methods. |
|
|
|
|
static FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None; |
|
|
|
|
static FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None; |
|
|
|
|
|
|
|
|
|
[ListCommand] |
|
|
|
|
[Description("Prints a test message to the console.")] |
|
|
|
|
[Parameters("None")] |
|
|
|
@ -34,12 +43,12 @@ namespace WetPancakeCLI
|
|
|
|
|
public static string GenerateRandomText() |
|
|
|
|
{ |
|
|
|
|
string result = String.Empty; |
|
|
|
|
try { return RequestRandomText(); } |
|
|
|
|
try { return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result; } |
|
|
|
|
catch (Exception e) |
|
|
|
|
{ |
|
|
|
|
Debug.WriteLine(e.Message); |
|
|
|
|
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command..."); |
|
|
|
|
return RequestRandomText(); |
|
|
|
|
return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|