Browse Source

add Validation.fs and implement draw-image command.

Minor moving of code in places through the solution.
master
Craig Oates 6 years ago
parent
commit
c4a50cd476
  1. 6
      SmoulderingBeachBall/InternalServices.fs
  2. 26
      SmoulderingBeachBallCLI/ConsoleCommands.fs
  3. 5
      SmoulderingBeachBallCLI/SmoulderingBeachBallCLI.fsproj
  4. 39
      SmoulderingBeachBallCLI/Validation.fs
  5. 1
      SmoulderingBeachBallCLI/packages.config

6
SmoulderingBeachBall/InternalServices.fs

@ -59,7 +59,7 @@
graphics.FillRectangle (spec.colour, rectangle)
match spec.overlay.IsSome with
| true -> addOverlayToImage graphics spec
| false -> printfn "[INFO.] No overlay specified. Creating image without one."
| false -> printfn "[INFO.] No overlay specified. Creating image withoutone."
bitmap.Save (spec.filePath)
bitmap.Dispose()
graphics.Dispose()
graphics.Dispose()
bitmap.Dispose()

26
SmoulderingBeachBallCLI/ConsoleCommands.fs

@ -2,28 +2,30 @@
module ConsoleCommands =
open System
open Console.Waterworks
open SmoulderingBeachBall
open SmoulderingBeachBall.Domain
open SmoulderingBeachBall.Services
open System
open Validation
open System.Drawing
let test () = "This program is working."
let showEndOfCommandMessage = "[INFO.] Execution completed."
let exit () = Environment.Exit (Environment.ExitCode)
let test () = "Smouldering Beach Ball CLI seems to be working."
let ``draw-image`` () =
// makeImage
//"Image completed."
"Command not implemented."
let exit () = Environment.Exit (Environment.ExitCode)
let ``draw-image`` imgWidth imgHeight mainColour path =
buildBasicSpec imgWidth imgHeight mainColour path
|> makeImage
|> Async.RunSynchronously
showEndOfCommandMessage
let ``draw-borderedImage`` () =
//"Image completed."
"Command not implemented."
showEndOfCommandMessage
let ``draw-overlayedImage`` () =
//"Image completed."
"Command not implemented."
showEndOfCommandMessage

5
SmoulderingBeachBallCLI/SmoulderingBeachBallCLI.fsproj

@ -46,6 +46,7 @@
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Validation.fs" />
<Compile Include="ConsoleCommands.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
@ -61,6 +62,10 @@
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common">
<HintPath>..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple">
<Private>True</Private>

39
SmoulderingBeachBallCLI/Validation.fs

@ -0,0 +1,39 @@
module Validation
open System.Drawing
open SmoulderingBeachBall.Domain.DomainTypes
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" "The colour specifed cannot is invalid."
// "Please use the ListAvailableColours command for a list"?
let buildBasicSpec iWidth iHeight mainColour path =
let brush = (parseColour mainColour)
let spec =
{ width = iWidth;
height = iHeight;
colour = brush
filePath = path
overlay = None }
spec

1
SmoulderingBeachBallCLI/packages.config

@ -2,5 +2,6 @@
<packages>
<package id="Console.Waterworks" version="0.1.0.0-alpha1" targetFramework="net471" />
<package id="FSharp.Core" version="4.5.2" targetFramework="net471" />
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
</packages>
Loading…
Cancel
Save