Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MpnsTemplateRegistrationDescription"/> class.
        /// </summary>
        /// <param name="sourceRegistration">The source registration.</param>
        public MpnsTemplateRegistrationDescription(MpnsTemplateRegistrationDescription sourceRegistration)
            : base(sourceRegistration)
        {
            this.MpnsHeaders = new MpnsHeaderCollection();
            if (sourceRegistration.MpnsHeaders != null)
            {
                foreach (var header in sourceRegistration.MpnsHeaders)
                {
                    this.MpnsHeaders.Add(header.Key, header.Value);
                }
            }

            this.BodyTemplate = sourceRegistration.BodyTemplate;
            this.TemplateName = sourceRegistration.TemplateName;
        }
        /// <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 SetMpnsType(this MpnsTemplateRegistrationDescription registration)
        {
            if (registration == null || registration.IsJsonObjectPayLoad())
            {
                return;
            }

            if (registration.MpnsHeaders != null && registration.MpnsHeaders.ContainsKey(MpnsRegistrationDescription.NotificationClass))
            {
                int notificationClass = Int32.Parse(registration.MpnsHeaders[MpnsRegistrationDescription.NotificationClass], CultureInfo.InvariantCulture);
                if ((notificationClass >= 3 && notificationClass <= 10) ||
                    (notificationClass >= 13 && notificationClass <= 20) ||
                    (notificationClass >= 23 && notificationClass <= 31))
                {
                    // raw type
                    return;
                }
            }

            if (registration.IsXmlPayLoad())
            {
                if (registration.MpnsHeaders == null)
                {
                    registration.MpnsHeaders = new MpnsHeaderCollection();
                }

                switch (DetectMpnsTemplateRegistationType(registration.BodyTemplate, SRClient.NotSupportedXMLFormatAsBodyTemplateForMpns))
                {
                case MpnsTemplateBodyType.Tile:
                    AddOrUpdateHeader(registration.MpnsHeaders, MpnsRegistrationDescription.Type, MpnsRegistrationDescription.Tile);
                    AddOrUpdateHeader(registration.MpnsHeaders, MpnsRegistrationDescription.NotificationClass, MpnsRegistrationDescription.TileClass);
                    break;

                case MpnsTemplateBodyType.Toast:
                    AddOrUpdateHeader(registration.MpnsHeaders, MpnsRegistrationDescription.Type, MpnsRegistrationDescription.Toast);
                    AddOrUpdateHeader(registration.MpnsHeaders, MpnsRegistrationDescription.NotificationClass, MpnsRegistrationDescription.ToastClass);
                    break;
                }
            }
        }