Exemplo n.º 1
0
        public static Dictionary <string, string> UpdatePluckPhotoDetails(string appName, Pluck.Config.PluckConfigElement pluckConfig, string description, string title, string tags, string photoKey)
        {
            var requests = new RequestBatch();

            #region Add UpdatePhotoActionRequest to batch
            var updateRequest = new UpdatePhotoActionRequest
            {
                Description = description,
                Title       = title,
                Tags        = tags,
                PhotoKey    = new PhotoKey {
                    Key = photoKey
                }
            };

            requests.AddRequest(updateRequest);
            #endregion

            #region Add UpdateDiscoveryFilterFlagActionRequest to batch
            ////Make the photo not discoverable
            UpdateDiscoveryFilterFlagActionRequest discAction = new UpdateDiscoveryFilterFlagActionRequest();
            discAction.BaseKey = updateRequest.PhotoKey;
            discAction.ExcludeFromDiscovery = true;
            requests.AddRequest(discAction);
            #endregion

            #region Add PhotoRequest to batch
            requests.AddRequest(new PhotoRequest {
                PhotoKey = updateRequest.PhotoKey
            });
            #endregion

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

            ResponseBatch responseBatch = pluckService.SendRequest(requests, authToken);

            Dictionary <string, string> resultURI = new Dictionary <string, string>();
            if (responseBatch != null)
            {
                if (responseBatch.Envelopes[0].Payload.ResponseStatus.Exceptions != null && responseBatch.Envelopes[0].Payload.ResponseStatus.Exceptions.Length > 0)
                {
                    throw new ApplicationException(responseBatch.Envelopes[0].Payload.ResponseStatus.Exceptions[0].ExceptionMessage);
                }

                IResponse     photoObject  = responseBatch.Envelopes[2].GetResponse();
                PhotoResponse photoDetails = (PhotoResponse)photoObject;

                resultURI.Add("tiny", photoDetails.Photo.Image.Tiny);
                resultURI.Add("full", photoDetails.Photo.Image.Full);
                resultURI.Add("small", photoDetails.Photo.Image.Small);   //60x60
                resultURI.Add("medium", photoDetails.Photo.Image.Medium); //h=200
            }
            return(resultURI);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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
            }
        }
Exemplo n.º 4
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
            }
        }
Exemplo n.º 5
0
        public static Dictionary<string, string> UpdatePluckPhotoDetails(string appName, Pluck.Config.PluckConfigElement pluckConfig, string description, string title, string tags, string photoKey)
        {
            var requests = new RequestBatch();

            #region Add UpdatePhotoActionRequest to batch
            var updateRequest = new UpdatePhotoActionRequest
            {
                Description = description,
                Title = title,
                Tags = tags,
                PhotoKey = new PhotoKey { Key = photoKey }
            };

            requests.AddRequest(updateRequest);
            #endregion

            #region Add UpdateDiscoveryFilterFlagActionRequest to batch
            ////Make the photo not discoverable
            UpdateDiscoveryFilterFlagActionRequest discAction = new UpdateDiscoveryFilterFlagActionRequest();
            discAction.BaseKey = updateRequest.PhotoKey;
            discAction.ExcludeFromDiscovery = true;
            requests.AddRequest(discAction);
            #endregion

            #region Add PhotoRequest to batch
            requests.AddRequest(new PhotoRequest { PhotoKey = updateRequest.PhotoKey });
            #endregion

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

            ResponseBatch responseBatch = pluckService.SendRequest(requests, authToken);

            Dictionary<string, string> resultURI = new Dictionary<string, string>();
            if (responseBatch != null)
            {
                if (responseBatch.Envelopes[0].Payload.ResponseStatus.Exceptions != null && responseBatch.Envelopes[0].Payload.ResponseStatus.Exceptions.Length > 0)
                {
                    throw new ApplicationException(responseBatch.Envelopes[0].Payload.ResponseStatus.Exceptions[0].ExceptionMessage);
                }

                IResponse photoObject = responseBatch.Envelopes[2].GetResponse();
                PhotoResponse photoDetails = (PhotoResponse)photoObject;

                resultURI.Add("tiny", photoDetails.Photo.Image.Tiny);
                resultURI.Add("full", photoDetails.Photo.Image.Full);
                resultURI.Add("small", photoDetails.Photo.Image.Small);//60x60
                resultURI.Add("medium", photoDetails.Photo.Image.Medium);//h=200
            }
            return resultURI;
        }
Exemplo n.º 6
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);
        }