Browse Source

GenerateCleanText command-method completed (minus the help attributes).

master
Craig Oates 6 years ago
parent
commit
0bb49dd713
  1. 18
      WetPancake/ProductServices.fs
  2. 36
      WetPancakeCLI/ConsoleCommands.cs

18
WetPancake/ProductServices.fs

@ -11,6 +11,15 @@ module Pancake =
open System
open System.IO
// TODO: Add XML comments to CleanResult function.
let CleanResult noOfSentences text =
async {
let cleanText =
text
|> RemoveArtifactSentences noOfSentences
return cleanText
}
/// <summary>
/// An asynchronous function which generates random text.
/// </summary>
@ -143,11 +152,10 @@ module Pancake =
return files
}
// Finish annotating this function when this branch (0.7-p2) is merged back into 0.7-p1.
let CleanResult noOfSentences text =
let RequestCleanTextAsync (gibberishLevel: int) (sentences: int) =
async {
let cleanText =
text
|> RemoveArtifactSentences noOfSentences
let! text =
RequestTextAsync gibberishLevel sentences
let! cleanText = CleanResult sentences text
return cleanText
}

36
WetPancakeCLI/ConsoleCommands.cs

@ -44,7 +44,10 @@ namespace WetPancakeCLI
[Usage("> GenerateRandomText")]
public static string GenerateRandomText()
{
try { return FSharpAsync.StartAsTask(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result; }
try
{
return FSharpAsync.StartAsTask(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
@ -60,9 +63,14 @@ namespace WetPancakeCLI
{
try
{
if (gibberishLevel < 2 || gibberishLevel > 20) throw new ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel");
if (sentences < 1) throw new ArgumentException("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
if (gibberishLevel < 2 || gibberishLevel > 20)
throw new ArgumentException
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel");
if (sentences < 1)
throw new ArgumentException
("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask
(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
@ -113,5 +121,25 @@ namespace WetPancakeCLI
throw;
}
}
public static string GenerateCleanText(int gibberishLevel, int sentences)
{
try
{
if (gibberishLevel < 2 || gibberishLevel > 20)
throw new ArgumentException
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel");
if (sentences < 1)
throw new ArgumentException
("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask
(RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
throw;
}
}
}
}

Loading…
Cancel
Save