Esempio n. 1
0
 /// <summary>
 /// Downloads Argos Programs and Platforms from the Argos Server, then uploads and processes the files.
 /// Any processing errors are written to the database, any other errors are emailed to the system admin,
 /// and optionally the PI of the platform/program.  This prgram is intended to be run in the background
 /// as a scheduled daily task.
 /// </summary>
 /// <param name="args">
 /// If there are no args, then process all active programs and platforms for all users. (An active platform
 ///   is one where the platform is active, and the parent program is neither active or inactive, i.e null)
 /// All args are checked to see if they are a program identifier, and if so the program is downloaded.
 /// If an arg is not a program it is checked to see if it is a platform identifier, and if so the platform
 ///   is downloaded.
 ///  as a program, if it is not a valid or as a platform if it the integer is not a program.
 /// If there is only one arg and that arg is a project investigator, then download all programs and
 ///   platforms for that PI
 /// If there is only one arg and that arg in the form /d:XX, where XX is an integer, then download
 ///   that many days for all programs and platforms for all users
 /// If there is only two arguments, and one  arg is a project investigator and the other arg is in the
 ///   form /d:XX, where XX is an integer, then download that many days for all programs and platforms for that PI
 /// An integer arg between 0 and 100, that is not a valid program or platform or an arg in the form /d:XX or
 ///   /days:XX, where XX is an integer defines the number of days (subject to Min/Max Days stipulated by the
 ///   Argos Server) to download for the remaining args.
 /// An arg in the form /nodays, clears a previous setting of days, so the remaining arguments will download
 ///   the number of days recommended by the database (this is the default behavior).
 /// Finally an argument is checked to see if it is a project investigator's login (with domain - as stored in
 ///   Login column of the ProjectINvestigators table.  If a valid PI is provided as the only argument, or optionally
 ///   with a days argument (before or after), then all active programs and platforms (as defined above) for that PI
 ///   are downloaded (for the last X days if the optional days argument was provided)
 /// If the only argument provided was the days argument, then all programs and platforms (as defined above) for all
 ///   users for the last X days will be downloaded.
 /// Any argument in the form /program:XXXX where XXX is a valid ProgramId will be processed as a program.
 /// Any argument in the form /platform:XXXX where XXX is a valid PlatformId will be processed as a platform.
 /// All other args are ignored with an error message to the console.
 /// </param>
 /// <remarks>
 /// If the downloaded data contains raw Gen4 data and if a copy of TDC.exe is NOT available (the path is specified
 /// in the config file) then this program will request that the database invoke the file processor on the server,
 /// otherwise, this program will process the downloaded data locally and send the results to the database.
 /// </remarks>
 private static void Main(string[] args)
 {
     try
     {
         _emails = new Dictionary <string, string>();
         _admin  = Settings.GetSystemEmail();
         if (args.Length == 0)
         {
             FileDownloader.DownloadAll(exceptionHandler);
         }
         else
         {
             int?days = null;
             ProjectInvestigator pi = null;
             foreach (var arg in args)
             {
                 var program = GetProgram(arg);
                 if (program != null)
                 {
                     try
                     {
                         FileDownloader.DownloadArgosProgram(program, days);
                     }
                     catch (Exception ex)
                     {
                         exceptionHandler(ex, program, null);
                     }
                     continue;
                 }
                 var platform = GetPlatform(arg);
                 if (platform != null)
                 {
                     try
                     {
                         FileDownloader.DownloadArgosPlatform(platform, days);
                     }
                     catch (Exception ex)
                     {
                         exceptionHandler(ex, null, platform);
                     }
                     continue;
                 }
                 var daysArg = GetDays(arg);
                 if (daysArg != null)
                 {
                     days = daysArg == Int32.MinValue ? null : daysArg;
                     continue;
                 }
                 var piArg = GetProjectInvestigator(arg);
                 if (piArg != null)
                 {
                     pi = piArg;
                     continue;
                 }
                 Console.WriteLine("Unhandled argument: {0}", arg);
             }
             if ((args.Length == 1 && (days != null || pi != null)) ||
                 (args.Length == 2 && days != null && pi != null))
             {
                 FileDownloader.DownloadAll(exceptionHandler, pi, days);
             }
         }
         SendEmails();
     }
     catch (Exception ex)
     {
         ReportException("Unhandled Exception: '" + ex.Message);
     }
 }