/// <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); } }
/// <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(); } }); }