Example #1
0
        /// <summary>
        /// Coordinates the specified geography.
        /// </summary>
        /// <param name="geography">The geography.</param>
        /// <returns></returns>
        public static List <MapCoordinate> Coordinates(this System.Data.Entity.Spatial.DbGeography geography)
        {
            var coordinates = new List <MapCoordinate>();

            var match = Regex.Match(geography.AsText(), @"(?<=POLYGON \(\()[^\)]*(?=\)\))");

            if (match.Success)
            {
                string[] longSpaceLat = match.ToString().Split(',');

                for (int i = 0; i < longSpaceLat.Length; i++)
                {
                    string[] longLat = longSpaceLat[i].Trim().Split(' ');
                    if (longLat.Length == 2)
                    {
                        double?lat = longLat[1].AsDoubleOrNull();
                        double?lon = longLat[0].AsDoubleOrNull();
                        if (lat.HasValue && lon.HasValue)
                        {
                            coordinates.Add(new MapCoordinate(lat, lon));
                        }
                    }
                }
            }

            return(coordinates);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject location    = JObject.Load(reader);
            JToken  token       = location["Geography"]["WellKnownText"];
            string  tokenString = token.ToString();

            System.Data.Entity.Spatial.DbGeography converted = DbGeographyHelper.CreatePolygon(tokenString);
            return(converted);
        }
