Пример #1
0
        public async Task EqualToWithCloudSearchOverCloudObject()
        {
            var custom     = new CB.CloudTable("CustomRelation");
            var newColumn1 = new CB.Column("newColumn7");

            newColumn1.DataType = CB.DataType.Relation.ToString();
            custom.AddColumn(newColumn1);
            await custom.SaveAsync();

            var loc  = new CB.CloudGeoPoint(17.7, 80.0);
            var obj  = new CB.CloudObject("CustomRelation");
            var obj1 = new CB.CloudObject("student1");

            obj1.Set("name", "Ranjeet");
            obj.Set("newColumn7", obj1);
            await obj.SaveAsync();

            var search = new CB.CloudSearch("CustomRelation");

            search.SearchFilter = new CB.SearchFilter();
            search.SearchFilter.EqualTo("newColumn7", obj.Get("newColumn7"));
            var list = (List <CB.CloudObject>) await search.Search();

            if (list.Count > 0)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("should have retrieved data");
            }
        }
Пример #2
0
        public async Task getDataFromServerNearFunction()
        {
            var custom     = new CB.CloudTable("CustomGeoPoint");
            var newColumn7 = new CB.Column("location");

            newColumn7.DataType = CB.DataType.GeoPoint.ToString();
            custom.AddColumn(newColumn7);
            var response = await custom.SaveAsync();

            var loc = new CB.CloudGeoPoint(17.7, 80.0);
            var obj = new CB.CloudObject("CustomGeoPoint");

            obj.Set("location", loc);
            await obj.SaveAsync();

            var search = new CB.CloudSearch("CustomGeoPoint");

            search.SearchFilter = new CB.SearchFilter();
            search.SearchFilter.Near("location", loc, 1);
            var list = (List <CB.CloudObject>) await search.Search();

            if (list.Count > 0)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("should have retrieved data");
            }
        }
Пример #3
0
        public async Task SaveGeoPoint()
        {
            var obj = new CB.CloudObject("Custom5");
            var loc = new CB.CloudGeoPoint((decimal)17.7, (decimal)78.9);

            obj.Set("geopoint", loc);
            await obj.SaveAsync();

            Assert.IsTrue(true);
        }
Пример #4
0
        public async Task saveGeoPoint()
        {
            var obj = new CB.CloudObject("Custom5");
            var loc = new CB.CloudGeoPoint(17.7, 78.9);

            obj.Set("location", loc);
            await obj.SaveAsync();

            Assert.IsTrue(true);
        }
Пример #5
0
        public async Task shouldIncludeRelationOnSearch()
        {
            var obj = new CB.CloudObject("Custom5");
            var loc = new CB.CloudGeoPoint(18.19, 79.3);

            loc.Latitude  = 78;
            loc.Longitude = 17;
            obj.Set("location", loc);
            await obj.SaveAsync();
        }
Пример #6
0
        public async Task shouldSaveLatitudeAndLongitude()
        {
            var obj = new CB.CloudObject("Custom5");
            var loc = new CB.CloudGeoPoint(17.7, 80.0);

            obj.Set("location", loc);
            await obj.SaveAsync();

            Assert.IsTrue(true);
        }
Пример #7
0
        private double greatCircleFormula(CB.CloudGeoPoint point)
        {
            coordinates       = (double[])dictionary["coordinates"];
            point.coordinates = (double[])point.dictionary["coordinates"];

            double dLat = toRad(coordinates[1] - point.coordinates[1]);
            double dLon = toRad(coordinates[0] - point.coordinates[0]);

            double lat1 = toRad(point.coordinates[1]);
            double lat2 = toRad(coordinates[1]);

            double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2);
            double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            return(c);
        }
Пример #8
0
        private decimal greatCircleFormula(CB.CloudGeoPoint point)
        {
            coordinates       = (decimal[])dictionary["coordinates"];
            point.coordinates = (decimal[])point.dictionary["coordinates"];

            decimal dLat = (decimal)toRad((double)(coordinates[1] - point.coordinates[1]));
            decimal dLon = (decimal)toRad((double)(coordinates[0] - point.coordinates[0]));

            decimal lat1 = (decimal)toRad((double)point.coordinates[1]);
            decimal lat2 = (decimal)toRad((double)coordinates[1]);

            decimal a = (decimal)(Math.Sin((double)dLat / 2) * Math.Sin((double)dLat / 2) + Math.Sin((double)dLon / 2) * Math.Sin((double)dLon / 2) * Math.Cos((double)lat1) * Math.Cos((double)lat2));
            decimal c = (decimal)(2 * Math.Atan2(Math.Sqrt((double)a), Math.Sqrt(1 - (double)a)));

            return(c);
        }
