private static void Banner() { Assembly entryAssembly = Assembly.GetEntryAssembly(); IEnumerable <Attribute> attributes = entryAssembly.GetCustomAttributes(); string version = entryAssembly.GetName().Version.ToString(); ConsoleUtils.LogMessage(Resources.Banner, Resources.ApplicationName, version); var copyrightAttribute = attributes.Single(a => a is AssemblyCopyrightAttribute) as AssemblyCopyrightAttribute; string copyright = copyrightAttribute.Copyright; ConsoleUtils.LogMessage(copyright); ConsoleUtils.LogMessage(string.Empty); }
private static string GenerateScreenshotFileName(string description, string outputFolder) { var outputFolderInfo = new DirectoryInfo(outputFolder); if (!outputFolderInfo.Exists) { outputFolderInfo.Create(); ConsoleUtils.LogMessage(Resources.InfoCreatedOutputFolder, outputFolderInfo.FullName); } var fileName = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss_ff") + "-" + description + ".png"; fileName = Path.Combine(outputFolderInfo.FullName, fileName); return(fileName); }
public Process DumpProcessNow(int processId, string description) { string dumpFileName = GenerateCrashDumpFileName(description); ConsoleUtils.LogMessage( Resources.InfoTerminatingProcess, description, dumpFileName); var processStartInfo = new ProcessStartInfo { Arguments = GetProcDumpArgumentsForImmediateDump(processId, dumpFileName), CreateNoWindow = true, FileName = _procDumpPath, UseShellExecute = false }; return(Process.Start(processStartInfo)); }
public static void SaveScreen(string description, string outputFolder) { try { var fileName = GenerateScreenshotFileName(description, outputFolder); ConsoleUtils.LogMessage(Resources.InfoSavedScreenshot, fileName); SaveScreenToFile(fileName); } catch (Win32Exception ex) { // System.ComponentModel.Win32Exception (0x80004005): The handle is invalid. This // means we're not running in a console session, hence there's no UI to take a // screenshot of. This is perfectly normal on the server. ConsoleUtils.LogError(ErrorCode.CannotTakeScreenShotNoConsoleSession, Resources.ErrorCannotTakeScreenshotNoConsoleSession, ex); } catch (Exception ex) { // This is something else, we'd better know about this. ConsoleUtils.LogError(ErrorCode.CannotTakeScreenShotUnexpectedError, Resources.ErrorCannotTakeScreenshotUnexpectedError, ex); } }
private int Run() { if (_options.TimeLimit <= 0) { ConsoleUtils.LogError(Resources.ErrorInvalidTimeLimit, _options.TimeLimit); return(1); } _timeLimit = TimeSpan.FromSeconds(_options.TimeLimit); if (_options.PollingInterval <= 0) { ConsoleUtils.LogError(Resources.ErrorInvalidPollingInterval, _options.PollingInterval); return(1); } if (!File.Exists(_options.ProcDumpPath)) { ConsoleUtils.LogError(Resources.ErrorProcDumpNotFound, _options.ProcDumpPath); return(1); } var processStartInfo = new ProcessStartInfo { FileName = _options.Executable, Arguments = _options.Arguments }; Process parentProcess = Process.Start(processStartInfo); ProcDump procDump = new ProcDump(_options.ProcDumpPath, _options.OutputFolder); using (ProcessTracker processTracker = new ProcessTracker(parentProcess, procDump)) { while (!processTracker.AllFinished) { if (DateTime.Now - parentProcess.StartTime > _timeLimit) { ConsoleUtils.LogError( Resources.ErrorProcessTimedOut, _options.Executable, parentProcess.Id, _options.TimeLimit); if (_options.Screenshot) { ScreenshotSaver.SaveScreen(_options.Executable, _options.OutputFolder); } processTracker.TerminateAll(); return(1); } Thread.Sleep(_options.PollingInterval); processTracker.Update(); } ConsoleUtils.LogMessage( Resources.ProcessExited, _options.Executable, parentProcess.ExitTime - parentProcess.StartTime); } return(0); }