コード例 #1
0
ファイル: TideDbAccess.cs プロジェクト: thatjohnbell/CS235AM
 public void Delete(Tides tide)
 {
     Connect();
     db.Delete(tide);
     db.Commit();
     db.Close();
 }
コード例 #2
0
        public void FinishRequest()
        {
            FishingRecord record;

            // validate fields
            try
            {
                // date and time
                CommonPresenterStuff.ValidateDateEarlierThanNow(_view.DateTimeStart, "start date and time");
                CommonPresenterStuff.ValidateCronologicalDates(_view.DateTimeStart, _view.DateTimeEnd,
                                                               "start date and time", "end date and time");

                // location name
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.Location, "location");

                // nature events
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.Wind, "wind");
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.MoonPhase, "moon phase");
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.Tide, "tide");
            }
            catch (Exception e)
            {
                _view.ShowErrorMessage(e.Message);
                return;
            }

            // if fish catch or sale is empty, warn user
            if (_fishCatch.GetCaughtFish().Count == 0)
            {
                if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("fish catch")))
                {
                    return;
                }
            }
            if (_fishCatch.GetSoldFish().Count == 0)
            {
                if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("fish sale")))
                {
                    return;
                }
            }

            // try create record
            Winds      wind      = CommonPresenterStuff.GetWindEnum(_view.Wind);
            MoonPhases moonPhase = CommonPresenterStuff.GetMoonPhaseEnum(_view.MoonPhase);
            Tides      tide      = CommonPresenterStuff.GetTideEnum(_view.Tide);

            try
            {
                record = FishingRecordFactory.CreateFishingRecord(_view.DateTimeStart, _view.DateTimeEnd,
                                                                  _view.Location, wind, moonPhase, tide, _fishCatch);
            }
            catch (Exception)
            {
                _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage());
                return;
            }

            Finish(record);
        }
コード例 #3
0
ファイル: TideDbAccess.cs プロジェクト: thatjohnbell/CS235AM
 public void Update(Tides tide)
 {
     Connect();
     db.Update(tide);
     db.Commit();
     db.Close();
 }
コード例 #4
0
ファイル: TideDbAccess.cs プロジェクト: thatjohnbell/CS235AM
 public void AddEntry(Tides tide) {
     Connect();
     db.BeginTransaction();
     db.Insert(tide);
     db.Commit();
     db.Close();
 }
コード例 #5
0
ファイル: TideList.cs プロジェクト: thatjohnbell/CS235AM
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            string        dbPath;
            List <TideDB> tides;
            List <String> tidelist = new List <String>();
            Tides         newtide  = new Tides();

            // Check for database and create object
            dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TidesDB.s3db");
            if (!File.Exists(dbPath))
            {
                using (Stream inStream = Assets.Open("TidesDB.s3db"))
                    using (Stream outStream = File.Create(dbPath))
                        inStream.CopyTo(outStream);
            }

            TideDbAccess tideDb   = new TideDbAccess(dbPath);
            WsDbAccess   wsDb     = new WsDbAccess(dbPath);
            TideRest     tideRest = new TideRest();

            string inputLocation = Intent.GetStringExtra("Location");
            string inputDate     = Intent.GetStringExtra("Date");

            tides = tideDb.RetrieveTide(inputLocation, inputDate);

            if (tides.Count <= 0)
            {
                //loading from web service if we didn't get any entries
                string       location = wsDb.GetId(inputLocation).Id.ToString();
                var          tidedata = tideRest.GetTide(location, inputDate.Replace("/", string.Empty));
                List <Tides> tlist    = tideRest.XmlToTide(tidedata, inputLocation);


                foreach (Tides t in tlist)
                {
                    //saving to db
                    tideDb.AddEntry(t);
                }

                //now we'll reload the database so we have one with valid values and resume as normal
                tideDb = new TideDbAccess(dbPath);
                tides  = tideDb.RetrieveTide(inputLocation, inputDate);
            }


            foreach (TideDB tide in tides)
            {
                tidelist.Add(tide.Day + ", " + tide.Date + " at " + tide.Time + System.Environment.NewLine + tide.HL + " tide of " + tide.Cen);
            }


            ListAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, tidelist);
        }
コード例 #6
0
        public void AddFishingRecordRequest()
        {
            // ensure nature contex is not empty
            if (_view.Wind == "")
            {
                _view.ShowErrorMessage(_windEmptyError);
                return;
            }
            if (_view.MoonPhase == "")
            {
                _view.ShowErrorMessage(_moonPhaseEmptyError);
                return;
            }
            if (_view.Tide == "")
            {
                _view.ShowErrorMessage(_tideEmptyError);
                return;
            }

            Winds      wind      = CommonFunctionalities.GetWindEnum(_view.Wind);
            MoonPhases moonPhase = CommonFunctionalities.GetMoonPhaseEnum(_view.MoonPhase);
            Tides      tide      = CommonFunctionalities.GetTideEnum(_view.Tide);

            try
            {
                FishingRecord record = FishingRecordFactory.CreateFishingRecord(_view.StartDateTime, _view.EndDateTime,
                                                                                _view.Location, wind, moonPhase, tide, fishCatch);

                FishingRecordRepository.GetInstance().AddRecord(record);
            }
            catch (FishermanBaseException e)
            {
                _view.ShowErrorMessage(e.Info);
                return;
            }

            _parent.AddRecordName(DateTime.Now);

            _view.End();
        }
