Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
OutSystems Now v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luissilvaos committed Apr 27, 2015
1 parent 6995220 commit 55a4efd
Show file tree
Hide file tree
Showing 1,259 changed files with 259,592 additions and 0 deletions.
17 changes: 17 additions & 0 deletions PushSDK/Classes/JsonHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json.Linq;

namespace PushSDK.Classes
{
internal static class JsonHelpers
{
internal static int GetStatusCode(JObject jRoot)
{
return jRoot.Value<int>("status_code");
}

internal static string GetStatusMessage(JObject jRoot)
{
return jRoot.Value<string>("status_message");
}
}
}
16 changes: 16 additions & 0 deletions PushSDK/Classes/Request/AppEventRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace PushSDK.Classes
{
[JsonObject]
internal class AppEventRequest : BaseRequest
{
[JsonProperty("goal")]
public string Goal { get; set; }

[JsonProperty("count")]
public int Count { get; set; }

public override string GetMethodName() { return "applicationEvent"; }
}
}
10 changes: 10 additions & 0 deletions PushSDK/Classes/Request/AppOpenRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace PushSDK.Classes
{
[JsonObject]
internal class AppOpenRequest : BaseRequest
{
public override string GetMethodName() { return "applicationOpen"; }
}
}
35 changes: 35 additions & 0 deletions PushSDK/Classes/Request/BaseRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace PushSDK.Classes
{
[JsonObject]
internal abstract class BaseRequest
{
[JsonProperty("application")]
public string AppId { get; set; }

// Note: this requires ID_CAP_IDENTITY_DEVICE
// to be added to the capabilities of the WMAppManifest
// this will then warn users in marketplace
[JsonProperty("hwid")]
public string HardwareId
{
get { return SDKHelpers.GetDeviceUniqueId(); }
}

[JsonProperty("v")]
public string SDKVersion
{
//returns SDK version
get { return "2.3"; }
}

[JsonIgnore]
public string ErrorMessage { get; set; }

public virtual void ParseResponse(JObject jRoot) { }

public abstract string GetMethodName();
}
}
16 changes: 16 additions & 0 deletions PushSDK/Classes/Request/GeozoneRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace PushSDK.Classes
{
[JsonObject]
internal class GeozoneRequest : BaseRequest
{
[JsonProperty("lat")]
public double Lat { get; set; }

[JsonProperty("lng")]
public double Lon { get; set; }

public override string GetMethodName() { return "getNearestZone"; }
}
}
19 changes: 19 additions & 0 deletions PushSDK/Classes/Request/GetTagsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace PushSDK.Classes
{
[JsonObject]
internal class GetTagsRequest : BaseRequest
{
[JsonIgnore]
public JObject Tags { get; set; }

public override void ParseResponse(JObject jRoot)
{
Tags = jRoot["response"].Value<JObject>("result");
}

public override string GetMethodName() { return "getTags"; }
}
}
49 changes: 49 additions & 0 deletions PushSDK/Classes/Request/RegistrationRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Threading;
using Newtonsoft.Json;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using System.Text.RegularExpressions;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.ApplicationModel;

namespace PushSDK.Classes
{
[JsonObject]
internal class RegistrationRequest : BaseRequest
{
[JsonProperty("device_type")]
public int DeviceType
{
get { return Constants.DeviceType; }
}

[JsonProperty("push_token")]
public string PushToken { get; set; }

[JsonProperty("language")]
public string Language
{
get { return System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; }
}

[JsonProperty("timezone")]
public double Timezone
{
get { return TimeZoneInfo.Local.BaseUtcOffset.TotalSeconds; }
}

[JsonProperty("app_version")]
public string AppVersion
{
get
{
var version = Package.Current.Id.Version;
return String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
}
}

public override string GetMethodName() { return "registerDevice"; }
}
}
13 changes: 13 additions & 0 deletions PushSDK/Classes/Request/SendBadgeRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace PushSDK.Classes
{
[JsonObject]
internal class SendBadgeRequest : BaseRequest
{
[JsonProperty("badge")]
public int Badge { get; set; }

public override string GetMethodName() { return "setBadge"; }
}
}
25 changes: 25 additions & 0 deletions PushSDK/Classes/Request/SendPurchaseRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace PushSDK.Classes
{
[JsonObject]
internal class SendPurchaseRequest : BaseRequest
{
[JsonProperty("productIdentifier")]
public string ProductIdentifier { get; set; }

[JsonProperty("quantity")]
public int Quantity { get; set; }

[JsonProperty("transactionDate")]
public int DateTimeStamp { get; set; }

[JsonProperty("price")]
public double Price { get; set; }

[JsonProperty("currency")]
public string Currency { get; set; }

public override string GetMethodName() { return "setPurchase"; }
}
}
40 changes: 40 additions & 0 deletions PushSDK/Classes/Request/SetTagsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;

