Exemple #1
0
        public BackendlessCollection <SearchMatchesResult> RelativeFind(BackendlessGeoQuery geoQuery)
        {
            if (geoQuery == null)
            {
                throw new ArgumentNullException(ExceptionMessage.NULL_GEO_QUERY);
            }

            if (geoQuery.RelativeFindMetadata.Count == 0 || geoQuery.RelativeFindPercentThreshold == 0)
            {
                throw new ArgumentException(ExceptionMessage.INCONSISTENT_GEO_RELATIVE);
            }

            Invoker.Api api   = Invoker.Api.UNKNOWN;
            string      query = GetGetPointsQuery(geoQuery, out api);

            BackendlessCollection <SearchMatchesResult> result = null;
            Dictionary <string, BackendlessCollection <SearchMatchesResult> > r = Invoker.InvokeSync <Dictionary <string, BackendlessCollection <SearchMatchesResult> > >(Invoker.Api.GEOSERVICE_RELATIVEFIND, new Object[] { null, query });

            if (r != null && r.ContainsKey(COLLECTION))
            {
                result       = (BackendlessCollection <SearchMatchesResult>)r[COLLECTION];
                result.Query = geoQuery;
            }

            return(result);
        }
Exemple #2
0
        public void RelativeFind(BackendlessGeoQuery geoQuery, AsyncCallback <BackendlessCollection <SearchMatchesResult> > callback)
        {
            try
            {
                if (geoQuery == null)
                {
                    throw new ArgumentNullException(ExceptionMessage.NULL_GEO_QUERY);
                }

                if (geoQuery.RelativeFindMetadata.Count == 0 || geoQuery.RelativeFindPercentThreshold == 0)
                {
                    throw new ArgumentException(ExceptionMessage.INCONSISTENT_GEO_RELATIVE);
                }

                Invoker.Api api   = Invoker.Api.UNKNOWN;
                string      query = GetGetPointsQuery(geoQuery, out api);

                var responder = new AsyncCallback <Dictionary <string, BackendlessCollection <SearchMatchesResult> > >(r =>
                {
                    BackendlessCollection <SearchMatchesResult> result = null;
                    if (r != null && r.ContainsKey(COLLECTION))
                    {
                        result       = (BackendlessCollection <SearchMatchesResult>)r[COLLECTION];
                        result.Query = geoQuery;
                    }
                    if (callback != null)
                    {
                        callback.ResponseHandler.Invoke(result);
                    }
                }, f =>
                {
                    if (callback != null)
                    {
                        callback.ErrorHandler.Invoke(f);
                    }
                    else
                    {
                        throw new BackendlessException(f);
                    }
                });

                Invoker.InvokeAsync <Dictionary <string, BackendlessCollection <SearchMatchesResult> > >(Invoker.Api.GEOSERVICE_RELATIVEFIND, new Object[] { null, query }, responder);
            }
            catch (System.Exception ex)
            {
                if (callback != null)
                {
                    callback.ErrorHandler.Invoke(new BackendlessFault(ex));
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #3
0
        public void SavePoint(GeoPoint geoPoint, AsyncCallback <GeoPoint> callback)
        {
            try
            {
                if (geoPoint == null)
                {
                    throw new ArgumentNullException(ExceptionMessage.NULL_GEOPOINT);
                }

                CheckCoordinates(geoPoint.Latitude, geoPoint.Longitude);

                var responder = new AsyncCallback <Dictionary <string, GeoPoint> >(r =>
                {
                    GeoPoint result = null;
                    if (r != null && r.ContainsKey(GEOPOINT))
                    {
                        result = (GeoPoint)r[GEOPOINT];
                    }
                    if (callback != null)
                    {
                        callback.ResponseHandler.Invoke(result);
                    }
                }, f =>
                {
                    if (callback != null)
                    {
                        callback.ErrorHandler.Invoke(f);
                    }
                    else
                    {
                        throw new BackendlessException(f);
                    }
                });

                Invoker.Api api = Invoker.Api.GEOSERVICE_SAVEPOINT;
                if (string.IsNullOrEmpty(geoPoint.ObjectId) == false)
                {
                    api = Invoker.Api.GEOSERVICE_UPDATEPOINT;
                }

                Invoker.InvokeAsync <Dictionary <string, GeoPoint> >(api, new object[] { null, GetSavePointQuery(geoPoint) }, responder);
            }
            catch (System.Exception ex)
            {
                if (callback != null)
                {
                    callback.ErrorHandler.Invoke(new BackendlessFault(ex));
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #4
0
        public void GetPoints(BackendlessGeoQuery geoQuery, AsyncCallback <BackendlessCollection <GeoPoint> > callback)
        {
            try
            {
                checkGeoQuery(geoQuery);

                Invoker.Api api   = Invoker.Api.UNKNOWN;
                string      query = GetGetPointsQuery(geoQuery, out api);

                var responder = new AsyncCallback <Dictionary <string, BackendlessCollection <GeoPoint> > >(r =>
                {
                    BackendlessCollection <GeoPoint> result = null;
                    if (r != null && r.ContainsKey(COLLECTION))
                    {
                        result       = (BackendlessCollection <GeoPoint>)r[COLLECTION];
                        result.Query = geoQuery;
                    }

                    if (callback != null)
                    {
                        callback.ResponseHandler.Invoke(result);
                    }
                }, f =>
                {
                    if (callback != null)
                    {
                        callback.ErrorHandler.Invoke(f);
                    }
                    else
                    {
                        throw new BackendlessException(f);
                    }
                });

                Invoker.InvokeAsync <Dictionary <string, BackendlessCollection <GeoPoint> > >(api, new Object[] { null, query }, responder);
            }
            catch (System.Exception ex)
            {
                if (callback != null)
                {
                    callback.ErrorHandler.Invoke(new BackendlessFault(ex));
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #5
0
        public BackendlessCollection <GeoPoint> GetPoints(BackendlessGeoQuery geoQuery)
        {
            checkGeoQuery(geoQuery);

            Invoker.Api api   = Invoker.Api.UNKNOWN;
            string      query = GetGetPointsQuery(geoQuery, out api);

            BackendlessCollection <GeoPoint> result = null;
            Dictionary <string, BackendlessCollection <GeoPoint> > r = Invoker.InvokeSync <Dictionary <string, BackendlessCollection <GeoPoint> > >(api, new Object[] { null, query });

            if (r != null && r.ContainsKey(COLLECTION))
            {
                result       = (BackendlessCollection <GeoPoint>)r[COLLECTION];
                result.Query = geoQuery;
            }

            return(result);
        }
Exemple #6
0
        private static string GetGetPointsQuery(BackendlessGeoQuery geoQuery, out Invoker.Api api)
        {
            string query = null;

            if (geoQuery != null)
            {
                double[] searchRectangle = geoQuery.SearchRectangle;
                if (searchRectangle != null)
                {
                    api = Invoker.Api.GEOSERVICE_GETRECT;

                    if (searchRectangle.Length == 4)
                    {
                        AddQuery(ref query, "nwlat=" + searchRectangle[0]);
                        AddQuery(ref query, "nwlon=" + searchRectangle[1]);
                        AddQuery(ref query, "selat=" + searchRectangle[2]);
                        AddQuery(ref query, "selon=" + searchRectangle[3]);
                    }
                }
                else
                {
                    api = Invoker.Api.GEOSERVICE_GETPOINTS;

                    Dictionary <string, string> relativeFindMetadataList = geoQuery.RelativeFindMetadata;
                    if (relativeFindMetadataList != null && relativeFindMetadataList.Count > 0)
                    {
                        api = Invoker.Api.GEOSERVICE_RELATIVEFIND;

                        string metadata = JsonMapper.ToJson(relativeFindMetadataList);
                        if (string.IsNullOrEmpty(metadata) == false)
                        {
                            AddQuery(ref query, "relativeFindMetadata=" + UnityEngine.WWW.EscapeURL(metadata));
                        }

                        AddQuery(ref query, "relativeFindPercentThreshold=" + geoQuery.RelativeFindPercentThreshold);
                    }

                    if (Double.NaN.Equals(geoQuery.Latitude) == false)
                    {
                        AddQuery(ref query, "lat=" + geoQuery.Latitude);
                    }

                    if (Double.NaN.Equals(geoQuery.Longitude) == false)
                    {
                        AddQuery(ref query, "lon=" + geoQuery.Longitude);
                    }

                    if (Double.NaN.Equals(geoQuery.Radius) == false)
                    {
                        AddQuery(ref query, "r=" + geoQuery.Radius);
                    }

                    Units?unit = geoQuery.Units;
                    if (unit != null)
                    {
                        AddQuery(ref query, "units=" + unit.ToString());
                    }
                }

                List <string> categoriesList = geoQuery.Categories;
                if (categoriesList != null && categoriesList.Count > 0)
                {
                    string categories = "";
                    foreach (string category in categoriesList)
                    {
                        if (string.IsNullOrEmpty(categories) == false)
                        {
                            categories += ",";
                        }
                        categories += category;
                    }
                    if (string.IsNullOrEmpty(categories) == false)
                    {
                        AddQuery(ref query, "categories=" + categories);
                    }
                }

                Dictionary <string, string> metadataList = geoQuery.Metadata;
                if (metadataList != null && metadataList.Count > 0)
                {
                    string metadata = JsonMapper.ToJson(metadataList);
                    if (string.IsNullOrEmpty(metadata) == false)
                    {
                        AddQuery(ref query, "metadata=" + UnityEngine.WWW.EscapeURL(metadata));
                    }
                }

                AddQuery(ref query, "includemetadata=" + geoQuery.IncludeMeta.ToString().ToLower());

                AddQuery(ref query, "pagesize=" + geoQuery.PageSize);

                AddQuery(ref query, "offset=" + geoQuery.Offset);
            }
            else
            {
                api = Invoker.Api.UNKNOWN;
            }

            return(query);
        }