@@ -96,11 +96,6 @@ protected string XmlEncode(string text)
96
96
97
97
public class WindowsPhoneToastNotification : WindowsPhoneNotification
98
98
{
99
- public WindowsPhoneToastNotification ( )
100
- : base ( )
101
- {
102
- }
103
-
104
99
public string Text1 { get ; set ; }
105
100
public string Text2 { get ; set ; }
106
101
@@ -110,23 +105,23 @@ public WindowsPhoneToastNotification()
110
105
111
106
public override string PayloadToString ( )
112
107
{
113
- var sb = new StringBuilder ( ) ;
108
+ XNamespace wp = "WPNotification" ;
109
+ var notification = new XElement ( wp + "Notification" , new XAttribute ( XNamespace . Xmlns + "wp" , "WPNotification" ) ) ;
114
110
115
- sb . AppendLine ( "<?xml version=\" 1.0\" encoding=\" utf-8\" ?>" ) ;
116
- sb . AppendLine ( "<wp:Notification xmlns:wp=\" WPNotification\" >" ) ;
117
- sb . AppendLine ( "<wp:Toast>" ) ;
111
+ var toast = new XElement ( wp + "Toast" ) ;
118
112
119
113
if ( ! string . IsNullOrEmpty ( Text1 ) )
120
- sb . AppendLine ( "<wp:Text1>" + XmlEncode ( Text1 ) + "</wp: Text1>" ) ;
114
+ toast . Add ( new XElement ( wp + "Text1" , XmlEncode ( Text1 ) ) ) ;
121
115
122
116
if ( ! string . IsNullOrEmpty ( Text2 ) )
123
- sb . AppendLine ( "<wp:Text2>" + XmlEncode ( Text2 ) + "</wp:Text2>" ) ;
124
-
117
+ toast . Add ( new XElement ( wp + "Text2" , XmlEncode ( Text2 ) ) ) ;
118
+
119
+
125
120
if ( this . OSVersion > WindowsPhoneDeviceOSVersion . Seven )
126
121
{
127
122
if ( ! string . IsNullOrEmpty ( NavigatePath ) || ( Parameters != null && Parameters . Count > 0 ) )
128
123
{
129
- sb . Append ( "<wp:Param>" ) ;
124
+ var sb = new StringBuilder ( ) ;
130
125
131
126
if ( ! string . IsNullOrEmpty ( NavigatePath ) )
132
127
sb . Append ( XmlEncode ( "/" + NavigatePath . TrimStart ( '/' ) ) ) ;
@@ -139,25 +134,20 @@ public override string PayloadToString()
139
134
sb . Append ( XmlEncode ( key + "=" + Parameters [ key ] . ToString ( ) ) + "&" ) ;
140
135
}
141
136
142
- sb . AppendLine ( "</wp:Param>" ) ;
137
+ var paramValue = sb . ToString ( ) ;
138
+
139
+ if ( ! string . IsNullOrEmpty ( paramValue ) )
140
+ toast . Add ( new XElement ( wp + "Param" , paramValue ) ) ;
143
141
}
144
142
}
145
143
146
- sb . AppendLine ( "</wp:Toast>" ) ;
147
- sb . AppendLine ( "</wp:Notification>" ) ;
148
-
149
- return sb . ToString ( ) ;
144
+ notification . Add ( toast ) ;
145
+ return notification . ToString ( ) ;
150
146
}
151
147
}
152
148
153
149
public class WindowsPhoneRawNotification : WindowsPhoneNotification
154
150
{
155
- public WindowsPhoneRawNotification ( )
156
- : base ( )
157
- {
158
- }
159
-
160
-
161
151
public string Raw { get ; set ; }
162
152
163
153
public override string PayloadToString ( )
@@ -168,11 +158,6 @@ public override string PayloadToString()
168
158
169
159
public class WindowsPhoneTileNotification : WindowsPhoneNotification
170
160
{
171
- public WindowsPhoneTileNotification ( )
172
- : base ( )
173
- {
174
- }
175
-
176
161
public string TileId { get ; set ; } //Secondary tile id, leave blank for application tile
177
162
178
163
public string BackgroundImage { get ; set ; }
@@ -194,56 +179,48 @@ public WindowsPhoneTileNotification()
194
179
195
180
public override string PayloadToString ( )
196
181
{
197
- var sb = new StringBuilder ( ) ;
198
-
199
- sb . AppendLine ( "<?xml version=\" 1.0\" encoding=\" utf-8\" ?>" ) ;
200
- sb . AppendLine ( "<wp:Notification xmlns:wp=\" WPNotification\" >" ) ;
201
-
202
- sb . Append ( "<wp:Tile" ) ;
203
-
204
- if ( this . OSVersion > WindowsPhoneDeviceOSVersion . Seven )
205
- {
206
- if ( ! string . IsNullOrEmpty ( this . TileId ) )
207
- sb . Append ( " Id=\" " + XmlEncode ( this . TileId ) + "\" " ) ;
208
- }
182
+ XNamespace wp = "WPNotification" ;
183
+ var notification = new XElement ( wp + "Notification" , new XAttribute ( XNamespace . Xmlns + "wp" , "WPNotification" ) ) ;
209
184
210
- sb . AppendLine ( ">" ) ;
185
+ var tile = new XElement ( wp + "Tile" ) ;
186
+
187
+ if ( this . OSVersion > WindowsPhoneDeviceOSVersion . Seven && ! string . IsNullOrEmpty ( this . TileId ) )
188
+ tile . Add ( new XAttribute ( "Id" , XmlEncode ( this . TileId ) ) ) ;
211
189
212
190
if ( ! string . IsNullOrEmpty ( BackgroundImage ) )
213
- sb . AppendLine ( "<wp:BackgroundImage>" + XmlEncode ( this . BackgroundImage ) + "</wp: BackgroundImage>" ) ;
214
-
191
+ tile . Add ( new XElement ( wp + "BackgroundImage" , XmlEncode ( BackgroundImage ) ) ) ;
192
+
215
193
if ( ClearCount )
216
- sb . AppendLine ( "<wp: Count Action= \" Clear\" ></wp:Count>" ) ;
194
+ tile . Add ( new XElement ( wp + " Count" , new XAttribute ( " Action" , " Clear" ) ) ) ;
217
195
else if ( Count . HasValue )
218
- sb . AppendLine ( "<wp:Count>" + Count . ToString ( ) + "</wp:Count>" ) ;
196
+ tile . Add ( new XElement ( wp + " Count" , XmlEncode ( Count . ToString ( ) ) ) ) ;
219
197
220
198
if ( ClearTitle )
221
- sb . AppendLine ( "<wp: Title Action= \" Clear\" ></wp:Title>" ) ;
199
+ tile . Add ( new XElement ( wp + " Title" , new XAttribute ( " Action" , " Clear" ) ) ) ;
222
200
else if ( ! string . IsNullOrEmpty ( Title ) )
223
- sb . AppendLine ( "<wp:Title>" + XmlEncode ( Title ) + "</wp: Title>" ) ;
224
-
225
- if ( this . OSVersion > WindowsPhoneDeviceOSVersion . Seven )
201
+ tile . Add ( new XElement ( wp + "Title" , XmlEncode ( Title ) ) ) ;
202
+
203
+ if ( OSVersion > WindowsPhoneDeviceOSVersion . Seven )
226
204
{
227
- if ( ClearBackBackgroundImage )
228
- sb . AppendLine ( "<wp:BackBackgroundImage Action=\" Clear\" ></wp:BackBackgroundImage>" ) ;
229
- else if ( ! string . IsNullOrEmpty ( BackBackgroundImage ) )
230
- sb . AppendLine ( "<wp:BackBackgroundImage>" + XmlEncode ( BackBackgroundImage ) + "</wp:BackBackgroundImage>" ) ;
231
-
232
205
if ( ClearBackTitle )
233
- sb . AppendLine ( "<wp:BackTitle Action=\" Clear\" ></wp:BackTitle>" ) ;
234
- else if ( ! string . IsNullOrEmpty ( BackTitle ) )
235
- sb . AppendLine ( "<wp:BackTitle>" + XmlEncode ( BackTitle ) + "</wp:BackTitle>" ) ;
206
+ tile . Add ( new XElement ( wp + "BackTitle" , new XAttribute ( "Action" , "Clear" ) ) ) ;
207
+ else if ( ! string . IsNullOrEmpty ( Title ) )
208
+ tile . Add ( new XElement ( wp + "BackTitle" , XmlEncode ( BackTitle ) ) ) ;
209
+
210
+ if ( ClearBackBackgroundImage )
211
+ tile . Add ( new XElement ( wp + "BackBackgroundImage" , new XAttribute ( "Action" , "Clear" ) ) ) ;
212
+ else if ( ! string . IsNullOrEmpty ( Title ) )
213
+ tile . Add ( new XElement ( wp + "BackBackgroundImage" , XmlEncode ( BackBackgroundImage ) ) ) ;
236
214
237
215
if ( ClearBackContent )
238
- sb . AppendLine ( "<wp:BackContent Action=\" Clear\" ></wp:BackContent>" ) ;
239
- else if ( ! string . IsNullOrEmpty ( BackContent ) )
240
- sb . AppendLine ( "<wp:BackContent>" + XmlEncode ( BackContent ) + "</wp:BackContent>" ) ;
216
+ tile . Add ( new XElement ( wp + "BackContent" , new XAttribute ( "Action" , "Clear" ) ) ) ;
217
+ else if ( ! string . IsNullOrEmpty ( Title ) )
218
+ tile . Add ( new XElement ( wp + "BackContent" , XmlEncode ( BackContent ) ) ) ;
219
+
241
220
}
242
221
243
- sb . AppendLine ( "</wp:Tile>" ) ;
244
- sb . AppendLine ( "</wp:Notification>" ) ;
245
-
246
- return sb . ToString ( ) ;
222
+ notification . Add ( tile ) ;
223
+ return notification . ToString ( ) ;
247
224
}
248
225
}
249
226
@@ -473,8 +450,7 @@ public override string PayloadToString()
473
450
tile . Add ( new XElement ( wp + "Count" , new XAttribute ( "Action" , "Clear" ) ) ) ;
474
451
else if ( Count . HasValue )
475
452
tile . Add ( new XElement ( wp + "Count" , XmlEncode ( Count . Value . ToString ( ) ) ) ) ;
476
-
477
-
453
+
478
454
if ( ClearCycleImage1 )
479
455
tile . Add ( new XElement ( wp + "CycleImage1" , new XAttribute ( "Action" , "Clear" ) ) ) ;
480
456
else if ( ! string . IsNullOrEmpty ( Title ) )
@@ -520,7 +496,6 @@ public override string PayloadToString()
520
496
else if ( ! string . IsNullOrEmpty ( Title ) )
521
497
tile . Add ( new XElement ( wp + "CycleImage9" , XmlEncode ( CycleImage9 ) ) ) ;
522
498
523
-
524
499
notification . Add ( tile ) ;
525
500
526
501
return notification . ToString ( ) ;
0 commit comments