Example #1
0
        /// <summary>
        /// Unregisters device from specified groups, if <seealso cref="NetmeraDeviceDetail"/> groups are set; otherwise unregisters from broadcast group
        /// </summary>
        /// <param name="channelName">Channel name to be unregistered</param>
        /// <param name="deviceDetail"><seealso cref="NetmeraDeviceDetail"/> object keeping device details</param>
        /// <param name="callback">>Method to be called just after unregister</param>
        public static void unregister(String channelName, NetmeraDeviceDetail deviceDetail, Action <Exception> callback)
        {
            Channel_Name = channelName;
            if (deviceDetail != null)
            {
                Groups          = deviceDetail.getDeviceGroups();
                Device_Location = deviceDetail.getDeviceLocation();
            }

            Channel = HttpNotificationChannel.Find(Channel_Name);
            if (Channel != null)
            {
                UnregisterFromNotificationService(ex =>
                {
                    if (callback != null)
                    {
                        callback(ex);
                    }
                    //if (ex != null)
                    //    callback(ex);
                    //else
                    //    Channel.Close();
                });
            }
            else
            {
                if (callback != null)
                {
                    callback(new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "Unregister failed since such a channel not found!"));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Gets device details if registered
        /// </summary>
        /// <param name="channelName">Channel name the device registered</param>
        /// <param name="callback">Method to be called just after getting details</param>
        public static void getDeviceDetail(String channelName, Action <NetmeraDeviceDetail, Exception> callback)
        {
            Channel_Name = channelName;
            Channel      = HttpNotificationChannel.Find(Channel_Name);
            if (Channel != null)
            {
                NetmeraDeviceDetail deviceDetail = new NetmeraDeviceDetail(Channel.ChannelUri.ToString());

                Dictionary <string, object> postParameters = new Dictionary <string, object>();
                postParameters.Add(NetmeraConstants.Netmera_Push_Registration_Id, deviceDetail.regId);
                postParameters.Add(NetmeraConstants.Netmera_Push_Apikey, NetmeraClient.securityToken);

                String url = NetmeraConstants.Netmera_Domain_Url + NetmeraConstants.Netmera_Push_Server_Url + NetmeraConstants.Netmera_Push_Device_Details;

                NetmeraHttpUtils.getDeviceDetails(url, postParameters, deviceDetail, callback);
            }
            else if (callback != null)
            {
                callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "A channel with such a name is not registered"));
            }
        }
Example #3
0
        /// <summary>
        /// Registers device to specified groups, if <seealso cref="NetmeraDeviceDetail"/> groups are set; otherwise registers to broadcast group
        /// </summary>
        /// <param name="channelName">Channel name to be registered</param>
        /// <param name="deviceDetail"><seealso cref="NetmeraDeviceDetail"/> object keeping device details</param>
        /// <param name="callback">Method to be called just after registration</param>
        public static void register(String channelName, NetmeraDeviceDetail deviceDetail, Action <Exception> callback)
        {
            Channel_Name = channelName;
            if (deviceDetail != null)
            {
                Groups          = deviceDetail.getDeviceGroups();
                Device_Location = deviceDetail.getDeviceLocation();
            }

            Channel = HttpNotificationChannel.Find(Channel_Name);
            if (Channel == null)
            {
                Channel = new HttpNotificationChannel(Channel_Name, Service_Name);
                Channel.ChannelUriUpdated += (s, e) =>
                {
                    ChannelUriUpdated(s, e, callback);
                };

                try
                {
                    Channel.Open();
                }
                catch (InvalidOperationException ex)
                {
                    if (callback != null)
                    {
                        callback(new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "Maximum channel number have already been opened in this device." + ex.Message));
                    }
                }
            }
            else
            {
                //RegisterForNotifications(callback);
                RegisterWithNotificationService(callback);
            }
        }
Example #4
0
        /// <summary>
        /// Unregisters device
        /// </summary>
        /// <param name="channelName">Channel name to be unregistered</param>
        /// <param name="callback">Method to be called just after unregister</param>
        public static void unregister(String channelName, Action <Exception> callback)
        {
            NetmeraDeviceDetail device = new NetmeraDeviceDetail();

            NetmeraPushService.unregister(channelName, device, callback);
        }