All pastes #16288 Raw Edit

Something

public text v1 · immutable
#16288 ·published 2005-06-29 09:39 UTC
rendered paste body
using System;
using System.Xml;
using System.Xml.XPath;
//
using IShopSimpleQuery;

class Driver
{
  /*
  public struct CommandLineParameters
  {
    //
    public string midbUsername;
    public string midbPassword;
    public string midbUri;
    public string midbPort;
    //
    public string tedUsername;
    public string tedPassword;
    public string tedUri;
    public string tedPort;
    //
    public string countryCode;
    public string categoryCode;
    //
    public bool verbose;
    public bool debug;
    //
    public string logFilename;
    public string countryFilename;
    public string equipmentFilename;
  }
  */
  
  [STAThread]
  static void Main(string[] args)
  {
    Arguments CommandLine = new Arguments(args);

    CommandLineParameters parameters = new CommandLineParameters ();
    
    string configFilenamePath = string.Empty;
    string debugFlag = bool.FalseString;
    string helpFlag = bool.FalseString;
    
    //
    // Look for specific arguments values and display 
    // them if they exist (return null if they don't)
    //
    //*************************************************************************
    //** Config Argument
    //*************************************************************************
    if (CommandLine["config"] != null)
    {
      configFilenamePath = CommandLine["config"];
  
      if(configFilenamePath.Equals (bool.TrueString))
      {
        configFilenamePath = string.Empty;
      }
    }
    else
    {
      helpFlag = bool.TrueString;
    }
    //*************************************************************************
    //** Help Argument
    //*************************************************************************
    if (CommandLine["help"] != null)
    {
      helpFlag = CommandLine["help"];
    }
    else
    {
      //helpFlag = bool.TrueString;
    }
    //*************************************************************************
    //** Debug Argument
    //*************************************************************************
    if (CommandLine["debug"] != null)
    {
      debugFlag = CommandLine["debug"];
    }
    else
    {
      //helpFlag = bool.TrueString;
    }
    //*************************************************************************

    //########################################################################
    //## Process Command Arguments
    //########################################################################    
    if (helpFlag.Equals (bool.TrueString))
    {
      Usage (string.Empty);
    }
    else
    {
      //This string.Empty means the arg is invalid.
      if (configFilenamePath.Equals (string.Empty)) 
      {
        Usage ("config");     
      }
      //This string equal to "format" means print out the xml format of the
      //config file.
      else if (configFilenamePath.Equals ("format"))
      {
        PrintConfigFileFormat ();
      }
      //if configFilename is filled with some string.
      else
      {
        parameters = ParseConfigFile (configFilenamePath);
        
        if (debugFlag.Equals (bool.TrueString))
        {
          Console.WriteLine ("Config Filename: {0}", configFilenamePath);
        }
      }
    }
    //########################################################################

    //QueryDriver driver = new QueryDriver ();
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="path"></param>
  /// <returns></returns>
  static CommandLineParameters ParseConfigFile(string path)
  {
    CommandLineParameters parameters = new CommandLineParameters ();

    return parameters;
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="command"></param>
  static void Usage(string command)
  {
    if (command.Equals (string.Empty))
    {
      PrintUsage ();
    }
    else
    {
      Console.WriteLine ("Argument: {0} is invalid.\n", command);
      PrintUsage ();
    }
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="arg"></param>
  /// <param name="description"></param>
  static void PrintArgument(string arg, string description)
  {
    string usageMessage = arg.PadRight (30, ' ').PadLeft (32, ' ') 
                        + description.PadLeft (description.Length + 2, ' ');

    Console.WriteLine (usageMessage);
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="arg"></param>
  /// <param name="description"></param>
  static void PrintArgument(string arg, string description, bool newline)
  {
    string usageMessage = arg.PadRight (30, ' ').PadLeft (32, ' ') 
      + description.PadLeft (description.Length + 2, ' ');

    if (newline)
    {
      usageMessage = usageMessage + "\n";
    }

    Console.WriteLine (usageMessage);
  }

  /// <summary>
  /// 
  /// </summary>
  static void PrintUsage()
  {
    Console.WriteLine ("usage: test.exe --config [<file>|format] | --help | --debug\n");
    
    //              123456789012345678901234567890    
    PrintArgument ("-u | --midbUsername <username>", 
                   "The username for login to the IShop/MIDB");
    PrintArgument (string.Empty , "webservice.", true);
    
    PrintArgument ("-p | --midbPassword <password>", 
                   "The password for login to the IShop/MIDB");
    PrintArgument (string.Empty , "webservice.", true);
    
    PrintArgument ("-o | --midbPortNumber <number>", 
                   "The port number for connection to the");
    PrintArgument (string.Empty , "IShop/MIDB webservice.", true);

    PrintArgument ("-i | --midbURI <uri>", 
                   "The uri/url that is used to connect to the");
    PrintArgument (string.Empty , "IShop/MIDB webservice.", true);

    PrintArgument ("-U | --tedUsername <username>", 
                   "The username for login to the TED webservice.", true);

    PrintArgument ("-P | --tedPassword <password>", 
                   "The password for login to the TED webservice.", true);

    PrintArgument ("-O | --tedPortNumber <number>", 
                   "The port number for connection to the TED");
    PrintArgument (string.Empty , "webservice.", true);

    PrintArgument ("-I | --tedURI <uri>", 
                   "The uri/url that is used to connect to the");
    PrintArgument (string.Empty , "TED webservice.", true);

    PrintArgument ("-cc | --countryCode <code>", 
                   "The two character country code.", true);

    PrintArgument ("-CC | --categoryCode <code>", 
                   "The 5 digit category code.", true);   

    PrintArgument ("--config <file> | format", "Filename of configuration file.");
    PrintArgument (string.Empty , "NOTE: To do more than one country/category");
    PrintArgument (string.Empty , "code use this argument.", true);

    PrintArgument ("--help", "Prints this usage message.", true);
    
    PrintArgument ("--debug", "Turns on debugging information.", true);
  }

  static void PrintConfigFileFormat()
  {
    string xml = "<xml>";

    Console.WriteLine (xml);
  }

}