Example #1
0
        /// <summary>
        /// Copies this notification, and validates the content of it to ensure that it can be
        /// serialized into the JSON format expected by the FCM service.
        /// </summary>
        internal AndroidNotification CopyAndValidate()
        {
            var copy = new AndroidNotification()
            {
                Title        = this.Title,
                Body         = this.Body,
                Icon         = this.Icon,
                Color        = this.Color,
                Sound        = this.Sound,
                Tag          = this.Tag,
                ClickAction  = this.ClickAction,
                TitleLocKey  = this.TitleLocKey,
                TitleLocArgs = this.TitleLocArgs?.ToList(),
                BodyLocKey   = this.BodyLocKey,
                BodyLocArgs  = this.BodyLocArgs?.ToList(),
                ChannelId    = this.ChannelId,
            };

            if (copy.Color != null && !Regex.Match(copy.Color, "^#[0-9a-fA-F]{6}$").Success)
            {
                throw new ArgumentException("Color must be in the form #RRGGBB.");
            }

            if (copy.TitleLocArgs?.Any() == true && string.IsNullOrEmpty(copy.TitleLocKey))
            {
                throw new ArgumentException("TitleLocKey is required when specifying TitleLocArgs.");
            }

            if (copy.BodyLocArgs?.Any() == true && string.IsNullOrEmpty(copy.BodyLocKey))
            {
                throw new ArgumentException("BodyLocKey is required when specifying BodyLocArgs.");
            }

            return(copy);
        }
Example #2
0
        /// <summary>
        /// Copies this notification, and validates the content of it to ensure that it can be
        /// serialized into the JSON format expected by the FCM service.
        /// </summary>
        internal AndroidNotification CopyAndValidate()
        {
            var copy = new AndroidNotification()
            {
                Title                 = this.Title,
                Body                  = this.Body,
                Icon                  = this.Icon,
                Color                 = this.Color,
                Sound                 = this.Sound,
                Tag                   = this.Tag,
                ImageUrl              = this.ImageUrl,
                ClickAction           = this.ClickAction,
                TitleLocKey           = this.TitleLocKey,
                TitleLocArgs          = this.TitleLocArgs?.ToList(),
                BodyLocKey            = this.BodyLocKey,
                BodyLocArgs           = this.BodyLocArgs?.ToList(),
                ChannelId             = this.ChannelId,
                Ticker                = this.Ticker,
                Sticky                = this.Sticky,
                EventTimestamp        = this.EventTimestamp,
                LocalOnly             = this.LocalOnly,
                Priority              = this.Priority,
                VibrateTimingsMillis  = this.VibrateTimingsMillis,
                DefaultVibrateTimings = this.DefaultVibrateTimings,
                DefaultSound          = this.DefaultSound,
                DefaultLightSettings  = this.DefaultLightSettings,
                Visibility            = this.Visibility,
                NotificationCount     = this.NotificationCount,
            };

            if (copy.Color != null && !Regex.Match(copy.Color, "^#[0-9a-fA-F]{6}$").Success)
            {
                throw new ArgumentException("Color must be in the form #RRGGBB.");
            }

            if (copy.TitleLocArgs?.Any() == true && string.IsNullOrEmpty(copy.TitleLocKey))
            {
                throw new ArgumentException("TitleLocKey is required when specifying TitleLocArgs.");
            }

            if (copy.BodyLocArgs?.Any() == true && string.IsNullOrEmpty(copy.BodyLocKey))
            {
                throw new ArgumentException("BodyLocKey is required when specifying BodyLocArgs.");
            }

            if (copy.ImageUrl != null && !Uri.IsWellFormedUriString(copy.ImageUrl, UriKind.Absolute))
            {
                throw new ArgumentException($"Malformed image URL string: {copy.ImageUrl}.");
            }

            copy.LightSettings = this.LightSettings?.CopyAndValidate();

            return(copy);
        }