internal static Tuple <HttpStatusCode, IDictionary <string, object> > ReponseResolve(Tuple <HttpStatusCode, string> response, CancellationToken cancellationToken) { Tuple <HttpStatusCode, string> result = response; HttpStatusCode code = result.Item1; string item2 = result.Item2; if (item2 == null) { cancellationToken.ThrowIfCancellationRequested(); return(new Tuple <HttpStatusCode, IDictionary <string, object> >(code, null)); } IDictionary <string, object> strs = null; try { strs = (!item2.StartsWith("[") ? AVClient.DeserializeJsonString(item2) : new Dictionary <string, object>() { { "results", Json.Parse(item2) } }); } catch (Exception exception) { throw new AVException(AVException.ErrorCode.OtherCause, "Invalid response from server", exception); } var codeValue = (int)code; if (codeValue > 203 || codeValue < 200) { throw new AVException((AVException.ErrorCode)((int)((strs.ContainsKey("code") ? (long)strs["code"] : (long)-1))), (strs.ContainsKey("error") ? strs["error"] as string : item2), null); } cancellationToken.ThrowIfCancellationRequested(); return(new Tuple <HttpStatusCode, IDictionary <string, object> >(code, strs)); }
static AVPush() { PlatformHooks.GetToastChannelTask.ContinueWith(t => { if (t.Result != null) { t.Result.ShellToastNotificationReceived += (sender, args) => { toastNotificationReceived.Invoke(AVInstallation.CurrentInstallation, args); var payload = PushJson(args); parsePushNotificationReceived.Invoke(AVInstallation.CurrentInstallation, new AVPushNotificationEventArgs(payload)); }; t.Result.HttpNotificationReceived += (sender, args) => { pushNotificationReceived.Invoke(AVInstallation.CurrentInstallation, args); // TODO (hallucinogen): revisit this since we haven't officially support this yet. var payloadStream = args.Notification.Body; var streamReader = new StreamReader(payloadStream); var payloadString = streamReader.ReadToEnd(); // Always assume it's a JSON payload. var payload = AVClient.DeserializeJsonString(payloadString); parsePushNotificationReceived.Invoke(AVInstallation.CurrentInstallation, new AVPushNotificationEventArgs(payload)); }; } }); }
private static IDictionary <string, object> PushJson(string jsonString) { try { return(AVClient.DeserializeJsonString(jsonString) ?? new Dictionary <string, object>()); } catch (Exception) { return(new Dictionary <string, object>()); } }
private SettingsWrapper() { if (string.IsNullOrEmpty(Settings.Default.ApplicationSettings)) { data = new Dictionary <string, object>(); Save(); } else { data = AVClient.DeserializeJsonString(Settings.Default.ApplicationSettings); } }
internal static IDictionary <string, object> PushJson(string uri) { var queryTokens = uri.Substring(uri.LastIndexOf('?') + 1).Split('&'); foreach (var token in queryTokens) { if (token.StartsWith("pushJson=")) { var rawValue = token.Substring("pushJson=".Length); var decoded = HttpUtility.UrlDecode(rawValue); return(AVClient.DeserializeJsonString(decoded)); } } return(new Dictionary <string, object>()); }
// Obj-C type -> .NET type is impossible to do flawlessly (especially // on NSNumber). We can't transform NSDictionary into string because of this reason. #if !IOS internal AVPushNotificationEventArgs(string stringPayload) { StringPayload = stringPayload; Payload = AVClient.DeserializeJsonString(stringPayload); }