private Status Export(string nameBase, ExportCommand c, int i) { try { var fileName = GetFileFullPath(nameBase, c, i); // Although the file name has been checked to have no conflict, if the user choose // to export multiple files to the same folder, the file names can still collide. var newName = File.Exists(fileName) ? GenerateFileName(nameBase + i.ToString().PadLeft(2, '0'), c) : fileName; File.WriteAllText(newName, Providers.Types.GetExportText(c.ProviderType, route, navaids, airports)); return(new Status(newName, true, "", false)); } catch (Exception ex) { LoggerInstance.Log(ex); var mayBePermissionIssue = ex is UnauthorizedAccessException || ex is SecurityException; return(new Status(c.CustomDirectory, false, ex.Message, mayBePermissionIssue)); } }
public static void Log(ScreenLogDefinition screenLog) { try { if (!ApplicationMonitoringEnabled) { return; } switch (screenLog.ScreenType) { case "WEB": break; case "SMS": break; default: break; } LoggerInstance.Log(screenLog); } catch (Exception e) { logthrottle.WriteErrorWithThrottle(EventLogger.WriteError, "Error sending log: " + e.ToString()); } }
public static void Log(RequestEventDefinition log) { try { LoggerInstance.Log(log); } catch (Exception e) { logthrottle.WriteErrorWithThrottle(EventLogger.WriteError, "Error sending log: " + e.ToString()); } }
private static void HandleException(Exception ex) { LoggerInstance.Log(ex); var frm = new UnhandledExceptionForm(); frm.Init(ex.ToString()); frm.ShowDialog(); Environment.Exit(1); }
public static XDocument Load(string fileName) { try { return(XDocument.Load(Path.Combine(Directory, fileName))); } catch (Exception ex) { LoggerInstance.Log(ex); return(null); } }
public static void Log(ServiceAPILogDefinition log) { try { if (!ApplicationMonitoringEnabled) { return; } LoggerInstance.Log(log); } catch (Exception e) { logthrottle.WriteErrorWithThrottle(EventLogger.WriteError, "Error sending log: " + e.ToString()); } }
// Must use full path for fileName, if it is a file instead of webpage. public static void TryOpenFile(string fileName, Control parentControl = null) { try { Process.Start(fileName); } catch (Exception ex) { LoggerInstance.Log(ex); MsgBoxHelper.ShowWarning(parentControl, "Cannot open the specified file."); } }
/// <summary> /// Basically always use this to avoid errors due to .Net using old /// security protocols by default. /// </summary> public static void SetSecuityProtocol() { try { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; } catch (System.Exception e) { LoggerInstance.Log(e); } }
public void Log(LogType type, string message, LogTarget target) { CreateInstance(target, new LogItem() { Id = Guid.NewGuid(), Message = message, Type = type, TimeStamp = DateTime.Now }); LoggerInstance.Log(); }
/// <summary> /// If the file does not exist, create one. /// Then read the file into an AppOptions instance. /// Return value is never null. /// </summary> /// <exception cref="Exception"></exception> public static AppOptions ReadOrCreateFile() { try { return(ReadFromFile()); } catch (Exception ex) { LoggerInstance.Log(ex); SaveToFile(AppOptions.Default); return(ReadFromFile()); } }
// Returns whether the creation was successful. private static bool CreateTmpHtml(string html) { try { Directory.CreateDirectory(Path.GetDirectoryName(tmpFilePath)); File.WriteAllText(tmpFilePath, html); return(true); } catch (Exception e) { LoggerInstance.Log(e); return(false); } }
private static void HandleException(Exception ex) { LoggerInstance.Log(ex); var versionStr = "Version: " + Updates.Utilities.TryGetVersion(); var res = UnhandledExceptionForm.ShowModal(ex.ToString()); if (res == UnhandledExceptionForm.FormDialogResult.Yes) { ReportError(versionStr + '\n' + ex.ToString()); } Environment.Exit(1); }
private void DeleteCurrentConfigFile() { var file = currentConfig.FilePath; try { File.Delete(file); } catch (Exception e) { LoggerInstance.Log(e); ParentControl.ShowWarning("The config was saved but the old config cannot" + $"be deleted. Please manually delete {Path.GetFullPath(file)}."); } }
public static void Log(ErrorLogDefinition log) { try { if (LoggerInstance != null) { LoggerInstance.Log(log); } else { EventLogger.WriteError(log.Message); } } catch (Exception e) { EventLogger.WriteError("Error sending log: " + e.ToString()); } }
public static void Save(string fileName, XElement elem) { try { var filePath = Path.Combine(Directory, fileName); System.IO.Directory.CreateDirectory(Directory); using (StreamWriter writer = File.CreateText(filePath)) { writer.Write(elem); } } catch (Exception ex) { LoggerInstance.Log(ex); } }
public static void Log(ServiceAPIDetailLogDefinition log) { try { if (!ApplicationMonitoringEnabled) { return; } if (LoggerInstance != null) { LoggerInstance.Log(log); } else { EventLogger.WriteInfo(log.Message); } } catch (Exception e) { logthrottle.WriteErrorWithThrottle(EventLogger.WriteError, "Error sending log: " + e.ToString()); } }
// Returns null if failed to load or create file. private XDocument LoadOrCreateFile() { if (File.Exists(filePath)) { return(XDocument.Load(filePath)); } try { var doc = CreateDoc(); File.WriteAllText(filePath, doc.ToString()); return(doc); } catch (Exception e) { LoggerInstance.Log(e); return(null); } }
// Returns whether the addition succeeds. public bool Add(string registration) { var old = DeletedRegistration(); if (old == null) { return(false); } var elem = old.Concat(registration).Select(reg => new XElement("Item", reg)); var root = new XElement("Root", elem.ToArray()); try { File.WriteAllText(filePath, new XDocument(root).ToString()); return(true); } catch (Exception e) { LoggerInstance.Log(e); return(false); } }
/// <exception cref="WaypointFileReadException"></exception> /// <exception cref="LoadCountryNamesException"></exception> public LoadResult LoadFromFile() { var wptList = new WaypointList(); var countryCodes = new FixesLoader(wptList, Logger.Instance) .ReadFromFile(waypointsFilePath); var err = AtsFileLoader.ReadFromFile(wptList, atsFilePath); if (err != null) { LoggerInstance.Log(err); } var countryFullNames = FullNamesLoader.Load(); var countryManager = new CountryCodeManager(countryCodes, countryFullNames); return(new LoadResult() { WptList = wptList, CountryCodes = countryManager }); }
public static void Log(GeneralLogDefinition log) { try { if (!ApplicationMonitoringEnabled) { return; } if (log.ModuleName == "ALARM") { EventLogger.WriteWarning(log.Message); } if (LoggerInstance != null) { LoggerInstance.Log(log); } else { EventLogger.WriteInfo(log.Message); } } catch (Exception e) { logthrottle.WriteErrorWithThrottle(EventLogger.WriteError, "Error sending log: " + e.ToString()); } }
private static void ReportError(string message) { try { var url = config.GetString("ErrorReportUrl"); var assemblyLocation = Assembly.GetExecutingAssembly().Location; var info = new ProcessStartInfo() { WorkingDirectory = Path.GetDirectoryName(assemblyLocation), FileName = "ErrorReport.exe", Arguments = Strings.EscapeCommandLineArg(url) + " " + Strings.EscapeCommandLineArg(message), WindowStyle = ProcessWindowStyle.Hidden }; Process.Start(info); } catch (Exception e) { MsgBoxHelper.ShowError(null, "Failed to report the error."); LoggerInstance.Log(e); } }