/// <summary> /// Find type from xml string, and it should set to WnsHeaders["X-WNS-Type"]; /// If the header already there, this function won't overwrite. /// </summary> private static void SetWnsType(this WindowsTemplateRegistrationDescription registration) { if (registration == null || registration.IsJsonObjectPayLoad()) { return; } if (registration.IsXmlPayLoad()) { if (registration.WnsHeaders == null) { registration.WnsHeaders = new WnsHeaderCollection(); } if (registration.WnsHeaders.ContainsKey(WindowsRegistrationDescription.Type) && registration.WnsHeaders[WindowsRegistrationDescription.Type].Equals(WindowsRegistrationDescription.Raw, StringComparison.OrdinalIgnoreCase)) { try { XmlDocument xmlPayload = new XmlDocument(); using (var reader = XmlTextReader.Create(new StringReader(registration.BodyTemplate))) { xmlPayload.Load(reader); } } catch (XmlException) { throw new ArgumentException(SRClient.NotSupportedXMLFormatAsBodyTemplate); } } else { switch (DetectWindowsTemplateRegistationType(registration.BodyTemplate, SRClient.NotSupportedXMLFormatAsBodyTemplate)) { case WindowsTemplateBodyType.Toast: AddOrUpdateHeader(registration.WnsHeaders, WindowsRegistrationDescription.Type, WindowsRegistrationDescription.Toast); break; case WindowsTemplateBodyType.Tile: AddOrUpdateHeader(registration.WnsHeaders, WindowsRegistrationDescription.Type, WindowsRegistrationDescription.Tile); break; case WindowsTemplateBodyType.Badge: AddOrUpdateHeader(registration.WnsHeaders, WindowsRegistrationDescription.Type, WindowsRegistrationDescription.Badge); break; default: break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="T:Microsoft.Azure.NotificationHubs.WindowsTemplateRegistrationDescription"/> class. /// </summary> /// <param name="sourceRegistration">The source registration.</param> public WindowsTemplateRegistrationDescription(WindowsTemplateRegistrationDescription sourceRegistration) : base(sourceRegistration) { this.WnsHeaders = new WnsHeaderCollection(); if (sourceRegistration.WnsHeaders != null) { foreach (var header in sourceRegistration.WnsHeaders) { this.WnsHeaders.Add(header.Key, header.Value); } } this.BodyTemplate = sourceRegistration.BodyTemplate; this.TemplateName = sourceRegistration.TemplateName; }