From 149c20443c44c3fccdb9fc4b02fbbc968dc45918 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Mon, 10 Sep 2018 23:47:13 +0100 Subject: [PATCH] add validate file function. Create an IO file and test script for file validation in library. --- DeathSocket/DeathSocket.fsproj | 2 ++ DeathSocket/GridPainter.fs | 4 +++- DeathSocket/IO.fs | 2 ++ DeathSocket/ScratchPad.fsx | 25 ++++++++++++++++++------- DeathSocket/Validation.fs | 10 ++++++++++ 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 DeathSocket/IO.fs create mode 100644 DeathSocket/Validation.fs diff --git a/DeathSocket/DeathSocket.fsproj b/DeathSocket/DeathSocket.fsproj index 730fba5..57a8936 100644 --- a/DeathSocket/DeathSocket.fsproj +++ b/DeathSocket/DeathSocket.fsproj @@ -7,6 +7,8 @@ + + diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index b7b930d..6cb95ae 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -2,6 +2,8 @@ namespace DeathSocket module GridPainter = + open Validation + let applyGridToImage spec = - //validateFilePath + validateFilePath |> ignore 0 \ No newline at end of file diff --git a/DeathSocket/IO.fs b/DeathSocket/IO.fs new file mode 100644 index 0000000..5b3461a --- /dev/null +++ b/DeathSocket/IO.fs @@ -0,0 +1,2 @@ +module IO + diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index f2008bf..619843b 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,11 +1,13 @@ -#load "GridPainter.fs" +#load "Validation.fs" +#load "GridPainter.fs" -open DeathSocket open System.Drawing open System open System.Drawing.Imaging +open Validation +open DeathSocket -// Initial Idea ============================================================== +// INITIAL IDEA =============================================================== // Change the image or its path to suit your purposes. let img = Bitmap.FromFile (__SOURCE_DIRECTORY__ + "/test-img.jpg") @@ -25,9 +27,18 @@ let horizontalLine = let pen = new Pen (Brushes.Red, width = (float32 (10)) ) graphics.DrawLine (pen, verticalLine.[0], verticalLine.[1]) graphics.DrawLine (pen, horizontalLine.[0], horizontalLine.[1]) -let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) -let savePath = desktop + "/test-grid.png" // Change this to suit you. -img.Save (savePath) +let formSavePath = + let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) + desktop + "/test-grid.png" // Change this to suit you. +img.Save (formSavePath) img.Dispose graphics.Dispose -pen.Dispose \ No newline at end of file +pen.Dispose + +// DEATH SOCKET TESTING ======================================================= + +let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) +let savePath = desktop + "/test-grid.png" // Change this to suit you. + +// Throws an exception if no file is found. +let validationTest = validateFilePath savePath \ No newline at end of file diff --git a/DeathSocket/Validation.fs b/DeathSocket/Validation.fs new file mode 100644 index 0000000..86b075a --- /dev/null +++ b/DeathSocket/Validation.fs @@ -0,0 +1,10 @@ +module internal Validation + +open System.IO + + let validateFilePath path = + match File.Exists path with + | true -> () + | false -> + invalidArg "File Path" "The image can not be loaded because the file path specified does not exist." +