コード例 #1
0
ファイル: PushClient.cs プロジェクト: wiertel/TizenFX
 internal static void Notify(PushMessageEventArgs args)
 {
     if (_notificationReceived != null)
     {
         _notificationReceived(null, args);
     }
 }
コード例 #2
0
ファイル: PushImpl.cs プロジェクト: prjung/TizenFX
 internal void PushServiceConnect(string pushAppId)
 {
     Interop.PushClient.VoidStateChangedCallback stateDelegate = (int state, string err, IntPtr userData) =>
     {
         if (err == null)
         {
             err = "";
         }
         PushConnectionStateEventArgs args = new PushConnectionStateEventArgs((PushConnectionStateEventArgs.PushState)state, err);
         PushClient.StateChange(args);
     };
     Interop.PushClient.VoidNotifyCallback notifyDelegate = (IntPtr notification, IntPtr userData) =>
     {
         Interop.PushClient.ServiceError result;
         PushMessageEventArgs            ob = new PushMessageEventArgs();
         string data;
         result = Interop.PushClient.GetNotificationData(notification, out data);
         if ((result == Interop.PushClient.ServiceError.None) && !(String.IsNullOrEmpty(data)))
         {
             ob.AppData = data;
         }
         else
         {
             ob.AppData = "";
         }
         string message;
         result = Interop.PushClient.GetNotificationMessage(notification, out message);
         if ((result == Interop.PushClient.ServiceError.None) && !(String.IsNullOrEmpty(message)))
         {
             ob.Message = message;
         }
         else
         {
             ob.Message = "";
         }
         string sender;
         result = Interop.PushClient.GetNotificationSender(notification, out sender);
         if ((result == Interop.PushClient.ServiceError.None) && !(String.IsNullOrEmpty(sender)))
         {
             ob.Sender = sender;
         }
         else
         {
             ob.Sender = "";
         }
         string sessioninfo;
         result = Interop.PushClient.GetNotificationSessionInfo(notification, out sessioninfo);
         if ((result == Interop.PushClient.ServiceError.None) && !(String.IsNullOrEmpty(sessioninfo)))
         {
             ob.SessionInfo = sessioninfo;
         }
         else
         {
             ob.SessionInfo = "";
         }
         string requestid;
         result = Interop.PushClient.GetNotificationRequestId(notification, out requestid);
         if ((result == Interop.PushClient.ServiceError.None) && !(String.IsNullOrEmpty(requestid)))
         {
             ob.RequestId = requestid;
         }
         else
         {
             ob.RequestId = "";
         }
         int time;
         result = Interop.PushClient.GetNotificationTime(notification, out time);
         DateTime utc;
         if ((result == Interop.PushClient.ServiceError.None) && (time != 0))
         {
             Log.Info(Interop.PushClient.LogTag, "Ticks received: " + time);
             utc           = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(time), DateTimeKind.Utc);
             ob.ReceivedAt = utc.ToLocalTime();
         }
         else
         {
             Log.Info(Interop.PushClient.LogTag, "No Date received");
             ob.ReceivedAt = DateTime.Now;
         }
         int type = -1;
         result = Interop.PushClient.GetNotificationType(notification, out type);
         if (result == Interop.PushClient.ServiceError.None)
         {
             ob.Type = type;
         }
         PushClient.Notify(ob);
     };
     Interop.PushClient.ServiceError connectResult = Interop.PushClient.ServiceConnect(pushAppId, stateDelegate, notifyDelegate, IntPtr.Zero, out _connection);
     if (connectResult != Interop.PushClient.ServiceError.None)
     {
         Log.Error(Interop.PushClient.LogTag, "Connect failed with " + connectResult);
         throw PushExceptionFactory.CreateResponseException(connectResult);
     }
 }