Skip to content

Commit 1467866

Browse files
committed
Added FlipTile, IconicTile, and CycleTile Templates to Windows Phone
1 parent 290024e commit 1467866

File tree

3 files changed

+781
-22
lines changed

3 files changed

+781
-22
lines changed

Diff for: PushSharp.WindowsPhone/WindowsPhoneNotification.cs

+296
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Xml.Linq;
6+
using System.Xml.Schema;
67

78
namespace PushSharp.WindowsPhone
89
{
@@ -43,6 +44,21 @@ public WindowsPhoneToastNotification Toast()
4344
{
4445
return new WindowsPhoneToastNotification();
4546
}
47+
48+
public WindowsPhoneCycleTile CycleTile()
49+
{
50+
return new WindowsPhoneCycleTile();
51+
}
52+
53+
public WindowsPhoneFlipTile FlipTile()
54+
{
55+
return new WindowsPhoneFlipTile();
56+
}
57+
58+
public WindowsPhoneIconicTile IconicTile()
59+
{
60+
return new WindowsPhoneIconicTile();
61+
}
4662
}
4763

4864
public abstract class WindowsPhoneNotification : Common.Notification
@@ -230,4 +246,284 @@ public override string PayloadToString()
230246
return sb.ToString();
231247
}
232248
}
249+
250+
public class WindowsPhoneFlipTile : WindowsPhoneNotification
251+
{
252+
public string Title { get; set; }
253+
public bool ClearTitle { get; set; }
254+
255+
public string BackTitle { get; set; }
256+
public bool ClearBackTitle { get; set; }
257+
258+
public string BackContent { get; set; }
259+
public bool ClearBackContent { get; set; }
260+
261+
public string WideBackContent { get; set; }
262+
public bool ClearWideBackContent { get; set; }
263+
264+
public int? Count { get; set; }
265+
public bool ClearCount { get; set; }
266+
267+
public string SmallBackgroundImage { get; set; }
268+
public bool ClearSmallBackgroundImage { get; set; }
269+
270+
public string BackgroundImage { get; set; }
271+
public bool ClearBackgroundImage { get; set; }
272+
273+
public string BackBackgroundImage { get; set; }
274+
public bool ClearBackBackgroundImage { get; set; }
275+
276+
public string WideBackgroundImage { get; set; }
277+
public bool ClearWideBackgroundImage { get; set; }
278+
279+
public string WideBackBackgroundImage { get; set; }
280+
public bool ClearWideBackBackgroundImage { get; set; }
281+
282+
public override string PayloadToString()
283+
{
284+
XNamespace wp = "WPNotification";
285+
var notification = new XElement(wp + "Notification", new XAttribute(XNamespace.Xmlns + "wp", "WPNotification"));
286+
287+
var tile = new XElement(wp + "Tile", new XAttribute("Template", "FlipTile"));
288+
289+
if (ClearTitle)
290+
tile.Add(new XElement(wp + "Title", new XAttribute("Action", "Clear")));
291+
else if (!string.IsNullOrEmpty(Title))
292+
tile.Add(new XElement(wp + "Title", XmlEncode(Title)));
293+
294+
if (ClearBackTitle)
295+
tile.Add(new XElement(wp + "BackTitle", new XAttribute("Action", "Clear")));
296+
else if (!string.IsNullOrEmpty(Title))
297+
tile.Add(new XElement(wp + "BackTitle", XmlEncode(BackTitle)));
298+
299+
if (ClearBackContent)
300+
tile.Add(new XElement(wp + "BackContent", new XAttribute("Action", "Clear")));
301+
else if (!string.IsNullOrEmpty(Title))
302+
tile.Add(new XElement(wp + "BackContent", XmlEncode(BackContent)));
303+
304+
if (ClearWideBackContent)
305+
tile.Add(new XElement(wp + "WideBackContent", new XAttribute("Action", "Clear")));
306+
else if (!string.IsNullOrEmpty(Title))
307+
tile.Add(new XElement(wp + "WideBackContent", XmlEncode(WideBackContent)));
308+
309+
if (ClearCount)
310+
tile.Add(new XElement(wp + "Count", new XAttribute("Action", "Clear")));
311+
else if (Count.HasValue)
312+
tile.Add(new XElement(wp + "Count", XmlEncode(Count.Value.ToString())));
313+
314+
if (ClearSmallBackgroundImage)
315+
tile.Add(new XElement(wp + "SmallBackgroundImage", new XAttribute("Action", "Clear")));
316+
else if (!string.IsNullOrEmpty(Title))
317+
tile.Add(new XElement(wp + "SmallBackgroundImage", XmlEncode(SmallBackgroundImage)));
318+
319+
if (ClearBackgroundImage)
320+
tile.Add(new XElement(wp + "BackgroundImage", new XAttribute("Action", "Clear")));
321+
else if (!string.IsNullOrEmpty(Title))
322+
tile.Add(new XElement(wp + "BackgroundImage", XmlEncode(BackgroundImage)));
323+
324+
if (ClearBackBackgroundImage)
325+
tile.Add(new XElement(wp + "BackBackgroundImage", new XAttribute("Action", "Clear")));
326+
else if (!string.IsNullOrEmpty(Title))
327+
tile.Add(new XElement(wp + "BackBackgroundImage", XmlEncode(BackBackgroundImage)));
328+
329+
if (ClearWideBackgroundImage)
330+
tile.Add(new XElement(wp + "WideBackgroundImage", new XAttribute("Action", "Clear")));
331+
else if (!string.IsNullOrEmpty(Title))
332+
tile.Add(new XElement(wp + "WideBackgroundImage", XmlEncode(WideBackgroundImage)));
333+
334+
if (ClearWideBackBackgroundImage)
335+
tile.Add(new XElement(wp + "WideBackBackgroundImage", new XAttribute("Action", "Clear")));
336+
else if (!string.IsNullOrEmpty(Title))
337+
tile.Add(new XElement(wp + "WideBackBackgroundImage", XmlEncode(WideBackBackgroundImage)));
338+
339+
notification.Add(tile);
340+
341+
return notification.ToString();
342+
}
343+
}
344+
345+
public class WindowsPhoneIconicTile : WindowsPhoneNotification
346+
{
347+
public string Title { get; set; }
348+
public bool ClearTitle { get; set; }
349+
350+
public string WideContent1 { get; set; }
351+
public bool ClearWideContent1 { get; set; }
352+
353+
public string WideContent2 { get; set; }
354+
public bool ClearWideContent2 { get; set; }
355+
356+
public string WideContent3 { get; set; }
357+
public bool ClearWideContent3 { get; set; }
358+
359+
public int? Count { get; set; }
360+
public bool ClearCount { get; set; }
361+
362+
public string SmallIconImage { get; set; }
363+
public bool ClearSmallIconImage { get; set; }
364+
365+
public string IconImage { get; set; }
366+
public bool ClearIconImage { get; set; }
367+
368+
public string BackgroundColor { get; set; }
369+
public bool ClearBackgroundColor { get; set; }
370+
371+
372+
public override string PayloadToString()
373+
{
374+
XNamespace wp = "WPNotification";
375+
var notification = new XElement(wp + "Notification", new XAttribute(XNamespace.Xmlns + "wp", "WPNotification"));
376+
377+
var tile = new XElement(wp + "Tile", new XAttribute("Template", "FlipTile"));
378+
379+
if (ClearTitle)
380+
tile.Add(new XElement(wp + "Title", new XAttribute("Action", "Clear")));
381+
else if (!string.IsNullOrEmpty(Title))
382+
tile.Add(new XElement(wp + "Title", XmlEncode(Title)));
383+
384+
if (ClearWideContent1)
385+
tile.Add(new XElement(wp + "WideContent1", new XAttribute("Action", "Clear")));
386+
else if (!string.IsNullOrEmpty(Title))
387+
tile.Add(new XElement(wp + "WideContent1", XmlEncode(WideContent1)));
388+
389+
if (ClearWideContent2)
390+
tile.Add(new XElement(wp + "WideContent2", new XAttribute("Action", "Clear")));
391+
else if (!string.IsNullOrEmpty(Title))
392+
tile.Add(new XElement(wp + "WideContent2", XmlEncode(WideContent2)));
393+
394+
if (ClearWideContent3)
395+
tile.Add(new XElement(wp + "WideContent3", new XAttribute("Action", "Clear")));
396+
else if (!string.IsNullOrEmpty(Title))
397+
tile.Add(new XElement(wp + "WideContent3", XmlEncode(WideContent3)));
398+
399+
if (ClearCount)
400+
tile.Add(new XElement(wp + "Count", new XAttribute("Action", "Clear")));
401+
else if (Count.HasValue)
402+
tile.Add(new XElement(wp + "Count", XmlEncode(Count.Value.ToString())));
403+
404+
if (ClearSmallIconImage)
405+
tile.Add(new XElement(wp + "SmallIconImage", new XAttribute("Action", "Clear")));
406+
else if (!string.IsNullOrEmpty(Title))
407+
tile.Add(new XElement(wp + "SmallIconImage", XmlEncode(SmallIconImage)));
408+
409+
if (ClearIconImage)
410+
tile.Add(new XElement(wp + "IconImage", new XAttribute("Action", "Clear")));
411+
else if (!string.IsNullOrEmpty(Title))
412+
tile.Add(new XElement(wp + "IconImage", XmlEncode(IconImage)));
413+
414+
if (ClearBackgroundColor)
415+
tile.Add(new XElement(wp + "BackgroundColor", new XAttribute("Action", "Clear")));
416+
else if (!string.IsNullOrEmpty(Title))
417+
tile.Add(new XElement(wp + "BackgroundColor", XmlEncode(BackgroundColor)));
418+
419+
notification.Add(tile);
420+
421+
return notification.ToString();
422+
}
423+
}
424+
425+
public class WindowsPhoneCycleTile : WindowsPhoneNotification
426+
{
427+
public string Title { get; set; }
428+
public bool ClearTitle { get; set; }
429+
430+
public int? Count { get; set; }
431+
public bool ClearCount { get; set; }
432+
433+
public string CycleImage1 { get; set; }
434+
public bool ClearCycleImage1 { get; set; }
435+
436+
public string CycleImage2 { get; set; }
437+
public bool ClearCycleImage2 { get; set; }
438+
439+
public string CycleImage3 { get; set; }
440+
public bool ClearCycleImage3 { get; set; }
441+
442+
public string CycleImage4 { get; set; }
443+
public bool ClearCycleImage4 { get; set; }
444+
445+
public string CycleImage5 { get; set; }
446+
public bool ClearCycleImage5 { get; set; }
447+
448+
public string CycleImage6 { get; set; }
449+
public bool ClearCycleImage6 { get; set; }
450+
451+
public string CycleImage7 { get; set; }
452+
public bool ClearCycleImage7 { get; set; }
453+
454+
public string CycleImage8 { get; set; }
455+
public bool ClearCycleImage8 { get; set; }
456+
457+
public string CycleImage9 { get; set; }
458+
public bool ClearCycleImage9 { get; set; }
459+
460+
public override string PayloadToString()
461+
{
462+
XNamespace wp = "WPNotification";
463+
var notification = new XElement(wp + "Notification", new XAttribute(XNamespace.Xmlns + "wp", "WPNotification"));
464+
465+
var tile = new XElement(wp + "Tile", new XAttribute("Template", "FlipTile"));
466+
467+
if (ClearTitle)
468+
tile.Add(new XElement(wp + "Title", new XAttribute("Action", "Clear")));
469+
else if (!string.IsNullOrEmpty(Title))
470+
tile.Add(new XElement(wp + "Title", XmlEncode(Title)));
471+
472+
if (ClearCount)
473+
tile.Add(new XElement(wp + "Count", new XAttribute("Action", "Clear")));
474+
else if (Count.HasValue)
475+
tile.Add(new XElement(wp + "Count", XmlEncode(Count.Value.ToString())));
476+
477+
478+
if (ClearCycleImage1)
479+
tile.Add(new XElement(wp + "CycleImage1", new XAttribute("Action", "Clear")));
480+
else if (!string.IsNullOrEmpty(Title))
481+
tile.Add(new XElement(wp + "CycleImage1", XmlEncode(CycleImage1)));
482+
483+
if (ClearCycleImage2)
484+
tile.Add(new XElement(wp + "CycleImage2", new XAttribute("Action", "Clear")));
485+
else if (!string.IsNullOrEmpty(Title))
486+
tile.Add(new XElement(wp + "CycleImage2", XmlEncode(CycleImage2)));
487+
488+
if (ClearCycleImage3)
489+
tile.Add(new XElement(wp + "CycleImage3", new XAttribute("Action", "Clear")));
490+
else if (!string.IsNullOrEmpty(Title))
491+
tile.Add(new XElement(wp + "CycleImage3", XmlEncode(CycleImage3)));
492+
493+
if (ClearCycleImage4)
494+
tile.Add(new XElement(wp + "CycleImage4", new XAttribute("Action", "Clear")));
495+
else if (!string.IsNullOrEmpty(Title))
496+
tile.Add(new XElement(wp + "CycleImage4", XmlEncode(CycleImage4)));
497+
498+
if (ClearCycleImage5)
499+
tile.Add(new XElement(wp + "CycleImage5", new XAttribute("Action", "Clear")));
500+
else if (!string.IsNullOrEmpty(Title))
501+
tile.Add(new XElement(wp + "CycleImage5", XmlEncode(CycleImage5)));
502+
503+
if (ClearCycleImage6)
504+
tile.Add(new XElement(wp + "CycleImage6", new XAttribute("Action", "Clear")));
505+
else if (!string.IsNullOrEmpty(Title))
506+
tile.Add(new XElement(wp + "CycleImage6", XmlEncode(CycleImage6)));
507+
508+
if (ClearCycleImage7)
509+
tile.Add(new XElement(wp + "CycleImage7", new XAttribute("Action", "Clear")));
510+
else if (!string.IsNullOrEmpty(Title))
511+
tile.Add(new XElement(wp + "CycleImage7", XmlEncode(CycleImage7)));
512+
513+
if (ClearCycleImage8)
514+
tile.Add(new XElement(wp + "CycleImage8", new XAttribute("Action", "Clear")));
515+
else if (!string.IsNullOrEmpty(Title))
516+
tile.Add(new XElement(wp + "CycleImage8", XmlEncode(CycleImage8)));
517+
518+
if (ClearCycleImage9)
519+
tile.Add(new XElement(wp + "CycleImage9", new XAttribute("Action", "Clear")));
520+
else if (!string.IsNullOrEmpty(Title))
521+
tile.Add(new XElement(wp + "CycleImage9", XmlEncode(CycleImage9)));
522+
523+
524+
notification.Add(tile);
525+
526+
return notification.ToString();
527+
}
528+
}
233529
}

