Пример #1
0
        public string Execute(IList <string> parameters)
        {
            if (parameters.Count == 0)
            {
                return(this.Execute());
            }
            else
            {
                var matches = excelImporter.ImportMatches(parameters[0]);

                writer.WriteLine("Total records in dataset: " + matches.Count);
                var counterAdded      = 0;
                var counterDuplicates = 0;

                writer.Write("Importing matches' data...");

                var newLog = logger.CreateNewLog("Matches import: ");


                foreach (var m in matches)
                {
                    try
                    {
                        var newMatch = modelsFactory.CreateMatch(
                            m.DatePlayed,
                            m.Winner,
                            m.Loser,
                            m.Result,
                            m.TournamentName,
                            m.Round
                            );



                        this.dataProvider.Matches.Add(newMatch);
                        counterAdded++;
                    }
                    catch (ArgumentException ex)
                    {
                        var logDetail = logger.CreateNewLogDetail(
                            "Excel import problem: " + ex.Message,
                            newLog);

                        counterDuplicates++;
                    }
                }

                this.dataProvider.UnitOfWork.Finished();
                writer.Write(Environment.NewLine);

                newLog.TimeStamp = DateTime.Now;
                newLog.Message   = newLog.Message + String.Format("Records added: {0}, Duplicated records: {1}", counterAdded, counterDuplicates);
                logger.Log(newLog);
                return(String.Format("Records added: {0}{1}Duplicated records: {2}", counterAdded, Environment.NewLine, counterDuplicates));
            }
        }
Пример #2
0
        public string Execute(IList <string> parameters)
        {
            writer.Clear();

            if (parameters.Count < 8)
            {
                return(this.Execute());
            }
            else
            {
                int tournamentId = -1;

                var datePlayed = parameters[0];

                var    wfirstName = parameters[1];
                var    wlastName  = parameters[2];
                string winner     = $"{wfirstName} {wlastName}";

                var    lfirstName = parameters[3];
                var    llastName  = parameters[4];
                string loser      = $"{lfirstName} {llastName}";

                var result = parameters[5];

                tournamentId = int.Parse(parameters[6]);
                string tournament = dp.Tournaments.Get(tournamentId).Name;

                if (tournament == null)
                {
                    throw new ArgumentNullException($"No tournament with id {tournamentId} found!");
                }

                var round = parameters[7];

                var match = factory.CreateMatch(datePlayed, winner, loser, result, tournament, round);
                if (match != null)
                {
                    dp.Matches.Add(match);
                    dp.UnitOfWork.Finished();
                    return($"Match {winner} vs {loser} from {datePlayed} created successfully!");
                }
                else
                {
                    throw new ArgumentNullException("Match cannot be null!");
                }
            }
        }