Пример #9
0
        public async Task NearTest()
        {
            var query = new CB.CloudQuery("Custom5");
            var loc   = new CB.CloudGeoPoint((decimal)17.7, (decimal)78.9);

            query.Near("geopoint", loc, 400000);
            var response = await query.FindAsync();

            if (response.Count > 0)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("should retrieve saved data with particular value");
            }
        }
Пример #10
0
 public CloudQuery Near(string columnName, CB.CloudGeoPoint geoPoint, double maxDistance)
 {
     if (((Dictionary <string, Object>)(this.dictionary["query"]))[columnName] == null)
     {
         ((Dictionary <string, Object>)(this.dictionary["query"]))[columnName] = new Dictionary <string, Object>();
         Dictionary <string, object> near     = new Dictionary <string, object>();
         Dictionary <string, object> geometry = new Dictionary <string, object>();
         double[] coordinates = (double[])geoPoint.dictionary["coordinates"];
         geometry.Add("coordinates", coordinates);
         geometry.Add("type", "Point");
         near.Add("$geometry", geometry);
         near.Add("$maxDistance", maxDistance);
         near.Add("$minDistance", null);
         ((Dictionary <string, Object>)(((Dictionary <string, Object>)(this.dictionary["query"]))[columnName]))["$near"] = near;
     }
     return(this);
 }
Пример #11
0
        public async Task nearTest()
        {
            var query = new CB.CloudQuery("Custom5");
            var loc   = new CB.CloudGeoPoint(17.7, 78.9);

            query.Near("location", loc, 400000);
            var response = (List <CB.CloudObject>) await query.FindAsync();

            if (response.Count > 0)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("should retrieve saved data with particular value");
            }
        }
Пример #12
0
        public async Task geoWithinTestCircle()
        {
            var query = new CB.CloudQuery("Custom5");
            var loc   = new CB.CloudGeoPoint(17.3, 78.3);

            query.Limit = 4;
            query.GeoWithin("location", loc, 1000);
            var response = (List <CB.CloudObject>) await query.FindAsync();

            if (response.Count > 0)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("should retrieve saved data with particular value");
            }
        }
Пример #13
0
        public async Task geoWithinTestLimit()
        {
            var query = new CB.CloudQuery("Custom5");
            var loc1  = new CB.CloudGeoPoint(18.4, 78.9);
            var loc2  = new CB.CloudGeoPoint(17.4, 78.4);
            var loc3  = new CB.CloudGeoPoint(17.7, 80.4);

            CB.CloudGeoPoint[] loc = { loc1, loc2, loc3 };
            query.Limit = 4;
            query.GeoWithin("location", loc);
            var response = (List <CB.CloudObject>) await query.FindAsync();

            if (response.Count > 0)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("should retrieve saved data with particular value");
            }
        }
Пример #14
0
        public async Task GeoWithinTest()
        {
            var query = new CB.CloudQuery("Custom5");
            var loc1  = new CB.CloudGeoPoint((decimal)18.4, (decimal)78.9);
            var loc2  = new CB.CloudGeoPoint((decimal)17.4, (decimal)78.4);
            var loc3  = new CB.CloudGeoPoint((decimal)17.7, (decimal)80.4);

            CB.CloudGeoPoint[] loc = { loc1, loc2, loc3 };

            query.GeoWithin("location", loc);
            var response = await query.FindAsync();

            if (response.Count > 0)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("should retrieve saved data with particular value");
            }
        }
Пример #15
0
        public double DistanceInKMs(CB.CloudGeoPoint point)
        {
            int earthRedius = 6371; //in Kilometer

            return(earthRedius * greatCircleFormula(point));
        }
Пример #16
0
 public void createGeoPointWithZero()
 {
     var loc = new CB.CloudGeoPoint(0, 0);
 }
Пример #17
0
        internal static object Deserialize(object data)
        {
            if (data.GetType() == typeof(ArrayList))
            {
                ArrayList newList = new ArrayList();

                for (int i = 0; i < ((ArrayList)data).Count; i++)
                {
                    newList.Add(Deserialize((((ArrayList)data)[i])));
                }

                return(newList);
            }
            else if (data.GetType().IsArray || data.GetType() == typeof(JArray))
            {
                ArrayList newList = new ArrayList(((IEnumerable)data).Cast <object>()
                                                  .Select(x => Deserialize(x))
                                                  .ToList());
                return(newList);
            }
            else if (data.GetType() == typeof(Dictionary <string, Object>) || data.GetType() == typeof(JObject))
            {
                CB.CloudObject obj = null;

                Dictionary <string, Object> tempData = null;

                if (data.GetType() == typeof(JObject))
                {
                    tempData = ((JObject)data).ToObject <Dictionary <string, object> >();
                }
                else
                {
                    tempData = (Dictionary <string, Object>)data;
                }

                if (((Dictionary <string, Object>)(tempData)).ContainsKey("_type"))
                {
                    if (obj == null && ((Dictionary <string, Object>)(tempData))["_type"] != null && ((Dictionary <string, Object>)(tempData))["_type"].ToString() == "custom")
                    {
                        obj = new CloudObject(((Dictionary <string, Object>)(tempData))["_tableName"].ToString());
                    }

                    if (obj == null && ((Dictionary <string, Object>)(tempData))["_type"] != null && ((Dictionary <string, Object>)(tempData))["_type"].ToString() == "user")
                    {
                        obj = new CloudUser();
                    }

                    if (obj == null && ((Dictionary <string, Object>)(tempData))["_type"] != null && ((Dictionary <string, Object>)(tempData))["_type"].ToString() == "role")
                    {
                        obj = new CloudRole(((Dictionary <string, Object>)(tempData))["name"].ToString());
                    }

                    if (obj == null && ((Dictionary <string, Object>)(tempData))["_type"] != null && ((Dictionary <string, Object>)(tempData))["_type"].ToString() == "point")
                    {
                        //return geopoint dictionary.
                        CloudGeoPoint point = new CloudGeoPoint(Decimal.Parse(((Dictionary <string, Object>)(tempData))["longitude"].ToString()), Decimal.Parse(((Dictionary <string, Object>)(tempData))["latitude"].ToString()));
                        return(point);
                    }

                    foreach (var param in ((Dictionary <string, Object>)(tempData)))
                    {
                        if (param.Value == null)
                        {
                            obj.dictionary[param.Key] = null;
                        }
                        else if (param.Key == "ACL")
                        {
                            var acl = new CB.ACL();
                            obj.dictionary[param.Key] = acl;
                        }
                        else if (param.Key == "expires")
                        {
                            obj.dictionary["expires"] = ((Dictionary <string, Object>)(tempData))["expires"];
                        }
                        else if (param.Value != null && typeof(JObject) == param.Value.GetType() && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >().ContainsKey("_type") && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["_type"].ToString() == "custom")
                        {
                            CB.CloudObject cbObj = new CB.CloudObject(((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["_tableName"].ToString());
                            cbObj = (CloudObject)Deserialize(((JObject)(param.Value)).ToObject <Dictionary <string, object> >());
                            obj.dictionary[param.Key] = cbObj;
                        }
                        else if (param.Value != null && typeof(JObject) == param.Value.GetType() && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >().ContainsKey("_type") && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["_type"].ToString() == "user")
                        {
                            CB.CloudUser cbObj = new CB.CloudUser();
                            cbObj = (CloudUser)Deserialize(((JObject)(param.Value)).ToObject <Dictionary <string, object> >());
                            obj.dictionary[param.Key] = cbObj;
                        }
                        else if (param.Value != null && typeof(JObject) == param.Value.GetType() && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >().ContainsKey("_type") && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["_type"].ToString() == "custom")
                        {
                            CB.CloudRole cbObj = new CB.CloudRole(((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["name"].ToString());
                            cbObj = (CloudRole)Deserialize(((JObject)(param.Value)).ToObject <Dictionary <string, object> >());
                            obj.dictionary[param.Key] = cbObj;
                        }
                        else if (param.Value != null && typeof(JObject) == param.Value.GetType() && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >().ContainsKey("_type") && ((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["_type"].ToString() == "point")
                        {
                            CB.CloudGeoPoint cbObj = new CB.CloudGeoPoint(Decimal.Parse(((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["longitude"].ToString()), Decimal.Parse(((JObject)(param.Value)).ToObject <Dictionary <string, object> >()["latitude"].ToString()));
                            cbObj = (CloudGeoPoint)(Deserialize(((JObject)(param.Value)).ToObject <Dictionary <string, object> >()));
                            obj.dictionary[param.Key] = cbObj;
                        }
                        else if (param.Value.GetType() == typeof(ArrayList))
                        {
                            obj.dictionary[param.Key] = Deserialize(param.Value);
                        }
                        else if (param.Value.GetType().IsArray)
                        {
                            obj.dictionary[param.Key] = Deserialize(param.Value);
                        }
                        else if (param.Value.GetType() == typeof(JArray))
                        {
                            obj.dictionary[param.Key] = Deserialize(param.Value);
                        }
                        else
                        {
                            obj.dictionary[param.Key] = param.Value;
                        }
                    }

                    return(obj);
                }
                else
                {
                    return(tempData);
                }
            }

            return(data);
        }
Пример #18
0
 public double DistanceInRadians(CB.CloudGeoPoint point)
 {
     return(this.greatCircleFormula(point));
 }
Пример #19
0
        public double DistanceInMiles(CB.CloudGeoPoint point)
        {
            int earthRedius = 3959; // in Miles

            return(earthRedius * greatCircleFormula(point));
        }