Example #3
0
        public virtual int spAddAdvert(Nullable <int> category, string name, string description, Nullable <System.Guid> createdUserId, Nullable <double> price, string address, string phone, Nullable <int> messageType, System.Data.Entity.Spatial.DbGeography position, string imgUrls, string youTubeUrl)
        {
            var categoryParameter = category.HasValue ?
                                    new ObjectParameter("Category", category) :
                                    new ObjectParameter("Category", typeof(int));

            var nameParameter = name != null ?
                                new ObjectParameter("Name", name) :
                                new ObjectParameter("Name", typeof(string));

            var descriptionParameter = description != null ?
                                       new ObjectParameter("Description", description) :
                                       new ObjectParameter("Description", typeof(string));

            var createdUserIdParameter = createdUserId.HasValue ?
                                         new ObjectParameter("CreatedUserId", createdUserId) :
                                         new ObjectParameter("CreatedUserId", typeof(System.Guid));

            var priceParameter = price.HasValue ?
                                 new ObjectParameter("Price", price) :
                                 new ObjectParameter("Price", typeof(double));

            var addressParameter = address != null ?
                                   new ObjectParameter("Address", address) :
                                   new ObjectParameter("Address", typeof(string));

            var phoneParameter = phone != null ?
                                 new ObjectParameter("Phone", phone) :
                                 new ObjectParameter("Phone", typeof(string));

            var messageTypeParameter = messageType.HasValue ?
                                       new ObjectParameter("MessageType", messageType) :
                                       new ObjectParameter("MessageType", typeof(int));

            var positionParameter = position != null ?
                                    new ObjectParameter("Position", position) :
                                    new ObjectParameter("Position", typeof(System.Data.Entity.Spatial.DbGeography));

            var imgUrlsParameter = imgUrls != null ?
                                   new ObjectParameter("ImgUrls", imgUrls) :
                                   new ObjectParameter("ImgUrls", typeof(string));

            var youTubeUrlParameter = youTubeUrl != null ?
                                      new ObjectParameter("YouTubeUrl", youTubeUrl) :
                                      new ObjectParameter("YouTubeUrl", typeof(string));

            return(((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("spAddAdvert", categoryParameter, nameParameter, descriptionParameter, createdUserIdParameter, priceParameter, addressParameter, phoneParameter, messageTypeParameter, positionParameter, imgUrlsParameter, youTubeUrlParameter));
        }
Example #4
0
        public virtual int GetHelpers(Nullable <int> rADIUS, string lAT, string lONG, System.Data.Entity.Spatial.DbGeography gEO1)
        {
            var rADIUSParameter = rADIUS.HasValue ?
                                  new ObjectParameter("RADIUS", rADIUS) :
                                  new ObjectParameter("RADIUS", typeof(int));

            var lATParameter = lAT != null ?
                               new ObjectParameter("LAT", lAT) :
                               new ObjectParameter("LAT", typeof(string));

            var lONGParameter = lONG != null ?
                                new ObjectParameter("LONG", lONG) :
                                new ObjectParameter("LONG", typeof(string));

            var gEO1Parameter = gEO1 != null ?
                                new ObjectParameter("GEO1", gEO1) :
                                new ObjectParameter("GEO1", typeof(System.Data.Entity.Spatial.DbGeography));

            return(((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("GetHelpers", rADIUSParameter, lATParameter, lONGParameter, gEO1Parameter));
        }
Example #5
0
        public SubscriptionMatchGroup GetSubscriptionMatches(OCM.Core.Data.OCMEntities dataModel, POIManager poiManager, OCM.Core.Data.UserSubscription subscription, DateTime?dateFrom = null)
        {
            SubscriptionMatchGroup subscriptionMatchGroup = new SubscriptionMatchGroup();

            var checkFromDate = DateTime.UtcNow.AddMinutes(-CHECK_INTERVAL_MINS); //check from last 5 mins etc

            if (subscription.DateLastNotified != null)
            {
                checkFromDate = subscription.DateLastNotified.Value;                                        //check from date last notified
            }
            else
            {
                checkFromDate = subscription.DateCreated;
            }

            if (dateFrom != null)
            {
                checkFromDate = dateFrom.Value;
            }

            subscriptionMatchGroup.DateFrom = checkFromDate;

            System.Data.Entity.Spatial.DbGeography searchPos = null;

            UserSubscriptionFilter filter = null;

            if (subscription.FilterSettings != null)
            {
                try
                {
                    filter = JsonConvert.DeserializeObject <UserSubscriptionFilter>(subscription.FilterSettings);
                }
                catch (Exception)
                {
                    //failed to parse subscription filter
                }
            }

            if (subscription.Latitude != null && subscription.Longitude != null)
            {
                searchPos = System.Data.Entity.Spatial.DbGeography.PointFromText("POINT(" + subscription.Longitude + " " + subscription.Latitude + ")", 4326);
            }

            if (subscription.NotifyEmergencyChargingRequests)
            {
                var emergencyCharging = dataModel.UserChargingRequests.Where(c => c.DateCreated >= checkFromDate && c.IsActive == true && c.IsEmergency == true);
                var subscriptionMatch = new SubscriptionMatch {
                    Category = SubscriptionMatchCategory.ChargingRequestEmergency, Description = "New Emergency Charging Requests"
                };

                foreach (var chargingRequest in emergencyCharging)
                {
                    //filter on location
                    if (searchPos != null)
                    {
                        if (GeoManager.CalcDistance(chargingRequest.Latitude, chargingRequest.Longitude, (double)searchPos.Latitude, (double)searchPos.Longitude, DistanceUnit.KM) < subscription.DistanceKM)
                        {
                            subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                Item = chargingRequest
                            });
                        }
                    }
                    else
                    {
                        subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                            Item = chargingRequest
                        });
                    }
                }
                if (subscriptionMatch.ItemList.Any())
                {
                    subscriptionMatchGroup.SubscriptionMatches.Add(subscriptionMatch);
                }
            }

            if (subscription.NotifyGeneralChargingRequests)
            {
                //TODO: subscription not filtered on lat/long will return global charging requests
                var generalCharging   = dataModel.UserChargingRequests.Where(c => c.DateCreated >= checkFromDate && c.IsActive == true && c.IsEmergency == false);
                var subscriptionMatch = new SubscriptionMatch {
                    Category = SubscriptionMatchCategory.ChargingRequestGeneral, Description = "New Charging Requests"
                };
                //filter on location
                foreach (var gc in generalCharging)
                {
                    if (searchPos != null)
                    {
                        if (GeoManager.CalcDistance(gc.Latitude, gc.Longitude, (double)searchPos.Latitude, (double)searchPos.Longitude, DistanceUnit.KM) < subscription.DistanceKM)
                        {
                            subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                Item = gc
                            });
                        }
                    }
                    else
                    {
                        subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                            Item = gc
                        });
                    }
                }

                if (subscriptionMatch.ItemList.Any())
                {
                    subscriptionMatchGroup.SubscriptionMatches.Add(subscriptionMatch);
                }
            }

            //check if any POI Edits (pending approval) match this subscription
            if (subscription.NotifyPOIEdits)
            {
                var poiEdits = dataModel.EditQueueItems.Where(c => c.DateSubmitted >= checkFromDate && c.PreviousData != null && c.IsProcessed == false);
                if (poiEdits.Any())
                {
                    var subscriptionMatch = new SubscriptionMatch {
                        Category = SubscriptionMatchCategory.EditedPOI, Description = "Proposed POI Edits"
                    };
                    foreach (var p in poiEdits)
                    {
                        try
                        {
                            var updatedPOI = JsonConvert.DeserializeObject <ChargePoint>(p.EditData);
                            if (IsPOISubscriptionFilterMatch(updatedPOI, filter, subscription))
                            {
                                if (searchPos != null)
                                {
                                    if (GeoManager.CalcDistance(updatedPOI.AddressInfo.Latitude, updatedPOI.AddressInfo.Longitude, (double)searchPos.Latitude, (double)searchPos.Longitude, DistanceUnit.KM) < subscription.DistanceKM)
                                    {
                                        subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                            Item = p, POI = updatedPOI
                                        });
                                    }
                                }
                                else
                                {
                                    subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                        Item = p, POI = updatedPOI
                                    });
                                }
                            }
                        }
                        catch (Exception)
                        {
                            ;;
                        }
                    }
                    if (subscriptionMatch.ItemList.Any())
                    {
                        subscriptionMatchGroup.SubscriptionMatches.Add(subscriptionMatch);
                    }
                }
            }

            //check if any new POIs
            if (subscription.NotifyPOIAdditions)
            {
                /* var newPOIs = dataModel.ChargePoints.Where(c => c.DateCreated >= checkFromDate && c.SubmissionStatusType.IsLive == true &&
                 *    (searchPos == null ||
                 *       (searchPos != null &&
                 *           c.AddressInfo.SpatialPosition.Distance(searchPos) / 1000 < subscription.DistanceKM
                 *       ))
                 *     ).ToList();*/

                var filterParams = new APIRequestParams {
                    CreatedFromDate = checkFromDate, AllowMirrorDB = true
                };
                if (searchPos != null)
                {
                    filterParams.DistanceUnit = DistanceUnit.KM;
                    filterParams.Distance     = subscription.DistanceKM;
                    filterParams.Latitude     = searchPos.Latitude;
                    filterParams.Longitude    = searchPos.Longitude;
                }
                if (subscription.CountryID != null)
                {
                    filterParams.CountryIDs = new int[] { (int)subscription.CountryID };
                }
                var poiCollection = poiManager.GetChargePoints(filterParams);

                if (poiCollection.Any())
                {
                    var subscriptionMatch = new SubscriptionMatch {
                        Category = SubscriptionMatchCategory.NewPOI, Description = "New POIs Added"
                    };
                    foreach (var p in poiCollection)
                    {
                        //var poi = OCM.API.Common.Model.Extensions.ChargePoint.FromDataModel(p);
                        if (IsPOISubscriptionFilterMatch(p, filter, subscription))
                        {
                            subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                POI = p
                            });
                        }
                    }
                    if (subscriptionMatch.ItemList.Any())
                    {
                        subscriptionMatchGroup.SubscriptionMatches.Add(subscriptionMatch);
                    }
                }
            }

            //check if any POI Updates match this subscription
            if (subscription.NotifyPOIUpdates)
            {
                var poiUpdates = dataModel.EditQueueItems.Where(c => c.DateProcessed >= checkFromDate && c.IsProcessed == true && c.PreviousData != null);
                if (poiUpdates.Any())
                {
                    var subscriptionMatch = new SubscriptionMatch {
                        Category = SubscriptionMatchCategory.UpdatedPOI, Description = "POIs Updated"
                    };
                    foreach (var p in poiUpdates)
                    {
                        try
                        {
                            var updatedPOI = JsonConvert.DeserializeObject <ChargePoint>(p.EditData);
                            if (IsPOISubscriptionFilterMatch(updatedPOI, filter, subscription))
                            {
                                if (searchPos != null)
                                {
                                    if (GeoManager.CalcDistance(updatedPOI.AddressInfo.Latitude, updatedPOI.AddressInfo.Longitude, (double)searchPos.Latitude, (double)searchPos.Longitude, DistanceUnit.KM) < subscription.DistanceKM)
                                    {
                                        subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                            Item = p, POI = updatedPOI
                                        });
                                    }
                                }
                                else
                                {
                                    subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                        Item = p, POI = updatedPOI
                                    });
                                }
                            }
                        }
                        catch (Exception)
                        {
                            ;;
                        }
                    }
                    if (subscriptionMatch.ItemList.Any())
                    {
                        subscriptionMatchGroup.SubscriptionMatches.Add(subscriptionMatch);
                    }
                }
            }

            //check if any new comments match this subscription
            if (subscription.NotifyComments)
            {
                var newComments = dataModel.UserComments.Where(c => c.DateCreated >= checkFromDate &&
                                                               (searchPos == null ||
                                                                (searchPos != null &&
                                                                 c.ChargePoint.AddressInfo.SpatialPosition.Distance(searchPos) / 1000 < subscription.DistanceKM
                                                                ))
                                                               );
                if (newComments.Any())
                {
                    var subscriptionMatch = new SubscriptionMatch {
                        Category = SubscriptionMatchCategory.NewComment, Description = "New Comments Added"
                    };
                    foreach (var c in newComments)
                    {
                        var poi = OCM.API.Common.Model.Extensions.ChargePoint.FromDataModel(c.ChargePoint);
                        if (IsPOISubscriptionFilterMatch(poi, filter, subscription))
                        {
                            subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                Item = OCM.API.Common.Model.Extensions.UserComment.FromDataModel(c, true), POI = poi
                            });
                        }
                    }
                    if (subscriptionMatch.ItemList.Any())
                    {
                        subscriptionMatchGroup.SubscriptionMatches.Add(subscriptionMatch);
                    }
                }
            }

            //check if any new Media uploads match this subscription
            if (subscription.NotifyMedia)
            {
                var newMedia = dataModel.MediaItems.Where(c => c.DateCreated >= checkFromDate &&
                                                          (searchPos == null ||
                                                           (searchPos != null &&
                                                            c.ChargePoint.AddressInfo.SpatialPosition.Distance(searchPos) / 1000 < subscription.DistanceKM
                                                           ))
                                                          );
                if (newMedia.Any())
                {
                    var subscriptionMatch = new SubscriptionMatch {
                        Category = SubscriptionMatchCategory.NewMediaUpload, Description = "New Photos Added"
                    };
                    foreach (var c in newMedia)
                    {
                        var poi = OCM.API.Common.Model.Extensions.ChargePoint.FromDataModel(c.ChargePoint);
                        if (IsPOISubscriptionFilterMatch(poi, filter, subscription))
                        {
                            subscriptionMatch.ItemList.Add(new SubscriptionMatchItem {
                                Item = OCM.API.Common.Model.Extensions.MediaItem.FromDataModel(c), POI = poi
                            });
                        }
                    }
                    if (subscriptionMatch.ItemList.Any())
                    {
                        subscriptionMatchGroup.SubscriptionMatches.Add(subscriptionMatch);
                    }
                }
            }

            return(subscriptionMatchGroup);
        }
        public virtual int EditarMapa(Nullable <int> id, string nombre, string descripcion, Nullable <double> lat, Nullable <double> lng, Nullable <short> radio, string direccion, System.Data.Entity.Spatial.DbGeography geographic)
        {
            var idParameter = id.HasValue ?
                              new ObjectParameter("id", id) :
                              new ObjectParameter("id", typeof(int));

            var nombreParameter = nombre != null ?
                                  new ObjectParameter("nombre", nombre) :
                                  new ObjectParameter("nombre", typeof(string));

            var descripcionParameter = descripcion != null ?
                                       new ObjectParameter("descripcion", descripcion) :
                                       new ObjectParameter("descripcion", typeof(string));

            var latParameter = lat.HasValue ?
                               new ObjectParameter("lat", lat) :
                               new ObjectParameter("lat", typeof(double));

            var lngParameter = lng.HasValue ?
                               new ObjectParameter("lng", lng) :
                               new ObjectParameter("lng", typeof(double));

            var radioParameter = radio.HasValue ?
                                 new ObjectParameter("radio", radio) :
                                 new ObjectParameter("radio", typeof(short));

            var direccionParameter = direccion != null ?
                                     new ObjectParameter("direccion", direccion) :
                                     new ObjectParameter("direccion", typeof(string));

            var geographicParameter = geographic != null ?
                                      new ObjectParameter("geographic", geographic) :
                                      new ObjectParameter("geographic", typeof(System.Data.Entity.Spatial.DbGeography));

            return(((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("EditarMapa", idParameter, nombreParameter, descripcionParameter, latParameter, lngParameter, radioParameter, direccionParameter, geographicParameter));
        }
        public virtual ObjectResult <Nullable <decimal> > AgregarMapaMovil(string nombre, string descripcion, Nullable <double> lat, Nullable <double> lng, Nullable <short> radio, System.Data.Entity.Spatial.DbGeography geozona, Nullable <short> tipoGeozona)
        {
            var nombreParameter = nombre != null ?
                                  new ObjectParameter("nombre", nombre) :
                                  new ObjectParameter("nombre", typeof(string));

            var descripcionParameter = descripcion != null ?
                                       new ObjectParameter("descripcion", descripcion) :
                                       new ObjectParameter("descripcion", typeof(string));

            var latParameter = lat.HasValue ?
                               new ObjectParameter("lat", lat) :
                               new ObjectParameter("lat", typeof(double));

            var lngParameter = lng.HasValue ?
                               new ObjectParameter("lng", lng) :
                               new ObjectParameter("lng", typeof(double));

            var radioParameter = radio.HasValue ?
                                 new ObjectParameter("radio", radio) :
                                 new ObjectParameter("radio", typeof(short));

            var geozonaParameter = geozona != null ?
                                   new ObjectParameter("geozona", geozona) :
                                   new ObjectParameter("geozona", typeof(System.Data.Entity.Spatial.DbGeography));

            var tipoGeozonaParameter = tipoGeozona.HasValue ?
                                       new ObjectParameter("tipoGeozona", tipoGeozona) :
                                       new ObjectParameter("tipoGeozona", typeof(short));

            return(((IObjectContextAdapter)this).ObjectContext.ExecuteFunction <Nullable <decimal> >("AgregarMapaMovil", nombreParameter, descripcionParameter, latParameter, lngParameter, radioParameter, geozonaParameter, tipoGeozonaParameter));
        }
        public virtual int uspInsertWarningData(string wARNINGTYPE, string mESSAGEID, System.Data.Entity.Spatial.DbGeography sHAPE, Nullable <System.DateTime> zTIME_END, Nullable <System.DateTime> zTIME_START, string iD, string iSSUEWFO)
        {
            var wARNINGTYPEParameter = wARNINGTYPE != null ?
                                       new ObjectParameter("WARNINGTYPE", wARNINGTYPE) :
                                       new ObjectParameter("WARNINGTYPE", typeof(string));

            var mESSAGEIDParameter = mESSAGEID != null ?
                                     new ObjectParameter("MESSAGEID", mESSAGEID) :
                                     new ObjectParameter("MESSAGEID", typeof(string));

            var sHAPEParameter = sHAPE != null ?
                                 new ObjectParameter("SHAPE", sHAPE) :
                                 new ObjectParameter("SHAPE", typeof(System.Data.Entity.Spatial.DbGeography));

            var zTIME_ENDParameter = zTIME_END.HasValue ?
                                     new ObjectParameter("ZTIME_END", zTIME_END) :
                                     new ObjectParameter("ZTIME_END", typeof(System.DateTime));

            var zTIME_STARTParameter = zTIME_START.HasValue ?
                                       new ObjectParameter("ZTIME_START", zTIME_START) :
                                       new ObjectParameter("ZTIME_START", typeof(System.DateTime));

            var iDParameter = iD != null ?
                              new ObjectParameter("ID", iD) :
                              new ObjectParameter("ID", typeof(string));

            var iSSUEWFOParameter = iSSUEWFO != null ?
                                    new ObjectParameter("ISSUEWFO", iSSUEWFO) :
                                    new ObjectParameter("ISSUEWFO", typeof(string));

            return(((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("uspInsertWarningData", wARNINGTYPEParameter, mESSAGEIDParameter, sHAPEParameter, zTIME_ENDParameter, zTIME_STARTParameter, iDParameter, iSSUEWFOParameter));
        }