×
Back to book

Running C#Bot

Learn how to run C#Bot

This article demonstrates the relevant procedure to configure database connection, install node modules, and run the C#Bot application.

This article assumes you have already setup a development environment for your specific operating system ([Windows](), [Linux]() and [Mac]()), and the [Setup Source Code]() lesson has been completed.

For this guide, we assume Windows users are using Powershell and Linux/Mac users are using Bash as their shell.

A. First time setup

Database Connection Configuration

If you have followed the Setting Up Your Development Environment guide for your specific operating system (Windows, Linux and Mac) and chosen to use the default database configuration while installing PostgreSQL, you can skip these Database Connection Configuration steps.

You can configure your database credentials by changing the projects appsettings.xml, appsettings.Test.xml and appsettings.Development.xml files:

appsettings.xml contains the settings used for productions.
appsettings.Development.xml contains the settings used for development.
appsettings.Test.xml contains the settings used for the testing framework.

  1. Launch Powershell or Bash if Linux/Mac and navigate to the project directory.

    cd [path to application]
  2. Open the desired appsetting files and update the DbConnectionString username and password properties to match the username and password set during postgresSQL setup.

DownloadNetCore2.2Image

The port can be set by appending to the connection string Port=x; where x is the desired port number.

See this Official Documentation from the npgsql website for more information on database connection string properties.

  1. Once you have customised your database connection string, you will need to turn on the protected region to prevent C#Bot from overriding your changes in the future.

DownloadNetCore2.2Image

Database Update

Now that the database connection has been configured, the database itself needs to have all tables setup before first run.

Navigate to the source folder on the server-side.

cd [path to application]/serverside/src

Create the migrations script

dotnet ef migrations add [migration name]

Execute the migrations

dotnet ef database update

Installing Node Modules

Before the application can be run for the first time, the javascript dependancies need to be installed.

  1. Navigate to the clientside folder from your windows or Linux/Mac terminal of choice.
cd [path to application]/clientside
  1. Use npm to install yarn package manager.
npm install -g yarn
  1. Install node modules using yarn.
yarn install

Creating a Solution file

By default a sln file is not created, but this can be fixed from the dotnet command line.

Navigate to the root directory of your project.

cd [path to application]

Create a new solution file.

dotnet new sln

To add the dependent projects to the solution run the following commands in the same directory as the sln file

dotnet sln add serverside/src/[name of your application].csproj
dotnet sln add testtarget/Serverside/[name of your application]Test.csproj
dotnet sln add testtarget/Selenium/SeleniumTests.csproj

B. Launching the development environment

C#Bot writes applications that can be launched with a single dotnet command. This means the serverside and clientside of the application are launched together since the client requires API's with the serverside to operate.

  1. Firstly navigate to the serverside directory from your windows or Linux/Mac terminal of choice.
cd [path to application]/serverside/src
  1. Run the following command to start the development server and clientside
dotnet run
  1. Launch a browser of your choice i.e. firefox or chrome etc and navigate to http://localhost:5000. The development application should now be running.

C. Launching the production environment

  1. Firstly navigate to the serverside directory from your windows or Linux/Mac terminal of choice.
cd [path to application]/serverside/src
  1. Enter the following command to publish the production .dll's
dotnet publish -c Release
  1. Navigate to the directory where the files have been published
cd [path to application]/serverside/src/bin/Release/netcoreapp2.2/publish
  1. Run the production build:
dotnet [application name].dll
  1. To run the application, launch your favorite browser i.e. chrome and navigate to http://localhost:5000. The production application should now be running.

D. Logging in to the application

When navigating to http://localhost:5000 you should be redirected to a login screen. You can use these credentials to log in, or you can create a new user account.

Username: super@example.com
Password: password

DownloadNetCore2.2Image

Related Articles