Пример #1
0
        public static bool sendHttpWithJsonwithReturn(String url, String jsonCall, String method)
        {
            bool flag = false;

            try
            {
                StringBuilder strBuild = new StringBuilder(url);
                strBuild.Append("&").Append(NetmeraConstants.Netmera_SDK_Params).Append(NetmeraConstants.Netmera_SDK_Value);
                strBuild.Append("&").Append(NetmeraConstants.Netmera_SDKVERSION_Params).Append(NetmeraConstants.Netmera_SDKVERSION_Value);

                WebRequest webRequest = WebRequest.Create(url);
                webRequest.Method      = method;
                webRequest.ContentType = NetmeraConstants.Http_Content_Type;

                // it is for json call (add json body to the request. e.g. for user update operation)
                if (!String.IsNullOrEmpty(jsonCall))
                {
                    Stream       writerStream = ((HttpWebRequest)webRequest).GetRequestStream();
                    StreamWriter writer       = new StreamWriter(writerStream);
                    writer.Write(jsonCall);
                    writer.Flush();
                    writer.Close();
                }

                HttpWebResponse b = (HttpWebResponse)webRequest.GetResponse();

                Stream       readerStream = b.GetResponseStream();
                StreamReader uberReader   = new StreamReader(readerStream);
                String       response     = uberReader.ReadToEnd();
                b.Close();

                NetmeraClient.finish();
                if (response.IndexOf("true") != -1)
                {
                    flag = true;
                }
                return(flag);
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "A general Web exception occurred.");
            }
        }
Пример #2
0
        /// <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();
                }
            });
        }
Пример #3
0
        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();
                }
            });
        }
Пример #4
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>
        /// <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();
                }
            });
        }
Пример #5
0
        /// <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();
            });
        }