using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using DominionBase.Cards; namespace DominionBase.Players.AI { public class OpeningProcessor { private static Boolean IsDownloadedNew = false; private static Boolean IsDownloading = false; private static System.Threading.Mutex _Mutex; private static OpeningProcessor _Instance = null; private OpeningProcessor () { } static OpeningProcessor() { _Instance = new OpeningProcessor(); _Mutex = new System.Threading.Mutex(); } private Boolean _IsReady = false; private OpeningCollection _Openings = new OpeningCollection(); public Boolean IsReady { get { return _IsReady; } } public OpeningCollection Openings { get { return _Openings; } } public static OpeningProcessor Acquire() { _Mutex.WaitOne(); return _Instance; } public static void Release() { _Mutex.ReleaseMutex(); } public void Run() { IsDownloading = true; if (!System.IO.File.Exists("output.txt") || DateTime.Now - System.IO.File.GetLastWriteTime("output.txt") > TimeSpan.FromDays(1)) { try { Utilities.DownloadFileSlowly.DownloadFromUrl("http://councilroom.com/openings?card=All+cards", "output.txt", 108096); //String data = Utilities.DownloadFileSlowly.DownloadFromUrl("http://councilroom.com/openings?card=All+cards", 8096); } catch (Exception ex) { IsDownloading = false; return; } IsDownloadedNew = true; _IsReady = false; } IsDownloading = false; if (!IsReady) { CardCollection allCards = CardCollection.GetAllCards(c => c.Location == Location.Kingdom || c.Location == Location.General); if (IsDownloadedNew || !System.IO.File.Exists(OpeningCollection.Filename)) { String data = System.IO.File.ReadAllText("output.txt"); Match tableObject = Regex.Match(data, "