@@ -24,29 +24,58 @@ namespace FirebaseAdmin.Messaging
2424 public sealed class AndroidConfig
2525 {
2626 /// <summary>
27- /// A collapse key for the message. Collapse key serves as an identifier for a group of
28- /// messages that can be collapsed, so that only the last message gets sent when delivery can be
29- /// resumed. A maximum of 4 different collapse keys may be active at any given time.
27+ /// Gets or sets a collapse key for the message. Collapse key serves as an identifier for a
28+ /// group of messages that can be collapsed, so that only the last message gets sent when
29+ /// delivery can be resumed. A maximum of 4 different collapse keys may be active at any
30+ /// given time.
3031 /// </summary>
3132 [ JsonProperty ( "collapse_key" ) ]
3233 public string CollapseKey { get ; set ; }
3334
3435 /// <summary>
35- /// The priority of the message.
36+ /// Gets or sets the priority of the message.
3637 /// </summary>
3738 [ JsonIgnore ]
3839 public Priority ? Priority { get ; set ; }
3940
4041 /// <summary>
41- /// String representation of the <see cref="Priority"/> as accepted by the FCM backend
42- /// service.
42+ /// Gets or sets the time-to-live duration of the message.
43+ /// </summary>
44+ [ JsonIgnore ]
45+ public TimeSpan ? TimeToLive { get ; set ; }
46+
47+ /// <summary>
48+ /// Gets or sets the package name of the application where the registration tokens must
49+ /// match in order to receive the message.
50+ /// </summary>
51+ [ JsonProperty ( "restricted_package_name" ) ]
52+ public string RestrictedPackageName { get ; set ; }
53+
54+ /// <summary>
55+ /// Gets or sets a collection of key-value pairs that will be added to the message as data
56+ /// fields. Keys and the values must not be null. When set, overrides any data fields set
57+ /// on the top-level
58+ /// <see cref="Message"/>.
59+ /// </summary>
60+ [ JsonProperty ( "data" ) ]
61+ public IReadOnlyDictionary < string , string > Data { get ; set ; }
62+
63+ /// <summary>
64+ /// Gets or sets the Android notification to be included in the message.
65+ /// </summary>
66+ [ JsonProperty ( "notification" ) ]
67+ public AndroidNotification Notification { get ; set ; }
68+
69+ /// <summary>
70+ /// Gets or sets the string representation of <see cref="Priority"/> as accepted by the FCM
71+ /// backend service.
4372 /// </summary>
4473 [ JsonProperty ( "priority" ) ]
4574 private string PriorityString
4675 {
4776 get
4877 {
49- switch ( Priority )
78+ switch ( this . Priority )
5079 {
5180 case Messaging . Priority . High :
5281 return "high" ;
@@ -56,15 +85,16 @@ private string PriorityString
5685 return null ;
5786 }
5887 }
88+
5989 set
6090 {
6191 switch ( value )
6292 {
6393 case "high" :
64- Priority = Messaging . Priority . High ;
94+ this . Priority = Messaging . Priority . High ;
6595 return ;
6696 case "normal" :
67- Priority = Messaging . Priority . High ;
97+ this . Priority = Messaging . Priority . High ;
6898 return ;
6999 default :
70100 throw new FirebaseException (
@@ -75,69 +105,46 @@ private string PriorityString
75105 }
76106
77107 /// <summary>
78- /// The time-to-live duration of the message.
79- /// </summary>
80- [ JsonIgnore ]
81- public TimeSpan ? TimeToLive { get ; set ; }
82-
83- /// <summary>
84- /// String representation of <see cref="TimeToLive"/> as accepted by the FCM backend
85- /// service. The string ends in the suffix "s" (indicating seconds) and is preceded
86- /// by the number of seconds, with nanoseconds expressed as fractional seconds.
108+ /// Gets or sets the string representation of <see cref="TimeToLive"/> as accepted by the
109+ /// FCM backend service. The string ends in the suffix "s" (indicating seconds) and is
110+ /// preceded by the number of seconds, with nanoseconds expressed as fractional seconds.
87111 /// </summary>
88112 [ JsonProperty ( "ttl" ) ]
89113 private string TtlString
90114 {
91115 get
92116 {
93- if ( TimeToLive == null )
117+ if ( this . TimeToLive == null )
94118 {
95119 return null ;
96120 }
97- var totalSeconds = TimeToLive . Value . TotalSeconds ;
98- var seconds = ( long ) Math . Floor ( totalSeconds ) ;
99- var subsecondNanos = ( long ) ( ( totalSeconds - seconds ) * 1e9 ) ;
121+
122+ var totalSeconds = this . TimeToLive . Value . TotalSeconds ;
123+ var seconds = ( long ) Math . Floor ( totalSeconds ) ;
124+ var subsecondNanos = ( long ) ( ( totalSeconds - seconds ) * 1e9 ) ;
100125 if ( subsecondNanos > 0 )
101126 {
102- return String . Format ( "{0}.{1:D9}s" , seconds , subsecondNanos ) ;
127+ return string . Format ( "{0}.{1:D9}s" , seconds , subsecondNanos ) ;
103128 }
104- return String . Format ( "{0}s" , seconds ) ;
129+
130+ return string . Format ( "{0}s" , seconds ) ;
105131 }
132+
106133 set
107134 {
108135 var segments = value . TrimEnd ( 's' ) . Split ( '.' ) ;
109- var seconds = Int64 . Parse ( segments [ 0 ] ) ;
136+ var seconds = long . Parse ( segments [ 0 ] ) ;
110137 var ttl = TimeSpan . FromSeconds ( seconds ) ;
111138 if ( segments . Length == 2 )
112139 {
113- var subsecondNanos = Int64 . Parse ( segments [ 1 ] . TrimStart ( '0' ) ) ;
140+ var subsecondNanos = long . Parse ( segments [ 1 ] . TrimStart ( '0' ) ) ;
114141 ttl = ttl . Add ( TimeSpan . FromMilliseconds ( subsecondNanos / 1e6 ) ) ;
115142 }
116- TimeToLive = ttl ;
143+
144+ this . TimeToLive = ttl ;
117145 }
118146 }
119147
120- /// <summary>
121- /// The package name of the application where the registration tokens must match in order
122- /// to receive the message.
123- /// </summary>
124- [ JsonProperty ( "restricted_package_name" ) ]
125- public string RestrictedPackageName { get ; set ; }
126-
127- /// <summary>
128- /// A collection of key-value pairs that will be added to the message as data fields. Keys
129- /// and the values must not be null. When set, overrides any data fields set on the top-level
130- /// <see cref="Message"/>.
131- /// </summary>
132- [ JsonProperty ( "data" ) ]
133- public IReadOnlyDictionary < string , string > Data { get ; set ; }
134-
135- /// <summary>
136- /// The Android notification to be included in the message.
137- /// </summary>
138- [ JsonProperty ( "notification" ) ]
139- public AndroidNotification Notification { get ; set ; }
140-
141148 /// <summary>
142149 /// Copies this Android config, and validates the content of it to ensure that it can be
143150 /// serialized into the JSON format expected by the FCM service.
@@ -164,20 +171,4 @@ internal AndroidConfig CopyAndValidate()
164171 return copy ;
165172 }
166173 }
167-
168- /// <summary>
169- /// Priority levels that can be set on an <see cref="AndroidConfig"/>.
170- /// </summary>
171- public enum Priority
172- {
173- /// <summary>
174- /// High priority message.
175- /// </summary>
176- High ,
177-
178- /// <summary>
179- /// Normal priority message.
180- /// </summary>
181- Normal ,
182- }
183174}
0 commit comments