예제 #1
0
        protected LeaderboardElement buildLeaderboardElement(CategoryJSON category, IList <LeaderboardJSON> leaderboard)
        {
            LeaderboardElement le      = null;
            List <SKBitmap>    bitmaps = new List <SKBitmap>();

            if (leaderboard.Count > 0)    // only build leaderboards with images.
            {
                foreach (LeaderboardJSON leader in leaderboard)
                {
                    SKBitmap bitmap = GlobalSingletonHelpers.SKBitmapFromBytes(leader.imgStr);
                    if (bitmap != null)
                    {
                        bitmaps.Add(bitmap);
                    }
                }
                le = new LeaderboardElement(category.description, category.categoryId, bitmaps, leaderboard);
#if DEBUG
                le.title = le.title + " - " + le.categoryId;
#endif
            }
            return(le);
        }
예제 #2
0
        /// <summary>
        /// created an instance in globalsingletonhelpers.
        /// @deprecated
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="attempt"></param>
        /// <returns></returns>
        protected async Task <SKBitmap> loadBitmapAsync(long pid, int attempt = 0)
        {
            Debug.WriteLine("DHB:ImageScrollingPage:loadBitmapAsync depth:" + attempt);
            SKBitmap output = null;

            byte[] result = await requestImageAsync(pid);

            if (result != null)
            {
                try {
                    /*
                     * PreviewResponseJSON resp = JsonConvert.DeserializeObject<PreviewResponseJSON>(result);
                     * if (resp != null) {
                     *  output = GlobalSingletonHelpers.SKBitmapFromBytes(resp.imgStr);
                     * }
                     */
                    //output = SKBitmap.Decode(result);
                    output = GlobalSingletonHelpers.SKBitmapFromBytes(result);
                } catch (Exception e) {
                    Debug.WriteLine("DHB:ImageScrollingPage:loadBitmapAsync err:" + e.ToString());
                }
            }
            if (output == null)
            {
                //output = GlobalSingletonHelpers.loadSKBitmapFromResourceName("ImageImprov.IconImages.alert.png", assembly);
                if (attempt < 10)    // fail after 10 attempts.
                {
                    await Task.Delay(3000);
                    await loadBitmapAsync(pid, attempt + 1);  // will recurse down till we get it.
                }
                else
                {
                    Debug.WriteLine("DHB:ImageScrollingPage:loadBitmapAsync MaxDepth hit");
                    output = GlobalSingletonHelpers.loadSKBitmapFromResourceName("ImageImprov.IconImages.alert.png", assembly);
                }
            }
            return(output);
        }