static void Main()

in dotnetv3/dynamodb/FromSQL/CreateIndexExample/CreateIndexExample/CreateIndex.cs [23:148]


    static void Main(string[] args)
    {
      var configfile = "app.config";
      string region;
      string table;
      var indexName = string.Empty;
      var mainKey = string.Empty;
      var mainKeyType = string.Empty;
      var secondaryKey = string.Empty;
      var secondaryKeyType = string.Empty;

      int i = 0;
      while (i < args.Length)
      {
        switch (args[i])
        {
          case "-i":
            i++;
            indexName = args[i];
            break;
          case "-m":
            i++;
            mainKey = args[i];
            break;
          case "-k":
            i++;
            mainKeyType = args[i];
            break;
          case "-s":
            i++;
            secondaryKey = args[i];
            break;
          case "-t":
            i++;
            secondaryKeyType = args[i];
            break;
        }

        i++;
      }

      bool empty = false;
      StringBuilder sb = new StringBuilder("You must supply a non-empty ");

      if (indexName == string.Empty)
      {
        empty = true;
        sb.Append("index name (-i INDEX), ");
      }

      if (mainKey == string.Empty)
      {
        empty = true;
        sb.Append("mainkey (-m PARTITION-KEY), ");
      }

      if (mainKeyType == string.Empty)
      {
        empty = true;
        sb.Append("main key type (-k TYPE), ");
      }

      if (secondaryKey == string.Empty)
      {
        empty = true;
        sb.Append("secondary key (-s SORT-KEY), ");
      }

      if (secondaryKeyType == string.Empty)
      {
        empty = true;
        sb.Append("secondary key type (-t TYPE), ");
      }

      if (empty)
      {
        Console.WriteLine(sb.ToString());
        return;
      }

      if ((mainKeyType != "string") && (mainKeyType != "number"))
      {
        Console.WriteLine("The main key type must be string or number");
        return;
      }

      if ((secondaryKeyType != "string") && (secondaryKeyType != "number"))
      {
        Console.WriteLine("The secondary key type must be string or number");
        return;
      }

      // Get default Region and table from config file
      var efm = new ExeConfigurationFileMap
      {
        ExeConfigFilename = configfile,
      };

      Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(efm, ConfigurationUserLevel.None);

      if (configuration.HasFile)
      {
        AppSettingsSection appSettings = configuration.AppSettings;
        region = appSettings.Settings["Region"].Value;
        table = appSettings.Settings["Table"].Value;

        if ((region == string.Empty) || (table == string.Empty))
        {
          Console.WriteLine("You must specify Region and Table values in " + configfile);
          return;
        }
      }
      else
      {
        Console.WriteLine("Could not find " + configfile);
        return;
      }

      var newRegion = RegionEndpoint.GetBySystemName(region);
      IAmazonDynamoDB client = new AmazonDynamoDBClient(newRegion);

      Task<UpdateTableResponse> response = AddIndexAsync(client, table, indexName, mainKey, mainKeyType, secondaryKey, secondaryKeyType);

      Console.WriteLine("Task status:   " + response.Status);
      Console.WriteLine("Result status: " + response.Result.HttpStatusCode);
    }