public IEnumerable <StarWarsPun> GetPuns()
        {
            List <StarWarsPun> puns = new List <StarWarsPun>();

            int          counter = 0;
            string       question;
            StreamReader file = new StreamReader(this.filePath);

            while ((question = file.ReadLine()) != null)
            {
                string answer = file.ReadLine();

                if (answer != null)
                {
                    StarWarsPun pun = new StarWarsPun(counter, question, answer);
                    puns.Add(pun);
                }

                counter++;

                Console.WriteLine("Q: {0}\nA: {1}", question, answer);
            }

            file.Close();
            System.Console.WriteLine("There were {0} puns.", counter);

            return(puns);
        }
示例#2
0
        public async Task <StarWarsPun> Load(int id)
        {
            if (id < 0)
            {
                throw new ArgumentOutOfRangeException("id");
            }

            StarWarsPun pun = await _context.LoadAsync <StarWarsPun>(id);

            return(pun);
        }
示例#3
0
        public SkillResponse Handle(SkillRequest skillRequest)
        {
            logger.LogTrace("BEGIN AddPlayer. RequestId: {0}.", skillRequest.Request.RequestId);

            long itemCount = Task.Run(async() => await _repository.Count()).Result;

            Random random   = new Random();
            int    randomId = random.Next(0, (Int32)itemCount);

            StarWarsPun pun = Task.Run(async() => await _repository.Load(randomId)).Result;

            SkillResponse response = string.Format("{0}<break time=\"3s\"/>{1}", pun.Question, pun.Answer).Tell(true);

            logger.LogTrace("END AddPlayer. RequestId: {0}.", skillRequest.Request.RequestId);

            return(response);
        }