1

I’m creating a monitoring application which tests if the servers are running or not.

I would like the user to choose the environment that they are running as in Dev, stage or Prod and then do the testing for that particular environment.

I’m new to c# and hence would like some guidance how to go about with this..

In pseudocode,

  1. Define all the server address for the different environments

  2. Ask the user to choose the environment they would like to test

  3. Read the user’s input and take them to the method (having the same name as the input) that would read the environment and start testing if the server is running.

I’m not sure how to go about this… any help?

So far this is what I have have:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Please choose your environment and Username to test from below");
        Console.WriteLine("Dev");
        Console.WriteLine("Stage");
        Console.WriteLine("Prod");

        string inputtedText = "";
        inputtedText = Console.ReadLine();

        if (inputtedText == "Dev") { Program.TestServer(null); }
        if (inputtedText == "Stage") { Program.TestServer(null); }
        if (inputtedText == "Prod") { Program.TestServer(null); }
    }

    static void TestServer (string[] args)
    {
      //how to read the specific username and server for this credential creation? 
    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ServerName, UserName);
    }
Kilazur
  • 3,089
  • 1
  • 22
  • 48
tintin
  • 11
  • 3
  • I'm not sure about what you want to do; you want to read an input and call a method having the same name as what's inputed? – Kilazur Mar 07 '17 at 11:32
  • yes thats right, sorry I didn't make it clear – tintin Mar 07 '17 at 11:36
  • You already know how to ask user to input environment name and use it. What is the problem with credentials? Can't you do the same - ask user to enter them? – Renatas M. Mar 07 '17 at 11:36
  • The server Id for the dev stage and prod are different and the user might not know the exact Id for it.. I need to specify the server id in the credential.. – tintin Mar 07 '17 at 11:38
  • Why not store your information regarding users in DataBase or in Config file and then do specific task? – J.SMTBCJ15 Mar 07 '17 at 11:42
  • So, about the method calling part, [see this](http://stackoverflow.com/questions/540066/calling-a-function-from-a-string-in-c-sharp) – Kilazur Mar 07 '17 at 11:45

1 Answers1

0

Because of lack of details and from what I heard, I guess you are looking for something like that:

static void Main(string[] args)
{
    Console.WriteLine("Please choose your environment and Username to test from below");
    Console.WriteLine("Dev");
    Console.WriteLine("Stage");
    Console.WriteLine("Prod");

    string inputtedText = "";
    inputtedText = Console.ReadLine();

    if (inputtedText == "Dev") { Program.TestServer("DevMachine", "DevUser", "DevPass"); }
    if (inputtedText == "Stage") { Program.TestServer("StageMachine", "StageUser", "StagePass"); }
    if (inputtedText == "Prod") { Program.TestServer("ProdMachine", "ProdUser", "ProdPass"); }
}

static void TestServer (string ServerName, string UserName, string UserPassword)
{
  //Use ServerName UserName and UserPassword
}

The code above uses hard-coded values. You should consider storing those values for example in config file.

Renatas M.
  • 11,694
  • 1
  • 43
  • 62