private static void InvalidatePoliticianImage(string politicianKey)
        {
            // We do this via updates to avoid synchronization problems
            var oldBlobs = PoliticiansImagesBlobsLocal.GetDataByPoliticianKey(politicianKey);

            if (oldBlobs.Count == 1)
            {
                var newBlobs =
                    PoliticiansImagesBlobsGlobal.GetCacheDataByPoliticianKey(politicianKey);
                switch (newBlobs.Count)
                {
                case 1:
                {
                    var oldRow = oldBlobs[0];
                    var newRow = newBlobs[0];
                    oldRow.Profile300  = newRow.Profile300;
                    oldRow.Profile200  = newRow.Profile200;
                    oldRow.Headshot100 = newRow.Headshot100;
                    oldRow.Headshot75  = newRow.Headshot75;
                    oldRow.Headshot50  = newRow.Headshot50;
                    oldRow.Headshot35  = newRow.Headshot35;
                    oldRow.Headshot25  = newRow.Headshot25;
                    oldRow.Headshot20  = newRow.Headshot20;
                    oldRow.Headshot15  = newRow.Headshot15;
                    PoliticiansImagesBlobsLocal.UpdateTable(oldBlobs);
                }
                break;

                case 0:
                    PoliticiansImagesBlobsLocal.DeleteByPoliticianKey(politicianKey);
                    break;
                }
            }
            var oldData = PoliticiansImagesDataLocal.GetDataByPoliticianKey(politicianKey);

            if (oldData.Count != 1)
            {
                return;
            }
            var newData =
                PoliticiansImagesDataGlobal.GetDataByPoliticianKey(politicianKey);

            switch (newData.Count)
            {
            case 1:
            {
                var oldRow = oldData[0];
                var newRow = newData[0];
                oldRow.ProfileOriginalDate = newRow.ProfileOriginalDate;
                oldRow.HeadshotDate        = newRow.HeadshotDate;
                oldRow.HeadshotResizeDate  = newRow.HeadshotResizeDate;
                PoliticiansImagesDataLocal.UpdateTable(oldData);
            }
            break;

            case 0:
                PoliticiansImagesDataLocal.DeleteByPoliticianKey(politicianKey);
                break;
            }
        }
Exemplo n.º 2
0
        public static ImageModDates GetImageModDates(string politicianKey)
        {
            ImageModDates result;

            lock (ImageModDatesCache)
                if (!ImageModDatesCache.TryGetValue(politicianKey, out result))
                {
                    var table = PoliticiansImagesData.GetData(politicianKey);
                    if (table.Count == 0)
                    {
                        ImageManager.CopyCommonDataToLocal(politicianKey);
                        table = PoliticiansImagesData.GetData(politicianKey);
                    }
                    result = RefreshImageModDates(table);
                }
            // check for cache expiration
            if (result.RefreshDate + new TimeSpan(0, CacheExpiration, 0) < DateTime.UtcNow)
            {
                lock (ImageModDatesCache)
                {
                    // expired
                    ImageManager.CopyCommonDataToLocal(politicianKey);
                    var table = PoliticiansImagesData.GetData(politicianKey);
                    result = RefreshImageModDates(table);
                }
            }
            return(result ?? new ImageModDates());
        }