Ignore:
Timestamp:
Aug 1, 2011, 5:47:03 PM (13 years ago)
Author:
bayral
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgProxyReponseHelper.cs

    r11850 r11872  
    66
    77using Com.Piwigo.Lib.DTO.Helper;
     8using System.Xml;
     9using Com.Piwigo.Lib.DTO;
    810
    911namespace Com.Piwigo.Lib.Proxy.Helper
     
    1113    internal static class PwgProxyReponseHelper
    1214    {
     15        internal static void buildDicFieldFromArray<T>(List<T> values, String paramName, ref Dictionary<String, String> dcFields)
     16        {
     17            String FormatString = String.Empty;
     18            String ParamValue = String.Empty;
     19
     20            Boolean firstOcc = true;
     21            if (values != null)
     22            {
     23                foreach (T occurance in values)
     24                {
     25                    if (firstOcc == true)
     26                    {
     27                        firstOcc = false;
     28                        FormatString = "{0}";
     29                    }
     30                    else
     31                    {
     32                        FormatString = ",{0}";
     33                    }
     34
     35                    ParamValue += String.Format(FormatString,GetString(occurance));
     36                }
     37
     38                dcFields.Add(paramName, ParamValue);
     39            }
     40        }
     41
     42        internal static void buildDicFieldFromValue<T>(Nullable<T> nullableValue, String paramName, ref Dictionary<String, String> dcFields) where T : struct
     43        {
     44            if (nullableValue.HasValue)
     45            {
     46                buildDicFieldFromValue<T>(nullableValue.Value, paramName, ref dcFields);
     47            }
     48        }
     49
     50        internal static void buildDicFieldFromValue<T>(T value, String paramName, ref Dictionary<String, String> dcFields)
     51        {
     52            String FormatString = String.Empty;
     53            String ParamValue = String.Empty;
     54
     55            FormatString = "{0}";
     56
     57            ParamValue = GetString(value);
     58
     59            dcFields.Add(paramName, ParamValue);
     60        }
     61
    1362        internal static void buildQueryFromArray<T>(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
    1463        {
     
    3180                foreach (T occurance in values)
    3281                {
    33                     queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(occurance.ToString().ToLower()));
     82                    queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(GetString(occurance)));
    3483                    firstOcc = false;
    3584                }
     
    3887        }
    3988
    40         internal static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
    41             where T: struct
     89        internal static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder) where T : struct
    4290        {
    4391            if (nullableValue.HasValue)
     
    52100            String ParamValue = String.Empty;
    53101           
    54             if (value != null)
    55             {
    56102                FormatString = "{0}={1}";
    57103                if (firstOcc != true)
     
    60106                }
    61107
    62                 if (typeof(T).IsEnum)
    63                 {
    64                     ParamValue = HttpUtility.UrlEncode(PwgEnumHelper<T>.StringValueOf(value));
    65                 }
    66                 else
    67                 {
    68                     ParamValue = HttpUtility.UrlEncode(value.ToString().ToLower());
    69                 }
     108                ParamValue = HttpUtility.UrlEncode(GetString(value));
    70109               
    71110                queryStringBuilder.AppendFormat(FormatString, paramName, ParamValue);
    72111               
    73112                firstOcc = false;
     113        }
     114
     115        public static String GetString<T>(T value)
     116        {
     117            String strRet = String.Empty;
     118            if (value is String)
     119            {
     120                strRet = (value as String);
    74121            }
     122            else if (typeof(T).IsEnum)
     123            {
     124                strRet = PwgEnumHelper<T>.StringValueOf(value);
     125            }
     126            else if (value is PwgTag)
     127            {
     128
     129                strRet = (value as PwgTag).Name;
     130            }
     131            else
     132            {
     133
     134                strRet = (value as Object).ToString().ToLowerInvariant();
     135            }
     136
     137            return strRet;
    75138        }
    76139    }
Note: See TracChangeset for help on using the changeset viewer.