namespace PushSDK.Classes
{
[JsonObject]
internal class SetTagsRequest : BaseRequest
{
[JsonProperty("tags")]
public JObject Tags { get; set; }

public void BuildTags(IEnumerable<KeyValuePair<string, object>> tagList)
{
JObject tags = new JObject();
foreach (var tag in tagList)
{
tags.Add(new JProperty(tag.Key, tag.Value));
}

Tags = tags;
}

public void BuildTags(String[] key, object[] values)
{
JObject tags = new JObject();

int lenght = key.Length >= values.Length ? values.Length : key.Length;
for (int i = 0; i < lenght; i++)
{
tags.Add(new JProperty(key[i], values[i]));
}

Tags = tags;
}

public override string GetMethodName() { return "setTags"; }
}
}
13 changes: 13 additions & 0 deletions PushSDK/Classes/Request/StatisticRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace PushSDK.Classes
{
[JsonObject]
internal class StatisticRequest : BaseRequest
{
[JsonProperty("hash", NullValueHandling = NullValueHandling.Ignore)]
public string Hash { get; set; }

public override string GetMethodName() { return "pushStat"; }
}
}
12 changes: 12 additions & 0 deletions PushSDK/Classes/Request/UnregisterRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Threading;
using Newtonsoft.Json;

namespace PushSDK.Classes
{
[JsonObject]
internal class UnregisterRequest : BaseRequest
{
public override string GetMethodName() { return "unregisterDevice"; }
}
}
100 changes: 100 additions & 0 deletions PushSDK/Classes/SDKHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using Windows.Networking.Connectivity;
using System.Runtime.InteropServices.WindowsRuntime;
using Newtonsoft.Json.Linq;

namespace PushSDK.Classes
{
internal static class SDKHelpers
{
private static string _deviceId;

public static string GetDeviceUniqueId()
{
if (_deviceId == null)
{
try
{
_deviceId = NetworkInformation.GetConnectionProfiles().
Where(p => p.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.ConstrainedInternetAccess).
Select(p => p.NetworkAdapter.NetworkAdapterId).
OrderBy(p => p).First().ToString();
}
catch
{
_deviceId = BitConverter.ToString(Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null).Id.ToArray());
}
}

return _deviceId;
}

internal static ToastPush ParsePushData(String args)
{
try
{
args = System.Net.WebUtility.UrlDecode(args);
args = args.Replace("/PushSDK;component/Controls/PushPage.xaml?", "");

JObject jRoot = JObject.Parse(args);

ToastPush toast = new ToastPush();

if (jRoot["pushwoosh"] == null)
return toast;

jRoot = (JObject)jRoot["pushwoosh"];

if (jRoot["content"] != null)
toast.Content = jRoot["content"].ToString();

if (jRoot["p"] != null)
toast.Hash = jRoot["p"].ToString();

if (jRoot["h"] != null)
toast.HtmlId = jRoot["h"].ToObject<int>();

if (jRoot["data"] != null)
toast.UserData = jRoot["data"].ToString();

try
{
if (jRoot["l"] != null)
toast.Url = new Uri(jRoot["l"].ToString(), UriKind.Absolute);
}
catch { }

return toast;
}
catch { }

return null;
}

private static Dictionary<string,string> ParseQueryString(string s)
{
var list = new Dictionary<string, string>();

// remove anything other than query string from url
if (s.Contains("?"))
{
s = s.Substring(s.IndexOf('?') + 1);
}

foreach (string vp in Regex.Split(s, "&"))
{
string[] singlePair = Regex.Split(vp, "=");
if (singlePair.Length == 2)
list[singlePair[0]] = singlePair[1];
else
// only one key with no value specified in query string
list[singlePair[0]] = string.Empty;
}
return list;
}
}
}
Loading

0 comments on commit 55a4efd

Please sign in to comment.