<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using TowerDefense.Main;

namespace TowerDefense.Main
{
    public class HighscoreProvider
    {
        private const int MAX_NUMBER_OF_ENTRIES = 5;

        public string FilePath
        {
            get;
            private set;
        }

        private List<Player> highscoreEntries;
        public IEnumerable<Player> HighscoreEntries
        {
            // TODO :
            get
            {
                throw new NotImplementedException();
            }
            private set
            {
                throw new NotImplementedException();
            }
        }

        public HighscoreProvider(string filePath)
        {
            this.FilePath = filePath;
        }

        public void AddHighscoreEntry(Player player)
        {

        }

        public void Persist()
        {
            // Format:<commit_msg>Implemented HighscoreProvider<commit_after>﻿namespace TowerDefense.Main
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using TowerDefense.Main;

    public class HighscoreProvider
    {
        private const int MAX_NUMBER_OF_ENTRIES = 5;

        public string FilePath
        {
            get;
            private set;
        }

        private List<Player> highscoreEntries;
        public IEnumerable<Player> HighscoreEntries
        {
            get
            {
                return this.highscoreEntries;
            }
            private set
            {
                if (value.Count() >= MAX_NUMBER_OF_ENTRIES)
                {
                    //throw new ArgumentOutOfRangeException("Too much entries");
                }
                this.highscoreEntries.AddRange(value);
            }
        }

        public HighscoreProvider(string filePath)
        {
            this.FilePath = filePath;
            this.highscoreEntries = new List<Player>();
        }

        public void AddHighscoreEntry(Player player)
        {
            this.highscoreEntries.Add(player);
        }

        public void Persist()
        {
            var writer = new StreamWriter(this.FilePath, false);
            using (writer)
            {
                int counter = 1;
                foreach (var highscore in this.HighscoreEntries)
                {
                    writer.WriteLine(string.Format("{0}. {1,17}{2,-10}", counter, highscore.Name, highscore.Score));
                    counter++;
                }
                counter = 1;
            }
            // Format:
{'fraction_non_alphanumeric': 0.07340143776012108, 'fraction_numerical': 0.004161937192584185, 'mean_word_length': 1.3713004484304934, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2541458', 'n_tokens_mistral': 665, 'n_tokens_neox': 633, 'n_words': 143}