// 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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Retrieves data for an Argos Program from the Argos Web Server
        /// </summary>
        /// <param name="program">The Argos Program (contains Platforms) to retrieve from the server</param>
        /// <param name="daysToRetrieve">The number of most recent days to retrieve from the server</param>
        public static void DownloadArgosProgram(ArgosProgram program, int?daysToRetrieve = null)
        {
            int daysSinceLastDownload;

            if (daysToRetrieve.HasValue)
            {
                daysSinceLastDownload = daysToRetrieve.Value;
            }
            else
            {
                var database           = new AnimalMovementDataContext();
                var dateOfLastDownload = (from log in database.ArgosDownloads
                                          where log.ProgramId == program.ProgramId && log.FileId != null
                                          orderby log.TimeStamp descending
                                          select log.TimeStamp).FirstOrDefault();
                //Problem: using Days always truncates.
                // If I download at 1am on day 1, and then 11pm on day 2, (1.9 days -> 1day),
                //   I will miss any data created between 1am and 11pm on day 1.
                // However, rounding up may cause a lot of duplication,
                // (i.e. 6:01am on day1 and then 6:02am on day2, will need to download 2 days to get the extra minute)
                // by default we should round up to make sure that all data is obtained.  However, since this is
                // typically called on a scheduled task at the same time (+/- download/processing time) everyday.
                // I will check if we are close to an even day, and then round tword that day
                var timespan = DateTime.Now - dateOfLastDownload;
                int extraDay = timespan.Hours == 0 && timespan.Minutes < 5 ? 0 : 1;
                daysSinceLastDownload = timespan.Days + extraDay;
            }
            var days = Math.Min(ArgosWebSite.MaxDays, daysSinceLastDownload);

            if (days < ArgosWebSite.MinDays)
            {
                return;
            }
            string errors;
            var    results = ArgosWebSite.GetProgram(program.UserName, program.Password, program.ProgramId, days,
                                                     out errors);
            CollarFile file = FileLoader.LoadProgram(program, days, results, errors);

            if (file == null)
            {
                return;
            }
            FileProcessor.ProcessFile(file);
        }