master
Craig Oates 4 years ago
parent
commit
6c9bfb80bc
  1. 248
      Wiring-Console.Waterworks-into-Your-Project.md

248
Wiring-Console.Waterworks-into-Your-Project.md

@ -1,124 +1,124 @@
This section assumes you have already created an F# console project. It, also, assumes you have added the appropriate Console.Waterworks (C.W.) version to it. If you have not and are unsure on how to do this, please refer to the following link:
- [Adding Console.Waterworks to Your Project](Adding-Console.Waterworks-to-Your-Project)
Once you have added Console.Waterworks(.Core) to your console project, you can begin using it. One thing to note with Console.Waterworks (C.W.) is how invasive it is. Because it has taken a lot out of your hands, it requires your project to look a certain way. The first thing you need to do is create a file called "ConsoleCommands.fs". When you have done that, to create a name-space called `Commands` and a module called `ConsoleCommands` within it. Whilst you are still in "ConsoleCommands.fs", add "open Console.Waterworks" to the module. If you are writing a .Net Core program, add `open Console.Waterworks.Core` statement in its place. Once that is set-up, add a function called `test`. You should end up with something which looks like this:
### .Net Version
This code resides in ConsoleCommands.fs, in the BrittleFish project.
```f#
namespace Commands
module ConsoleCommands
open Console.Waterworks
let test () = "The console is working"
```
### .Net Core Version
This code resides in ConsoleCommands.fs, in the BrittleFishCore project.
```f#
namespace Commands
module ConsoleCommands
open Console.Waterworks
let test () = "The console is working"
```
With `ConsoleCommands` set-up, head back to "program.fs". We can now tell C.W. where to look for your `business logic`. To do this, add the following code to `main`:
```f#
let liaison = new CW_Liaison()
liaison.run("Commands", true)
```
As an aside, you can name the "ConsoleCommands.fs" file anything you like. This is because the `CW_liaison` object looks for the name-space of the `ConsoleCommands` **class**. The name of the file is actually irrelevant. It is, also, important to note the `ConsoleCommands` module. Underneath the covers, C.W. looks for a static **class** called `ConsoleCommands`. Luckily, C.W. recognises F#'s modules as static classes so we can use them instead -- because F#'s "classes" are a bit clunky.
With everything set-up, you can now run the program. When you do, it will await your input. If you type "test" into the prompt and press ENTER, you should see  "You have set-up Console.Waterworks". And with that, you are ready to start building out your "business logic".
![console-test-screenshot](console-test-screenshot.png)
If you change `true` to `false` in the `run` method (in `main`), the programs assembly information will not appear at run-time.
![console screenshot with no assembly info](console-screenshot-no-assembly-info.png)
## Changing the Assembly Information for you Console Program
To change your console program's assembly information, you need to alter its "Assemblyinfo.fs" file. There are several ways to do this and it differs between the traditional .Net and .Net Core versions.
### .Net
One way to change the assembly information in your .Net program is to alter it via the "Properties" menu. You can access it by right-clicking on a project in Solution Explorer and clicking on "Properties". For a more detailed guide, you can use the following links:
- [Setting Assembly Attributes](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/set-assembly-attributes): This applies to the traditional and Core versions of .Net. It provides information on what resides in Assembly Information manifests and files.
- [How to Target a version of .Net](https://docs.microsoft.com/en-us/visualstudio/ide/how-to-target-a-version-of-the-dotnet-framework?view=vs-2019): This provides extra context on the Properties page in Visual Studio and how it fits the Assembly Information dialog box into it -- from a traditional .Net angle.
- [The AssemblyInfo.fs file for BrittleFish](https://git.abbether.net/craig.oates/Brittle-Fish/blob/master/BrittleFish/AssemblyInfo.fs): The actual Assembly Information file for the BrittleFish console program. Use this as a reference for your own projects.
You might find you do not have a file called "AssemblyInfo.fs" within your project. If you are unfamiliar with these types of files, feel free to peruse the links above for help on learning how to add it. As an alternative, you can create a file in your project (in Visual Studio) and call it "AssemblyInfo.fs" -- make sure it is at the **root** level. From there, you can copy and paste the following code block into it (making sure you replace the code wrapped in `{delete the braces when you add your own info.}`):
```f#
namespace {YOUR-PROJECT-NAME-HERE}.AssemblyInfo
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[<assembly: AssemblyTitle("")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("")>]
[<assembly: AssemblyCopyright("")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyCulture("")>]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]
// The following GUID is for the ID of the typelib if this project is exposed to COM
// You should generate a new Guid here...
[<assembly: Guid("9d146c28-drde-8c70-bdc5-44b68925ca07")>]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("1.0.0.0")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]
do
()
```
To help you get a sense of where this file should live, please review the file structure for BrittleFish. You can do that by using the following link:
- [BrittleFish (Console Project) File Structure](https://git.abbether.net/craig.oates/Brittle-Fish/tree/master/BrittleFish)
### .Net Core
Like the traditional .Net version, you can use the Properties dialog box in Visual Studio. Use the links below for extra information, which are:
- [Application Page, Project Designer (C#)](https://docs.microsoft.com/en-us/visualstudio/ide/reference/application-page-project-designer-csharp?view=vs-2019): This show you how to access the Properties page box and provides more information on how the Assembly Information dialog box fits into it -- from a .Net Core perspective.
- [The AssemblyInfo.fs file for BrittleFishCore](https://git.abbether.net/craig.oates/Brittle-Fish/blob/master/BrittleFishCore/AssemblyInfo.fs): The actual Assembly Information file for the BrittleFishCore console program. Use this as a reference for your own projects.
I tend to find, Visual Studio automatically makes a "AssemblyInfo.fs" file when I create a .Net Core project. So, I do not need to go out of my way to make one. If, for some reason, you find yourself without one, you can use the same technique in the ".Net" section above. The same applies to the code block within it.
Like the section above, you can get a sense of where "AssemblyInfo.fs" should live (in a .Net Core project) by reviewing the file structure for BrittleFishCore. You can do that by using the following link:
- [BrittleFishCore (Console Project) File Structure](https://git.abbether.net/craig.oates/Brittle-Fish/tree/master/BrittleFishCore)
This section assumes you have already created an F# console project. It, also, assumes you have added the appropriate Console.Waterworks (C.W.) version to it. If you have not and are unsure on how to do this, please refer to the following link:
- [Adding Console.Waterworks to Your Project](Adding-Console.Waterworks-to-Your-Project)
Once you have added Console.Waterworks(.Core) to your console project, you can begin using it. One thing to note with Console.Waterworks (C.W.) is how invasive it is. Because it has taken a lot out of your hands, it requires your project to look a certain way. The first thing you need to do is create a file called "ConsoleCommands.fs". When you have done that, to create a name-space called `Commands` and a module called `ConsoleCommands` within it. Whilst you are still in "ConsoleCommands.fs", add "open Console.Waterworks" to the module. If you are writing a .Net Core program, add `open Console.Waterworks.Core` statement in its place. Once that is set-up, add a function called `test`. You should end up with something which looks like this:
### .Net Version
This code resides in ConsoleCommands.fs, in the BrittleFish project.
```f#
namespace Commands
module ConsoleCommands
open Console.Waterworks
let test () = "The console is working"
```
### .Net Core Version
This code resides in ConsoleCommands.fs, in the BrittleFishCore project.
```f#
namespace Commands
module ConsoleCommands
open Console.Waterworks
let test () = "The console is working"
```
With `ConsoleCommands` set-up, head back to "program.fs". We can now tell C.W. where to look for your `business logic`. To do this, add the following code to `main`:
```f#
let liaison = new CW_Liaison()
liaison.run("Commands", true)
```
As an aside, you can name the "ConsoleCommands.fs" file anything you like. This is because the `CW_liaison` object looks for the name-space of the `ConsoleCommands` **class**. The name of the file is actually irrelevant. It is, also, important to note the `ConsoleCommands` module. Underneath the covers, C.W. looks for a static **class** called `ConsoleCommands`. Luckily, C.W. recognises F#'s modules as static classes so we can use them instead -- because F#'s "classes" are a bit clunky.
With everything set-up, you can now run the program. When you do, it will await your input. If you type "test" into the prompt and press ENTER, you should see  "You have set-up Console.Waterworks". And with that, you are ready to start building out your "business logic".
![console-test-screenshot](console-test-screenshot.png)
If you change `true` to `false` in the `run` method (in `main`), the programs assembly information will not appear at run-time.
![console screenshot with no assembly info](console-screenshot-no-assembly-info.png)
## Changing the Assembly Information for you Console Program
To change your console program's assembly information, you need to alter its "Assemblyinfo.fs" file. There are several ways to do this and it differs between the traditional .Net and .Net Core versions.
### .Net
One way to change the assembly information in your .Net program is to alter it via the "Properties" menu. You can access it by right-clicking on a project in Solution Explorer and clicking on "Properties". For a more detailed guide, you can use the following links:
- [Setting Assembly Attributes](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/set-assembly-attributes): This applies to the traditional and Core versions of .Net. It provides information on what resides in Assembly Information manifests and files.
- [How to Target a version of .Net](https://docs.microsoft.com/en-us/visualstudio/ide/how-to-target-a-version-of-the-dotnet-framework?view=vs-2019): This provides extra context on the Properties page in Visual Studio and how it fits the Assembly Information dialog box into it -- from a traditional .Net angle.
- [The AssemblyInfo.fs file for BrittleFish](https://git.abbether.net/craig.oates/Brittle-Fish/src/branch/master/BrittleFish/AssemblyInfo.fs): The actual Assembly Information file for the BrittleFish console program. Use this as a reference for your own projects.
You might find you do not have a file called "AssemblyInfo.fs" within your project. If you are unfamiliar with these types of files, feel free to peruse the links above for help on learning how to add it. As an alternative, you can create a file in your project (in Visual Studio) and call it "AssemblyInfo.fs" -- make sure it is at the **root** level. From there, you can copy and paste the following code block into it (making sure you replace the code wrapped in `{delete the braces when you add your own info.}`):
```f#
namespace {YOUR-PROJECT-NAME-HERE}.AssemblyInfo
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[<assembly: AssemblyTitle("")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("")>]
[<assembly: AssemblyCopyright("")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyCulture("")>]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]
// The following GUID is for the ID of the typelib if this project is exposed to COM
// You should generate a new Guid here...
[<assembly: Guid("9d146c28-drde-8c70-bdc5-44b68925ca07")>]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("1.0.0.0")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]
do
()
```
To help you get a sense of where this file should live, please review the file structure for BrittleFish. You can do that by using the following link:
- [BrittleFish (Console Project) File Structure](https://git.abbether.net/craig.oates/Brittle-Fish/tree/master/BrittleFish)
### .Net Core
Like the traditional .Net version, you can use the Properties dialog box in Visual Studio. Use the links below for extra information, which are:
- [Application Page, Project Designer (C#)](https://docs.microsoft.com/en-us/visualstudio/ide/reference/application-page-project-designer-csharp?view=vs-2019): This show you how to access the Properties page box and provides more information on how the Assembly Information dialog box fits into it -- from a .Net Core perspective.
- [The AssemblyInfo.fs file for BrittleFishCore](https://git.abbether.net/craig.oates/Brittle-Fish/blob/master/BrittleFishCore/AssemblyInfo.fs): The actual Assembly Information file for the BrittleFishCore console program. Use this as a reference for your own projects.
I tend to find, Visual Studio automatically makes a "AssemblyInfo.fs" file when I create a .Net Core project. So, I do not need to go out of my way to make one. If, for some reason, you find yourself without one, you can use the same technique in the ".Net" section above. The same applies to the code block within it.
Like the section above, you can get a sense of where "AssemblyInfo.fs" should live (in a .Net Core project) by reviewing the file structure for BrittleFishCore. You can do that by using the following link:
- [BrittleFishCore (Console Project) File Structure](https://git.abbether.net/craig.oates/Brittle-Fish/tree/master/BrittleFishCore)

Loading…
Cancel
Save