public void CommandOptions_Lack_Of_Arguments_Test()
 {
     var options = new CommandOptions();
     var parser = new CommandLine.CommandLineParser();
     var parsed = parser.ParseArguments(new[] { "-m", "-s"}, options);
     Assert.AreEqual(false, parsed);
 }
 public void CommandOptions_Mode_Source_Destination_Test()
 {
     var options = new CommandOptions();
     var parser = new CommandLine.CommandLineParser();
     parser.ParseArguments(new[] { "-m", "backup", "-s", "mySource", "-d", "myDestination" }, options);
     Assert.AreEqual("backup", options.Mode);
     Assert.AreEqual("mySource", options.Source);
     Assert.AreEqual("myDestination", options.Destination);
 }
Example #3
0
        public static void Main(string[] args)
        {
            var options = new Options();
             CommandLine.ICommandLineParser cmdParser =
               new CommandLine.CommandLineParser(new CommandLine.CommandLineParserSettings(System.Console.Error));

             if (cmdParser.ParseArguments(args, options)) {
            string connectionString = string.Format("URI=file:{0}", options.Database);

            #if (NET)
            var connection = new System.Data.SQLite.SQLiteConnection(connectionString);
            #else
            var connection = new Mono.Data.Sqlite.SqliteConnection(connectionString);
            #endif

            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText =
              "CREATE TABLE IF NOT EXISTS at (id INTEGER PRIMARY KEY  NOT NULL,name VARCHAR,surname VARCHAR,year INTEGER,gender CHAR,time VARCHAR)";
            command.ExecuteNonQuery();
            var repo = new AthleteRepository(command);
            switch (options.Action) {
               case Action.Module: {
                  // 10mm d=> 28pt
                  // 15mm => 42pt
                  //float marginLeft, float marginRight, float marginTop, float marginBottom
                  var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36);
                  iTextSharp.text.pdf.PdfWriter.GetInstance(document,
                                                            new System.IO.FileStream("./module.pdf", System.IO.FileMode.Create));
                  document.Open();
                  var builder = new ModuleBuilder(document, options.YearEdition, 10);
                  for (int page = 0; page < 10; page++) {
                     builder.AddPage();
                  }
                  document.Close();
                  break;
               }
               case Action.Insert: {
                  System.Console.WriteLine("Drop all results?[y/N]?");
                  string yes  = System.Console.ReadLine();
                  if (yes == "y") {
                     FileHelpers.FileHelperEngine<Athlete> engine = new FileHelpers.FileHelperEngine<Athlete>();
                     Athlete[] athletes = engine.ReadFile(options.Input);

                     repo.DeleteAll();
                     foreach (var a in athletes) {
                        System.Console.WriteLine(a.Name);
                        repo.Insert(a);
                     }
                  }
                  break;
               }
               case Action.CreateList:
               case Action.CreateResult: {
                  string catFileName = GetCatFileName(options);
                  string reportFileName = GetReportFileName(options);
                  var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 36, 36);
                  iTextSharp.text.pdf.PdfWriter.GetInstance(document,
                                                            new System.IO.FileStream(reportFileName, System.IO.FileMode.Create));
                  document.Open();
                  IBuilder builder = null;

                  if (options.Action == Action.CreateList) {
                     builder = new ListBuilder(document);
                  } else {
                     builder = new PdfBuilder(document);
                  }

                  Category[] cats = GetCategories(catFileName);
                  foreach (Category cat in cats) {
                     if (log.IsDebugEnabled) log.Debug("parse" + cat.Id);
                     builder.BeginReport(cat.Title, options.YearEdition);
                     var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition));
                     foreach (Athlete athlete in athletes) {
                        builder.Add(athlete);
                     }
                     builder.EndReport();
                  }
                  document.Close();
                  break;
               }
               case Action.Interactive: {
                  Category[] cats = GetCategories(GetCatFileName(options));
                  var parser = new TimeParser();
                  foreach (Category cat in cats) {
                     System.Console.WriteLine("========{0}=========", cat.Id);
                     var athletes = repo.Query(string.Format (cat.Sql, options.YearEdition));
                     foreach (Athlete athlete in athletes) {
                        System.Console.Write("{0:00} {1}\t{2}({3}):", athlete.Id, athlete.Surname, athlete.Name, athlete.Gender);
                        string time = string.Empty;
                        string fmt = string.Empty;
                        do {
                           time = System.Console.ReadLine();
                           fmt = parser.Parse(time);
                           if (!string.IsNullOrEmpty(fmt) ) {
                              System.Console.WriteLine(fmt);
                              repo.UpdateTime(athlete.Id, fmt);
                           } else {
                              if (time != "s") {
                                 System.Console.WriteLine("invalid..");
                              }
                           }
                        } while (string.IsNullOrEmpty(fmt) && time != "s");
                     }
                  }
                  break;
               }
            }
            connection.Close();
             }
        }