From c3649f2e89bfe9e8035869c2d3d36500e63b967f Mon Sep 17 00:00:00 2001 From: Craig Date: Wed, 24 Jul 2019 17:43:56 +0100 Subject: [PATCH] create Wiring C.W.C. into Your Proj. --- ...nsole.Waterworks.Core-into-Your-Project.md | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Wiring-Console.Waterworks.Core-into-Your-Project.md diff --git a/Wiring-Console.Waterworks.Core-into-Your-Project.md b/Wiring-Console.Waterworks.Core-into-Your-Project.md new file mode 100644 index 0000000..3e3e085 --- /dev/null +++ b/Wiring-Console.Waterworks.Core-into-Your-Project.md @@ -0,0 +1,87 @@ +This section assumes you have already added Console.Waterworks.Core (C.W.C.) to your project. If you have not, please review the following page: + +- [Adding Console.Waterworks.Core to Your Project](Adding-Console.Waterworks.Core-to-Your-Project) + +Once you have added C.W.C. to your console project, you can begin using it. One thing to note with C.W.C. 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.cs". When you have done that, make a note of the file/classes name-space -- you will need it in a little bit. When you have do that, head over to the `Main` method in "Program.cs" and enter the following code into it, + +```c# +// Do not forget change the ConsoleCommands name-space in Run. +var liaison = new CW_Liaison(); +liaison.Run("YOUR CONSOLECOMMADS.CS NAME-SPACE GOES HERE.", true); +``` + +After you have done that, Visual Studio should start complaining about *using statement* This means you will need to add the following line of code with your other using statements, + +```c# +// Place with your other using statements in Program.cs. +using Console.Waterworks.Core +``` + +Overall, your Program.cs should look similar to the code below, + +```c# +using Console.Waterworks.Core; +using System; + +namespace CW_Core_Console // This will differ in your project. +{ + class Program + { + static void Main(string[] args) + { + var liaison = new CW_Liaison(); + liaison.Run("CW_Core_Console", true); + } + } +} +``` + +**You might need to decorate you `Main` function with the `[STAThread]` attribute. If Visual Studio starts complaining about "single-threaded/async. problems", add the `[STAThread]` attribute above your `Main` method.That should fix the problem.** + +When that is done, head back to ConsoleCommands.cs and you can begin adding your first command-method. I will not go into too much detail about command-methods just yet. The focus of this page is to get you set-up. + +The first thing you need to do is make sure the `ConsoleCommands` class is marked as `public` and `static`. After that, enter the following method to your class, + +```c# +public static string Test() +{ + return "ConsoleCommands is working." +} +``` + +When you have done that, your ConsoleCommands.cs file should look similar to the following code snippet, + +```c# +using System; +using Console.Waterworks.Core; + +namespace CW_Core_Console // This will be different to yours. +{ + public static class ConsoleCommands + { + public static string Test() + { + return "ConsoleCommands is working." + } + } +} +``` + +If all has gone well, your program should run (press F5) and when you enter "Test" into the console, you should see something similar to the image below. + +![successful c.w.c. set-up screenshot](attachments/successful-console-set-up.png) + +Within the `Main` function is a method called `Run`, which takes two arguments. The first the name-space of the `ConsoleCommands` class and the second one is a `bool`. In the example above, I have used `true` but I could have used `false` if I wanted. The reason I used `true` is because I prefer my console programs to display its assembly information when I run it. If you prefer just the prompt, change the `true` variable to `false`. If all has gone well, you should see something similar to the screenshot below. + +![assembly info screenshot](attachments/assembly-info-screenshot.png) + +I will not go into too much detail about changing a project's assembly information because there is already an amble amount of information on the subject. Instead, I will provide the following links to get to started: + +- [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 easiest way to get to the Assembly Information dialog box is as follows: + +1. In "Solution Explorer", open the *right-click* menu on the project (I.E. your console project) you want to change, and then choose "Properties". +2. In the left column of the Properties window, *left-click* the "Application" tab. +3. *Left-click* the button labelled "Assembly Information".