public IList <MusicContract> GetAll()
        {
            var musicContractFlatLines = _inputData
                                         .GetAssetData()
                                         .Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
                                         .Skip(1);

            var retList = new List <MusicContract>();

            foreach (var musicContractFlatLine in musicContractFlatLines)
            {
                var data = musicContractFlatLine.Split('|');

                if (data.Length != 5)
                {
                    throw new ArgumentException("Cannot create MusicContract object from invalid data");
                }

                var contract = new MusicContract()
                {
                    Artist = data[0],
                    Title  = data[1],
                    DistributionChannels = data[2].Split(',', StringSplitOptions.RemoveEmptyEntries).Select(dc => dc.Trim()).ToList(),
                    StartDate            = _dateParser.Parse(data[3]),
                    EndDate = _dateParser.Parse(data[4]),
                };

                retList.Add(contract);
            }

            return(retList);
        }
        public void Parse(string[] args)
        {
            if (args.Length != 4)
            {
                throw new ArgumentException("Could not resolve partner name and date from the given arguments");
            }

            PartnerName   = args[0];
            EffectiveDate = _dateParser.Parse(String.Join(" ", args.Skip(1))).Value;
        }
        public async Task Run(string[] args)
        {
            // An argument parser could be used here
            if (args.Length == 0)
            {
                _appOutput.WriteLine("A date must be provided in the format yyyy-MM-dd");

                // No date provided so terminate early
                return;
            }

            DateTime?dateTime = _dateParser.Parse(args[0]);

            if (!dateTime.HasValue)
            {
                _appOutput.WriteLine($"the input date '{args[0]}' must be provided in the format yyyy-MM-dd");

                // No date could be parsed so terminate early
                return;
            }

            DaySummaryDto daySummaryDto = await _daySummaryService.GetSummaryAsync(dateTime.Value);

            if (daySummaryDto == null)
            {
                _appOutput.WriteLine(
                    $"an error occured when trying to retrieve the summary for the date '{dateTime.Value}'. " +
                    $"Please try again.");

                // Unable to retrieve summary properly, so terminate early
                return;
            }

            _appOutput.WriteLine($"Summary for date: {dateTime.Value:yyyy-MM-dd}");
            _appOutput.WriteLine($"Total questions: {daySummaryDto.QuestionTotal}");
            _appOutput.WriteLine($"Total views: {daySummaryDto.ViewTotal}");
            _appOutput.WriteLine("Tags:");

            string tags = _tagFormatter.Format(daySummaryDto.UniqueTags);

            _appOutput.WriteLine(tags);
        }
 public override Expression VisitDate(DateContext context)
 {
     var value = context.GetText();
     var date = _dateParser.Parse(value);
     return Expression.Constant(date, typeof(DateTime));
 }