internal AddArgosPlatformForm(ArgosProgram program = null) { InitializeComponent(); RestoreWindow(); Program = program; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpControls(); }
public ArgosProgramDetailsForm(ArgosProgram program) { InitializeComponent(); RestoreWindow(); Program = program; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpForm(); }
internal static void exceptionHandler(Exception ex, ArgosProgram program, ArgosPlatform platform) { if (program == null && platform == null) { AddErrorToEmail(_admin, null, null, "Downloader exception handler called without a program or platform: " + ex.Message); return; } string errors = null; if (program != null) { errors = "Download error '" + ex.Message + "' for program " + program.ProgramId; } //If program and platform are both non-null (unanticipated), then program is ignored. if (platform != null) { errors = "Download error '" + ex.Message + "' for platform " + platform.ProgramId; program = platform.ArgosProgram; } AddErrorToEmail(program.ProjectInvestigator.Email, program.UserName, program.ProgramId, errors); AddErrorToEmail(_admin, program.UserName, program.ProgramId, errors); }
/// <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); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Program is in a different DataContext, get one in this DataContext if (Program != null) Program = Database.ArgosPrograms.FirstOrDefault(p => p.ProgramId == Program.ProgramId); //Validate Program and Editor on load, so we can show a messagebox. }
// ReSharper restore UnusedAutoPropertyAccessor.Local private void LoadPlatformsListBox(ArgosProgram program) { var query = from platform in program.ArgosPlatforms select new PlatformListItem { Platform = platform, Name = GetPlatformName(platform), CanDelete = !platform.ArgosDeployments.Any() }; var sortedList = query.OrderBy(p => p.Platform.Active ? 0 : 1).ThenBy(p => p.Name).ToList(); PlatformsListBox.DataSource = sortedList; PlatformsListBox.DisplayMember = "Name"; PlatformsListBoxLabel.Text = sortedList.Count < 5 ? "Argos Ids" : String.Format("Argos Ids ({0})", sortedList.Count); PlatformsListBox.ClearItemColors(); for (int i = 0; i < sortedList.Count; i++) { var programStatus = sortedList[i].Platform.ArgosProgram.Active; var platformStatus = sortedList[i].Platform.Active; if ((programStatus.HasValue && !programStatus.Value) || (!programStatus.HasValue && !platformStatus)) PlatformsListBox.SetItemColor(i, Color.DarkGray); } }
private static string GetProgramName(ArgosProgram program) { var active = program.Active.HasValue ? (program.Active.Value ? "Active download" : "Inactive download") : "Download status defered to platforms"; return program + " (" + active + ")"; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Platform is in a different DataContext, get one in this DataContext if (Program != null) Program = Database.ArgosPrograms.FirstOrDefault(p => p.ProgramId == Program.ProgramId); if (Program == null) throw new InvalidOperationException("Argos Platform Details Form not provided a valid Platform."); var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(Program.Manager, CurrentUser) ?? false; }