private CollarParameterFile UploadParameterFile(ProjectInvestigator owner, LookupCollarParameterFileFormat format, string filename) { LoadAndHashFile(filename); if (_fileContents == null) { return(null); } if (AbortBecauseDuplicate()) { return(null); } var file = new CollarParameterFile { FileName = System.IO.Path.GetFileName(filename), LookupCollarParameterFileFormat = format, ProjectInvestigator = owner, LookupFileStatus = (LookupFileStatus)StatusComboBox.SelectedItem, Contents = _fileContents }; Database.CollarParameterFiles.InsertOnSubmit(file); if (SubmitChanges()) { return(file); } return(null); }
private void EnableForm() { Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); // Make sure the wait cursor is shown; var db = new AnimalMovementDataContext(); try { _investigator = db.ProjectInvestigators.FirstOrDefault(pi => pi.Login == _currentUser); } catch (Exception ex) { Cursor.Current = Cursors.Default; MyProfileButton.Text = "Connection Failed"; MyProfileButton.Enabled = false; MessageBox.Show(Environment.NewLine + ex.Message + Environment.NewLine + "Connection String:" + Environment.NewLine + db.Connection.ConnectionString, "Unable to connect to the database", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Cursor.Current = Cursors.Default; MyProfileButton.Visible = _investigator != null; MyProfileButton.Text = "Project Investigator Details"; ProjectsButton.Enabled = true; InvestigatorsButton.Enabled = true; UploadButton.Enabled = true; GenerateMapButton.Enabled = true; QuickStartWizardButton.Enabled = true; }
/// <summary> /// Download programs and/or platforms /// </summary> /// <param name="handler">An exception handler to allow processing additional items despite an exception. /// If the handler is null, processing will stop on first exception. /// The handler can throw it's own exception to halt further processing</param> /// <param name="pi">A project investigator. /// If provided, only the programs/platforms for that PI will be downloaded, /// otherwise all programs/platforms will be downloaded</param> /// <param name="daysToRetrieve">The number of days to download. If it is null, then the database is consulted /// to get the number of days since the last successful download. If the number is less than MinDays then nothing is /// downloaded (the server is not contacted at all). If the number is truncated to MaxDays. /// MinDays and MaxDays are set in the config file of the calling application.</param> public static void DownloadAll(Action<Exception, ArgosProgram, ArgosPlatform> handler = null, ProjectInvestigator pi = null, int? daysToRetrieve = null) { var db = new AnimalMovementDataContext(); foreach (var program in db.ArgosPrograms.Where(p => (pi == null || pi == p.ProjectInvestigator) && p.Active.HasValue && p.Active.Value)) { try { DownloadArgosProgram(program, daysToRetrieve); } catch (Exception ex) { if (handler == null) throw; handler(ex, program, null); } } foreach (var platform in db.ArgosPlatforms.Where(p => (pi == null || pi == p.ArgosProgram.ProjectInvestigator) && p.Active && !p.ArgosProgram.Active.HasValue)) { try { DownloadArgosPlatform(platform, daysToRetrieve); } catch (Exception ex) { if (handler == null) throw; handler(ex, null, platform); } } }
private void InvestigatorComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (Visible) { Investigator = InvestigatorComboBox.SelectedItem as ProjectInvestigator; } NextButton.Enabled = Investigator != null; }
public AddDeploymentCsvForm(ProjectInvestigator investigator = null) { InitializeComponent(); Investigator = investigator; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpControls(); }
public AddArgosProgramForm(ProjectInvestigator investigator = null) { InitializeComponent(); RestoreWindow(); Investigator = investigator; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpControls(); }
internal AddCollarParameterFileForm(ProjectInvestigator investigator = null) { InitializeComponent(); RestoreWindow(); CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; Investigator = investigator; LoadDataContext(); SetUpForm(); }
internal AddCollarForm(ProjectInvestigator investigator) { InitializeComponent(); RestoreWindow(); ProjectInvestigator = investigator; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpControls(); }
/// <summary> /// Attempts to load the file (or all the files in a folder) into the database /// </summary> /// <param name="path">A complete file or folder path to data that will be loaded</param> /// <param name="handler">Delegate to handle exceptions on each file, so that processing can continue. /// If the handler is null, processing will stop on first exception. /// The handler can throw it's own exception to halt further processing</param> /// <param name="project">Associate the new file with this Project (optional)</param> /// <param name="manager">Associate the new file with this Project Investigator (optional)</param> /// <param name="collar">This file contains data for this collar. Not required for files with Argos data, or /// if the collar can be determined from the file contents</param> /// <param name="status">The new file should be (A)ctive (generate fixes, default) or (I)nactive (no fixes)</param> /// <param name="allowDups">File will not be rejected if the contents match an existing file</param> /// <remarks>Only one of project and manager can be non-null.</remarks> public static void LoadPath(string path, Action <Exception, string, Project, ProjectInvestigator> handler = null, Project project = null, ProjectInvestigator manager = null, Collar collar = null, char status = 'A', bool allowDups = false) { if (path == null) { throw new ArgumentNullException("path", "A path must be provided"); } if (project != null && manager != null) { throw new InvalidOperationException( String.Format("Project: {0} and Manager: {1} cannot both be non-null.", project.ProjectId, manager.Login)); } if (File.Exists(path)) { try { LoadAndProcessFilePath(path, project, manager, collar, status, allowDups); } catch (Exception ex) { if (handler == null) { throw; } handler(ex, path, project, manager); } } else { if (Directory.Exists(path)) { foreach (var file in Directory.EnumerateFiles(path)) { try { LoadAndProcessFilePath(file, project, manager, collar, status, allowDups); } catch (Exception ex) { if (handler == null) { throw; } handler(ex, file, project, manager); } } } else { throw new InvalidOperationException(path + " is not a folder or file"); } } }
internal InvestigatorDetailsForm(ProjectInvestigator investigator) { InitializeComponent(); RestoreWindow(); Investigator = investigator; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; SetDefaultPropertiesBeforeFormLoad(); LoadDataContext(); SetUpGeneral(); }
internal UploadFilesForm(Project project = null, ProjectInvestigator pi = null) { Project = project; Investigator = pi; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; InitializeComponent(); RestoreWindow(); LoadDataContext(); SetUpForm(); }
/// <summary> /// Find and process all of the Argos or DataLog files that need full or partial processing /// </summary> /// <param name="handler">Delegate to handle exceptions on each file, so that processing can continue. /// If the handler is null, processing will stop on first exception. /// The handler can throw it's own exception to halt further processing</param> /// <param name="pi">A project investigator. /// If provided, only files owned by or in projects managed by the given PI will be processed /// If null, then all files needing processing will be processed</param> public static void ProcessAll(Action <Exception, CollarFile, ArgosPlatform> handler = null, ProjectInvestigator pi = null) { var database = new AnimalMovementDataContext(); var views = new AnimalMovementViews(); foreach (var fileId in views.NeverProcessedArgosFiles.Select(x => x.FileId) .Concat(views.NeverProcessedDataLogFiles.Select(x => x.FileId)) .Concat(views.NeverProcessedIdfFiles.Select(x => x.FileId))) { var file = database.CollarFiles.First(f => f.FileId == fileId); if (pi != null && (file.ProjectInvestigator == null || file.ProjectInvestigator.Login != pi.Login) && (file.Project == null || file.Project.ProjectInvestigator1.Login != pi.Login)) { continue; } try { ProcessFile(file); } catch (Exception ex) { if (handler == null) { throw; } handler(ex, file, null); } } foreach (var item in views.PartiallyProcessedArgosFiles) { var file = database.CollarFiles.First(f => f.FileId == item.FileId); var platform = database.ArgosPlatforms.First(p => p.PlatformId == item.PlatformId); if (pi != null && file.ProjectInvestigator != pi && (file.Project == null || file.Project.ProjectInvestigator1 != pi)) { continue; } try { ProcessFile(file, platform); } catch (Exception ex) { if (handler == null) { throw; } handler(ex, file, platform); } } }
internal AddEditorForm(Project project, ProjectInvestigator investigator = null, bool lockSelector = false) { InitializeComponent(); RestoreWindow(); Project = project; Investigator = investigator; LockSelector = lockSelector; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpControls(); EnableControls(); }
private void SetUpInvestigatorPage() { InvestigatorComboBox.DataSource = Database.ProjectInvestigators.Where(pi => pi.Login == CurrentUser || pi.ProjectInvestigatorAssistants.Any(a => a.Assistant == CurrentUser)); InvestigatorComboBox.DisplayMember = "Name"; if (Investigator == null && InvestigatorComboBox.Items.Count == 1) { Investigator = (ProjectInvestigator)InvestigatorComboBox.Items[0]; } InvestigatorComboBox.SelectedItem = Investigator; if (Investigator == null && InvestigatorComboBox.Items.Count == 0) { NextButton.Text = "Finish"; var dbaContact = Settings.GetSystemDbaContact(); InstructionsRichTextBox.Text = "You must be a Project Investigator (PI), or an assistant for a PI to use this wizard. " + "A PI manages collars and projects that track animal movements. " + "A PI can give other people permission to act on their behalf as an assistant. " + "If you want to be an assistant, then contact the PI. " + "If you want to be a PI, then you must contact " + (String.IsNullOrEmpty(dbaContact) ? "the database administrator" : dbaContact) + "."; } const string text = "This wizard will help you create animals, collars, and the link between them." + "You can also setup the automatic download of Argos data, as well as load existing collar data. "; if (Investigator == null && InvestigatorComboBox.Items.Count > 1) { InstructionsRichTextBox.Text = text + "You must first select the Project Investigator (PI) you are working for today " + "then click the Next button to proceed."; } if (Investigator != null && InvestigatorComboBox.Items.Count > 1) { InstructionsRichTextBox.Text = "You can do this for yourself, or one of the other Project Investigators you can assist." + "First select the correct Project Investigator then click the Next button to proceed."; } if (InvestigatorComboBox.Items.Count == 1) { InstructionsRichTextBox.Text = text + "Click the Next button to proceed."; } }
private void CreateParameters(ProjectInvestigator owner, CollarParameterFile paramFile) { var tpfFile = new TpfFile(_fileContents); foreach (TpfCollar tpfCollar in tpfFile.GetCollars()) { if (IgnoreSuffixCheckBox.Checked && tpfCollar.Ctn.Length > 6) { tpfCollar.Ctn = tpfCollar.Ctn.Substring(0, 6); } //Does this collar exist? var collar = Database.Collars.FirstOrDefault(c => c.CollarManufacturer == "Telonics" && c.CollarId == tpfCollar.Ctn); if (collar == null && !CreateCollarsCheckBox.Checked) { continue; } if (collar == null) { collar = CreateTpfCollar(owner, tpfCollar.Ctn, tpfCollar.Frequency); if (collar == null) { continue; } } //Does this Argos platform exist? var fileHasArgos = !String.IsNullOrEmpty(tpfCollar.PlatformId) && tpfCollar.Platform == "Argos" && !tpfCollar.PlatformId.Trim().Normalize().Equals("?", StringComparison.OrdinalIgnoreCase); if (fileHasArgos) { var platform = Database.ArgosPlatforms.FirstOrDefault(p => p.PlatformId == tpfCollar.PlatformId && tpfCollar.Platform == "Argos"); if (platform == null && CreateCollarsCheckBox.Checked) { platform = CreatePlatform(tpfCollar.PlatformId); } if (platform != null) { //If not paired, then try to parit the collar and platform. If it fails, or the the dates are wrong, they can correct that later if (!Database.ArgosDeployments.Any(d => d.Collar == collar && d.ArgosPlatform == platform)) { CreateDeployment(collar, platform, tpfCollar.TimeStamp); } } } CreateParameter(collar, paramFile, tpfCollar.TimeStamp); } }
private Collar CreateTpfCollar(ProjectInvestigator owner, string collarId, double frequency) { var collarAdded = false; var form = new AddCollarForm(owner); form.DatabaseChanged += (o, x) => collarAdded = true; form.SetDefaultFrequency(frequency); form.SetDefaultModel("Telonics", "Gen4"); form.SetDefaultId(collarId); form.ShowDialog(this); //Blocks until form closed if (!collarAdded) { return(null); } return(Database.Collars.FirstOrDefault(c => c.CollarManufacturer == "Telonics" && c.CollarId == collarId)); }
/// <summary> /// Find and process all of the Argos or DataLog files that need full or partial processing /// </summary> /// <param name="handler">Delegate to handle exceptions on each file, so that processing can continue. /// If the handler is null, processing will stop on first exception. /// The handler can throw it's own exception to halt further processing</param> /// <param name="pi">A project investigator. /// If provided, only files owned by or in projects managed by the given PI will be processed /// If null, then all files needing processing will be processed</param> public static void ProcessAll(Action<Exception, CollarFile, ArgosPlatform> handler = null, ProjectInvestigator pi = null) { var database = new AnimalMovementDataContext(); var views = new AnimalMovementViews(); foreach (var fileId in views.NeverProcessedArgosFiles.Select(x => x.FileId) .Concat(views.NeverProcessedDataLogFiles.Select(x => x.FileId)) .Concat(views.NeverProcessedIdfFiles.Select(x => x.FileId))) { var file = database.CollarFiles.First(f => f.FileId == fileId); if (pi != null && (file.ProjectInvestigator == null || file.ProjectInvestigator.Login != pi.Login) && (file.Project == null || file.Project.ProjectInvestigator1.Login != pi.Login)) continue; try { ProcessFile(file); } catch (Exception ex) { if (handler == null) throw; handler(ex, file, null); } } foreach (var item in views.PartiallyProcessedArgosFiles) { var file = database.CollarFiles.First(f => f.FileId == item.FileId); var platform = database.ArgosPlatforms.First(p => p.PlatformId == item.PlatformId); if (pi != null && file.ProjectInvestigator != pi && (file.Project == null || file.Project.ProjectInvestigator1 != pi)) continue; try { ProcessFile(file, platform); } catch (Exception ex) { if (handler == null) throw; handler(ex, file, platform); } } }
// This is a template for client side usage private static void LoadAndProcessFilePath(string filePath, Project project, ProjectInvestigator owner, Collar collar, char status, bool allowDups) { var fileLoader = new FileLoader(filePath) { Project = project, Owner = owner, Collar = collar, Status = status, AllowDuplicates = allowDups }; var file = fileLoader.Load(); if (file.LookupCollarFileFormat.ArgosData == 'Y' || file.Format == 'H') { FileProcessor.ProcessFile(file); } }
private void CreateParameters(ProjectInvestigator owner, CollarParameterFile paramFile) { var tpfFile = new TpfFile(_fileContents); foreach (TpfCollar tpfCollar in tpfFile.GetCollars()) { if (IgnoreSuffixCheckBox.Checked && tpfCollar.Ctn.Length > 6) tpfCollar.Ctn = tpfCollar.Ctn.Substring(0, 6); //Does this collar exist? var collar = Database.Collars.FirstOrDefault(c => c.CollarManufacturer == "Telonics" && c.CollarId == tpfCollar.Ctn); if (collar == null && !CreateCollarsCheckBox.Checked) continue; if (collar == null) { collar = CreateTpfCollar(owner, tpfCollar.Ctn, tpfCollar.Frequency); if (collar == null) continue; } //Does this Argos platform exist? var fileHasArgos = !String.IsNullOrEmpty(tpfCollar.PlatformId) && tpfCollar.Platform == "Argos" && !tpfCollar.PlatformId.Trim().Normalize().Equals("?", StringComparison.OrdinalIgnoreCase); if (fileHasArgos) { var platform = Database.ArgosPlatforms.FirstOrDefault(p => p.PlatformId == tpfCollar.PlatformId && tpfCollar.Platform == "Argos"); if (platform == null && CreateCollarsCheckBox.Checked) platform = CreatePlatform(tpfCollar.PlatformId); if (platform != null) //If not paired, then try to parit the collar and platform. If it fails, or the the dates are wrong, they can correct that later if (!Database.ArgosDeployments.Any(d => d.Collar == collar && d.ArgosPlatform == platform)) CreateDeployment(collar, platform, tpfCollar.TimeStamp); } CreateParameter(collar, paramFile, tpfCollar.TimeStamp); } }
/// <summary> /// Full or partially processes telonics data in argos files. This program is designed to run regularly /// as a scheduled task (with no arguments) as well as being called by the database with a single fileid /// argument (to fully process that file), or with two arguments, platformid and fileid (to partially /// process that file for just the single platform). When a file is fully or partially processed, it /// clears any prior processing results and issues, to prevent duplicates. /// Any processing errors are written to the database, any other errors are written to the console. /// </summary> /// <param name="args"> /// If there are no args then ask the database for a list of files that need processing and process them all. /// If there is only one argument and that argument is the login (domain\username) of a project /// investigator in the database, then process all the files that belong to the PI or his projects and /// need processing. /// If the argument matches /np[latform], or '/na[rgos]', then the remaining files will be fully processed /// If the argument matches /nf[ile], then the next argos platform specified will not be used to /// partially process the previously specified file /// If the argument matches /a[rgos]:xxx or /p[latform]:xxx or xxx and xxx is a platform id in the /// database, then the previously specified file (or the next file if no has been specified) will be /// partially processed for only this platform. /// if the argument matches /f[ile]:xxx or xxx, and xxx is a fileid in the database, then the file will /// be partially processed if an argos platform has been provided as a prior argument, otherwise it will /// be fully processed. /// In the unlikely event that an argument matches a valid platform and a valid file, then the tie will go /// to the file. /// Any other argument is ignored with a warning /// Note: /// A project investigator login will be accepted as an argument in any position, but is only /// meaningful as the first and only argument /// If you want to partially process a file, you must provide the Argos platform first /// Examples: /// To fully process multiple files /// ArgosProcessor,exe f1 f2 f3 ... /// To partially process multiple files with for one Argos platform /// ArgosProcessor,exe p1 f1 f2 f3 ... /// To partially process one file for multiple Argos platforms /// ArgosProcessor,exe p1 f1 p2 p3 ... /// To partially process multiple files with multiple Argos platforms /// ArgosProcessor,exe p1 f1 p2 p3 /nf p4 f2 p5 p6 ... /// To fully process files f1 and f2 and partially process files f3 and f4 /// ArgosProcessor,exe f1 f2 p1 f3 p2 /nf p3 f4 p4 ... /// or ArgosProcessor,exe p1 f3 p2 /nf p3 f4 p4 /np f1 f2 ... /// </param> /// <remarks> /// If a copy of TDC.exe is available from this program (as specified in the config file), /// then the processor will be make use of it to process the files locally and send the /// results to the database, otherwise the processor will request that the database /// invoke the ArgosProcessor on the server. /// </remarks> private static void Main(string[] args) { try { if (args.Length == 0) { FileProcessor.ProcessAll(HandleException); } else { ArgosPlatform platform = null; CollarFile file = null; ProjectInvestigator pi = null; foreach (var arg in args) { if (ClearPlatform(arg)) { platform = null; } else { if (ClearCollarFile(arg)) { file = null; } else { var fileArg = GetCollarFile(arg); if (fileArg != null) { file = fileArg; } else { var platformArg = GetPlatform(arg); if (platformArg != null) { platform = platformArg; } else { var piArg = GetProjectInvestigator(arg); if (piArg != null) { pi = piArg; } else { Console.WriteLine("Unhandled argument: {0}", arg); } } } } } if (args.Length == 1 && pi != null) { FileProcessor.ProcessAll(HandleException, pi); } if (file != null) { try { FileProcessor.ProcessFile(file, platform); } catch (Exception ex) { HandleException(ex, file, platform); } } } } } catch (Exception ex) { Console.WriteLine("Unhandled Exception: {0}", ex.Message); } }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; Investigator = Database.ProjectInvestigators.FirstOrDefault(pi => pi.Login == CurrentUser); }
/// <summary> /// Downloads Argos Programs and Platforms from the Argos Server, then uploads and processes the files. /// Any processing errors are written to the database, any other errors are emailed to the system admin, /// and optionally the PI of the platform/program. This prgram is intended to be run in the background /// as a scheduled daily task. /// </summary> /// <param name="args"> /// If there are no args, then process all active programs and platforms for all users. (An active platform /// is one where the platform is active, and the parent program is neither active or inactive, i.e null) /// All args are checked to see if they are a program identifier, and if so the program is downloaded. /// If an arg is not a program it is checked to see if it is a platform identifier, and if so the platform /// is downloaded. /// as a program, if it is not a valid or as a platform if it the integer is not a program. /// If there is only one arg and that arg is a project investigator, then download all programs and /// platforms for that PI /// If there is only one arg and that arg in the form /d:XX, where XX is an integer, then download /// that many days for all programs and platforms for all users /// If there is only two arguments, and one arg is a project investigator and the other arg is in the /// form /d:XX, where XX is an integer, then download that many days for all programs and platforms for that PI /// An integer arg between 0 and 100, that is not a valid program or platform or an arg in the form /d:XX or /// /days:XX, where XX is an integer defines the number of days (subject to Min/Max Days stipulated by the /// Argos Server) to download for the remaining args. /// An arg in the form /nodays, clears a previous setting of days, so the remaining arguments will download /// the number of days recommended by the database (this is the default behavior). /// Finally an argument is checked to see if it is a project investigator's login (with domain - as stored in /// Login column of the ProjectINvestigators table. If a valid PI is provided as the only argument, or optionally /// with a days argument (before or after), then all active programs and platforms (as defined above) for that PI /// are downloaded (for the last X days if the optional days argument was provided) /// If the only argument provided was the days argument, then all programs and platforms (as defined above) for all /// users for the last X days will be downloaded. /// Any argument in the form /program:XXXX where XXX is a valid ProgramId will be processed as a program. /// Any argument in the form /platform:XXXX where XXX is a valid PlatformId will be processed as a platform. /// All other args are ignored with an error message to the console. /// </param> /// <remarks> /// If the downloaded data contains raw Gen4 data and if a copy of TDC.exe is NOT available (the path is specified /// in the config file) then this program will request that the database invoke the file processor on the server, /// otherwise, this program will process the downloaded data locally and send the results to the database. /// </remarks> private static void Main(string[] args) { try { _emails = new Dictionary <string, string>(); _admin = Settings.GetSystemEmail(); if (args.Length == 0) { FileDownloader.DownloadAll(exceptionHandler); } else { int?days = null; ProjectInvestigator pi = null; foreach (var arg in args) { var program = GetProgram(arg); if (program != null) { try { FileDownloader.DownloadArgosProgram(program, days); } catch (Exception ex) { exceptionHandler(ex, program, null); } continue; } var platform = GetPlatform(arg); if (platform != null) { try { FileDownloader.DownloadArgosPlatform(platform, days); } catch (Exception ex) { exceptionHandler(ex, null, platform); } continue; } var daysArg = GetDays(arg); if (daysArg != null) { days = daysArg == Int32.MinValue ? null : daysArg; continue; } var piArg = GetProjectInvestigator(arg); if (piArg != null) { pi = piArg; continue; } Console.WriteLine("Unhandled argument: {0}", arg); } if ((args.Length == 1 && (days != null || pi != null)) || (args.Length == 2 && days != null && pi != null)) { FileDownloader.DownloadAll(exceptionHandler, pi, days); } } SendEmails(); } catch (Exception ex) { ReportException("Unhandled Exception: '" + ex.Message); } }
/// <summary> /// Download programs and/or platforms /// </summary> /// <param name="handler">An exception handler to allow processing additional items despite an exception. /// If the handler is null, processing will stop on first exception. /// The handler can throw it's own exception to halt further processing</param> /// <param name="pi">A project investigator. /// If provided, only the programs/platforms for that PI will be downloaded, /// otherwise all programs/platforms will be downloaded</param> /// <param name="daysToRetrieve">The number of days to download. If it is null, then the database is consulted /// to get the number of days since the last successful download. If the number is less than MinDays then nothing is /// downloaded (the server is not contacted at all). If the number is truncated to MaxDays. /// MinDays and MaxDays are set in the config file of the calling application.</param> public static void DownloadAll(Action <Exception, ArgosProgram, ArgosPlatform> handler = null, ProjectInvestigator pi = null, int?daysToRetrieve = null) { var db = new AnimalMovementDataContext(); foreach (var program in db.ArgosPrograms.Where(p => (pi == null || pi == p.ProjectInvestigator) && p.Active.HasValue && p.Active.Value)) { try { DownloadArgosProgram(program, daysToRetrieve); } catch (Exception ex) { if (handler == null) { throw; } handler(ex, program, null); } } foreach (var platform in db.ArgosPlatforms.Where(p => (pi == null || pi == p.ArgosProgram.ProjectInvestigator) && p.Active && !p.ArgosProgram.Active.HasValue)) { try { DownloadArgosPlatform(platform, daysToRetrieve); } catch (Exception ex) { if (handler == null) { throw; } handler(ex, null, platform); } } }
private Collar CreateTpfCollar(ProjectInvestigator owner, string collarId, double frequency) { var collarAdded = false; var form = new AddCollarForm(owner); form.DatabaseChanged += (o, x) => collarAdded = true; form.SetDefaultFrequency(frequency); form.SetDefaultModel("Telonics", "Gen4"); form.SetDefaultId(collarId); form.ShowDialog(this); //Blocks until form closed if (!collarAdded) return null; return Database.Collars.FirstOrDefault(c => c.CollarManufacturer == "Telonics" && c.CollarId == collarId); }
private static void HandleException(Exception ex, string path, Project project, ProjectInvestigator manager) { //TODO - distinguish between loading and processing (loaded fine) errors var msg = String.Format("Unable to load file: {0} for project: {1} or manager: {2} reason: {3}", path, project == null ? "<null>" : project.ProjectId, manager == null ? "<null>" : manager.Login, ex.Message); MessageBox.Show(msg, "File Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
private CollarParameterFile UploadParameterFile(ProjectInvestigator owner, LookupCollarParameterFileFormat format, string filename) { LoadAndHashFile(filename); if (_fileContents == null) return null; if (AbortBecauseDuplicate()) return null; var file = new CollarParameterFile { FileName = System.IO.Path.GetFileName(filename), LookupCollarParameterFileFormat = format, ProjectInvestigator = owner, LookupFileStatus = (LookupFileStatus)StatusComboBox.SelectedItem, Contents = _fileContents }; Database.CollarParameterFiles.InsertOnSubmit(file); if (SubmitChanges()) return file; return null; }
private static void HandleException(Exception ex, string path, Project project, ProjectInvestigator manager) { Console.WriteLine("Unable to load file: {0} for project: {1} or manager: {2} reason: {3}", path, project == null ? "<null>" : project.ProjectId, manager == null ? "<null>" : manager.Login, ex.Message); }