Craig Oates
6 years ago
4 changed files with 61 additions and 14 deletions
@ -1,17 +1,23 @@
|
||||
namespace Commands |
||||
|
||||
module ConsoleCommands = |
||||
open DeathSocket |
||||
open System.Drawing |
||||
open System |
||||
open DeathSocket.GridPainter |
||||
open Validation |
||||
open System.IO |
||||
|
||||
let showEndOfCommandMessage = "[INFO.] Execution completed." |
||||
|
||||
let test () = "Death Socket is working." |
||||
|
||||
let ``add-grid`` imgPath numRows numColumns pWidth (colour: string) newPath = |
||||
let spec = |
||||
{ originalPath = imgPath |
||||
savePath = newPath |
||||
colour = Brushes.Red |
||||
penWidth = pWidth |
||||
rows = numRows |
||||
columns = numColumns } |
||||
GridPainter.applyGrid spec |> Async.RunSynchronously |
||||
let ``add-grid`` imgPath numRows numColumns pWidth colour newPath = |
||||
try |
||||
printfn "[INFO.] Adding grid to image..." |
||||
buildSpec imgPath numRows numColumns pWidth colour newPath |
||||
|> applyGrid |
||||
|> Async.RunSynchronously |
||||
showEndOfCommandMessage |
||||
with |
||||
| :? FileNotFoundException as ex -> "[ERROR] No file was found at " + ex.FileName |
||||
| :? ArgumentException as ex -> "[ERROR] Invalid argument: " + ex.Message |
||||
| _ as ex -> ex.Message |
@ -0,0 +1,41 @@
|
||||
module Validation |
||||
|
||||
open DeathSocket |
||||
open System.Drawing |
||||
open System |
||||
|
||||
let colourList = |
||||
[ "blue", Brushes.AliceBlue |
||||
"brown", Brushes.Brown |
||||
"black", Brushes.Black |
||||
"gray", Brushes.Gray |
||||
"green", Brushes.Green |
||||
"purple", Brushes.Purple |
||||
"red", Brushes.Red |
||||
"white", Brushes.White |
||||
"yellow", Brushes.Yellow ] |
||||
|> Map.ofList |
||||
|
||||
let isColourValid (colour: string) = |
||||
colourList |
||||
|> Map.containsKey (colour.ToLower()) |
||||
|
||||
let parseColour colour = |
||||
match (isColourValid colour) with |
||||
| true -> |
||||
colourList |
||||
|> Map.find (colour.ToLower()) |
||||
| false -> |
||||
invalidArg "Colour" |
||||
(String.Concat("The colour specifed is invalid.\n", |
||||
"Please use the 'list-colours' command to see what you can use.")) |
||||
|
||||
let buildSpec imgPath numRows numColumns pWidth colour newPath = |
||||
let spec = |
||||
{ originalPath = imgPath |
||||
savePath = newPath |
||||
colour = parseColour colour |
||||
penWidth = pWidth |
||||
rows = numRows |
||||
columns = numColumns } |
||||
spec |
Loading…
Reference in new issue