Ignore:
Timestamp:
Sep 17, 2009, 11:14:31 PM (15 years ago)
Author:
bayral
Message:

support for pwg.images.rate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/Service/PwgImagesService.cs

    r3835 r3861  
    22using System.Collections.Generic;
    33using System.Text;
     4using System.Globalization;
    45
    56using Com.Piwigo.Lib.DTO;
     
    1314    static public class PwgImagesService
    1415    {
     16        static public PwgImageRate RateImage(Int32 imageId, Int32 imageRate)
     17        {
     18            PwgImageRate returnValue = new PwgImageRate();
     19
     20            try
     21            {
     22                PwgImageRateProxyResponse response = PwgImagesProxy.pwg_images_rate(imageId, imageRate);
     23
     24                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
     25                {
     26                    if (response.Erreur != null)
     27                    {
     28                        throw new PwgServiceException("RateImage, the server has return the error.",
     29                            response.Erreur.Code,
     30                            response.Erreur.Message);
     31                    }
     32                    else
     33                    {
     34                        throw new PwgServiceException("RateImage : a error occurs during server process.");
     35                    }
     36                }
     37                else
     38                {
     39                    returnValue = ConvertProxyResponseToDTO(response);
     40                }
     41            }
     42            catch (PwgProxyException ex)
     43            {
     44                throw new PwgServiceException("RateImage : a error is raised by proxy.", ex);
     45            }
     46            return returnValue;
     47        }
     48
     49        /// <summary>
     50        /// private: convert response to dto object
     51        /// </summary>
     52        /// <param name="response"></param>
     53        /// <param name="session"></param>
     54        static public PwgImageRate ConvertProxyResponseToDTO(PwgImageRateProxyResponse response)
     55        {
     56            PwgImageRate returnValue = new PwgImageRate();
     57            Double aDouble = 0;
     58            NumberStyles style = NumberStyles.AllowDecimalPoint;
     59            CultureInfo en_us = CultureInfo.CreateSpecificCulture("en-US");
     60
     61            returnValue.Count = response.Count;
     62
     63            returnValue.Stdev = 0.0 ;
     64            if (Double.TryParse(response.Stdev, style, en_us, out aDouble))
     65            {
     66                returnValue.Stdev = aDouble;
     67            }
     68
     69            returnValue.Average = 0.0;
     70            if (Double.TryParse(response.Average, style, en_us, out aDouble))
     71            {
     72                returnValue.Average = aDouble;
     73            }
     74
     75
     76            return returnValue;
     77        }
     78
    1579        /// <summary>
    1680        /// private: convert response to dto object
Note: See TracChangeset for help on using the changeset viewer.