コード例 #7
0
        public static List <Tides> ConvertTides(StreamReader file, string locale = "not found")
        {
            Tides        tide  = new Tides();
            List <Tides> tides = new List <Tides>();
            string       date;

            using (XmlReader reader = XmlReader.Create(file))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "item":
                            tide        = new Tides();
                            tide.Locale = locale;
                            break;

                        case "date":
                            if (reader.Read() && tide != null)
                            {
                                date       = reader.Value.Trim();
                                tide.Date  = date;
                                tide.Index = Int32.Parse(date.Substring(5, 2));
                            }
                            break;

                        case "day":
                            if (reader.Read() && tide != null)
                            {
                                tide.Day = reader.Value.Trim();
                            }
                            break;

                        case "time":
                            if (reader.Read() && tide != null)
                            {
                                tide.Time = reader.Value.Trim();
                            }
                            break;

                        case "pred_in_ft":
                            if (reader.Read() && tide != null)
                            {
                                tide.Feet = reader.Value.Trim();
                            }
                            break;

                        case "pred_in_cm":
                            reader.Read();
                            tide.Cen = reader.Value.Trim();
                            break;

                        case "highlow":
                            if (reader.Read() && tide != null)
                            {
                                tide.HL = reader.Value.Trim();
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (reader.Name == "item")
                        {
                            tides.Add(tide); tide = null;
                        }
                    }
                }
            }
            tides.Sort((x, y) => x.Index.CompareTo(y.Index));
            return(tides);
        }
コード例 #8
0
        public static FishingRecord CreateFishingRecord(DateTime inDtStart, DateTime inDtEnd, string inLocationName,
                                                        Winds inWind, MoonPhases inMoonPhase, Tides inTide, FishCatch inFishCatch)
        {
            DateTime         dtAdded    = DateTime.Now;
            DateTimeInterval dtInterval = new DateTimeInterval(inDtStart, inDtEnd);
            Location         location   = LocationRepository.GetInstance().GetLocation(inLocationName);
            NatureEvents     nContext   = new NatureEvents(inWind, inMoonPhase, inTide);

            FishingRecord record = new FishingRecord(dtAdded, dtInterval, location, nContext, inFishCatch);

            return(record);
        }
コード例 #9
0
ファイル: SearchParamTide.cs プロジェクト: denjiz/fisherman
 public SearchParamTide(Tides inTide)
 {
     _value = inTide;
 }
コード例 #10
0
 public ParamTide(Tides inTide)
 {
     _value = inTide;
 }
コード例 #11
0
ファイル: NatureEvents.cs プロジェクト: denjiz/fisherman
 public NatureEvents(Winds inWind, MoonPhases inMoonPhase, Tides inTide)
 {
     Wind      = inWind;
     MoonPhase = inMoonPhase;
     Tide      = inTide;
 }
コード例 #12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            string        dbPath;
            List <TideDB> tides;
            List <String> tidelist = new List <String>();
            Tides         newtide  = new Tides();

            // Check for database and create object
            dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TidesDB.s3db");
            if (!File.Exists(dbPath))
            {
                using (Stream inStream = Assets.Open("TidesDB.s3db"))
                    using (Stream outStream = File.Create(dbPath))
                        inStream.CopyTo(outStream);
            }

            TideDbAccess tideDb   = new TideDbAccess(dbPath);
            WsDbAccess   wsDb     = new WsDbAccess(dbPath);
            TideRest     tideRest = new TideRest();

            Location startLoc = new Location("Current");
            Location endLoc   = new Location("Station");
            List <WeatherStation> stationlist = new List <WeatherStation>();
            float  distance      = 10000000000;
            string inputLocation = "none";

            stationlist = wsDb.GetStationData();
            String inputDate = new SimpleDateFormat("yyyy/MM/dd").Format(new Date());

            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            //string inputLocation = Intent.GetStringExtra("Location");
            //string inputDate = Intent.GetStringExtra("Date");

            // GetPositionAsynch will either get position information or timeout
            locator.GetPositionAsync(timeoutMilliseconds: 10000)
            // After getting position info or timing out, execution will continue here
            // t represents a Task object (GetPositionAsync returns a Task object)
            .ContinueWith(t =>
            {
                // t.Result is a Position object
                startLoc.Latitude  = t.Result.Latitude;
                startLoc.Longitude = t.Result.Longitude;

                // Specify the thread to continue on- it's the UI thread

                foreach (WeatherStation station in stationlist)
                {
                    endLoc           = new Location("Station");
                    endLoc.Longitude = station.Lon;
                    endLoc.Latitude  = station.Lat;

                    if (startLoc.DistanceTo(endLoc) < distance)
                    {
                        distance      = startLoc.DistanceTo(endLoc);
                        inputLocation = station.Name;
                    }
                }



                tides = tideDb.RetrieveTide(inputLocation, inputDate);

                if (tides.Count <= 0)
                {
                    //loading from web service if we didn't get any entries
                    string location    = wsDb.GetId(inputLocation).Id.ToString();
                    var tidedata       = tideRest.GetTide(location, inputDate.Replace("/", string.Empty));
                    List <Tides> tlist = tideRest.XmlToTide(tidedata, inputLocation);


                    foreach (Tides ti in tlist)
                    {
                        //saving to db
                        tideDb.AddEntry(ti);
                    }

                    //now we'll reload the database so we have one with valid values and resume as normal
                    tideDb = new TideDbAccess(dbPath);
                    tides  = tideDb.RetrieveTide(inputLocation, inputDate);
                }

                tidelist.Add("Tides For " + inputLocation);
                foreach (TideDB tide in tides)
                {
                    tidelist.Add(tide.Day + ", " + tide.Date + " at " + tide.Time + System.Environment.NewLine + tide.HL + " tide of " + tide.Cen);
                }



                ListAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, tidelist);
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }