public async Task loadDifficultyData(DateTime lastDate)
        {

            if (lastDate.Date != DateTime.Today)
            {
                // this assumes that there is only one day missing...
                // or that the difficulty has not changed since the last date, and today's date
                double daysMissing = (DateTime.Today - lastDate.Date).TotalDays;

                long currentNetworkDifficulty = 0;

                string blockexplorer_cache = "networkDifficulty";
                string result = "";

                if (HttpContext.Cache[blockexplorer_cache] == null)
                {
                    result = await service.GetBlockExplorerDifficultyAsync();
                    HttpContext.Cache.Insert(blockexplorer_cache, result, null, DateTime.UtcNow.AddHours(1), TimeSpan.Zero);
                }
                else
                {
                    result = (HttpContext.Cache[blockexplorer_cache].ToString());
                }

                currentNetworkDifficulty = Convert.ToInt64(Convert.ToDouble(result));

                for (int day = 1; day <= daysMissing; day++)
                {
                    metahistory m = new metahistory();
                    m.date = lastDate.AddDays(day);
                    m.difficulty = currentNetworkDifficulty;
                    database.metahistories.Add(m);
                }

                string msg = String.Format("Updated simcoin with {0} days of histories.", daysMissing);
                sendEmail("*****@*****.**", msg, "simcoin update");

                database.SaveChanges();
            }
        }
        public void loadArchivedDifficultyData()
        {
            var reader = new StreamReader(System.IO.File.OpenRead(HttpContext.Server.MapPath("~/Content/bitcoin-v2.csv")));
            List<string> listDates = new List<string>();
            List<string> listDifficulties = new List<string>();
            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();
                var values = line.Split(',');

                listDates.Add(values[0]);
                listDifficulties.Add(values[1]);
            }

            int addedDays = 0;

            StringBuilder s = new StringBuilder();

            DateTime lastDate = (from m in database.metahistories orderby m.date descending select m.date).FirstOrDefault();
            for (int i = 0; i <= 500; i++)
            {
                addedDays = addedDays + 1;
                DateTime currentDay = lastDate.AddDays(addedDays);

                if (currentDay.Date > DateTime.Now.Date)
                    break;


                Int64 difficulty = 1;
                Int64 lastDifficulty = 1;

                for (int x = 0; x < listDates.Count; x++)
                {

                    if (x > 0)
                    {
                        lastDifficulty = Int64.Parse(listDifficulties[x - 1]);
                    }

                    DateTime found = DateTime.Parse(listDates[x]);
                    difficulty = Int64.Parse(listDifficulties[x]);

                    //System.Diagnostics.Debug.Print(found.ToShortDateString() + "," + currentDay.ToShortDateString() + ":" + (currentDay.Date <= found.Date).ToString() + difficulty);

                    if (currentDay.Date < found.Date)
                    {
                        break;
                    }

                    if (currentDay.Date == found.Date || ((x == listDates.Count - 1) && currentDay.Date > found.Date))
                    {
                        lastDifficulty = difficulty;
                        break;
                    }

                }

                // now we need to find the corresponding difficulty...


                s.AppendLine(i.ToString() + ": " + currentDay.ToShortDateString() + ": " + lastDifficulty + "<br />");

                // now check to see if there are any days in the database that support this one already...
                //metahistory r = (from m in database.metahistories where m.date.Equals(currentDay) select m).FirstOrDefault();
                //if (r == null)
                //{
                metahistory a = new metahistory();
                a.date = currentDay;
                a.difficulty = lastDifficulty;

                database.metahistories.Add(a);

                //}

            }

            database.SaveChanges();
        }