Commit 4abccaf3 by Sebastián Katzer

Serialize/Deserialize trigger option on windows

parent cbdcee1b
......@@ -393,14 +393,17 @@ exports.cloneAll = function (objs) {
*/
exports.clone = function (obj) {
var ignore = ['action'],
dclone = ['trigger'],
clone = {};
if (obj === null) return null;
for (var prop in obj) {
if (ignore.includes(prop) || typeof obj[prop] === 'function')
continue;
try {
clone[prop] = obj[prop];
clone[prop] = dclone.includes(prop) ? exports.clone(obj[prop]) : obj[prop];
} catch (e) {
clone[prop] = null;
}
......
......@@ -105,6 +105,7 @@ namespace LocalNotificationProxy.LocalNotification
options.Id = int.Parse(node.GetAttribute("id"));
options.Badge = int.Parse(node.GetAttribute("badge"));
options.Trigger = Trigger.Parse(node.GetAttribute("trigger"));
if (node.GetAttributeNode("text") != null)
{
......@@ -169,6 +170,7 @@ namespace LocalNotificationProxy.LocalNotification
node.SetAttribute("id", this.Id.ToString());
node.SetAttribute("badge", this.Badge.ToString());
node.SetAttribute("trigger", this.Trigger.GetXml());
if (this.Title != null)
{
......
......@@ -19,6 +19,8 @@
* limitations under the License.
*/
using Windows.Data.Xml.Dom;
namespace LocalNotificationProxy.LocalNotification
{
public sealed class Trigger
......@@ -52,5 +54,52 @@ namespace LocalNotificationProxy.LocalNotification
/// Gets or sets trigger interval.
/// </summary>
public string Every { get; set; }
/// <summary>
/// Deserializes the XML string into an instance of Trigger.
/// </summary>
/// <param name="xml">The serialized instance of Options as an xml string.</param>
/// <returns>An instance where all properties have been assigned.</returns>
internal static Trigger Parse(string xml)
{
var doc = new XmlDocument();
doc.LoadXml(xml);
var trigger = new Trigger();
var node = doc.DocumentElement;
trigger.At = long.Parse(node.GetAttribute("at"));
trigger.In = long.Parse(node.GetAttribute("in"));
trigger.Count = int.Parse(node.GetAttribute("count"));
trigger.Occurrence = int.Parse(node.GetAttribute("occurrence"));
if (node.GetAttributeNode("every") != null)
{
trigger.Every = node.GetAttribute("every");
}
return trigger;
}
/// <summary>
/// Gets the instance as an serialized xml element.
/// </summary>
/// <returns>Element with all property values set as attributes.</returns>
internal string GetXml()
{
var node = new XmlDocument().CreateElement("trigger");
node.SetAttribute("at", this.At.ToString());
node.SetAttribute("in", this.In.ToString());
node.SetAttribute("count", this.Count.ToString());
node.SetAttribute("occurrence", this.Occurrence.ToString());
if (this.Every != null)
{
node.SetAttribute("every", this.Every);
}
return node.GetXml();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment