private void CreateButton_Click(object sender, EventArgs e)
        {
            var programId = ProgramIdTextBox.Text;

            if (Database.ArgosPrograms.Any(p => p.ProgramId == programId))
            {
                MessageBox.Show("The Program Id already exists in the database.  Try again", "Database Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                ProgramIdTextBox.Focus();
                CreateButton.Enabled = false;
                return;
            }
            var program = new ArgosProgram
            {
                ProgramId           = programId,
                ProjectInvestigator = (ProjectInvestigator)OwnerComboBox.SelectedItem,
                ProgramName         = ProgramNameTextBox.Text.NullifyIfEmpty(),
                UserName            = UserNameTextBox.Text,
                Password            = PasswordTextBox.Text,
                StartDate           = StartDateTimePicker.Checked ? StartDateTimePicker.Value.ToUniversalTime() : (DateTime?)null,
                EndDate             = EndDateTimePicker.Checked ? EndDateTimePicker.Value.ToUniversalTime() : (DateTime?)null,
                Active = ActiveCheckBox.CheckState == CheckState.Indeterminate ? (bool?)null : ActiveCheckBox.Checked,
                Notes  = NotesTextBox.Text.NullifyIfEmpty(),
            };

            Database.ArgosPrograms.InsertOnSubmit(program);
            if (!SubmitChanges())
            {
                ProgramIdTextBox.Focus();
                CreateButton.Enabled = false;
                return;
            }
            OnDatabaseChanged();
            Close();
        }
Пример #2
0
        // ReSharper restore UnusedAutoPropertyAccessor.Local

        private void LoadPlatformsListBox(ArgosProgram program)
        {
            var query = from platform in program.ArgosPlatforms
                        select new PlatformListItem
            {
                Platform  = platform,
                Name      = GetPlatformName(platform),
                CanDelete = !platform.ArgosDeployments.Any()
            };
            var sortedList = query.OrderBy(p => p.Platform.Active ? 0 : 1).ThenBy(p => p.Name).ToList();

            PlatformsListBox.DataSource    = sortedList;
            PlatformsListBox.DisplayMember = "Name";
            PlatformsListBoxLabel.Text     = sortedList.Count < 5 ? "Argos Ids" : String.Format("Argos Ids ({0})", sortedList.Count);
            PlatformsListBox.ClearItemColors();
            for (int i = 0; i < sortedList.Count; i++)
            {
                var programStatus  = sortedList[i].Platform.ArgosProgram.Active;
                var platformStatus = sortedList[i].Platform.Active;
                if ((programStatus.HasValue && !programStatus.Value) || (!programStatus.HasValue && !platformStatus))
                {
                    PlatformsListBox.SetItemColor(i, Color.DarkGray);
                }
            }
        }
Пример #3
0
        private static string GetProgramName(ArgosProgram program)
        {
            var active = program.Active.HasValue
                             ? (program.Active.Value ? "Active download" : "Inactive download")
                             : "Download status defered to platforms";

            return(program + " (" + active + ")");
        }
 public ArgosProgramDetailsForm(ArgosProgram program)
 {
     InitializeComponent();
     RestoreWindow();
     Program     = program;
     CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName;
     LoadDataContext();
     SetUpForm();
 }
 internal AddArgosPlatformForm(ArgosProgram program = null)
 {
     InitializeComponent();
     RestoreWindow();
     Program     = program;
     CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName;
     LoadDataContext();
     SetUpControls();
 }
Пример #6
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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        /// <summary>
        /// Loads and logs the download data for an Argos Program
        /// </summary>
        /// <param name="program">The Argos ProgramId 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 LoadProgram(ArgosProgram program, 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    = program.Manager,
                    FileName = "program_" + program.ProgramId + "_" + 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
            {
                ProgramId    = program.ProgramId,
                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);
        }