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("X-WNS-Type") || !registration.WnsHeaders["X-WNS-Type"].Equals("wns/raw", StringComparison.OrdinalIgnoreCase))
                {
                    switch (RegistrationSDKHelper.DetectWindowsTemplateRegistationType(registration.BodyTemplate, SRClient.NotSupportedXMLFormatAsBodyTemplate))
                    {
                    case WindowsTemplateBodyType.Toast:
                    {
                        RegistrationSDKHelper.AddOrUpdateHeader(registration.WnsHeaders, "X-WNS-Type", "wns/toast");
                        return;
                    }

                    case WindowsTemplateBodyType.Tile:
                    {
                        RegistrationSDKHelper.AddOrUpdateHeader(registration.WnsHeaders, "X-WNS-Type", "wns/tile");
                        return;
                    }

                    case WindowsTemplateBodyType.Badge:
                    {
                        RegistrationSDKHelper.AddOrUpdateHeader(registration.WnsHeaders, "X-WNS-Type", "wns/badge");
                        break;
                    }

                    default:
                    {
                        return;
                    }
                    }
                }
                else
                {
                    try
                    {
                        XmlDocument xmlDocument = new XmlDocument();
                        using (XmlReader xmlReader = XmlReader.Create(new StringReader(registration.BodyTemplate)))
                        {
                            xmlDocument.Load(xmlReader);
                        }
                    }
                    catch (XmlException xmlException)
                    {
                        throw new ArgumentException(SRClient.NotSupportedXMLFormatAsBodyTemplate);
                    }
                }
            }
        }
Example #2
0
 protected override void OnValidateAndPopulateHeaders()
 {
     if (base.Headers.ContainsKey("X-WNS-Type") && base.Headers["X-WNS-Type"].Equals("wns/raw", StringComparison.OrdinalIgnoreCase))
     {
         this.AddNotificationTypeHeader(WindowsTemplateBodyType.Raw);
         base.ContentType = "application/octet-stream";
         return;
     }
     this.AddNotificationTypeHeader(RegistrationSDKHelper.DetectWindowsTemplateRegistationType(base.Body, SRClient.NotSupportedXMLFormatAsPayload));
     base.Body = RegistrationSDKHelper.AddDeclarationToXml(base.Body);
 }