Exemplo n.º 1
0
        /// <summary>
        /// First Get GeoTagging from image path
        /// Adds Fall to the database
        /// </summary>
        /// <param name="fall">The new Fall to be add to the database</param>
        public void AddFall(Fall fall)
        {
            fall.FallLocation = GetGeoTaggingFromImage(fall.FallImage.ToString().Substring(8));
            try
            {
                fall.FallAddress = ReverseGeocode(fall.FallLocation.Latitude, fall.FallLocation.Longitude);


                //dal.AddFall(fall);
                DateTime dt = new DateTime(fall.FallTime.Year, fall.FallTime.Month, fall.FallTime.Day, fall.FallTime.Hour, fall.FallTime.Minute - fall.FallTime.Minute % 10, 0);
                List <FallPrediction> _fallPredictions = GetAllFallPredictions(fp => fp.FallPredictionFallKey == -1 && fp.FallPredictionTime == dt).ToList();
                if (_fallPredictions.Count == 0)
                {
                    throw new Exception("invalid fall time");
                }
                double   minDist = Double.MaxValue;
                DateTime minDT   = _fallPredictions[0].FallPredictionTime;
                double   currDist;
                int      _fallPredictionId = -1;
                for (int i = 0; i < _fallPredictions.Count(); i++)
                {
                    currDist = fall.GetCoordinate().GetDistanceTo(new GeoCoordinate(_fallPredictions[i].FallPredictionLocation.Latitude, _fallPredictions[i].FallPredictionLocation.Longitude));
                    if (currDist < minDist &&
                        fall.FallTime >= _fallPredictions[i].FallPredictionTime && fall.FallTime <= _fallPredictions[i].FallPredictionTime.AddMinutes(10))
                    {
                        _fallPredictionId = _fallPredictions[i].FallPredictionId;
                        minDist           = currDist;
                    }
                }
                FallPrediction temp = GetFallPrediction(_fallPredictionId);
                fall.FallPrediction = temp;
                dal.AddFall(fall);
                temp.FallPredictionFallKey = fall.FallId;
                UpdateFallPrediction(temp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            int st = fall.FallId;
        }