diff --git a/README.markdown b/README.markdown index 7540f2256..f13bd7256 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ ### Features -* Supports .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, MonoTouch, Mono for Android +* Supports .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, MonoTouch, Mono for Android, Compact Framework 3.5 * Easy installation using [NuGet](http://nuget.org/packages/RestSharp) for most .NET flavors * Automatic XML and JSON deserialization * Supports custom serialization and deserialization via ISerializer and IDeserializer diff --git a/RestSharp.Compact.sln b/RestSharp.Compact.sln new file mode 100644 index 000000000..39ae77eb7 --- /dev/null +++ b/RestSharp.Compact.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestSharp.Compact", "RestSharp\RestSharp.Compact.csproj", "{A29E330B-F854-4287-BEB2-C4CBE9D9C637}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A29E330B-F854-4287-BEB2-C4CBE9D9C637}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A29E330B-F854-4287-BEB2-C4CBE9D9C637}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A29E330B-F854-4287-BEB2-C4CBE9D9C637}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A29E330B-F854-4287-BEB2-C4CBE9D9C637}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/RestSharp/Authenticators/OAuth/Extensions/CollectionExtensions.cs b/RestSharp/Authenticators/OAuth/Extensions/CollectionExtensions.cs index d403b1cc0..9efadeb89 100644 --- a/RestSharp/Authenticators/OAuth/Extensions/CollectionExtensions.cs +++ b/RestSharp/Authenticators/OAuth/Extensions/CollectionExtensions.cs @@ -49,7 +49,7 @@ public static void ForEach(this IEnumerable items, Action action) } } -#if !WINDOWS_PHONE && !SILVERLIGHT +#if !WINDOWS_PHONE && !SILVERLIGHT && !PocketPC public static void AddRange(this IDictionary collection, NameValueCollection range) { diff --git a/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs b/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs index 66a57e4c7..4dd7ae3f9 100644 --- a/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs +++ b/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs @@ -104,7 +104,7 @@ public static string PercentEncode(this string s) } private const RegexOptions Options = -#if !WINDOWS_PHONE && !SILVERLIGHT +#if !WINDOWS_PHONE && !SILVERLIGHT && !PocketPC RegexOptions.Compiled | RegexOptions.IgnoreCase; #else RegexOptions.IgnoreCase; diff --git a/RestSharp/Authenticators/OAuth/HttpPostParameterType.cs b/RestSharp/Authenticators/OAuth/HttpPostParameterType.cs index 19d75efda..7dbce9a92 100644 --- a/RestSharp/Authenticators/OAuth/HttpPostParameterType.cs +++ b/RestSharp/Authenticators/OAuth/HttpPostParameterType.cs @@ -2,7 +2,7 @@ namespace RestSharp.Authenticators.OAuth { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif internal enum HttpPostParameterType diff --git a/RestSharp/Authenticators/OAuth/OAuthParameterHandling.cs b/RestSharp/Authenticators/OAuth/OAuthParameterHandling.cs index ae5c42604..3a7428c9a 100644 --- a/RestSharp/Authenticators/OAuth/OAuthParameterHandling.cs +++ b/RestSharp/Authenticators/OAuth/OAuthParameterHandling.cs @@ -2,7 +2,7 @@ namespace RestSharp.Authenticators.OAuth { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif public enum OAuthParameterHandling diff --git a/RestSharp/Authenticators/OAuth/OAuthSignatureMethod.cs b/RestSharp/Authenticators/OAuth/OAuthSignatureMethod.cs index 3ba76ca65..47d9266f1 100644 --- a/RestSharp/Authenticators/OAuth/OAuthSignatureMethod.cs +++ b/RestSharp/Authenticators/OAuth/OAuthSignatureMethod.cs @@ -2,7 +2,7 @@ namespace RestSharp.Authenticators.OAuth { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif public enum OAuthSignatureMethod diff --git a/RestSharp/Authenticators/OAuth/OAuthSignatureTreatment.cs b/RestSharp/Authenticators/OAuth/OAuthSignatureTreatment.cs index a13b32c74..3253a75ae 100644 --- a/RestSharp/Authenticators/OAuth/OAuthSignatureTreatment.cs +++ b/RestSharp/Authenticators/OAuth/OAuthSignatureTreatment.cs @@ -2,7 +2,7 @@ namespace RestSharp.Authenticators.OAuth { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif public enum OAuthSignatureTreatment diff --git a/RestSharp/Authenticators/OAuth/OAuthTools.cs b/RestSharp/Authenticators/OAuth/OAuthTools.cs index c81c4510c..0c6b421c3 100644 --- a/RestSharp/Authenticators/OAuth/OAuthTools.cs +++ b/RestSharp/Authenticators/OAuth/OAuthTools.cs @@ -6,7 +6,7 @@ namespace RestSharp.Authenticators.OAuth { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif internal static class OAuthTools @@ -20,13 +20,13 @@ internal static class OAuthTools private static readonly Random _random; private static readonly object _randomLock = new object(); -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC private static readonly RandomNumberGenerator _rng = RandomNumberGenerator.Create(); #endif static OAuthTools() { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC var bytes = new byte[4]; _rng.GetNonZeroBytes(bytes); _random = new Random(BitConverter.ToInt32(bytes, 0)); @@ -305,6 +305,7 @@ public static string GetSignature(OAuthSignatureMethod signatureMethod, string s string signature; switch (signatureMethod) { +#if !PocketPC case OAuthSignatureMethod.HmacSha1: { var crypto = new HMACSHA1(); @@ -315,6 +316,7 @@ public static string GetSignature(OAuthSignatureMethod signatureMethod, string s break; } +#endif case OAuthSignatureMethod.PlainText: { signature = "{0}&{1}".FormatWith(consumerSecret, tokenSecret); @@ -322,7 +324,11 @@ public static string GetSignature(OAuthSignatureMethod signatureMethod, string s break; } default: +#if PocketPC + throw new NotImplementedException("Only PlainText is currently supported."); +#else throw new NotImplementedException("Only HMAC-SHA1 is currently supported."); +#endif } var result = signatureTreatment == OAuthSignatureTreatment.Escaped diff --git a/RestSharp/Authenticators/OAuth/OAuthType.cs b/RestSharp/Authenticators/OAuth/OAuthType.cs index 33c6f0fda..96b05d624 100644 --- a/RestSharp/Authenticators/OAuth/OAuthType.cs +++ b/RestSharp/Authenticators/OAuth/OAuthType.cs @@ -2,7 +2,7 @@ namespace RestSharp.Authenticators.OAuth { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif public enum OAuthType diff --git a/RestSharp/Authenticators/OAuth/OAuthWebQueryInfo.cs b/RestSharp/Authenticators/OAuth/OAuthWebQueryInfo.cs index 865555f75..f1156f4ae 100644 --- a/RestSharp/Authenticators/OAuth/OAuthWebQueryInfo.cs +++ b/RestSharp/Authenticators/OAuth/OAuthWebQueryInfo.cs @@ -2,7 +2,7 @@ namespace RestSharp.Authenticators.OAuth { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif public class OAuthWebQueryInfo diff --git a/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs b/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs index f0fd3241a..183974b9f 100644 --- a/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs +++ b/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using RestSharp.Authenticators.OAuth.Extensions; -#if !WINDOWS_PHONE && !SILVERLIGHT +#if !WINDOWS_PHONE && !SILVERLIGHT && !PocketPC using RestSharp.Contrib; #endif @@ -213,19 +213,23 @@ public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebPa // Include url parameters in query pool var uri = new Uri(url); -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC var urlParameters = HttpUtility.ParseQueryString(uri.Query); #else var urlParameters = uri.Query.ParseQueryString(); #endif -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC foreach (var parameter in urlParameters.AllKeys) #else foreach (var parameter in urlParameters.Keys) #endif { +#if PocketPC + switch (method.ToUpper()) +#else switch (method.ToUpperInvariant()) +#endif { case "POST": parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter])); diff --git a/RestSharp/Authenticators/OAuth/WebPairCollection.cs b/RestSharp/Authenticators/OAuth/WebPairCollection.cs index 351f285f5..db9c7157b 100644 --- a/RestSharp/Authenticators/OAuth/WebPairCollection.cs +++ b/RestSharp/Authenticators/OAuth/WebPairCollection.cs @@ -30,7 +30,7 @@ public WebPairCollection(IEnumerable parameters) _parameters = new List(parameters); } -#if !WINDOWS_PHONE && !SILVERLIGHT +#if !WINDOWS_PHONE && !SILVERLIGHT && !PocketPC public WebPairCollection(NameValueCollection collection) : this() { AddCollection(collection); diff --git a/RestSharp/Authenticators/OAuth/WebParameter.cs b/RestSharp/Authenticators/OAuth/WebParameter.cs index 387c4eb97..5f46c794e 100644 --- a/RestSharp/Authenticators/OAuth/WebParameter.cs +++ b/RestSharp/Authenticators/OAuth/WebParameter.cs @@ -6,10 +6,10 @@ namespace RestSharp.Authenticators.OAuth { -#if !Smartphone +#if !Smartphone && !PocketPC [DebuggerDisplay("{Name}:{Value}")] #endif -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC [Serializable] #endif internal class WebParameter : WebPair diff --git a/RestSharp/Authenticators/OAuth/WebParameterCollection.cs b/RestSharp/Authenticators/OAuth/WebParameterCollection.cs index 5dae0f87f..1da58f01d 100644 --- a/RestSharp/Authenticators/OAuth/WebParameterCollection.cs +++ b/RestSharp/Authenticators/OAuth/WebParameterCollection.cs @@ -10,7 +10,7 @@ public WebParameterCollection(IEnumerable parameters) { } -#if !WINDOWS_PHONE && !SILVERLIGHT +#if !WINDOWS_PHONE && !SILVERLIGHT && !PocketPC public WebParameterCollection(NameValueCollection collection) : base(collection) { } diff --git a/RestSharp/Authenticators/OAuth1Authenticator.cs b/RestSharp/Authenticators/OAuth1Authenticator.cs index a13ce73a6..8cab1d458 100644 --- a/RestSharp/Authenticators/OAuth1Authenticator.cs +++ b/RestSharp/Authenticators/OAuth1Authenticator.cs @@ -156,7 +156,11 @@ private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflo url = url.Substring(0, queryStringStart); OAuthWebQueryInfo oauth; +#if PocketPC + var method = request.Method.ToString().ToUpper(); +#else var method = request.Method.ToString().ToUpperInvariant(); +#endif var parameters = new WebParameterCollection(); diff --git a/RestSharp/Deserializers/JsonDeserializer.cs b/RestSharp/Deserializers/JsonDeserializer.cs index 3dff63860..f546a7fea 100644 --- a/RestSharp/Deserializers/JsonDeserializer.cs +++ b/RestSharp/Deserializers/JsonDeserializer.cs @@ -194,7 +194,11 @@ private object ConvertValue(Type type, object value) { return stringValue; } - else if (type == typeof(DateTime) || type == typeof(DateTimeOffset)) + else if (type == typeof(DateTime) +#if !PocketPC + || type == typeof(DateTimeOffset) +#endif + ) { DateTime dt; if (DateFormat.HasValue()) @@ -207,6 +211,9 @@ private object ConvertValue(Type type, object value) dt = stringValue.ParseJsonDate(Culture); } +#if PocketPC + return dt; +#else if (type == typeof(DateTime)) { return dt; @@ -215,6 +222,7 @@ private object ConvertValue(Type type, object value) { return (DateTimeOffset)dt; } +#endif } else if (type == typeof(Decimal)) { diff --git a/RestSharp/Deserializers/XmlDeserializer.cs b/RestSharp/Deserializers/XmlDeserializer.cs index 3d7e93cd0..277b4fee6 100644 --- a/RestSharp/Deserializers/XmlDeserializer.cs +++ b/RestSharp/Deserializers/XmlDeserializer.cs @@ -171,6 +171,7 @@ protected virtual void Map(object x, XElement root) prop.SetValue(x, value, null); } +#if !PocketPC else if (type == typeof(DateTimeOffset)) { var toConvert = value.ToString(); @@ -198,6 +199,7 @@ protected virtual void Map(object x, XElement root) } } } +#endif else if (type == typeof(Decimal)) { value = Decimal.Parse(value.ToString(), Culture); @@ -264,7 +266,7 @@ protected virtual void Map(object x, XElement root) private static bool TryGetFromString(string inputString, out object result, Type type) { -#if !SILVERLIGHT && !WINDOWS_PHONE +#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC var converter = TypeDescriptor.GetConverter(type); if (converter.CanConvertFrom(typeof(string))) { diff --git a/RestSharp/Extensions/MiscExtensions.cs b/RestSharp/Extensions/MiscExtensions.cs index 0e179771a..110fdba7a 100644 --- a/RestSharp/Extensions/MiscExtensions.cs +++ b/RestSharp/Extensions/MiscExtensions.cs @@ -25,7 +25,7 @@ namespace RestSharp.Extensions /// public static class MiscExtensions { -#if !WINDOWS_PHONE +#if !WINDOWS_PHONE && !PocketPC /// /// Save a byte array to a file /// @@ -87,7 +87,7 @@ public static string AsString(this byte[] buffer) Encoding encoding = Encoding.UTF8; #if FRAMEWORK - return encoding.GetString(buffer); + return encoding.GetString(buffer, 0, buffer.Length); #else if (buffer == null || buffer.Length == 0) return ""; diff --git a/RestSharp/Extensions/MonoHttp/HtmlEncoder.cs b/RestSharp/Extensions/MonoHttp/HtmlEncoder.cs index c8b8eec22..e8113ca93 100644 --- a/RestSharp/Extensions/MonoHttp/HtmlEncoder.cs +++ b/RestSharp/Extensions/MonoHttp/HtmlEncoder.cs @@ -48,7 +48,11 @@ class HttpEncoder { static char[] hexChars = "0123456789abcdef".ToCharArray(); static object entitiesLock = new object(); +#if PocketPC + static Dictionary entities; +#else static SortedDictionary entities; +#endif #if NET_4_0 static Lazy defaultEncoder; static Lazy currentEncoderLazy; @@ -229,7 +233,8 @@ string UrlPathEncode(string value) for (int i = 0; i < length; i++) UrlPathEncodeChar(value[i], result); - return Encoding.ASCII.GetString(result.ToArray()); + byte[] bytes = result.ToArray(); + return Encoding.ASCII.GetString(bytes, 0, bytes.Length); } internal static byte[] UrlEncodeToBytes(byte[] bytes, int offset, int count) @@ -659,8 +664,11 @@ static void InitEntities() { // Build the hash table of HTML entity references. This list comes // from the HTML 4.01 W3C recommendation. +#if PocketPC + entities = new Dictionary(StringComparer.Ordinal); +#else entities = new SortedDictionary(StringComparer.Ordinal); - +#endif entities.Add("nbsp", '\u00A0'); entities.Add("iexcl", '\u00A1'); entities.Add("cent", '\u00A2'); diff --git a/RestSharp/Extensions/MonoHttp/HttpUtility.cs b/RestSharp/Extensions/MonoHttp/HttpUtility.cs index 64f7775a0..7fe8f2b2d 100644 --- a/RestSharp/Extensions/MonoHttp/HttpUtility.cs +++ b/RestSharp/Extensions/MonoHttp/HttpUtility.cs @@ -182,7 +182,7 @@ public static string UrlDecode(string s, Encoding e) byte[] buf = bytes.ToArray(); bytes = null; - return e.GetString(buf); + return e.GetString(buf, 0, buf.Length); } @@ -412,7 +412,8 @@ public static string UrlEncode(string s, Encoding Enc) // avoided GetByteCount call byte[] bytes = new byte[Enc.GetMaxByteCount(s.Length)]; int realLen = Enc.GetBytes(s, 0, s.Length, bytes, 0); - return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes, 0, realLen)); + byte[] r = UrlEncodeToBytes(bytes, 0, realLen); + return Encoding.ASCII.GetString(r, 0, r.Length); } public static string UrlEncode(byte[] bytes) @@ -422,8 +423,8 @@ public static string UrlEncode(byte[] bytes) if (bytes.Length == 0) return String.Empty; - - return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes, 0, bytes.Length)); + byte[] r = UrlEncodeToBytes(bytes, 0, bytes.Length); + return Encoding.ASCII.GetString(r, 0, r.Length); } public static string UrlEncode(byte[] bytes, int offset, int count) @@ -433,8 +434,8 @@ public static string UrlEncode(byte[] bytes, int offset, int count) if (bytes.Length == 0) return String.Empty; - - return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes, offset, count)); + byte[] r = UrlEncodeToBytes(bytes, offset, count); + return Encoding.ASCII.GetString(r, 0, r.Length); } public static byte[] UrlEncodeToBytes(string str) @@ -480,8 +481,8 @@ public static string UrlEncodeUnicode(string str) { if (str == null) return null; - - return Encoding.ASCII.GetString(UrlEncodeUnicodeToBytes(str)); + byte[] r = UrlEncodeUnicodeToBytes(str); + return Encoding.ASCII.GetString(r, 0, r.Length); } public static byte[] UrlEncodeUnicodeToBytes(string str) diff --git a/RestSharp/Extensions/ReflectionExtensions.cs b/RestSharp/Extensions/ReflectionExtensions.cs index ca7382975..82fa61625 100644 --- a/RestSharp/Extensions/ReflectionExtensions.cs +++ b/RestSharp/Extensions/ReflectionExtensions.cs @@ -65,7 +65,7 @@ public static class ReflectionExtensions public static object ChangeType(this object source, Type newType) { -#if FRAMEWORK +#if FRAMEWORK && !PocketPC return Convert.ChangeType(source, newType); #else return Convert.ChangeType(source, newType, null); @@ -91,7 +91,7 @@ public static object ChangeType(this object source, Type newType, CultureInfo cu /// public static object FindEnumValue(this Type type, string value, CultureInfo culture) { -#if FRAMEWORK +#if FRAMEWORK && !PocketPC var ret = Enum.GetValues( type ) .Cast() .FirstOrDefault(v => v.ToString().GetNameVariants(culture).Contains(value, StringComparer.Create(culture, true))); diff --git a/RestSharp/Extensions/StringExtensions.cs b/RestSharp/Extensions/StringExtensions.cs index eac4b12f4..92dfc35cc 100644 --- a/RestSharp/Extensions/StringExtensions.cs +++ b/RestSharp/Extensions/StringExtensions.cs @@ -38,10 +38,12 @@ namespace RestSharp.Extensions { public static class StringExtensions { +#if !PocketPC public static string UrlDecode(this string input) { return HttpUtility.UrlDecode(input); } +#endif /// /// Uses Uri.EscapeDataString() based on recommendations on MSDN @@ -69,6 +71,7 @@ public static string UrlEncode(this string input) return sb.ToString(); } +#if !PocketPC public static string HtmlDecode(this string input) { return HttpUtility.HtmlDecode(input); @@ -78,6 +81,7 @@ public static string HtmlEncode(this string input) { return HttpUtility.HtmlEncode(input); } +#endif #if FRAMEWORK public static string HtmlAttributeEncode(this string input) @@ -118,11 +122,14 @@ public static DateTime ParseJsonDate(this string input, CultureInfo culture) input = input.RemoveSurroundingQuotes(); - long unix; - if (Int64.TryParse(input, out unix)) + long? unix = null; + try { + unix = Int64.Parse(input); + } catch (Exception) { }; + if (unix.HasValue) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - return epoch.AddSeconds(unix); + return epoch.AddSeconds(unix.Value); } if (input.Contains("/Date(")) @@ -168,16 +175,28 @@ private static DateTime ParseFormattedDate(string input, CultureInfo culture) "M/d/yyyy h:mm:ss tt" // default format for invariant culture }; +#if PocketPC + foreach (string format in formats) { + try { + return DateTime.ParseExact(input, format, culture); + } catch (Exception) { + } + } + try { + return DateTime.Parse(input, culture); + } catch (Exception) { + } +#else DateTime date; if (DateTime.TryParseExact(input, formats, culture, DateTimeStyles.None, out date)) { return date; } - if (DateTime.TryParse(input, culture, DateTimeStyles.None, out date)) { return date; } +#endif return default(DateTime); } diff --git a/RestSharp/FileParameter.cs b/RestSharp/FileParameter.cs index 60bb99966..6f1f197e1 100644 --- a/RestSharp/FileParameter.cs +++ b/RestSharp/FileParameter.cs @@ -18,7 +18,7 @@ public class FileParameter ///The public static FileParameter Create(string name, byte[] data, string filename, string contentType) { -#if FRAMEWORK +#if FRAMEWORK && !PocketPC var length = data.LongLength; #else var length = (long)data.Length; diff --git a/RestSharp/Http.Async.cs b/RestSharp/Http.Async.cs index 0aea51437..826703585 100644 --- a/RestSharp/Http.Async.cs +++ b/RestSharp/Http.Async.cs @@ -29,7 +29,7 @@ using System.Windows; #endif -#if (FRAMEWORK && !MONOTOUCH && !MONODROID) +#if (FRAMEWORK && !MONOTOUCH && !MONODROID && !PocketPC) using System.Web; #endif @@ -84,7 +84,11 @@ public HttpWebRequest PatchAsync(Action action) /// public HttpWebRequest AsPostAsync(Action action, string httpMethod) { +#if PocketPC + return PutPostInternalAsync(httpMethod.ToUpper(), action); +#else return PutPostInternalAsync(httpMethod.ToUpperInvariant(), action); +#endif } /// @@ -94,7 +98,11 @@ public HttpWebRequest AsPostAsync(Action action, string httpMethod /// public HttpWebRequest AsGetAsync(Action action, string httpMethod) { +#if PocketPC + return GetStyleMethodInternalAsync(httpMethod.ToUpper(), action); +#else return GetStyleMethodInternalAsync(httpMethod.ToUpperInvariant(), action); +#endif } private HttpWebRequest GetStyleMethodInternalAsync(string method, Action callback) @@ -163,7 +171,7 @@ private void WriteRequestBodyAsync(HttpWebRequest webRequest, Action RequestStreamCallback(result, callback), webRequest); @@ -246,7 +254,7 @@ private void RequestStreamCallback(IAsyncResult result, Action cal private void SetTimeout(IAsyncResult asyncResult, TimeOutState timeOutState) { -#if FRAMEWORK +#if FRAMEWORK && !PocketPC if (Timeout != 0) { ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), timeOutState, Timeout, true); @@ -367,7 +375,9 @@ private HttpWebRequest ConfigureAsyncWebRequest(string method, Uri url) WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp); #endif var webRequest = (HttpWebRequest)WebRequest.Create(url); +#if !PocketPC webRequest.UseDefaultCredentials = UseDefaultCredentials; +#endif webRequest.PreAuthenticate = PreAuthenticate; AppendHeaders(webRequest); @@ -376,7 +386,7 @@ private HttpWebRequest ConfigureAsyncWebRequest(string method, Uri url) webRequest.Method = method; // make sure Content-Length header is always sent since default is -1 -#if !WINDOWS_PHONE +#if !WINDOWS_PHONE && !PocketPC // WP7 doesn't as of Beta doesn't support a way to set this value either directly // or indirectly if(!HasFiles && !AlwaysMultipartFormData) @@ -384,7 +394,7 @@ private HttpWebRequest ConfigureAsyncWebRequest(string method, Uri url) webRequest.ContentLength = 0; } #endif - + if(Credentials != null) { webRequest.Credentials = Credentials; diff --git a/RestSharp/Http.Sync.cs b/RestSharp/Http.Sync.cs index f7941a7ce..20430be4b 100644 --- a/RestSharp/Http.Sync.cs +++ b/RestSharp/Http.Sync.cs @@ -18,7 +18,7 @@ using System; using System.Net; -#if !MONOTOUCH && !MONODROID +#if !MONOTOUCH && !MONODROID && !PocketPC using System.Web; #endif @@ -94,7 +94,11 @@ public HttpResponse Patch() /// public HttpResponse AsGet(string httpMethod) { +#if PocketPC + return GetStyleMethodInternal(httpMethod.ToUpper()); +#else return GetStyleMethodInternal(httpMethod.ToUpperInvariant()); +#endif } /// @@ -104,7 +108,11 @@ public HttpResponse AsGet(string httpMethod) /// public HttpResponse AsPost(string httpMethod) { +#if PocketPC + return PostPutInternal(httpMethod.ToUpper()); +#else return PostPutInternal(httpMethod.ToUpperInvariant()); +#endif } private HttpResponse GetStyleMethodInternal(string method) @@ -217,7 +225,9 @@ private void WriteRequestBody(HttpWebRequest webRequest) private HttpWebRequest ConfigureWebRequest(string method, Uri url) { var webRequest = (HttpWebRequest)WebRequest.Create(url); +#if !PocketPC webRequest.UseDefaultCredentials = UseDefaultCredentials; +#endif webRequest.PreAuthenticate = PreAuthenticate; ServicePointManager.Expect100Continue = false; diff --git a/RestSharp/Http.cs b/RestSharp/Http.cs index 704e50fb0..895a76c2c 100644 --- a/RestSharp/Http.cs +++ b/RestSharp/Http.cs @@ -114,7 +114,9 @@ protected bool HasFiles /// /// The System.Net.CookieContainer to be used for the request /// +#if !PocketPC public CookieContainer CookieContainer { get; set; } +#endif /// /// The method to use to write the response instead of reading into RawBytes /// @@ -143,8 +145,9 @@ protected bool HasFiles /// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) /// will be sent along to the server. /// +#if !PocketPC public bool UseDefaultCredentials { get; set; } - +#endif /// /// HTTP headers to be sent with request /// @@ -272,9 +275,12 @@ private void AppendHeaders(HttpWebRequest webRequest) private void AppendCookies(HttpWebRequest webRequest) { +#if !PocketPC webRequest.CookieContainer = this.CookieContainer ?? new CookieContainer(); +#endif foreach (var httpCookie in Cookies) { +#if !PocketPC #if FRAMEWORK var cookie = new Cookie { @@ -291,6 +297,7 @@ private void AppendCookies(HttpWebRequest webRequest) }; var uri = webRequest.RequestUri; webRequest.CookieContainer.Add(new Uri(string.Format("{0}://{1}", uri.Scheme, uri.Host)), cookie); +#endif #endif } } @@ -380,6 +387,7 @@ private void ExtractResponseData(HttpResponse response, HttpWebResponse webRespo response.ResponseUri = webResponse.ResponseUri; response.ResponseStatus = ResponseStatus.Completed; +#if !PocketPC if (webResponse.Cookies != null) { foreach (Cookie cookie in webResponse.Cookies) @@ -402,7 +410,7 @@ private void ExtractResponseData(HttpResponse response, HttpWebResponse webRespo }); } } - +#endif foreach (var headerName in webResponse.Headers.AllKeys) { var headerValue = webResponse.Headers[headerName]; diff --git a/RestSharp/IHttp.cs b/RestSharp/IHttp.cs index b1a26f1df..782b59432 100644 --- a/RestSharp/IHttp.cs +++ b/RestSharp/IHttp.cs @@ -25,7 +25,9 @@ namespace RestSharp public interface IHttp { Action ResponseWriter { get; set; } +#if !PocketPC CookieContainer CookieContainer { get; set; } +#endif ICredentials Credentials { get; set; } /// @@ -43,8 +45,9 @@ public interface IHttp X509CertificateCollection ClientCertificates { get; set; } int? MaxRedirects { get; set; } #endif +#if !PocketPC bool UseDefaultCredentials { get; set; } - +#endif IList Headers { get; } IList Parameters { get; } IList Files { get; } diff --git a/RestSharp/IRestClient.cs b/RestSharp/IRestClient.cs index d00d4e930..0ac41af32 100644 --- a/RestSharp/IRestClient.cs +++ b/RestSharp/IRestClient.cs @@ -33,7 +33,9 @@ public interface IRestClient /// /// /// +#if !PocketPC CookieContainer CookieContainer { get; set; } +#endif /// /// /// diff --git a/RestSharp/RestClient.Async.cs b/RestSharp/RestClient.Async.cs index ce19f7054..721a87757 100644 --- a/RestSharp/RestClient.Async.cs +++ b/RestSharp/RestClient.Async.cs @@ -37,8 +37,11 @@ public partial class RestClient /// Callback function to be executed upon completion providing access to the async handle. public virtual RestRequestAsyncHandle ExecuteAsync(IRestRequest request, Action callback) { - +#if PocketPC + string method = request.Method.ToString(); +#else string method = Enum.GetName(typeof (Method), request.Method); +#endif switch (request.Method) { case Method.PATCH: @@ -84,6 +87,7 @@ private RestRequestAsyncHandle ExecuteAsync(IRestRequest request, Action response_cb = r => ProcessResponse(request, r, asyncHandle, callback); +#if !PocketPC if (UseSynchronizationContext && SynchronizationContext.Current != null) { var ctx = SynchronizationContext.Current; @@ -91,7 +95,7 @@ private RestRequestAsyncHandle ExecuteAsync(IRestRequest request, Action ctx.Post(s => cb(resp), null); } - +#endif asyncHandle.WebRequest = getWebRequest(http, response_cb, httpMethod); return asyncHandle; } diff --git a/RestSharp/RestClient.Sync.cs b/RestSharp/RestClient.Sync.cs index ff889cb93..fc90870f1 100644 --- a/RestSharp/RestClient.Sync.cs +++ b/RestSharp/RestClient.Sync.cs @@ -30,7 +30,11 @@ public byte[] DownloadData(IRestRequest request) /// RestResponse public virtual IRestResponse Execute(IRestRequest request) { +#if PocketPC + var method = request.Method.ToString(); +#else var method = Enum.GetName(typeof(Method), request.Method); +#endif switch (request.Method) { case Method.POST: diff --git a/RestSharp/RestClient.cs b/RestSharp/RestClient.cs index a6f38b37a..9af84a609 100644 --- a/RestSharp/RestClient.cs +++ b/RestSharp/RestClient.cs @@ -32,8 +32,11 @@ namespace RestSharp public partial class RestClient : IRestClient { // silverlight friendly way to get current version +#if PocketPC + static readonly Version version = Assembly.GetExecutingAssembly().GetName().Version; +#else static readonly Version version = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Version; - +#endif public IHttpFactory HttpFactory = new SimpleFactory(); /// @@ -172,7 +175,9 @@ IDeserializer GetHandler(string contentType) /// /// The CookieContainer used for requests made by this client instance /// +#if !PocketPC public CookieContainer CookieContainer { get; set; } +#endif /// /// UserAgent to use for requests made by this client instance @@ -302,11 +307,13 @@ private static string EncodeParameters(IEnumerable parameters) private void ConfigureHttp(IRestRequest request, IHttp http) { http.AlwaysMultipartFormData = request.AlwaysMultipartFormData; +#if !PocketPC http.UseDefaultCredentials = request.UseDefaultCredentials; +#endif http.ResponseWriter = request.ResponseWriter; - +#if !PocketPC http.CookieContainer = CookieContainer; - +#endif // move RestClient.DefaultParameters into Request.Parameters foreach (var p in DefaultParameters) { @@ -319,7 +326,11 @@ private void ConfigureHttp(IRestRequest request, IHttp http) } // Add Accept header based on registered deserializers if none has been set by the caller. +#if PocketPC + if (request.Parameters.All(p2 => p2.Name.ToLower() != "accept")) +#else if (request.Parameters.All(p2 => p2.Name.ToLowerInvariant() != "accept")) +#endif { var accepts = string.Join(", ", AcceptTypes.ToArray()); request.AddParameter("Accept", accepts, ParameterType.HttpHeader); diff --git a/RestSharp/RestSharp.Compact.csproj b/RestSharp/RestSharp.Compact.csproj new file mode 100644 index 000000000..7dcba3d69 --- /dev/null +++ b/RestSharp/RestSharp.Compact.csproj @@ -0,0 +1,160 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {A29E330B-F854-4287-BEB2-C4CBE9D9C637} + Library + Properties + RestSharp.Compact + RestSharp.Compact + {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + PocketPC + 4118C335-430C-497f-BE48-11C3316B135E + 5.1 + RestSharp.Compact + v3.5 + Windows Mobile 5.0 Pocket PC SDK + + + + + true + full + false + bin_compact\Debug\ + TRACE;DEBUG;PocketPC SIMPLE_JSON_NO_LINQ_EXPRESSION + true + true + prompt + 512 + 4 + Off + + + pdbonly + true + bin_compact\Release\ + TRACE;PocketPC SIMPLE_JSON_NO_LINQ_EXPRESSION FRAMEWORK + true + true + prompt + 512 + 4 + Off + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + T4Helper.log + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RestSharp/SharedAssemblyInfo.cs b/RestSharp/SharedAssemblyInfo.cs index fe4183df7..c7f7ed61b 100644 --- a/RestSharp/SharedAssemblyInfo.cs +++ b/RestSharp/SharedAssemblyInfo.cs @@ -26,7 +26,10 @@ // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion(SharedAssembylInfo.Version + ".0")] [assembly: AssemblyInformationalVersion(SharedAssembylInfo.Version)] + +#if !PocketPC [assembly: AssemblyFileVersion(SharedAssembylInfo.Version + ".0")] +#endif class SharedAssembylInfo { diff --git a/RestSharp/SimpleJson.cs b/RestSharp/SimpleJson.cs index aaff60eee..e5fc1066f 100644 --- a/RestSharp/SimpleJson.cs +++ b/RestSharp/SimpleJson.cs @@ -816,9 +816,17 @@ static string ParseString(char[] json, ref int index, ref bool success) { // parse the 32 bit hex into an integer codepoint uint codePoint; + +#if PocketPC + try { + codePoint = UInt32.Parse(new string(json, index, 4), NumberStyles.HexNumber); + } catch (Exception ex) { + return ""; + } +#else if (!(success = UInt32.TryParse(new string(json, index, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out codePoint))) return ""; - +#endif // convert the integer codepoint to a unicode char and add to string if (0xD800 <= codePoint && codePoint <= 0xDBFF) // if high surrogate { @@ -826,8 +834,18 @@ static string ParseString(char[] json, ref int index, ref bool success) remainingLength = json.Length - index; if (remainingLength >= 6) { - uint lowCodePoint; + uint lowCodePoint = 0; + +#if PocketPC + bool lowCodePointPassed = false; + try { + lowCodePoint = UInt32.Parse(new string(json, index + 2, 4), NumberStyles.HexNumber); + lowCodePointPassed = true; + } catch (Exception) { } + if (new string(json, index, 2) == "\\u" && lowCodePointPassed) +#else if (new string(json, index, 2) == "\\u" && UInt32.TryParse(new string(json, index + 2, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out lowCodePoint)) +#endif { if (0xDC00 <= lowCodePoint && lowCodePoint <= 0xDFFF) // if low surrogate { @@ -883,13 +901,33 @@ static object ParseNumber(char[] json, ref int index, ref bool success) if (str.IndexOf(".", StringComparison.OrdinalIgnoreCase) != -1 || str.IndexOf("e", StringComparison.OrdinalIgnoreCase) != -1) { double number; +#if PocketPC + try { + number = double.Parse(new string(json, index, charLength), NumberStyles.Any); + success = true; + } catch (Exception) { + number = 0; + success = false; + } +#else success = double.TryParse(new string(json, index, charLength), NumberStyles.Any, CultureInfo.InvariantCulture, out number); +#endif returnNumber = number; } else { long number; +#if PocketPC + try { + number = long.Parse(new string(json, index, charLength), NumberStyles.Any); + success = true; + } catch (Exception) { + number = 0; + success = false; + } +#else success = long.TryParse(new string(json, index, charLength), NumberStyles.Any, CultureInfo.InvariantCulture, out number); +#endif returnNumber = number; } index = lastIndex + 1; @@ -1304,8 +1342,10 @@ public virtual object DeserializeObject(object value, Type type) { if (type == typeof(DateTime) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTime))) return DateTime.ParseExact(str, Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); +#if !PocketPC if (type == typeof(DateTimeOffset) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTimeOffset))) return DateTimeOffset.ParseExact(str, Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); +#endif if (type == typeof(Guid) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(Guid))) return new Guid(str); return str; @@ -1422,8 +1462,10 @@ protected virtual bool TrySerializeKnownTypes(object input, out object output) bool returnValue = true; if (input is DateTime) output = ((DateTime)input).ToUniversalTime().ToString(Iso8601Format[0], CultureInfo.InvariantCulture); +#if !PocketPC else if (input is DateTimeOffset) output = ((DateTimeOffset)input).ToUniversalTime().ToString(Iso8601Format[0], CultureInfo.InvariantCulture); +#endif else if (input is Guid) output = ((Guid)input).ToString("D"); else if (input is Uri) @@ -1797,7 +1839,7 @@ public static ConstructorDelegate GetConstructorByExpression(Type type, params T public static GetDelegate GetGetMethod(PropertyInfo propertyInfo) { -#if SIMPLE_JSON_NO_LINQ_EXPRESSION +#if SIMPLE_JSON_NO_LINQ_EXPRESSION || PocketPC return GetGetMethodByReflection(propertyInfo); #else return GetGetMethodByExpression(propertyInfo); @@ -1806,7 +1848,7 @@ public static GetDelegate GetGetMethod(PropertyInfo propertyInfo) public static GetDelegate GetGetMethod(FieldInfo fieldInfo) { -#if SIMPLE_JSON_NO_LINQ_EXPRESSION +#if SIMPLE_JSON_NO_LINQ_EXPRESSION || PocketPC return GetGetMethodByReflection(fieldInfo); #else return GetGetMethodByExpression(fieldInfo); @@ -1824,7 +1866,7 @@ public static GetDelegate GetGetMethodByReflection(FieldInfo fieldInfo) return delegate(object source) { return fieldInfo.GetValue(source); }; } -#if !SIMPLE_JSON_NO_LINQ_EXPRESSION +#if !SIMPLE_JSON_NO_LINQ_EXPRESSION && !PocketPC public static GetDelegate GetGetMethodByExpression(PropertyInfo propertyInfo) {