Exemple #1
0
        public static void CopyCommonDataToLocal(string politicianKey)
        {
            CopyCommonBlobsToLocal(politicianKey);
            var table = PoliticiansImagesData.GetDataByPoliticianKey(politicianKey);

            // suppress errors on Insert because a parallel thread may have already
            // copied the row into the local database
            try
            {
                switch (table.Count)
                {
                case 1:
                {
                    var row = table[0];
                    DB.VoteImagesLocal.PoliticiansImagesData.Upsert(politicianKey,
                                                                    row.ProfileOriginalDate, row.HeadshotDate, row.HeadshotResizeDate,
                                                                    DateTime.UtcNow);
                }
                break;

                case 0:
                    DB.VoteImagesLocal.PoliticiansImagesData.Upsert(politicianKey,
                                                                    VoteDb.DateTimeMin, VoteDb.DateTimeMin, VoteDb.DateTimeMin,
                                                                    VoteDb.DateTimeMin);
                    break;
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch {}
        }
        private static void InvalidatePoliticianImage(string politicianKey)
        {
            // We do this via updates to avoid synchronization problems
            var oldBlobs = PoliticiansImagesBlobs.GetDataByPoliticianKey(politicianKey);

            if (oldBlobs.Count == 1)
            {
                var newBlobs =
                    DB.Vote.PoliticiansImagesBlobs.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;
                    PoliticiansImagesBlobs.UpdateTable(oldBlobs);
                }
                break;

                case 0:
                    PoliticiansImagesBlobs.DeleteByPoliticianKey(politicianKey);
                    break;
                }
            }
            var oldData = PoliticiansImagesData.GetDataByPoliticianKey(politicianKey);

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

            switch (newData.Count)
            {
            case 1:
            {
                var oldRow = oldData[0];
                var newRow = newData[0];
                //oldRow.ProfileOriginalContentType = newRow.ProfileOriginalContentType;
                oldRow.ProfileOriginalDate = newRow.ProfileOriginalDate;
                //oldRow.ProfileOriginalWidth = newRow.ProfileOriginalWidth;
                //oldRow.ProfileOriginalHeight = newRow.ProfileOriginalHeight;
                //oldRow.HeadshotContentType = newRow.HeadshotContentType;
                oldRow.HeadshotDate = newRow.HeadshotDate;
                //oldRow.HeadshotWidth = newRow.HeadshotWidth;
                //oldRow.HeadshotHeight = newRow.HeadshotHeight;
                oldRow.HeadshotResizeDate = newRow.HeadshotResizeDate;
                PoliticiansImagesData.UpdateTable(oldData);
            }
            break;

            case 0:
                PoliticiansImagesData.DeleteByPoliticianKey(politicianKey);
                break;
            }
        }