Example #1
0
        public static PhotoModerationStatus GetPhotoModerationStatus(PluckConfigElement pluckConfig, string photoKey)
        {
            var pluckService = new PluckService(pluckConfig.apiUrl);
            var authToken    = new UserAuthenticationToken(pluckConfig.userKey, pluckConfig.userNickname, pluckConfig.userEmail, pluckConfig.sharedSecret);

            var requests     = new RequestBatch();
            var photorequest = new PhotoRequest {
                PhotoKey = new PhotoKey {
                    Key = photoKey
                }
            };

            requests.AddRequest(photorequest);

            ResponseBatch responseBatch = pluckService.SendRequest(requests, authToken);
            var           photo         = (PhotoResponse)responseBatch.Envelopes[0].GetResponse();

            return(DetermineModerationStatus(photo));
        }
Example #2
0
        public static void GetPhotoModerationStatus(PluckConfigElement pluckConfig, List <string> photoKeys)
        {
            if (photoKeys.Count == 0)
            {
                return;
            }

            var          pluckService = new PluckService(pluckConfig.apiUrl);
            var          authToken    = new UserAuthenticationToken(pluckConfig.userKey, pluckConfig.userNickname, pluckConfig.userEmail, pluckConfig.sharedSecret);
            RequestBatch requests     = null;

            int numBatches = photoKeys.Count / PLUCK_BATCH_SIZE;

            if (photoKeys.Count % PLUCK_BATCH_SIZE > 0)
            {
                numBatches++;
            }

            int photoKeyIndex = 0;

            for (int batchNumber = 1; batchNumber <= numBatches; batchNumber++)
            {
                requests = new RequestBatch();
                #region build requests batch
                for (int i = 0; i < PLUCK_BATCH_SIZE; i++)
                {
                    photoKeyIndex = (batchNumber * PLUCK_BATCH_SIZE) - PLUCK_BATCH_SIZE + i;

                    if (photoKeyIndex == photoKeys.Count)
                    {
                        break;
                    }

                    var photorequest = new PhotoRequest()
                    {
                        PhotoKey = new PhotoKey {
                            Key = photoKeys[photoKeyIndex]
                        }
                    };

                    requests.AddRequest(photorequest);
                }
                #endregion

                ResponseBatch             responseBatch = pluckService.SendRequest(requests, authToken);
                Dictionary <string, bool> photoStatus   = new Dictionary <string, bool>();

                #region build responses batch
                if (responseBatch != null)
                {
                    foreach (var envelope in responseBatch.Envelopes)
                    {
                        var photo  = (PhotoResponse)envelope.GetResponse();
                        var status = DetermineModerationStatus(photo);

                        if (status == PhotoModerationStatus.Pending || status == PhotoModerationStatus.Unknown)
                        {
                            continue;
                        }

                        try
                        {
                            //var photokey = photoKeys[photoKeyIndex];
                            //UserSubmitDB.SetModerationStatus(photo.Photo.PhotoKey.Key, (status == PhotoModerationStatus.Approved));
                            if (status == PhotoModerationStatus.Approved)
                            {
                                photoStatus.Add(photo.Photo.PhotoKey.Key, true);
                            }
                            else
                            {
                                string photokey = photo.ResponseStatus.Exceptions.Where(e => e.Name == "PhotoKey").Select(e => e.Value).FirstOrDefault();
                                photoStatus.Add(photokey, false);
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
                #endregion
            }
        }