Inheritance: IPhotoService
Ejemplo n.º 1
0
        private List<Photo> GetPhotos(IApiProvider apiProvider)
        {
            const string cacheKey = "PhotoService";
            if (Caching.VideoProviderCache.Instance.InnerCache.ContainsKey(cacheKey))
            {
                return Caching.VideoProviderCache.Instance.InnerCache.GetValue(cacheKey) as List<Photo>;
            }

            List<Photo> result = new List<Photo>();
            IPhotoService photoService = new PhotoService(apiProvider);

            bool done = false;
            int page = 1;
            while (!done)
            {
                List<Photo> photos = photoService.GetList(new PhotoListParameters
                {
                    IncludeUnpublished = false,
                    Size = 100,
                    PageOffset = page++
                });

                if (photos.Count > 0)
                    result.AddRange(photos);

                if (photos.Count < 100)
                    done = true;
            }

            Caching.VideoProviderCache.Instance.InnerCache.Add(cacheKey, result, result.Count, TimeSpan.FromMinutes(10));
            return result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders the value field as video embed code
        /// </summary>
        /// <param name="photo_id"></param>
        /// <returns></returns>
        private static string EmbedCode(string photo_id)
        {
            int photoid;
            if (!string.IsNullOrEmpty(photo_id) && Int32.TryParse(photo_id, out photoid))
            {
                IPhotoService photoService = new PhotoService(Utilities.ApiProvider);
                Photo photo = photoService.Get(photoid, false);

                if (photo != null && photo.PhotoId.HasValue)
                {
                    return Utilities.EmbedCode(photo.PhotoId.Value.ToString(), photo.Token, photo.VideoMedium.Width ?? 580, null);
                }
            }
            return string.Empty;
        }