source: extensions/PiwigoLib/PiwigoLib/Proxy/Helper/PwgProxyReponseHelper.cs @ 11850

Last change on this file since 11850 was 11850, checked in by bayral, 13 years ago

MAj des truc existant et debut du upload de fichier

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Web;
6
7using Com.Piwigo.Lib.DTO.Helper;
8
9namespace Com.Piwigo.Lib.Proxy.Helper
10{
11    internal static class PwgProxyReponseHelper
12    {
13        internal static void buildQueryFromArray<T>(List<T> values, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
14        {
15            String FormatString = String.Empty;
16            if (values != null)
17            {
18                if (values.Count == 1)
19                {
20                    FormatString = "{0}={1}";
21                }
22                else
23                {
24                    FormatString = "{0}[]={1}";
25                }
26                if (firstOcc != true)
27                {
28                    FormatString = String.Format("&{0}", FormatString);
29                }
30
31                foreach (T occurance in values)
32                {
33                    queryStringBuilder.AppendFormat(FormatString, paramName, HttpUtility.UrlEncode(occurance.ToString().ToLower()));
34                    firstOcc = false;
35                }
36
37            }
38        }
39
40        internal static void buildQueryFromValue<T>(Nullable<T> nullableValue, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
41            where T: struct 
42        {
43            if (nullableValue.HasValue)
44            {
45                buildQueryFromValue<T>(nullableValue.Value, paramName, ref firstOcc, queryStringBuilder);
46            }
47        }
48
49        internal static void buildQueryFromValue<T>(T value, String paramName, ref Boolean firstOcc, StringBuilder queryStringBuilder)
50        {
51            String FormatString = String.Empty;
52            String ParamValue = String.Empty;
53           
54            if (value != null)
55            {
56                FormatString = "{0}={1}";
57                if (firstOcc != true)
58                {
59                    FormatString = String.Format("&{0}", FormatString);
60                }
61
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                }
70               
71                queryStringBuilder.AppendFormat(FormatString, paramName, ParamValue);
72               
73                firstOcc = false;
74            }
75        }
76    }
77}
Note: See TracBrowser for help on using the repository browser.