public static int Main(string[] args) { try { ArgumentOptions options = new ArgumentOptions(); var parser = new CommandLine.Parser(config => config.HelpWriter = Console.Out); if (parser.ParseArguments(args, options)) { if (!string.IsNullOrEmpty(options.Config)) { configPath = options.Config; } if (Directory.Exists(configPath)) { Config config = Config.Load(configPath); Output(string.Format("[{0}] Started Server Maintenance Process.", DateTime.Now)); using (TeknikEntities db = new TeknikEntities()) { // Scan all the uploads for viruses, and remove the bad ones if (options.ScanUploads && config.UploadConfig.VirusScanEnable) { ScanUploads(config, db); } // Warns all the invalid accounts via email if (options.WarnAccounts) { WarnInvalidAccounts(config, db); } // Cleans all inactive users if (options.CleanUsers) { CleanAccounts(config, db, options.DaysBeforeDeletion); } // Cleans the email for unused accounts if (options.CleanEmails) { CleanEmail(config, db); } // Cleans all the git accounts that are unused if (options.CleanGit) { CleanGit(config, db); } // Generates a file for all of the user's last seen dates if (options.GenerateLastSeen) { GenerateLastSeen(config, db, options.LastSeenFile); } // Generates a file for all of the invalid accounts if (options.GenerateInvalid) { GenerateInvalidAccounts(config, db, options.InvalidFile); } // Generates a file for all of the accounts to be cleaned if (options.GenerateCleaning) { GenerateCleaningList(config, db, options.CleaningFile, options.DaysBeforeDeletion); } } Output(string.Format("[{0}] Finished Server Maintenance Process.", DateTime.Now)); return(0); } else { string msg = string.Format("[{0}] Config File does not exist.", DateTime.Now); File.AppendAllLines(errorFile, new List <string> { msg }); Output(msg); } } else { Output(options.GetUsage()); } } catch (Exception ex) { string msg = string.Format("[{0}] Exception: {1}", DateTime.Now, ex.GetFullMessage(true)); File.AppendAllLines(errorFile, new List <string> { msg }); Output(msg); } return(-1); }
public static int Main(string[] args) { try { ArgumentOptions options = new ArgumentOptions(); var parser = new CommandLine.Parser(config => config.HelpWriter = Console.Out); if (parser.ParseArguments(args, options)) { if (!string.IsNullOrEmpty(options.Config)) configPath = options.Config; if (Directory.Exists(configPath)) { Config config = Config.Load(configPath); TeknikEntities db = new TeknikEntities(); Output(string.Format("[{0}] Started Server Maintenance Process.", DateTime.Now)); // Scan all the uploads for viruses, and remove the bad ones if (options.ScanUploads && config.UploadConfig.VirusScanEnable) { ScanUploads(config, db); } // Warns all the invalid accounts via email if (options.WarnAccounts) { WarnInvalidAccounts(config, db); } // Cleans all inactive users if (options.CleanUsers) { CleanAccounts(config, db, options.DaysBeforeDeletion); } // Cleans the email for unused accounts if (options.CleanEmails) { CleanEmail(config, db); } // Cleans all the git accounts that are unused if (options.CleanGit) { CleanGit(config, db); } // Generates a file for all of the user's last seen dates if (options.GenerateLastSeen) { GenerateLastSeen(config, db, options.LastSeenFile); } // Generates a file for all of the invalid accounts if (options.GenerateInvalid) { GenerateInvalidAccounts(config, db, options.InvalidFile); } // Generates a file for all of the accounts to be cleaned if (options.GenerateCleaning) { GenerateCleaningList(config, db, options.CleaningFile, options.DaysBeforeDeletion); } Output(string.Format("[{0}] Finished Server Maintenance Process.", DateTime.Now)); return 0; } else { string msg = string.Format("[{0}] Config File does not exist.", DateTime.Now); File.AppendAllLines(errorFile, new List<string> { msg }); Output(msg); } } else { Output(options.GetUsage()); } } catch (Exception ex) { string msg = string.Format("[{0}] Exception: {1}", DateTime.Now, ex.GetFullMessage(true)); File.AppendAllLines(errorFile, new List<string> { msg }); Output(msg); } return -1; }