Diff for: PushSharp.WindowsPhone/WindowsPhonePushChannel.cs

+22-22
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,35 @@ protected override void SendNotification(Notification notification)
3030
wr.ContentType = "text/xml";
3131
wr.Method = "POST";
3232

33+
var immediateValue = 3;
34+
var mediumValue = 13;
35+
var slowValue = 23;
36+
37+
if (wpNotification is WindowsPhoneToastNotification)
38+
{
39+
immediateValue = 2;
40+
mediumValue = 12;
41+
slowValue = 22;
42+
}
43+
else if (wpNotification is WindowsPhoneTileNotification)
44+
{
45+
immediateValue = 1;
46+
mediumValue = 11;
47+
slowValue = 21;
48+
}
49+
50+
var val = immediateValue;
51+
3352
if (wpNotification.NotificationClass.HasValue)
3453
{
35-
var immediateValue = 3;
36-
var mediumValue = 13;
37-
var slowValue = 23;
38-
39-
if (wpNotification is WindowsPhoneToastNotification)
40-
{
41-
immediateValue = 2;
42-
mediumValue = 12;
43-
slowValue = 22;
44-
}
45-
else if (wpNotification is WindowsPhoneTileNotification)
46-
{
47-
immediateValue = 1;
48-
mediumValue = 11;
49-
slowValue = 21;
50-
}
51-
52-
var val = immediateValue;
5354
if (wpNotification.NotificationClass.Value == BatchingInterval.Medium)
5455
val = mediumValue;
5556
else if (wpNotification.NotificationClass.Value == BatchingInterval.Slow)
5657
val = slowValue;
57-
58-
wr.Headers.Add("X-NotificationClass", val.ToString());
5958
}
60-
61-
59+
60+
wr.Headers.Add("X-NotificationClass", val.ToString());
61+
6262
if (wpNotification is WindowsPhoneToastNotification)
6363
wr.Headers.Add("X-WindowsPhone-Target", "toast");
6464
else if (wpNotification is WindowsPhoneTileNotification)

0 commit comments

Comments
 (0)