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 void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Collar and Animal 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 (Animal != null) { Animal = Database.Animals.FirstOrDefault( a => a.ProjectId == Animal.ProjectId && a.AnimalId == Animal.AnimalId); } if (Collar == null && Animal == null) { throw new InvalidOperationException("Add Collar Deployment Form not provided a valid Collar or a valid Animal."); } LockCollar = Collar != null; LockAnimal = Animal != null; var functions = new AnimalMovementFunctions(); IsEditor = (Animal != null && (functions.IsProjectEditor(Animal.ProjectId, CurrentUser) ?? false)) || (Collar != null && (functions.IsInvestigatorEditor(Collar.Manager, CurrentUser) ?? false)); }
private static void ProcessDataLogFile(CollarFile file) { LogGeneralMessage(String.Format("Start local processing of file {0}", file.FileId)); var databaseFunctions = new AnimalMovementFunctions(); //FIXME: check that this is generic to all telonics processing and not just Argos files databaseFunctions.ArgosFile_ClearProcessingResults(file.FileId); var processor = new Gen4Processor(null); var lines = processor.ProcessDataLog(file.Contents.ToArray()); //Add a newline, so that it exactly matches the direct output from TDC var data = Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, lines) + Environment.NewLine); var filename = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("yyyyMMdd") + ".csv"; var fileLoader = new FileLoader(filename, data) { Project = file.Project, Owner = file.ProjectInvestigator, Collar = new Collar { CollarManufacturer = file.CollarManufacturer, CollarId = file.CollarId }, Status = file.Status, ParentFileId = file.FileId, AllowDuplicates = true }; fileLoader.Load(); LogGeneralMessage("Finished local processing of file"); }
private static void ProcessIdfFile(CollarFile file) { LogGeneralMessage(String.Format("Start local processing of file {0}", file.FileId)); var databaseViews = new AnimalMovementViews(); var idfLink = databaseViews.CollarParametersForIridiumDownload(file.FileId).FirstOrDefault(); if (idfLink == null) { LogGeneralMessage("No parameters found. Skipping file."); return; } var database = new AnimalMovementDataContext(); var tpfFile = database.CollarParameterFiles.FirstOrDefault(f => f.FileId == idfLink.ParameterFileId); if (tpfFile == null) { LogGeneralMessage("No collar parameter file found. Skipping file."); return; } var collar = database.Collars.FirstOrDefault( c => c.CollarManufacturer == idfLink.CollarManufacturer && (c.CollarId == idfLink.CollarId || c.CollarId == idfLink.CollarId.Substring(0, 6))); if (collar == null) { LogGeneralMessage("No collar found. Skipping file."); return; } var databaseFunctions = new AnimalMovementFunctions(); //FIXME: check that this is generic to all telonics processing and not just Argos files databaseFunctions.ArgosFile_ClearProcessingResults(file.FileId); databaseFunctions.CollarFile_FixOwnerOfIdfFile((file.FileId)); var processor = new Gen4Processor(tpfFile.Contents.ToArray()); var lines = processor.ProcessIdf(file.Contents.ToArray()); var data = Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, lines) + Environment.NewLine); var filename = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("yyyyMMdd") + ".csv"; var fileLoader = new FileLoader(filename, data) { Project = null, Owner = tpfFile.ProjectInvestigator, //Must match result from databaseFunctions.CollarFile_FixOwnerOfIdfFile Collar = collar, Status = file.Status, ParentFileId = file.FileId, AllowDuplicates = false }; fileLoader.Load(); LogGeneralMessage("Finished local processing of file"); }
private bool CanEditCollar(Collar collar) { if (collar == null) { return(Database.ProjectInvestigators.Any( pi => pi.Login == CurrentUser || pi.ProjectInvestigatorAssistants.Any(a => a.Assistant == CurrentUser))); } var functions = new AnimalMovementFunctions(); return(functions.IsInvestigatorEditor(collar.Manager, CurrentUser) ?? false); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Get an ArgosDeployment in this data context ArgosDeployment = Database.ArgosDeployments.FirstOrDefault(d => d.DeploymentId == DeploymentId); if (ArgosDeployment == null) { throw new InvalidOperationException("Argos Deployments Form not provided a valid Argos Deployment Id."); } var functions = new AnimalMovementFunctions(); IsEditor = (functions.IsInvestigatorEditor(ArgosDeployment.Collar.Manager, CurrentUser) ?? false) || (functions.IsInvestigatorEditor(ArgosDeployment.ArgosPlatform.ArgosProgram.Manager, CurrentUser) ?? false); }
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 LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Collar is in a different DataContext, get one in this DataContext if (Collar != null) { Collar = Database.Collars.FirstOrDefault(c => c.CollarManufacturer == Collar.CollarManufacturer && c.CollarId == Collar.CollarId); } if (Collar == null) { throw new InvalidOperationException("Collar Details Form not provided a valid Collar."); } DatabaseFunctions = new AnimalMovementFunctions(); DatabaseViews = new AnimalMovementViews(); IsEditor = DatabaseFunctions.IsInvestigatorEditor(Collar.Manager, CurrentUser) ?? false; }
protected override void OnShown(EventArgs e) { if (Investigator != null) { var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(Investigator.Login, CurrentUser) ?? false; if (!IsEditor) MessageBox.Show("You do not have permission to add a file for this investigator", "Permission Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { IsEditor = OwnerComboBox.Items.Count > 0; if (!IsEditor) MessageBox.Show("You do not have permission to add a file", "Permission Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Animal is in a different DataContext, get one in this DataContext if (Animal != null) { Animal = Database.Animals.FirstOrDefault(a => a.ProjectId == Animal.ProjectId && a.AnimalId == Animal.AnimalId); } if (Animal == null) { throw new InvalidOperationException("Animal Details Form not provided a valid Animal."); } var functions = new AnimalMovementFunctions(); IsEditor = functions.IsProjectEditor(Animal.ProjectId, CurrentUser) ?? false; SetupHeader(); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Project is in a different DataContext, get one in this DataContext if (Project != null) { Project = Database.Projects.FirstOrDefault(p => p.ProjectId == Project.ProjectId); } if (Project == null) { throw new InvalidOperationException("Project Details Form not provided a valid project."); } var functions = new AnimalMovementFunctions(); IsInvestigator = Project.ProjectInvestigator.Normalize().Equals(CurrentUser.Normalize(), StringComparison.OrdinalIgnoreCase); IsEditor = functions.IsProjectEditor(Project.ProjectId, CurrentUser) ?? false; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //CollarParameter is in a different DataContext, get one in this DataContext if (CollarParameter != null) { CollarParameter = Database.CollarParameters.FirstOrDefault(p => p.ParameterId == CollarParameter.ParameterId); } if (CollarParameter == null) { throw new InvalidOperationException("Collar Parameters Form not provided a valid Collar Parameter Id."); } var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(CollarParameter.Collar.Manager, CurrentUser) ?? false; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Investigator is in a different DataContext, get one in this DataContext if (Investigator != null) { Investigator = Database.ProjectInvestigators.First(pi => pi.Login == Investigator.Login); } if (Investigator == null) { throw new InvalidOperationException("Investigator Form not provided a valid investigator."); } var functions = new AnimalMovementFunctions(); IsInvestigator = Investigator == Database.ProjectInvestigators.FirstOrDefault(pi => pi.Login == CurrentUser); IsEditor = functions.IsInvestigatorEditor(Investigator.Login, CurrentUser) ?? false; CollarsListBox.DataSource = null; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //File is in a different DataContext, get one in this DataContext if (File != null) { File = Database.CollarParameterFiles.FirstOrDefault(f => f.FileId == File.FileId); } if (File == null) { throw new InvalidOperationException("Collar Parameter File Details Form not provided a valid Parameter File."); } var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(File.Owner, CurrentUser) ?? false; HasParameters = File.CollarParameters.Any(); ParametersDataGridView.DataSource = null; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Get a CollarDeployment in this DataContext if (CollarDeployment != null) { CollarDeployment = Database.CollarDeployments.FirstOrDefault(d => d.DeploymentId == CollarDeployment.DeploymentId); } if (CollarDeployment == null) { throw new InvalidOperationException("Collar Deployments Form not provided a valid Deployment."); } var functions = new AnimalMovementFunctions(); IsEditor = (functions.IsProjectEditor(CollarDeployment.Animal.ProjectId, CurrentUser) ?? false) || (functions.IsInvestigatorEditor(CollarDeployment.Collar.Manager, CurrentUser) ?? false); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //File is in a different DataContext, get one in this DataContext if (File != null) { File = Database.CollarFiles.FirstOrDefault(f => f.FileId == File.FileId); } if (File == null) { throw new InvalidOperationException("File Details Form not provided a valid File."); } DatabaseViews = new AnimalMovementViews(); var functions = new AnimalMovementFunctions(); IsFileEditor = (functions.IsProjectEditor(File.ProjectId, CurrentUser) ?? false) || (functions.IsInvestigatorEditor(File.Owner, CurrentUser) ?? 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"); }
protected override void OnShown(EventArgs e) { if (Investigator != null) { var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(Investigator.Login, CurrentUser) ?? false; if (!IsEditor) { MessageBox.Show("You do not have permission to add a file for this investigator", "Permission Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { IsEditor = OwnerComboBox.Items.Count > 0; if (!IsEditor) { MessageBox.Show("You do not have permission to add a file", "Permission Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //ProjectInvestigator is in a different DataContext, get one in this DataContext if (ProjectInvestigator != null) { ProjectInvestigator = Database.ProjectInvestigators.FirstOrDefault(pi => pi.Login == ProjectInvestigator.Login); } //If Project Investigator is not provided, Current user must be a PI or an assistant if (ProjectInvestigator == null) { if (!Database.ProjectInvestigators.Any(pi => pi.Login == CurrentUser) && !Database.ProjectInvestigatorAssistants.Any(a => a.Assistant == CurrentUser)) { throw new InvalidOperationException("Add Collar Form not provided a valid Project Investigator or you are not a PI or an assistant."); } } Functions = new AnimalMovementFunctions(); IsEditor = ProjectInvestigator != null && (Functions.IsInvestigatorEditor(ProjectInvestigator.Login, CurrentUser) ?? false); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Project is in a different DataContext, get one in this DataContext if (Project != null) { Project = Database.Projects.FirstOrDefault(p => p.ProjectId == Project.ProjectId); } //If Project is not provided, Current user must be a PI or an project editor if (Project == null) { if (!Database.Projects.Any(p => p.ProjectInvestigator == CurrentUser) && !Database.ProjectEditors.Any(e => e.Editor == CurrentUser)) { throw new InvalidOperationException("Add Animal Form not provided a valid Project or you are not a PI or editor on any projects."); } } Functions = new AnimalMovementFunctions(); IsEditor = Project != null && (Functions.IsProjectEditor(Project.ProjectId, CurrentUser) ?? false); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Animal is in a different DataContext, get one in this DataContext if (Animal != null) Animal = Database.Animals.FirstOrDefault(a => a.ProjectId == Animal.ProjectId && a.AnimalId == Animal.AnimalId); if (Animal == null) throw new InvalidOperationException("Animal Details Form not provided a valid Animal."); var functions = new AnimalMovementFunctions(); IsEditor = functions.IsProjectEditor(Animal.ProjectId, CurrentUser) ?? false; SetupHeader(); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Get an ArgosDeployment in this data context ArgosDeployment = Database.ArgosDeployments.FirstOrDefault(d => d.DeploymentId == DeploymentId); if (ArgosDeployment == null) throw new InvalidOperationException("Argos Deployments Form not provided a valid Argos Deployment Id."); var functions = new AnimalMovementFunctions(); IsEditor = (functions.IsInvestigatorEditor(ArgosDeployment.Collar.Manager, CurrentUser) ?? false) || (functions.IsInvestigatorEditor(ArgosDeployment.ArgosPlatform.ArgosProgram.Manager, CurrentUser) ?? false); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Investigator is in a different DataContext, get one in this DataContext if (Investigator != null) Investigator = Database.ProjectInvestigators.First(pi => pi.Login == Investigator.Login); if (Investigator == null) throw new InvalidOperationException("Investigator Form not provided a valid investigator."); var functions = new AnimalMovementFunctions(); IsInvestigator = Investigator == Database.ProjectInvestigators.FirstOrDefault(pi => pi.Login == CurrentUser); IsEditor = functions.IsInvestigatorEditor(Investigator.Login, CurrentUser) ?? false; CollarsListBox.DataSource = null; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Collar and Animal 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 (Animal != null) Animal = Database.Animals.FirstOrDefault( a => a.ProjectId == Animal.ProjectId && a.AnimalId == Animal.AnimalId); if (Collar == null && Animal == null) throw new InvalidOperationException("Add Collar Deployment Form not provided a valid Collar or a valid Animal."); LockCollar = Collar != null; LockAnimal = Animal != null; var functions = new AnimalMovementFunctions(); IsEditor = (Animal != null && (functions.IsProjectEditor(Animal.ProjectId, CurrentUser) ?? false)) || (Collar != null && (functions.IsInvestigatorEditor(Collar.Manager, CurrentUser) ?? false)); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //CollarParameter is in a different DataContext, get one in this DataContext if (CollarParameter != null) CollarParameter = Database.CollarParameters.FirstOrDefault(p => p.ParameterId == CollarParameter.ParameterId); if (CollarParameter == null) throw new InvalidOperationException("Collar Parameters Form not provided a valid Collar Parameter Id."); var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(CollarParameter.Collar.Manager, CurrentUser) ?? false; }
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 LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Get a CollarDeployment in this DataContext if (CollarDeployment != null) CollarDeployment = Database.CollarDeployments.FirstOrDefault(d => d.DeploymentId == CollarDeployment.DeploymentId); if (CollarDeployment == null) throw new InvalidOperationException("Collar Deployments Form not provided a valid Deployment."); var functions = new AnimalMovementFunctions(); IsEditor = (functions.IsProjectEditor(CollarDeployment.Animal.ProjectId, CurrentUser) ?? false) || (functions.IsInvestigatorEditor(CollarDeployment.Collar.Manager, CurrentUser) ?? false); }
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 void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //File is in a different DataContext, get one in this DataContext if (File != null) File = Database.CollarParameterFiles.FirstOrDefault(f => f.FileId == File.FileId); if (File == null) throw new InvalidOperationException("Collar Parameter File Details Form not provided a valid Parameter File."); var functions = new AnimalMovementFunctions(); IsEditor = functions.IsInvestigatorEditor(File.Owner, CurrentUser) ?? false; HasParameters = File.CollarParameters.Any(); ParametersDataGridView.DataSource = null; }
private static void ProcessDataLogFile(CollarFile file) { LogGeneralMessage(String.Format("Start local processing of file {0}", file.FileId)); var databaseFunctions = new AnimalMovementFunctions(); //FIXME: check that this is generic to all telonics processing and not just Argos files databaseFunctions.ArgosFile_ClearProcessingResults(file.FileId); var processor = new Gen4Processor(null); var lines = processor.ProcessDataLog(file.Contents.ToArray()); //Add a newline, so that it exactly matches the direct output from TDC var data = Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, lines) + Environment.NewLine); var filename = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("yyyyMMdd") + ".csv"; var fileLoader = new FileLoader(filename, data) { Project = file.Project, Owner = file.ProjectInvestigator, Collar = new Collar { CollarManufacturer = file.CollarManufacturer, CollarId = file.CollarId }, Status = file.Status, ParentFileId = file.FileId, AllowDuplicates = true }; fileLoader.Load(); LogGeneralMessage("Finished local processing of file"); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Collar is in a different DataContext, get one in this DataContext if (Collar != null) Collar = Database.Collars.FirstOrDefault(c => c.CollarManufacturer == Collar.CollarManufacturer && c.CollarId == Collar.CollarId); if (Collar == null) throw new InvalidOperationException("Collar Details Form not provided a valid Collar."); DatabaseFunctions = new AnimalMovementFunctions(); DatabaseViews = new AnimalMovementViews(); IsEditor = DatabaseFunctions.IsInvestigatorEditor(Collar.Manager, CurrentUser) ?? 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 void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Project is in a different DataContext, get one in this DataContext if (Project != null) Project = Database.Projects.FirstOrDefault(p => p.ProjectId == Project.ProjectId); //If Project is not provided, Current user must be a PI or an project editor if (Project == null) if (!Database.Projects.Any(p => p.ProjectInvestigator == CurrentUser) && !Database.ProjectEditors.Any(e => e.Editor == CurrentUser)) throw new InvalidOperationException("Add Animal Form not provided a valid Project or you are not a PI or editor on any projects."); Functions = new AnimalMovementFunctions(); IsEditor = Project != null && (Functions.IsProjectEditor(Project.ProjectId, CurrentUser) ?? false); }
private static void ProcessIdfFile(CollarFile file) { LogGeneralMessage(String.Format("Start local processing of file {0}", file.FileId)); var databaseViews = new AnimalMovementViews(); var idfLink = databaseViews.CollarParametersForIridiumDownload(file.FileId).FirstOrDefault(); if (idfLink == null) { LogGeneralMessage("No parameters found. Skipping file."); return; } var database = new AnimalMovementDataContext(); var tpfFile = database.CollarParameterFiles.FirstOrDefault(f => f.FileId == idfLink.ParameterFileId); if (tpfFile == null) { LogGeneralMessage("No collar parameter file found. Skipping file."); return; } var collar = database.Collars.FirstOrDefault( c => c.CollarManufacturer == idfLink.CollarManufacturer && (c.CollarId == idfLink.CollarId || c.CollarId == idfLink.CollarId.Substring(0,6))); if (collar == null) { LogGeneralMessage("No collar found. Skipping file."); return; } var databaseFunctions = new AnimalMovementFunctions(); //FIXME: check that this is generic to all telonics processing and not just Argos files databaseFunctions.ArgosFile_ClearProcessingResults(file.FileId); databaseFunctions.CollarFile_FixOwnerOfIdfFile((file.FileId)); var processor = new Gen4Processor(tpfFile.Contents.ToArray()); var lines = processor.ProcessIdf(file.Contents.ToArray()); var data = Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, lines) + Environment.NewLine); var filename = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("yyyyMMdd") + ".csv"; var fileLoader = new FileLoader(filename, data) { Project = null, Owner = tpfFile.ProjectInvestigator, //Must match result from databaseFunctions.CollarFile_FixOwnerOfIdfFile Collar = collar, Status = file.Status, ParentFileId = file.FileId, AllowDuplicates = false }; fileLoader.Load(); LogGeneralMessage("Finished local processing of file"); }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //Project is in a different DataContext, get one in this DataContext if (Project != null) Project = Database.Projects.FirstOrDefault(p => p.ProjectId == Project.ProjectId); if (Project == null) throw new InvalidOperationException("Project Details Form not provided a valid project."); var functions = new AnimalMovementFunctions(); IsInvestigator = Project.ProjectInvestigator.Normalize().Equals(CurrentUser.Normalize(), StringComparison.OrdinalIgnoreCase); IsEditor = functions.IsProjectEditor(Project.ProjectId, CurrentUser) ?? false; }
private void LoadDataContext() { Database = new AnimalMovementDataContext(); //Database.Log = Console.Out; //File is in a different DataContext, get one in this DataContext if (File != null) File = Database.CollarFiles.FirstOrDefault(f => f.FileId == File.FileId); if (File == null) throw new InvalidOperationException("File Details Form not provided a valid File."); DatabaseViews = new AnimalMovementViews(); var functions = new AnimalMovementFunctions(); IsFileEditor = (functions.IsProjectEditor(File.ProjectId, CurrentUser) ?? false) || (functions.IsInvestigatorEditor(File.Owner, CurrentUser) ?? false); }