示例#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!"));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Searches the content by taking given location as a base and retrieves the contents that located given distance far away.
        /// </summary>
        /// <param name="startLocation">Base location to search near it.</param>
        /// <param name="distance">Distance used to create circle by taking the startLocation as a center.</param>
        /// <param name="locationSearchField">Name of the field that holds location data.</param>
        /// <returns>The list of <see cref="NetmeraContent"/>  object.</returns>
        public List <NetmeraContent> circleSearch(NetmeraGeoLocation startLocation, double distance, String locationSearchField)
        {
            RequestItem item = new RequestItem();

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.locationSearchType  = NetmeraConstants.LocationSearchType_Circle;
            item.distance            = distance;
            item.latitudes           = startLocation.getLatitude().ToString();
            item.longitudes          = startLocation.getLongitude().ToString();
            item.locationSearchField = locationSearchField;

            JArray jsonArray = new JArray(NetmeraHttpUtils.locationSearch(item));

            return(convertJsonArrayToNetmeraContent(jsonArray));
        }
        /// <summary>
        /// Gets the <see cref="NetmeraGeoLocation"/> object with the specified key.
        /// </summary>
        /// <param name="key">Key to get value</param>
        /// <returns><see cref="NetmeraGeoLocation"/> object with the specified key. If the object type is not an NetmeraGeoLocation or key does not exists then it returns null.</returns>
        public NetmeraGeoLocation getNetmeraGeoLocation(String key)
        {
            String locationKey  = key + NetmeraConstants.LocationField_Suffix;
            String latitudeKey  = key + NetmeraConstants.LocationLatitude_Suffix;
            String longitudeKey = key + NetmeraConstants.LocationLongitude_Suffix;

            if (data[locationKey] == null)
            {
                return(null);
            }

            String             latitude, longitude;
            NetmeraGeoLocation geoLocation;

            try
            {
                latitude  = Convert.ToString(data[latitudeKey].ToString());
                longitude = Convert.ToString(data[longitudeKey].ToString());

                geoLocation = new NetmeraGeoLocation(Double.Parse(latitude), Double.Parse(longitude));
            }
            catch (JsonException e)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_KEY, "Json with key [" + locationKey + "] is invalid.", e);
            }

            return(geoLocation);
        }
示例#4
0
 /// <summary>
 /// Sets the search type of this push notification to box search.
 /// </summary>
 /// <param name="firstLoc">First point of the box</param>
 /// <param name="secondLoc">Second point of the box</param>
 public void setBoxPush(NetmeraGeoLocation firstLoc, NetmeraGeoLocation secondLoc)
 {
     if (firstLoc != null && secondLoc != null)
     {
         this.locationType = NetmeraConstants.Netmera_Push_Type_Box_Location;
         this.firstLoc     = firstLoc;
         this.secondLoc    = secondLoc;
     }
 }
示例#5
0
 /// <summary>
 /// Sets the search type of this push notification to circle search.
 /// </summary>
 /// <param name="centerLoc">Center point of the circle.</param>
 /// <param name="distance">Distance radius of the circle in kilometers.</param>
 public void setCirclePush(NetmeraGeoLocation centerLoc, double distance)
 {
     if (centerLoc != null)
     {
         this.locationType = NetmeraConstants.Netmera_Push_Type_Circle_Location;
         this.distance     = distance;
         this.firstLoc     = centerLoc;
         this.secondLoc    = null;
     }
 }
示例#6
0
        /// <summary>
        /// Creates box using the given two location (latitude,longitude) data and searches inside that box.
        /// </summary>
        /// <param name="firstPoint"><see cref="NetmeraGeoLocation"/>  object</param>
        /// <param name="secondPoint"><see cref="NetmeraGeoLocation"/>  object</param>
        /// <param name="locationSearchField">Name of the field that holds location data.</param>
        /// <returns>The list of <see cref="NetmeraContent"/>  object.</returns>
        public List <NetmeraContent> boxSearch(NetmeraGeoLocation firstPoint, NetmeraGeoLocation secondPoint, String locationSearchField)
        {
            RequestItem item = new RequestItem();

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.locationSearchType = NetmeraConstants.LocationSearchType_Box;

            StringBuilder latitudes  = new StringBuilder();
            StringBuilder longitudes = new StringBuilder();

            if (firstPoint.getLatitude() < secondPoint.getLatitude())
            {
                latitudes.Append(firstPoint.getLatitude().ToString()).Append(",").Append(secondPoint.getLatitude().ToString());
            }
            else
            {
                latitudes.Append(secondPoint.getLatitude().ToString()).Append(",").Append(firstPoint.getLatitude().ToString());
            }

            if (firstPoint.getLongitude() < secondPoint.getLongitude())
            {
                longitudes.Append(firstPoint.getLongitude().ToString()).Append(",").Append(secondPoint.getLongitude().ToString());
            }
            else
            {
                longitudes.Append(secondPoint.getLongitude().ToString()).Append(",").Append(firstPoint.getLongitude().ToString());
            }

            item.latitudes           = latitudes.ToString();
            item.longitudes          = longitudes.ToString();
            item.locationSearchField = locationSearchField;

            JArray jsonArray = new JArray(NetmeraHttpUtils.locationSearch(item));

            return(convertJsonArrayToNetmeraContent(jsonArray));
        }
示例#7
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);
            }
        }
 /// <summary>
 /// Sets device location
 /// </summary>
 /// <param name="location">Device location in type <seealso cref="NetmeraGeoLocation"/></param>
 public void setDeviceLocation(NetmeraGeoLocation location)
 {
     this.deviceLocation = location;
 }
        /// <summary>
        /// Searches the content by taking given location as a base and retrieves the contents that located given distance far away.
        /// </summary>
        /// <param name="startLocation">Base location to search near it.</param>
        /// <param name="distance">Distance used to create circle by taking the startLocation as a center.</param>
        /// <param name="locationSearchField">Name of the field that holds location data.</param>
        /// <param name="callback">Method called when circle search operation finishes</param>
        public void circleSearch(NetmeraGeoLocation startLocation, double distance, String locationSearchField, Action <List <NetmeraContent>, Exception> callback)
        {
            RequestItem item = new RequestItem();

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.locationSearchType  = NetmeraConstants.LocationSearchType_Circle;
            item.distance            = distance;
            item.latitudes           = startLocation.getLatitude().ToString();
            item.longitudes          = startLocation.getLongitude().ToString();
            item.locationSearchField = locationSearchField;

            NetmeraHttpUtils.locationSearch(item, (lno, ex) =>
            {
                if (ex != null)
                {
                    if (callback != null)
                    {
                        callback(null, ex);
                    }
                }
                else if (lno != null)
                {
                    try
                    {
                        List <NetmeraContent> contentList = convertJsonArrayToNetmeraContent(new JArray(lno));
                        if (callback != null)
                        {
                            callback(contentList, null);
                        }
                    }
                    catch (JsonException e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of search method is invalid.", e.Message));
                        }
                    }
                    catch (IOException e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in search method.", e.Message));
                        }
                    }
                    catch (Exception e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred in search method.", e.Message));
                        }
                    }

                    NetmeraClient.finish();
                }
            });
        }