/// <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 static bool ProcessOnServer(CollarFile file, ArgosPlatform platform = null) { if (NeedTelonicsSoftware(file) && !HaveAccessToTelonicsSoftware()) { if (OnDatabaseServer()) { throw new InvalidOperationException("No access to Telonics software to process files."); } LogGeneralMessage(String.Format("Start processing file {0} on database", file.FileId)); var database = new AnimalMovementFunctions(); //FIXME: ProcessOnServer may be called with H and I (Teloncs files which need processing, but are not ArgosFiles) //FIXME: If called by Animal Movement App Upload Form on client machine with H or I files, this code will fail // if teloncs file but not argos // database.TelonicsData_Process(file.FileId); // if not telonics or not Argos then fail with warning if (platform == null) { database.ArgosFile_Process(file.FileId); } else { database.ArgosFile_ProcessPlatform(file.FileId, platform.PlatformId); } LogGeneralMessage("Finished processing file on database"); return(true); } return(false); }
/// <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 CreateDeployment(Collar collar, ArgosPlatform platform, DateTime startDateTime) { DateTime?endDateTime = null; if (platform.ArgosDeployments.Count > 0 || collar.ArgosDeployments.Count > 0) { if (!FixOtherDeployments(collar, platform, startDateTime, ref endDateTime)) { return; } } var deploy = new ArgosDeployment { ArgosPlatform = platform, Collar = collar, StartDate = startDateTime, EndDate = endDateTime }; Database.ArgosDeployments.InsertOnSubmit(deploy); //Creating a deployment is optional, so we submit now, so a failure will not stop other transactions. if (!SubmitChanges()) { Database.ArgosDeployments.DeleteOnSubmit(deploy); } }
private void CreateButton_Click(object sender, EventArgs e) { var argosId = ArgosIdTextBox.Text.NullifyIfEmpty(); var program = (ArgosProgram)ArgosProgramComboBox.SelectedItem; if (Database.ArgosPlatforms.Any(p => p.ArgosProgram == program && p.PlatformId == argosId)) { MessageBox.Show("The Argos Id is not unique. Try again", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ArgosIdTextBox.Focus(); CreateButton.Enabled = false; return; } var argos = new ArgosPlatform { ArgosProgram = program, PlatformId = argosId, DisposalDate = DisposalDateTimePicker.Checked ? DisposalDateTimePicker.Value.ToUniversalTime() : (DateTime?)null, Active = ActiveCheckBox.Checked, Notes = NotesTextBox.Text, }; Database.ArgosPlatforms.InsertOnSubmit(argos); if (!SubmitChanges()) { ArgosIdTextBox.Focus(); CreateButton.Enabled = false; return; } OnDatabaseChanged(); Close(); }
private static string GetPlatformName(ArgosPlatform platform) { var active = platform.ArgosProgram.Active.HasValue ? "" : (platform.Active ? " (Active)" : " (Inactive)"); return(platform.PlatformId + active); }
private bool FixOtherDeployments(Collar collar, ArgosPlatform platform, DateTime start, ref DateTime?endDate) { //I'm willing to move a existing null end dates (there can only be one for the platform and one for the collar) back to my start date. //Any existing non-null enddate must have been explicitly set by the user, so they should be dealt with explicitly //If this situation exists, and I correct it, I am guaranteed to be fine (the new one will exist in the space created) var deployment1 = collar.ArgosDeployments.SingleOrDefault(d => d.ArgosPlatform != platform && d.StartDate < start && d.EndDate == null); var deployment2 = platform.ArgosDeployments.SingleOrDefault(d => d.Collar != collar && d.StartDate < start && d.EndDate == null); if (deployment1 != null) { deployment1.EndDate = start; } if (deployment2 != null) { deployment2.EndDate = start; } if (deployment1 != null || deployment2 != null) { if (!SubmitChanges()) { return(false); } } //If my enddate is null, I should set my end to the earliest start time of the others that are larger than my start but smaller than my end (infinity, so all). //I don't try to fix a non-null end date, because that was explicitly set by the user, and be should explicitly changed. if (endDate == null) { endDate = Database.ArgosDeployments.Where(d => ((d.Collar == collar && d.ArgosPlatform != platform) || (d.Collar != collar && d.ArgosPlatform == platform)) && start < d.StartDate) .Select(d => d.StartDate).Min(); //If min gets an empty enumerable, it will return null, which in this case is no change. } //Since my startdate is non-null, there is no situation where I would need to change an existing null start date. //now check if the new deployment is in conflict with any existing deployments DateTime?end = endDate; var competition = Database.ArgosDeployments.Where(d => (d.Collar == collar && d.ArgosPlatform != platform) || (d.Collar != collar && d.ArgosPlatform == platform)).ToList(); bool conflict = competition.Any(d => DatesOverlap(d.StartDate, d.EndDate, start, end)); if (conflict) { MessageBox.Show( "The other deployment(s) for this collar or platform will require manual adjustment before this platform can be used on this collar", "Oh No!", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
public AddArgosDeploymentForm(Collar collar = null, ArgosPlatform platform = null) { InitializeComponent(); Collar = collar; Platform = platform; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpControls(); //Called before events are triggered }
public ArgosPlatformDetailsForm(ArgosPlatform platform) { InitializeComponent(); RestoreWindow(); Platform = platform; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpForm(); }
public ArgosPlatformDetailsForm(ArgosPlatform platform) { InitializeComponent(); RestoreWindow(); Platform = platform; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpForm(); }
public AddArgosDeploymentForm(Collar collar = null, ArgosPlatform platform = null) { InitializeComponent(); Collar = collar; Platform = platform; CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName; LoadDataContext(); SetUpControls(); //Called before events are triggered }
/// <summary> /// Full or partial processing of Telonics data in an Argos file /// </summary> /// <param name="file">The collar file with Argos data to processes. Must not be null</param> /// <param name="platform">The Argos platform in the file to process. /// If this is null, then all the platforms will be processed.</param> public static void ProcessFile(CollarFile file, ArgosPlatform platform = null) { if (file == null) throw new ArgumentNullException("file", "No collar file was provided to process."); if (!ProcessOnServer(file, platform)) if (file.Format == 'H') ProcessDataLogFile(file); else if (file.Format == 'I') ProcessIdfFile(file); else ProcessFile(file, GetArgosFile(file), platform); }
private void LoadArgosDataGridView(ArgosPlatform platform) { ArgosDeploymentsGridView.DataSource = platform.ArgosDeployments.Select(d => new { ArgosDeployment = d, d.Collar, ArgosId = d.PlatformId, Start = d.StartDate == null ? "Long ago" : d.StartDate.Value.ToString("g"), End = d.EndDate == null ? "Never" : d.EndDate.Value.ToString("g"), CanDelete = true }).ToList(); ArgosDeploymentsGridView.Columns[0].Visible = false; ArgosDeploymentsGridView.Columns[5].Visible = false; }
internal static void exceptionHandler(Exception ex, CollarFile file, ArgosPlatform platform) { if (file == null) { ReportException( String.Format("Unexpected Exception ({0}) when Loading an unknown collar file", ex.Message)); } else { ReportException( String.Format("Unexpected Exception ({0}) when Loading collar file (id: {1}, name:{2}", ex.Message, file.FileId, file.FileName)); } }
internal static void exceptionHandler(Exception ex, CollarFile file, ArgosPlatform platform) { if (file == null) { ReportException( String.Format("Unexpected Exception ({0}) when Loading an unknown collar file", ex.Message)); } else { ReportException( String.Format("Unexpected Exception ({0}) when Loading collar file (id: {1}, name:{2}", ex.Message, file.FileId, file.FileName)); } }
private static void HandleException(Exception ex, CollarFile file, ArgosPlatform platform) { if (file == null) { Console.WriteLine("Processor exception handler called without a file: {0}", ex.Message); return; } if (file.LookupCollarFileFormat.ArgosData != 'Y') { Console.WriteLine("Processor exception handler called with a Non-Argos Data file({1}): {0}", ex.Message, file.FileId); return; } var db = new AnimalMovementDataContext(); db.ArgosFileProcessingIssues_Insert(file.FileId, ex.Message, platform == null ? null : platform.PlatformId, null, null, null, null); }
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; } }
private static void HandleException(Exception ex, CollarFile file, ArgosPlatform platform) { if (file == null) { Console.WriteLine("Processor exception handler called without a file: {0}", ex.Message); return; } if (file.LookupCollarFileFormat.ArgosData != 'Y') { Console.WriteLine("Processor exception handler called with a Non-Argos Data file({1}): {0}", ex.Message, file.FileId); return; } var db = new AnimalMovementDataContext(); db.ArgosFileProcessingIssues_Insert(file.FileId, ex.Message, platform == null ? null : platform.PlatformId, null, null, null, null); }
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); }
private static void ProcessFile(CollarFile file, ArgosFile argos, ArgosPlatform platform) { LogGeneralMessage(String.Format("Start local processing of file {0}", file.FileId)); var databaseFunctions = new AnimalMovementFunctions(); if (platform == null) { databaseFunctions.ArgosFile_ClearProcessingResults(file.FileId); if (IsArgosAwsFileIncomplete(argos as ArgosAwsFile) ?? false) { LogIssueForFile(file.FileId, "The Argos server could not return all the data requested and this file is incomplete."); } } else { databaseFunctions.ArgosFile_UnProcessPlatform(file.FileId, platform.PlatformId); } var transmissionsByPlatform = from transmission in argos.GetTransmissions() group transmission by transmission.PlatformId into transmissions where platform == null || transmissions.Key == platform.PlatformId select transmissions; foreach (var transmissionSet in transmissionsByPlatform) { try { ProcessTransmissions(file, argos, transmissionSet); } catch (Exception ex) { var message = String.Format("ERROR {0} adding Argos {1} transmissions", ex.Message, transmissionSet.Key); LogIssueForFile(file.FileId, message, transmissionSet.Key); } } LogGeneralMessage("Finished local processing of file"); }
/// <summary> /// Full or partial processing of Telonics data in an Argos file /// </summary> /// <param name="file">The collar file with Argos data to processes. Must not be null</param> /// <param name="platform">The Argos platform in the file to process. /// If this is null, then all the platforms will be processed.</param> public static void ProcessFile(CollarFile file, ArgosPlatform platform = null) { if (file == null) { throw new ArgumentNullException("file", "No collar file was provided to process."); } if (!ProcessOnServer(file, platform)) { if (file.Format == 'H') { ProcessDataLogFile(file); } else if (file.Format == 'I') { ProcessIdfFile(file); } else { ProcessFile(file, GetArgosFile(file), platform); } } }
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> /// Loads and logs the download data for an Argos Platform /// </summary> /// <param name="platform">The Argos PlatformId that this data is for</param> /// <param name="days">The number of days that are included in this data set</param> /// <param name="results">The data returned from the Argos Web Server (may be null)</param> /// <param name="errors">Any errors returned by the Argos Web Server (may be null)</param> /// <returns>Returns the newly created collar file, complete with database calculated fields</returns> /// <remarks>Only one of results and errors can be non-null.</remarks> internal static CollarFile LoadPlatfrom(ArgosPlatform platform, int days, ArgosWebSite.ArgosWebResult results, string errors) { //if results is null, then errors should be non-null (database rule, insert will fail if false) CollarFile file = null; var database = new AnimalMovementDataContext(); //Linq to SQL wraps the changes in a transaction so file will not be created if log cannot be written if (results != null) { file = new CollarFile { Owner = platform.ArgosProgram.Manager, FileName = "platform_" + platform.PlatformId + "_" + DateTime.Now.ToString("yyyyMMdd") + ".aws", Status = 'A', Contents = results.ToBytes() }; database.CollarFiles.InsertOnSubmit(file); } //Linq to SQL does not return the PK (timestamp) of the new ArgosDownload object, so don't use it in this data context var log = new ArgosDownload { PlatformId = platform.PlatformId, CollarFile = file, Days = days, ErrorMessage = errors }; database.ArgosDownloads.InsertOnSubmit(log); database.SubmitChanges(); //Linq TO SQL Insert with SPROC dos not set associations, and provides not partial methods to expand if (file != null) { file.LookupCollarFileFormat = database.LookupCollarFileFormats.First(l => l.Code == file.Format); } return(file); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Platform is in a different DataContext, get one in this DataContext if (Platform != null) Platform = Database.ArgosPlatforms.FirstOrDefault(p => p.PlatformId == Platform.PlatformId); if (Platform == null) throw new InvalidOperationException("Argos Platform Details Form not provided a valid Platform."); var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(Platform.ArgosProgram.Manager, CurrentUser) ?? false; }
private void CreateButton_Click(object sender, EventArgs e) { var argosId = ArgosIdTextBox.Text.NullifyIfEmpty(); var program = (ArgosProgram) ArgosProgramComboBox.SelectedItem; if (Database.ArgosPlatforms.Any(p => p.ArgosProgram == program && p.PlatformId == argosId)) { MessageBox.Show("The Argos Id is not unique. Try again", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ArgosIdTextBox.Focus(); CreateButton.Enabled = false; return; } var argos = new ArgosPlatform { ArgosProgram = program, PlatformId = argosId, DisposalDate = DisposalDateTimePicker.Checked ? DisposalDateTimePicker.Value.ToUniversalTime() : (DateTime?)null, Active = ActiveCheckBox.Checked, Notes = NotesTextBox.Text, }; Database.ArgosPlatforms.InsertOnSubmit(argos); if (!SubmitChanges()) { ArgosIdTextBox.Focus(); CreateButton.Enabled = false; return; } OnDatabaseChanged(); Close(); }
private void LoadArgosDataGridView(ArgosPlatform platform) { ArgosDeploymentsGridView.DataSource = platform.ArgosDeployments.Select(d => new { ArgosDeployment = d, d.Collar, ArgosId = d.PlatformId, Start = d.StartDate == null ? "Long ago" : d.StartDate.Value.ToString("g"), End = d.EndDate == null ? "Never" : d.EndDate.Value.ToString("g"), CanDelete = true }).ToList(); ArgosDeploymentsGridView.Columns[0].Visible = false; ArgosDeploymentsGridView.Columns[5].Visible = false; }
private static void ProcessFile(CollarFile file, ArgosFile argos, ArgosPlatform platform) { LogGeneralMessage(String.Format("Start local processing of file {0}", file.FileId)); var databaseFunctions = new AnimalMovementFunctions(); if (platform == null) { databaseFunctions.ArgosFile_ClearProcessingResults(file.FileId); if (IsArgosAwsFileIncomplete(argos as ArgosAwsFile) ?? false) LogIssueForFile(file.FileId, "The Argos server could not return all the data requested and this file is incomplete."); } else { databaseFunctions.ArgosFile_UnProcessPlatform(file.FileId, platform.PlatformId); } var transmissionsByPlatform = from transmission in argos.GetTransmissions() group transmission by transmission.PlatformId into transmissions where platform == null || transmissions.Key == platform.PlatformId select transmissions; foreach (var transmissionSet in transmissionsByPlatform) try { ProcessTransmissions(file, argos, transmissionSet); } catch (Exception ex) { var message = String.Format("ERROR {0} adding Argos {1} transmissions", ex.Message, transmissionSet.Key); LogIssueForFile(file.FileId, message, transmissionSet.Key); } LogGeneralMessage("Finished local processing of file"); }
private bool FixOtherDeployments(Collar collar, ArgosPlatform platform, DateTime start, ref DateTime? endDate) { //I'm willing to move a existing null end dates (there can only be one for the platform and one for the collar) back to my start date. //Any existing non-null enddate must have been explicitly set by the user, so they should be dealt with explicitly //If this situation exists, and I correct it, I am guaranteed to be fine (the new one will exist in the space created) var deployment1 = collar.ArgosDeployments.SingleOrDefault(d => d.ArgosPlatform != platform && d.StartDate < start && d.EndDate == null); var deployment2 = platform.ArgosDeployments.SingleOrDefault(d => d.Collar != collar && d.StartDate < start && d.EndDate == null); if (deployment1 != null) deployment1.EndDate = start; if (deployment2 != null) deployment2.EndDate = start; if (deployment1 != null || deployment2 != null) if (!SubmitChanges()) return false; //If my enddate is null, I should set my end to the earliest start time of the others that are larger than my start but smaller than my end (infinity, so all). //I don't try to fix a non-null end date, because that was explicitly set by the user, and be should explicitly changed. if (endDate == null) endDate = Database.ArgosDeployments.Where(d => ((d.Collar == collar && d.ArgosPlatform != platform) || (d.Collar != collar && d.ArgosPlatform == platform)) && start < d.StartDate) .Select(d => d.StartDate).Min(); //If min gets an empty enumerable, it will return null, which in this case is no change. //Since my startdate is non-null, there is no situation where I would need to change an existing null start date. //now check if the new deployment is in conflict with any existing deployments DateTime? end = endDate; var competition = Database.ArgosDeployments.Where(d => (d.Collar == collar && d.ArgosPlatform != platform) || (d.Collar != collar && d.ArgosPlatform == platform)).ToList(); bool conflict = competition.Any(d => DatesOverlap(d.StartDate, d.EndDate, start, end)); if (conflict) { MessageBox.Show( "The other deployment(s) for this collar or platform will require manual adjustment before this platform can be used on this collar", "Oh No!", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return true; }
private void CreateDeployment(Collar collar, ArgosPlatform platform, DateTime startDateTime) { DateTime? endDateTime = null; if (platform.ArgosDeployments.Count > 0 || collar.ArgosDeployments.Count > 0) if (!FixOtherDeployments(collar, platform, startDateTime, ref endDateTime)) return; var deploy = new ArgosDeployment { ArgosPlatform = platform, Collar = collar, StartDate = startDateTime, EndDate = endDateTime }; Database.ArgosDeployments.InsertOnSubmit(deploy); //Creating a deployment is optional, so we submit now, so a failure will not stop other transactions. if (!SubmitChanges()) Database.ArgosDeployments.DeleteOnSubmit(deploy); }
/// <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 static bool ProcessOnServer(CollarFile file, ArgosPlatform platform = null) { if (NeedTelonicsSoftware(file) && !HaveAccessToTelonicsSoftware()) { if (OnDatabaseServer()) throw new InvalidOperationException("No access to Telonics software to process files."); LogGeneralMessage(String.Format("Start processing file {0} on database", file.FileId)); var database = new AnimalMovementFunctions(); //FIXME: ProcessOnServer may be called with H and I (Teloncs files which need processing, but are not ArgosFiles) //FIXME: If called by Animal Movement App Upload Form on client machine with H or I files, this code will fail // if teloncs file but not argos // database.TelonicsData_Process(file.FileId); // if not telonics or not Argos then fail with warning if (platform == null) database.ArgosFile_Process(file.FileId); else database.ArgosFile_ProcessPlatform(file.FileId, platform.PlatformId); LogGeneralMessage("Finished processing file on database"); return true; } return false; }
private static string GetPlatformName(ArgosPlatform platform) { var active = platform.ArgosProgram.Active.HasValue ? "" : (platform.Active ? " (Active)" : " (Inactive)"); return platform.PlatformId + active; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Collar and Platform are in a different DataContext, get them in this DataContext if (Collar != null) Collar = Database.Collars.FirstOrDefault( c => c.CollarManufacturer == Collar.CollarManufacturer && c.CollarId == Collar.CollarId); if (Platform != null) Platform = Database.ArgosPlatforms.FirstOrDefault(p => p.PlatformId == Platform.PlatformId); }
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; } }