private static int Exit(ExitCodes exitCode) { try { jobStatusInfo.CompletedAt = DateTime.Now; if (exitCode != ExitCodes.Success) { jobStatusInfo.Status = "FAILED: " + exitCode.ToString(); logger.Fatal("==== COMPLETED AS FAILED: " + exitCode.ToString()); } else { jobStatusInfo.Status = "COMPLETED"; logger.Info("===== COMPLETED"); } SaveJobStatusInfo(); return((int)exitCode); } catch (Exception ex) { Console.Error.WriteLine("Failed to save status: " + ex.GetBaseException().Message); } return((int)exitCode); }
private static void Restart(ExitCodes code) { // Starts a new instance of the program itself Process.Start(Assembly.GetExecutingAssembly().Location, code.ToString()); // Closes the current process Environment.Exit((int)code); }
public static void Exit(ExitCodes ExitCode) { #if DEBUG Print("Quitting: {0}", ExitCode.ToString()); Environment.Exit((int)ExitCode); #else // Todo: Add Log #endif }
public static void PrintError(ExitCodes Code, string text, params string[] para) { string final = DateTime.Now.ToString(@"dd/mm/yyyy HH:mm:ss") + " => " + Code.ToString() + " (" + (int)Code + ")\n" + String.Format(text, para) + "\n"; #if DEBUG Console.WriteLine(final); #else // Todo: Add Log #endif }
static void Main(string[] args) { do { // Show help? if (args.Length == 0) { ShowHelp(); break; } // Show licence? if (args[0] == "--licence") { ShowLicence(); break; } // Check number of arguaments if (args.Length < 2) { eExitCode = ExitCodes.eInvalidNumArgs; Console.WriteLine("Invalid number of arguments supplied."); break; } if (bDebug) { Console.WriteLine("DEBUG: Params Valid"); } // Is arg 0 a valid file? sExtractFile = args[0]; if (File.Exists(sExtractFile) == false) { eExitCode = ExitCodes.eFileNotFound; Console.WriteLine("File not found, " + sExtractFile); break; } if (bDebug) { Console.WriteLine("DEBUG: File is: " + sExtractFile); } // Is arg 1 a valid dir? sExportDir = args[1]; if (Directory.Exists(sExportDir) == false) { // Try and create it! try { Directory.CreateDirectory(sExportDir); if (bDebug) { Console.WriteLine("DEBUG: Directory Created: " + sExportDir); } } catch (Exception eXcep) { eExitCode = ExitCodes.eSaveDirInvalid; Console.WriteLine("Directory error, " + eXcep.Message); break; } } if (bDebug) { Console.WriteLine("DEBUG: Directory is: " + sExportDir); } // OK, lets get the icon... Icon icoExtract; try { icoExtract = IconTools.GetIconForExtension(Path.GetExtension(sExtractFile), ShellIconSize.LargeIcon); } catch (Exception eXcep) { eExitCode = ExitCodes.eIconExtractFailed; Console.WriteLine("Extract failed, " + eXcep.Message); break; } if (bDebug) { Console.WriteLine("DEBUG: Icon extracted to resource object"); } string sExtractedFileName = Path.GetExtension(sExtractFile).Substring(1) + "-ico.png"; string sFullPath = Path.Combine(sExportDir, sExtractedFileName); try { icoExtract.ToBitmap().Save(sFullPath, ImageFormat.Png); } catch (Exception eXcep) { eExitCode = ExitCodes.eSavePNGFailed; Console.WriteLine("Save PNG failed, " + eXcep.Message); break; } if (bDebug) { Console.WriteLine("DEBUG: Icon Saved: " + sFullPath); } } while (false); if (bDebug) { Console.WriteLine("End of program. Exit Code: " + eExitCode.ToString() + " (" + ((int)eExitCode).ToString() + ")."); Console.WriteLine("Press any key to exit..."); Console.ReadLine(); } Environment.Exit((int)eExitCode); }
private static void CleanExit(ExitCodes code) { Cleanup(); // Clear a line for neatness. Console.WriteLine(); if (code != ExitCodes.Success) { // Write out our reson. Console.WriteLine(string.Format("Exiting due to error: {0}", Regex.Replace(code.ToString(), @"(\B[A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $1"))); } // Exit. Environment.Exit((int)code); }