private static bool IsColumnNameProfileImage(string columnName)
        {
            var result = false;

            if (PoliticiansImagesBlobs.TryGetColumn(columnName, out var column))
            {
                var politicianImageInfo =
                    PoliticianImageInfoList.SingleOrDefault(
                        info => info.BlobsColumn == column);
                if (politicianImageInfo != null)
                {
                    result = politicianImageInfo.IsProfile;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        internal static byte[] GetPoliticianImage(string politicianKey,
                                                  string columnName, string defaultColumnName, bool noCache)
        {
            byte[] blob;

            if (noCache)
            {
                // Validate the columnName and get the column enum from the columnName
                PoliticiansImagesBlobs.Column column;

                if (columnName == null ||
                    !PoliticiansImagesBlobs.TryGetColumn(columnName, out column))
                {
                    return(null);
                }

                // The following will be null if the politicianKey is bad, if the image doesn't
                // exist, or if a valid but non-image column name was passed
                blob = PoliticiansImagesBlobs.GetColumn(column, politicianKey) as byte[];

                // Optional recursive call to return the appropriate NoPhoto image if
                // the requested image not found
                if (!string.IsNullOrWhiteSpace(defaultColumnName) && blob == null)
                {
                    // if the defaultColumnName is invalid, use the original column
                    if (!PoliticiansImagesBlobs.TryGetColumn(defaultColumnName, out column))
                    {
                        defaultColumnName = columnName;
                    }
                    blob = GetPoliticianImage("NoPhoto", defaultColumnName, null, true);
                }
            }
            else // normal caching
            {
                // Validate the columnName and get the column enum from the columnName
                DB.VoteImagesLocal.PoliticiansImagesBlobs.Column column;
                if (columnName == null ||
                    !DB.VoteImagesLocal.PoliticiansImagesBlobs.TryGetColumn(columnName,
                                                                            out column))
                {
                    return(null);
                }

                // The following will be null if the politicianKey is bad, if the image doesn't
                // exist, or if a valid but non-image column name was passed
                blob =
                    DB.VoteImagesLocal.PoliticiansImagesBlobs.GetColumn(column, politicianKey)
                    as byte[];

                // Optional recursive call to return the appropriate NoPhoto image if
                // the requested image not found
                if (!string.IsNullOrWhiteSpace(defaultColumnName) && blob == null)
                {
                    // make sure the NoPhoto image has been cached
                    if (
                        !DB.VoteImagesLocal.PoliticiansImagesData.PoliticianKeyExists("NoPhoto"))
                    {
                        CopyCommonDataToLocal("NoPhoto");
                    }
                    // if the defaultColumnName is invalid, use the original column
                    if (
                        !DB.VoteImagesLocal.PoliticiansImagesBlobs.TryGetColumn(
                            defaultColumnName, out column))
                    {
                        defaultColumnName = columnName;
                    }
                    blob = GetPoliticianImage("NoPhoto", defaultColumnName, null, false);
                }
            }

            return(blob);
        }