internal FileDetailsForm(CollarFile file)
 {
     InitializeComponent();
     RestoreWindow();
     File = file;
     CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName;
     LoadDataContext();
     SetUpControls();
 }
 /// <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);
 }
Esempio n. 3
0
 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));
     }
 }
Esempio n. 4
0
 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 static ArgosFile GetArgosFile(CollarFile file)
 {
     switch (file.Format)
     {
         case 'E':
             return new ArgosEmailFile(file.Contents.ToArray());
         case 'F':
             return new ArgosAwsFile(file.Contents.ToArray());
         case 'G':
             return new DebevekFile(file.Contents.ToArray());
         default:
             throw new InvalidOperationException("Unsupported file format: " + file.Format +
                                                 " (supported formats are E,F,G)");
     }
 }
 private static void ProcessTransmissions(CollarFile file, ArgosFile argos,
                                          IGrouping<string, ArgosTransmission> group)
 {
     LogGeneralMessage(String.Format("  Start processing transmissions for Argos Id {0}", group.Key));
     var platformId = group.Key;
     var transmissions = group.ToList();
     var first = transmissions.Min(t => t.DateTime);
     var last = transmissions.Max(t => t.DateTime);
     var databaseViews = new AnimalMovementViews();
     var parameterSets =
         databaseViews.GetTelonicsParametersForArgosDates(platformId, first, last)
                      .OrderBy(c => c.StartDate)
                      .ToList();
     if (parameterSets.Count == 0)
     {
         var msg = String.Format("No Collar for ArgosId {0} from {1:g} to {2:g}",
                                 platformId, first, last);
         LogIssueForFile(file.FileId, msg, platformId, null, null, first, last);
         return;
     }
     if (parameterSets[0].StartDate != null && first < parameterSets[0].StartDate)
     {
         var msg = String.Format("No Collar for ArgosId {0} from {1:g} to {2:g}",
                                 platformId, first, parameterSets[0].StartDate);
         LogIssueForFile(file.FileId, msg, platformId, null, null, first, parameterSets[0].StartDate);
     }
     int lastIndex = parameterSets.Count - 1;
     if (parameterSets[lastIndex].EndDate != null && parameterSets[lastIndex].EndDate < last)
     {
         var msg = String.Format("No Collar for ArgosId {0} from {1:g} to {2:g}",
                                 platformId, parameterSets[lastIndex].EndDate, last);
         LogIssueForFile(file.FileId, msg, platformId, null, null, parameterSets[lastIndex].EndDate, last);
     }
     foreach (var parameterSet in parameterSets)
     {
         if (parameterSet.ParameterId == null ||
             (parameterSet.CollarModel == "Gen3" && parameterSet.Gen3Period == null) ||
             (parameterSet.CollarModel == "Gen4" && parameterSet.Format == null))
         {
             var start = parameterSet.StartDate ?? first;
             var end = parameterSet.EndDate ?? last;
             var msg = String.Format("No Telonics Parameters for Collar {0}/{3} from {1:g} to {2:g}",
                                     parameterSet.CollarManufacturer, start, end, parameterSet.CollarId);
             LogIssueForFile(file.FileId, msg, platformId, parameterSet.CollarManufacturer, parameterSet.CollarId, start, end);
             continue;
         }
         try
         {
             ProcessParameterSet(file, argos, first, last, transmissions, parameterSet);
         }
         catch (Exception ex)
         {
             var message = String.Format(
                 "ERROR {0} adding Argos {1} transmissions from {2:g} to {3:g} to Collar {4}/{5}",
                 ex.Message, parameterSet.PlatformId, first, last,
                 parameterSet.CollarManufacturer, parameterSet.CollarId);
             LogIssueForFile(file.FileId, message, parameterSet.PlatformId, parameterSet.CollarManufacturer,
                             parameterSet.CollarId, first, last);
         }
     }
     LogGeneralMessage("  Finished processing transmissions");
 }
 private static void ProcessParameterSet(CollarFile file, ArgosFile argos, DateTime first, DateTime last,
                                         IEnumerable<ArgosTransmission> transmissions,
                                         GetTelonicsParametersForArgosDatesResult parameters)
 {
     LogGeneralMessage(String.Format("    Start processing collar {0}/{1}", parameters.CollarManufacturer,
                                     parameters.CollarId));
     var start = parameters.StartDate ?? DateTime.MinValue;
     if (start < first)
         start = first;
     var end = parameters.EndDate ?? DateTime.MaxValue;
     if (last < end)
         end = last;
     var processor = GetProcessor(file, parameters);
     var transmissionSubset = transmissions.Where(t => start <= t.DateTime && t.DateTime <= end);
     var lines = processor.ProcessTransmissions(transmissionSubset, argos);
     var data = Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, lines) + Environment.NewLine);
     var filename = Path.GetFileNameWithoutExtension(file.FileName) + "_" + parameters.CollarId + ".csv";
     var fileLoader = new FileLoader(filename, data)
         {
             Project = file.Project,
             Owner = file.ProjectInvestigator,
             Collar = new Collar {CollarManufacturer = parameters.CollarManufacturer,
                                  CollarId = parameters.CollarId},
             Status = file.Status,
             ParentFileId = file.FileId,
             ArgosDeploymentId = parameters.DeploymentId,
             CollarParameterId = parameters.ParameterId,
             AllowDuplicates = true
         };
     fileLoader.Load();
     var message =
         String.Format(
             "    Successfully added Argos {0} transmissions from {1:g} to {2:g} to Collar {3}/{4}",
             parameters.PlatformId, start, end,
             parameters.CollarManufacturer, parameters.CollarId);
     LogGeneralMessage(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 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");
        }
Esempio n. 10
0
        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");
        }
Esempio n. 11
0
        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");
        }
Esempio n. 12
0
 private static bool NeedTelonicsSoftware(CollarFile file)
 {
     var database = new AnimalMovementViews();
     return database.FileHasGen4Data(file.FileId) ?? false;
 }
Esempio n. 13
0
 private static IProcessor GetProcessor(CollarFile file, GetTelonicsParametersForArgosDatesResult parameters)
 {
     switch (file.Format)
     {
         case 'E':
         case 'F':
             switch (parameters.CollarModel)
             {
                 case "Gen3":
                     return GetGen3Processor(parameters);
                 case "Gen4":
                     return GetGen4Processor(parameters);
                 case "GPS8000":
                     return GetGps8000Processor(parameters);
                 default:
                     throw new InvalidOperationException("Unsupported collar model '" + parameters.CollarModel +
                                                         "'. (supported models are Gen3, and Gen4)");
             }
         case 'G':
             return new DebevekProcessor();
         default:
             throw new InvalidOperationException("Unsupported CollarFile Format '" + file.Format +
                                                 "'. (supported formats are E,F,G)");
     }
 }