Exemple #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!"));
                }
            }
        }
Exemple #2
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);
            }
        }