public static void Main(string[] args) { Arguments CommandLine = new Arguments(args); if (args.Length == 0) { PrintInfo("Run PSTMaster.exe /help to see usage."); } else if (args.Length == 1 && HelpRequired(args[0])) { DisplayHelp(); } else if (CommandLine["mode"] == null || CommandLine["jobname"] == null || CommandLine["location"] == null || CommandLine["collectpath"] == null) { PrintError("Looks like one or more paramters missed."); } else { string mode = CommandLine["mode"].ToLower(); string jobname = CommandLine["jobname"].ToLower(); string location = CommandLine["location"].ToLower(); string collectpath = CommandLine["collectpath"].ToLower(); string configpath = string.Format("{0}PSTCollect\\", Path.GetPathRoot(Environment.SystemDirectory)); string computername = System.Environment.MachineName; string outputfilename = string.Format("{0}.{1}.{2}.csv", computername, jobname, mode); string logfile = string.Format("{0}.{1}.log", computername, jobname); string fullogpath = string.Format("{0}\\{1}", configpath, logfile); string excemessage; /*dropfile(fullogpath, out excemessage); * if (excemessage != null) * { * PrintError(excemessage); * WriteLog(configpath, logfile, excemessage); * }*/ try { if (Directory.Exists(configpath)) { Console.WriteLine("The config directory:{0} exists already.", configpath); WriteLog(configpath, logfile, string.Format("The config directory:{0} exists already.", configpath)); } else { DirectoryInfo di = Directory.CreateDirectory(configpath); Console.WriteLine("The config directory was created successfully at {0}.", Directory.GetCreationTime(configpath)); WriteLog(configpath, logfile, string.Format("The config directory:{0} successfully created", configpath)); } if (!collectpath.EndsWith("\\")) { collectpath += "\\"; } if (Directory.Exists(collectpath)) { Console.WriteLine("Checked the collect path {0} is acessable.", collectpath); WriteLog(configpath, logfile, string.Format("The collect path:{0} is aceessable", collectpath)); } else { PrintError(string.Format("The collect path:{0} is unreachable,please make sure put in a accessible share,quitting the application.....", collectpath)); //PrintError("The collect path is unreachable, please make sure put in a accessible share,quitting the application....."); WriteLog(configpath, logfile, string.Format("The collect path:{0} is unreachable,please make sure put in a accessible share,quitting the application.....", collectpath)); return; } } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); WriteLog(configpath, logfile, e.Message); } if (mode != null && jobname != null && location != null && collectpath != null) { //dropfile(fullogpath, out excemessage); //WriteLog(configpath,logfile,excemessage); switch (mode) { case "find": DoMode.Find(location, collectpath, jobname, computername, configpath, outputfilename); break; case "collect": DoMode.Collect(location, collectpath, jobname, computername, configpath, outputfilename); break; case "remove": DoMode.Remove(location, collectpath, jobname, computername, configpath, outputfilename); break; default: PrintError(string.Format("{0} is not a support mode, plesae use Find, Collect, Remove, try /help to see the application useage smaples", mode)); WriteLog(configpath, logfile, string.Format("{0} is not a support mode, plesae use Find, Collect, Remove, try /help to see the application useage samples", mode)); break; } } else { PrintError("Looks like there is a paramter missing"); Environment.Exit(1); } CopyFile(logfile, configpath, collectpath, out excemessage); if (excemessage != null) { WriteLog(configpath, logfile, excemessage); } } }
public static void Main(string[] args) { Arguments CommandLine = new Arguments(args); if (args.Length == 0) { PrintInfo("Run PSTMaster.exe /help to see usage."); } else if (args.Length == 1 && HelpRequired(args[0])) { DisplayHelp(); } else if (CommandLine["mode"] == null || CommandLine["jobname"] == null || CommandLine["location"] == null || CommandLine["collectpath"] == null) { PrintError("Looks like one or more paramters missed."); } else { string mode = CommandLine["mode"].ToLower(); string jobname = CommandLine["jobname"].ToLower(); string location = CommandLine["location"].ToLower(); string collectpath = CommandLine["collectpath"].ToLower(); string configpath = string.Format("{0}PSTCollect\\", Path.GetPathRoot(Environment.SystemDirectory)); string computername = System.Environment.MachineName; string outputfilename = string.Format("{0}.{1}.{2}.csv", computername, jobname, mode); string logfile = string.Format("{0}.{1}.txt", computername, jobname); string fullogpath = string.Format("{0}\\{1}", configpath, logfile); try { if (Directory.Exists(configpath)) { Console.WriteLine("The config directory:{0} exists already.", configpath); } else { DirectoryInfo di = Directory.CreateDirectory(configpath); Console.WriteLine("The config directory was created successfully at {0}.", Directory.GetCreationTime(configpath)); } } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } if (!collectpath.EndsWith("\\")) { collectpath += "\\"; } if (mode != null && jobname != null && location != null && collectpath != null) { dropfile(fullogpath); switch (mode) { case "find": DoMode.Find(location, collectpath, jobname, computername, configpath, outputfilename); break; case "collect": DoMode.Collect(location, collectpath, jobname, computername, configpath, outputfilename); break; case "remove": DoMode.Remove(location, collectpath, jobname, computername, configpath, outputfilename); break; } } else { PrintError("Looks like there is a paramter missing"); Environment.Exit(1); } CopyFile(logfile, configpath, collectpath); } }