1 /// This File contains the Api's related to the PushManager class
3 /// Copyright 2016 by Samsung Electronics, Inc.,
5 /// This software is the confidential and proprietary information
6 /// of Samsung Electronics, Inc. ("Confidential Information"). You
7 /// shall not disclose such Confidential Information and shall use
8 /// it only in accordance with the terms of the license agreement
9 /// you entered into with Samsung.
13 using System.Threading.Tasks;
15 namespace Tizen.Messaging.Push
18 /// The PushManager API provides functions to connect to push service for receiving push messages.
21 /// The PushManager API provides the way to connect with the push service.
22 /// It provides api's to connect/disconnect from the push service.
23 /// Api's are provided so that an application can register itself
24 /// with the push server along with api's to request push message.
28 /// public class Program
30 /// static void Main(string[] args)
32 /// Push.PushServiceConnect("xxxxx");
33 /// Task<ServerResponse> tr = Push.PushServerRegister();
34 /// tr.GetAwaiter().OnCompleted(() => {
35 /// ServerResponse res = tr.Result;
36 /// Push.GetUnreadNotifications();
37 /// Task<ServerResponse> tu = Push.PushServerUnregister();
38 /// tu.GetAwaiter().OnCompleted(() => {
39 /// Push.PushServiceDisconnect();
42 /// Push.NotificationReceived += EventHandlerNotificationReceived;
43 /// Push.StateChanged += EventHandlerStateChanged;
46 /// static void EventHandlerNotificationReceived(object sender, PushMessageEventArgs e)
50 /// static void EventHandlerStateChanged(object sender, PushConnectionStateEventArgs e)
56 public static class Push
59 /// Event Handler for receiving the notifications.
61 public static event EventHandler<PushMessageEventArgs> NotificationReceived
67 _notificationReceived += value;
74 _notificationReceived -= value;
80 /// Event Handler for receiving changes in States of the connection.
82 public static event EventHandler<PushConnectionStateEventArgs> StateChanged
88 _stateChanged += value;
95 _stateChanged -= value;
101 /// API to connect with the push service.
103 /// <param name="pushAppId"> The Push Application Id Registered with the server.</param>
104 public static void PushServiceConnect(string pushAppId)
106 PushImpl.Instance.PushServiceConnect(pushAppId);
110 /// API to disconnect from the push service.
112 public static void PushServiceDisconnect()
114 PushImpl.Instance.PushServiceDisconnect();
120 /// API to Register the application with the push server.
123 /// The method returns a task which on completion with give a ServerResponse Object.
125 public static Task<ServerResponse> PushServerRegister()
127 return PushImpl.Instance.PushServerRegister();
131 /// API to Deregister the application from the push server.
134 /// The method returns a task which on completion with give a ServerResponse Object.
136 public static Task<ServerResponse> PushServerUnregister()
138 return PushImpl.Instance.PushServerUnregister();
142 /// Gets the unread notifications for the application.
144 public static void GetUnreadNotifications()
146 PushImpl.Instance.GetUnreadNotifications();
150 /// registration Id received from server. </summary>
152 /// It is the string which is the Id received from the server.
154 public static string GetRegistrationId()
156 return PushImpl.Instance.GetRegistrationId();
159 internal static void StateChange(PushConnectionStateEventArgs args)
161 if (_stateChanged != null)
162 _stateChanged(null, args);
165 internal static void Notify(PushMessageEventArgs args)
167 if (_notificationReceived != null)
168 _notificationReceived(null, args);
171 private static object _lock = new object();
172 private static event EventHandler<PushMessageEventArgs> _notificationReceived;
173 private static event EventHandler<PushConnectionStateEventArgs> _stateChanged;