public void bulkUpdate(Action <JObject, Exception> callback) { String tmpPath = path; NetmeraHttpUtils.updateBulkContent(data, (json, e) => { NetmeraContent content = new NetmeraContent(); content.setContent(json); if (mediaData != null && mediaData.Count != 0) { createMedia(content, (j, exc) => { if (callback != null) { callback(j, exc); } }); } else { if (callback != null) { if (callback != null) { callback(json, e); } } } }); }
/// <summary> /// Gets the NetmeraContent from the network, not the cache. /// </summary> /// <param name="path"></param> /// <returns></returns> private NetmeraContent getFromNetwork(String path) { RequestItem item = new RequestItem(); if (path == null || path.Length == 0) { throw new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Path cannot be null or empty"); } item.path = path; item.page = page; item.contentType = NetmeraConstants.Default_ContentType; item.customCondition = getCustomCondition(); JArray jsonArray = new JArray(NetmeraHttpUtils.get(item)); List <NetmeraContent> contentList = convertJsonArrayToNetmeraContent(jsonArray); if (contentList != null && contentList.Count != 0) { return(contentList.First()); } else { return(null); } }
private static JObject loginAsGuestRequest() { JObject json = null; try { json = NetmeraHttpUtils.loginAsGuest(); } catch (NetmeraException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while logging user"); } if (json != null) { if (json["data"] != null && json["data"].Count() != 0) { return((JObject)json.First.First); } else if (json["error"] != null) { String error = json["error"]["message"].ToString(); throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, error); } else { throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while logging user"); } } return(json); }
/// <summary> /// Updates the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="path">The path.</param> /// <param name="callback">method called when content update operation finishes</param> protected internal void update(JObject data, String path, Action <JObject, Exception> callback) { String tmpPath = path; NetmeraHttpUtils.updateContent(data, tmpPath, (json, e) => { NetmeraContent content = new NetmeraContent(); content.setContent(json); if (mediaData != null && mediaData.Count != 0) { createMedia(content, (j, exc) => { if (callback != null) { callback(j, exc); } }); } else { if (callback != null) { if (callback != null) { callback(json, e); } } } }); }
/// <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)); }
private void register(RequestItem item, Action <JObject, Exception> callback) { if (String.IsNullOrEmpty(item.getEmail())) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required")); } } if (String.IsNullOrEmpty(item.getNickname())) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserNickname + " is required")); } } if (String.IsNullOrEmpty(item.getPassword())) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserPassword + " is required")); } } NetmeraHttpUtils.registerUser(item, (json, e) => { if (json != null) { if (json["entry"] != null && json["entry"].First != null) { if (callback != null) { callback((JObject)json.First.First, e); } } else if (json["error"] != null) { String error = json["error"]["message"].ToString(); if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, error)); } } else { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while registering user")); } } } else { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while registering user")); } } }); }
private void deactivateUser(RequestItem item) { if (String.IsNullOrEmpty(item.getEmail())) { throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required"); } NetmeraHttpUtils.deactivateUser(item); }
/// <summary> /// Deletes data from the cloud. /// </summary> public bool delete() { bool flag = false; flag = NetmeraHttpUtils.deleteContent(getPath()); clearContent(); return(flag); }
/// <summary> /// Updates the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="path">The path.</param> protected internal JObject update(JObject data, String path) { JObject json = NetmeraHttpUtils.updateContent(data, path); NetmeraContent content = new NetmeraContent(); content.setContent(json); if (mediaData != null && mediaData.Count != 0) { json = createMedia(content); } return(json); }
/// <summary> /// Retrieves the all groups of all registered devices. /// </summary> /// <param name="callback">Method to be called just after getting device groups</param> public static void getDeviceGroups(Action <List <String>, Exception> callback) { Dictionary <string, object> postParameters = new Dictionary <string, object>(); postParameters.Add(NetmeraConstants.Netmera_Push_Apikey, NetmeraClient.securityToken); String url = NetmeraConstants.Netmera_Domain_Url + NetmeraConstants.Netmera_Push_Server_Url + NetmeraConstants.Netmera_Push_Get_Device_Groups; if (callback != null) { NetmeraHttpUtils.getDeviceGroups(url, postParameters, callback); } }
private static void getRichPushContent(Action <JObject, Exception> callback) { Dictionary <string, object> nvp = new Dictionary <string, object>(); JObject parameters = new JObject(); parameters.Add(NetmeraConstants.Netmera_Push_Apikey, NetmeraClient.securityToken); parameters.Add(NetmeraConstants.Netmera_Push_Id, richPushId); nvp.Add(NetmeraConstants.Netmera_Push_Notification, parameters); String url = NetmeraConstants.Netmera_Domain_Url + NetmeraConstants.Netmera_Push_Server_Url + NetmeraConstants.Rest_Version + NetmeraConstants.Netmera_Push_Get_Push_Content; NetmeraHttpUtils.getRichPushContent(url, nvp, callback); }
private JObject createMedia(NetmeraContent content) { JObject json = null; try { JObject mediaObject = new JObject(); bool isMediaFileAdded = false; IEnumerable <JProperty> jlist = mediaData.Properties(); foreach (JProperty token in jlist) { String key = token.Name; String tmpMediaDataJson = mediaData.Value <String>(key); byte[] tmpMediaData = JsonConvert.DeserializeObject <byte[]>(tmpMediaDataJson); NetmeraMedia file = new NetmeraMedia(tmpMediaData); isMediaFileAdded = true; String appId = content.getContent().Value <string>(NetmeraConstants.Site); String apiKey = NetmeraClient.getSecurityToken(); String contentPath = content.getPath(); String viewerId = content.getOwner().Value <String>(NetmeraConstants.Netmera_Owner_Node_Name); String mediaUrl = file.save(appId, apiKey, contentPath, viewerId); mediaObject.Add(key, mediaUrl); } if (isMediaFileAdded) { json = NetmeraHttpUtils.updateContent(mediaObject, content.getPath()); } } catch (JsonException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of creating media file is invalid"); } catch (WebException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while saving media data"); } catch (IOException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while saving media data"); } return(json); }
/// <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)); }
private void deactivateUser(RequestItem item, Action <Exception> callback) { if (String.IsNullOrEmpty(item.getEmail())) { if (callback != null) { callback(new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required")); } } NetmeraHttpUtils.deactivateUser(item, ex => { if (callback != null) { callback(new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while deactivating user")); } }); }
protected internal JObject createBulk(JObject data) { JObject jArray = NetmeraHttpUtils.createBulkContent(data); NetmeraContent content = new NetmeraContent(); //foreach (JObject json in jArray) //{ content.setContent(jArray); //if (mediaData != null && mediaData.Count != 0) //{ // jarray = createMedia(content); //} //} return((JObject)jArray); }
private void searchUser(RequestItem item, Action <List <NetmeraUser>, Exception> callback) { NetmeraHttpUtils.searchUser(item, (lno, ex) => { if (ex != null) { if (callback != null) { callback(null, ex); } } else if (lno != null) { try { List <NetmeraUser> userList = convertJsonArrayToNetmeraUser(new JArray(lno)); if (callback != null) { callback(userList, 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)); } } } }); }
/// <summary> /// Deletes data from the cloud in the background thread. /// </summary> /// <param name="callback">Method called when delete operation finishes</param> public void delete(Action <bool, Exception> callback) { NetmeraHttpUtils.deleteContent(getPath(), (returnValue, ex) => { if (ex != null) { if (callback != null) { callback(returnValue, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while deleting data.", ex.Message)); } } else { callback(returnValue, null); clearContent(); } }); }
private JObject register(RequestItem item) { JObject json = null; if (String.IsNullOrEmpty(item.getEmail())) { throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required"); } if (String.IsNullOrEmpty(item.getNickname())) { throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserNickname + " is required"); } if (String.IsNullOrEmpty(item.getPassword())) { throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserPassword + " is required"); } try { json = NetmeraHttpUtils.registerUser(item); } catch (NetmeraException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_REGISTER_ERROR, "Error occurred while registering user"); } if (json != null) { if (json["entry"] != null && json["entry"].Count() != 0) { return((JObject)json.First.First); } else if (json["error"] != null) { String error = json["error"]["message"].ToString(); throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_REGISTER_ERROR, error); } else { throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_REGISTER_ERROR, "Error occurred while registering user"); } } return(null); }
private List <NetmeraContent> searchFromNetwork() { 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; } JArray jsonArray = new JArray(NetmeraHttpUtils.search(item)); return(convertJsonArrayToNetmeraContent(jsonArray)); }
/// <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")); } }
/// <summary> /// Finds the number of <seealso cref="NetmeraContent"/> objects that matches with the query. /// </summary> /// <returns>Content count</returns> public long count() { RequestItem item = new RequestItem(); if (searchText != null) { item.searchText = searchText; } 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(); JArray jsonArray = new JArray(NetmeraHttpUtils.search(item)); return(getNumberOfTotalResults(jsonArray)); }
private static void RegisterWithNotificationService(Action <Exception> callback) { String groupString = null; if (Groups != null) { groupString = JsonConvert.SerializeObject(Groups); } Dictionary <string, object> postParameters = new Dictionary <string, object>(); postParameters.Add(NetmeraConstants.Netmera_Push_Registration_Id, Channel.ChannelUri.ToString()); postParameters.Add(NetmeraConstants.Netmera_Push_Channel, NetmeraConstants.Netmera_Push_Type_Wp); postParameters.Add(NetmeraConstants.Netmera_Push_Apikey, NetmeraClient.securityToken); postParameters.Add(NetmeraConstants.Netmera_Push_Device_Groups, groupString); if (Device_Location != null) { postParameters.Add(NetmeraConstants.Netmera_Push_Latitude_Params, Device_Location.getLatitude()); postParameters.Add(NetmeraConstants.Netmera_Push_Longitude_Params, Device_Location.getLongitude()); } String url = NetmeraConstants.Netmera_Domain_Url + NetmeraConstants.Netmera_Push_Server_Url + NetmeraConstants.Netmera_Push_Register; NetmeraHttpUtils.registerUnregisterPush(url, postParameters, ex => { if (ex != null) { unregister(Channel_Name, null); if (callback != null) { callback(new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "Registration failed.")); } } else if (callback != null) { callback(ex); } }); }
private static void UnregisterFromNotificationService(Action <Exception> callback) { String channelUri = Channel.ChannelUri.ToString(); String groupString = null; if (Groups != null) { groupString = JsonConvert.SerializeObject(Groups); } if (Groups == null || Groups.Count == 0) { Channel.Close(); } Dictionary <string, object> postParameters = new Dictionary <string, object>(); postParameters.Add(NetmeraConstants.Netmera_Push_Registration_Id, channelUri); postParameters.Add(NetmeraConstants.Netmera_Push_Channel, NetmeraConstants.Netmera_Push_Type_Wp); postParameters.Add(NetmeraConstants.Netmera_Push_Apikey, NetmeraClient.securityToken); postParameters.Add(NetmeraConstants.Netmera_Push_Device_Groups, groupString); String url = NetmeraConstants.Netmera_Domain_Url + NetmeraConstants.Netmera_Push_Server_Url + NetmeraConstants.Netmera_Push_Unregister; NetmeraHttpUtils.registerUnregisterPush(url, postParameters, ex => { if (ex != null) { if (callback != null) { callback(new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "Unregister failed.")); } } else if (callback != null) { callback(ex); } }); }
private static void loginAsGuestRequest(Action <JObject, Exception> callback) { NetmeraHttpUtils.loginAsGuest((json, ex) => { if (json != null) { if (json["data"] != null && json["data"].First != null) { if (callback != null) { callback((JObject)json.First.First, ex); } } else if (json["error"] != null) { String error = json["error"]["message"].ToString(); if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, error)); } } else if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while logging user")); } } else { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while logging user")); } } }); }
private void searchFromNetwork(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; } NetmeraHttpUtils.search(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(); } }); }
private JArray searchUser(RequestItem item) { return(new JArray(NetmeraHttpUtils.searchUser(item))); }
/// <summary> /// Gets the <see cref="NetmeraContent"/> from the network, not the cache. /// </summary> /// <param name="path">Content path to get</param> /// <param name="callback">Method finding the content as the result of get operation and exception if exists.</param> public void getFromNetwork(String path, Action <NetmeraContent, Exception> callback) { RequestItem item = new RequestItem(); if (path == null || path.Length == 0) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Path cannot be null or empty")); } } item.path = path; item.contentType = NetmeraConstants.Default_ContentType; item.customCondition = getCustomCondition(); NetmeraHttpUtils.get(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) { if (contentList != null && contentList.Count != 0) { callback(contentList.ToArray()[0], 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(); } }); }
/// <summary> /// send push message /// </summary> /// <param name="channelList">channel list</param> /// <param name="callback">push channel, netmera push detail</param> protected void sendPushMessage(List <String> channelList, Action <Dictionary <PushChannel, NetmeraPushDetail>, Exception> callback) { if (NetmeraClient.securityToken == null) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Apikey cannot be null, please call NetmeraClient.init() method first!")); } } if (string.IsNullOrEmpty(message)) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_MESSAGE_EMPTY, "Message cannot be empty")); } } else if (message.Length > 180) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_MESSAGE_LIMIT, "Message limit cannot exceed 180 characters")); } } else { try { String groupString = null; if (deviceGroups != null && deviceGroups.Count != 0) { JArray jsonArrayForDeviceGroups = JArray.FromObject(deviceGroups); groupString = jsonArrayForDeviceGroups.ToString(); } JArray jsonArrayForChannels = JArray.FromObject(channelList); String channels = jsonArrayForChannels.ToString(); Dictionary <string, object> postParameters = new Dictionary <string, object>(); postParameters.Add(NetmeraConstants.Netmera_Push_Android_Message, message); postParameters.Add(NetmeraConstants.Netmera_Push_Channels, channels); postParameters.Add(NetmeraConstants.Netmera_Push_Apikey, NetmeraClient.securityToken); postParameters.Add(NetmeraConstants.Netmera_Push_Device_Groups, groupString); if (this.locationType == NetmeraConstants.Netmera_Push_Type_Box_Location) { postParameters.Add(NetmeraConstants.Netmera_Push_LocationType_Params, NetmeraConstants.Netmera_Push_Type_Box_Location); postParameters.Add(NetmeraConstants.Netmera_Push_Latitude1_Params, this.firstLoc.getLatitude()); postParameters.Add(NetmeraConstants.Netmera_Push_Longitude1_Params, this.firstLoc.getLongitude()); postParameters.Add(NetmeraConstants.Netmera_Push_Latitude2_Params, this.secondLoc.getLatitude()); postParameters.Add(NetmeraConstants.Netmera_Push_Longitude2_Params, this.secondLoc.getLongitude()); } else if (this.locationType == NetmeraConstants.Netmera_Push_Type_Circle_Location) { postParameters.Add(NetmeraConstants.Netmera_Push_LocationType_Params, NetmeraConstants.Netmera_Push_Type_Circle_Location); postParameters.Add(NetmeraConstants.Netmera_Push_Latitude1_Params, this.firstLoc.getLatitude()); postParameters.Add(NetmeraConstants.Netmera_Push_Longitude1_Params, this.firstLoc.getLongitude()); postParameters.Add(NetmeraConstants.LocationDistance_Params, this.distance); } String url = NetmeraConstants.Netmera_Domain_Url + NetmeraConstants.Netmera_Push_Server_Url + NetmeraConstants.Netmera_Push_Send; NetmeraHttpUtils.sendPushMessage(url, postParameters, callback); } catch (ProtocolViolationException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_HTTP_PROTOCOL_EXCEPTION, "Protocol exception occurred while sending notification to devices")); } } catch (IOException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while sending notification to devices")); } } catch (JsonException) { if (callback != null) { callback(null, null); } } } }
/// <summary> /// Finds the number of <see cref="NetmeraContent"/> objects that matches with the query. /// </summary> /// <param name="callback">Method called when count operation finishes</param> public void count(Action <long, Exception> callback) { RequestItem item = new RequestItem(); if (searchText != null) { item.searchText = searchText; } 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(); NetmeraHttpUtils.search(item, (lno, ex) => { if (ex != null) { if (callback != null) { callback(0, ex); } } else if (lno != null) { try { long count = getNumberOfTotalResults(new JArray(lno)); if (callback != null) { callback(count, null); } } catch (JsonException e) { if (callback != null) { callback(0, 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(0, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in search method.", e.Message)); } } catch (Exception e) { if (callback != null) { callback(0, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred in search method.", e.Message)); } } NetmeraClient.finish(); } NetmeraClient.finish(); }); }
/// <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(); } }); }