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

namespace CodeCampService
{
    public class CampProvider
    {
        private FileSystemWatcher _watcher;
        private Dictionary<string, CampCacheItem> _cache;

        public CampProvider(string folderPath)
        {
            _cache = new Dictionary<string, CampCacheItem>();
            _watcher = new FileSystemWatcher(folderPath);

            _watcher.Filter = "*.xml";
            _watcher.Created += onFileCreatedOrChanged;
            _watcher.Changed += onFileCreatedOrChanged;
            _watcher.Deleted += onFileDeleted;

            _watcher.EnableRaisingEvents = true;

            initCache();
        }

        public int GetVersionNumber(string campKey)
        {
            return _cache[campKey.ToLower()].Version;
        }

        public string GetXml(string campKey)
        {
            return _cache[campKey.ToLower()].Xml;
        }

        private void initCache()
        {
            foreach (var file in Directory.GetFiles(_watcher.Path, "*.xml"))
            {
                updateCache(file);
            }
        }

        private void onFileDeleted(object sender, FileSystemEventArgs e)
        {
            _cache.Remove(e.Name);
        }

        private void onFileCreatedOrChanged(object sender, FileSystemEventArgs e)
        {
            updateCache(e.FullPath);
        }

        private void updateCache(string filePath)
        {
            try
            {
                var file = new FileInfo(filePath);
                var xml = XDocument.Load(filePath);

                _cache[getFileNameWithoutExtension(file).ToLower()] = 
                    new CampCacheItem
                    {
                        Version = int.Parse(xml.Root.Attribute("version").Value),
                        Xml = xml.ToString()
                    };    
            }
            catch
            {
            }
            
        }

        private string getFileNameWithoutExtension(FileInfo file)
        {
            return file.Name.Substring(0, file.Name.Length - file.Extension.Length);
        }

        private class CampCacheItem
        {
            public int Version { get; set; }
            public string Xml { get; set; }
        }
    }
}<commit_msg>that was silly...don't need file watcher logic when we'll be doing full pushes to AppHarbor for XML updates<commit_after>﻿using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;

namespace CodeCampService
{
    public class CampProvider
    {
        private Dictionary<string, CampCacheItem> _cache;

        public CampProvider(string folderPath)
        {
            _cache = new Dictionary<string, CampCacheItem>();

            foreach (var file in Directory.GetFiles(folderPath, "*.xml"))
            {
                updateCache(file);
            }
        }

        public int GetVersionNumber(string campKey)
        {
            return _cache[campKey.ToLower()].Version;
        }

        public string GetXml(string campKey)
        {
            return _cache[campKey.ToLower()].Xml;
        }

        private void updateCache(string filePath)
        {
            try
            {
                var file = new FileInfo(filePath);
                var xml = XDocument.Load(filePath);

                _cache[getFileNameWithoutExtension(file).ToLower()] = 
                    new CampCacheItem
                    {
                        Version = int.Parse(xml.Root.Attribute("version").Value),
                        Xml = xml.ToString()
                    };    
            }
            catch
            {
            }
        }

        private string getFileNameWithoutExtension(FileInfo file)
        {
            return file.Name.Substring(0, file.Name.Length - file.Extension.Length);
        }

        private class CampCacheItem
        {
            public int Version { get; set; }
            public string Xml { get; set; }
        }
    }
}
{'fraction_non_alphanumeric': 0.08260977424956586, 'fraction_numerical': 0.0004961548002976929, 'mean_word_length': 1.4812307692307691, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, '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': '2076837', 'n_tokens_mistral': 1028, 'n_tokens_neox': 982, 'n_words': 215}