protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); string dbPath; List <string> spinList = new List <string>(); string spinSelected = ""; // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); //move db from assets to file system 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); } //create object from db layer for population TideDbAccess tideDb = new TideDbAccess(dbPath); //place locales from db into spinner value list and update spinner with values foreach (TideDB tide in tideDb.RetrieveLocales()) { spinList.Add(tide.Locale); if (spinSelected == "") { spinSelected = tide.Locale; } } Spinner spinner = FindViewById <Spinner>(Resource.Id.SpinSelect); var spinCont = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, spinList); spinCont.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinner.Adapter = spinCont; //store selected item selected spinner.ItemSelected += (sender, e) => { spinSelected = spinner.GetItemAtPosition(e.Position).ToString(); }; //datepicker var datePicker = FindViewById <DatePicker>(Resource.Id.datePick); datePicker.MinDate = Long.ParseLong(ConvertToUnixTimestamp(tideDb.RetrieveDates(-1)[0].Date).ToString()); datePicker.MaxDate = Long.ParseLong(ConvertToUnixTimestamp(tideDb.RetrieveDates(1)[0].Date).ToString()); //do it to it!! var button = FindViewById <Button>(Resource.Id.submit); button.Click += delegate { var go = new Android.Content.Intent(this, typeof(TideList)); go.PutExtra("Location", spinSelected); go.PutExtra("Date", datePicker.DateTime.ToString("yyyy/MM/dd")); StartActivity(go); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); string dbPath; List <TideDB> tides; List <String> tidelist = new List <String>(); // 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); tides = tideDb.RetrieveTide(Intent.GetStringExtra("Location"), Intent.GetStringExtra("Date")); 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); }
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); }
public void SetUpTest() { tideDb = new TideDbAccess(dir); }
static void Main(string[] args) { List <Tides> tides = new List <Tides>(); string dir = @"../../../Files/"; string dbPath = System.AppDomain.CurrentDomain.BaseDirectory + "/Files/TidesDB.s3db"; TideDbAccess tideDb = new TideDbAccess(dbPath); string[] names = new string[3] { "depoebay.xml", "florence.xml", "yaquinabay.xml" }; string[] locales = new string[3] { "Depoe Bay", "Florence", "Yaquina Bay" }; int i = 0; foreach (string name in names) { StreamReader textIn = new StreamReader( new FileStream(dir + name, FileMode.OpenOrCreate, FileAccess.Read)); tides.AddRange(ConvertXMLtoTides.ConvertTides(textIn, locales[i++])); } //tideDb.Create(); //int ind = 0; //foreach (Tides tide in tides) //{ // tide.ID = ind++; // tideDb.AddEntry(tide); //} Console.WriteLine(tides.Count()); for (i = 0; i < 5; i++) { Console.WriteLine(i); Console.WriteLine(tideDb.Retrieve(i).Feet); } Console.WriteLine("Tide Locales"); foreach (TideDB tideL in tideDb.RetrieveLocales()) { Console.WriteLine(tideL.Locale); } Console.WriteLine("Tide Dates"); //cut this off at 10 entries to save space i = 0; foreach (TideDB tideD in tideDb.RetrieveDates(0)) { Console.WriteLine(tideD.Date); if (i++ > 10) { break; } } //select a locale and date Console.WriteLine("Tide for Deopoe Bay, 2017/01/23"); foreach (TideDB tide in tideDb.RetrieveTide("Depoe Bay", "2017/01/23")) { Console.WriteLine(tide.HL + " of " + tide.Cen + " at " + tide.Time); } Console.WriteLine("Minimum Date: " + tideDb.RetrieveDates(-1)[0].Date.Replace("/", "")); Console.WriteLine("Maximum Date: " + tideDb.RetrieveDates(1)[0].Date.Replace("/", "")); Console.ReadLine(); Console.WriteLine(); }
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()); }