/// <summary> /// Retrieves data for an Argos Platform from the Argos Web Server /// </summary> /// <param name="platform">The Argos Platform to retrieve from the server</param> /// <param name="daysToRetrieve">The number of most recent days to retrieve from the server</param> public static void DownloadArgosPlatform(ArgosPlatform platform, int?daysToRetrieve = null) { int daysSinceLastDownload; if (daysToRetrieve.HasValue) { daysSinceLastDownload = daysToRetrieve.Value; } else { var database = new AnimalMovementDataContext(); var dateOfLastDownload = (from log in database.ArgosDownloads where log.PlatformId == platform.PlatformId && log.FileId != null orderby log.TimeStamp descending select log.TimeStamp).FirstOrDefault(); daysSinceLastDownload = (DateTime.Now - dateOfLastDownload).Days; } var days = Math.Min(ArgosWebSite.MaxDays, daysSinceLastDownload); if (days < ArgosWebSite.MinDays) { return; } var program = platform.ArgosProgram; string errors; var results = ArgosWebSite.GetCollar(program.UserName, program.Password, platform.PlatformId, days, out errors); CollarFile file = FileLoader.LoadPlatfrom(platform, days, results, errors); if (file == null) { return; } FileProcessor.ProcessFile(file); }
private void AddMissingPlatformsButton_Click(object sender, EventArgs e) { AddMissingPlatformsButton.Enabled = false; AddMissingPlatformsButton.Text = "Working..."; Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); try { string error; var programPlatforms = ArgosWebSite.GetPlatformList(Program.UserName, Program.Password, out error); var addedNewPlatform = false; if (error != null) { MessageBox.Show("Argos Web Server returned an error" + Environment.NewLine + error, "Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (var item in programPlatforms) { if (item.Item1 == Program.ProgramId) { if (Program.ArgosPlatforms.All(p => p.PlatformId != item.Item2)) { var platform = new ArgosPlatform { ArgosProgram = Program, PlatformId = item.Item2, Active = true }; Database.ArgosPlatforms.InsertOnSubmit(platform); addedNewPlatform = true; } } } if (addedNewPlatform && SubmitChanges()) { PlatformDataChanged(); } } finally { AddMissingPlatformsButton.Enabled = true; AddMissingPlatformsButton.Text = "Add Missing Platforms"; Cursor.Current = Cursors.Default; } }
public static void TestGetPlatformList() { string error; var result = ArgosWebSite.GetPlatformList("xxx", "xxx", out error); if (error != null) { Console.WriteLine(error); } else { foreach (var tuple in result) { Console.WriteLine("Program: {0}, Platform: {1}", tuple.Item1, tuple.Item2); } } }
/// <summary> /// Retrieves data for an Argos Program from the Argos Web Server /// </summary> /// <param name="program">The Argos Program (contains Platforms) to retrieve from the server</param> /// <param name="daysToRetrieve">The number of most recent days to retrieve from the server</param> public static void DownloadArgosProgram(ArgosProgram program, int?daysToRetrieve = null) { int daysSinceLastDownload; if (daysToRetrieve.HasValue) { daysSinceLastDownload = daysToRetrieve.Value; } else { var database = new AnimalMovementDataContext(); var dateOfLastDownload = (from log in database.ArgosDownloads where log.ProgramId == program.ProgramId && log.FileId != null orderby log.TimeStamp descending select log.TimeStamp).FirstOrDefault(); //Problem: using Days always truncates. // If I download at 1am on day 1, and then 11pm on day 2, (1.9 days -> 1day), // I will miss any data created between 1am and 11pm on day 1. // However, rounding up may cause a lot of duplication, // (i.e. 6:01am on day1 and then 6:02am on day2, will need to download 2 days to get the extra minute) // by default we should round up to make sure that all data is obtained. However, since this is // typically called on a scheduled task at the same time (+/- download/processing time) everyday. // I will check if we are close to an even day, and then round tword that day var timespan = DateTime.Now - dateOfLastDownload; int extraDay = timespan.Hours == 0 && timespan.Minutes < 5 ? 0 : 1; daysSinceLastDownload = timespan.Days + extraDay; } var days = Math.Min(ArgosWebSite.MaxDays, daysSinceLastDownload); if (days < ArgosWebSite.MinDays) { return; } string errors; var results = ArgosWebSite.GetProgram(program.UserName, program.Password, program.ProgramId, days, out errors); CollarFile file = FileLoader.LoadProgram(program, days, results, errors); if (file == null) { return; } FileProcessor.ProcessFile(file); }