private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs args) { var dir = System.IO.Path.GetDirectoryName(PecaSettings.DefaultFileName); System.IO.Directory.CreateDirectory(dir); using (var file = System.IO.File.AppendText(System.IO.Path.Combine(dir, "exception.log"))) { file.WriteLine("{0}: {1} (OS:{2}, CLR:{3})", DateTime.Now, AppSettingsReader.GetString("AgentName", "PeerCastStation"), Environment.OSVersion, Environment.Version); file.WriteLine(args.ExceptionObject); } }
public VersionInfoViewModel(PeerCastApplication app) { this.AgentName = AppSettingsReader.GetString("AgentName", "PeerCastStation/Unknown"); items = app.Plugins.Select(plugin => { var info = plugin.GetVersionInfo(); return(new { Name = plugin.Name, IsUsable = plugin.IsUsable, FileName = info.FileName, Version = info.Version, AssemblyName = info.AssemblyName, Copyright = info.Copyright, }); }).ToArray(); }
protected static string GetConnStringValue(string connKey, string defaultValue, bool isThrow = true) { string text = AppSettingsReader.GetString(connKey); if (string.IsNullOrEmpty(text)) { if (isThrow) { if (!string.IsNullOrEmpty(defaultValue)) { return(defaultValue); } throw new ArgumentException("未能找到 【" + connKey + "】节点的相关配置"); } text = defaultValue; } return(text); }
public AppBase(string basepath, string[] args) { Args = args; basePath = basepath; var opts = optionParser.Parse(args); var optSettings = opts.FirstOrDefault(opt => opt.LongName == "--settings"); if (optSettings != null) { SettingsFileName = optSettings.Arguments[0]; } else { SettingsFileName = PecaSettings.DefaultFileName; } var optLinkPID = opts.FirstOrDefault(opt => opt.LongName == "--linkPID"); if (optLinkPID != null) { int pid = 0; if (Int32.TryParse(optLinkPID.Arguments[0], out pid)) { try { LinkProcess = System.Diagnostics.Process.GetProcessById(pid); LinkProcess.Exited += (sender, ev) => { Stop(); }; LinkProcess.EnableRaisingEvents = true; } catch (Exception) { } } } settings = new PecaSettings(SettingsFileName); peerCast.AgentName = AppSettingsReader.GetString("AgentName", "PeerCastStation"); LoadPlugins(); }
protected static string GetConfigValue(string configKey, string defaultValue, bool isThrow = true) { try { string appSettingString = AppSettingsReader.GetString(configKey); if (string.IsNullOrEmpty(appSettingString)) { if (isThrow) { if (string.IsNullOrEmpty(defaultValue)) { throw new ArgumentException("未能找到 【" + configKey + "】节点的相关配置"); } return(defaultValue); } return(defaultValue); } return(appSettingString); } catch (Exception innerException) { if (isThrow) { if (string.IsNullOrEmpty(defaultValue)) { throw new ArgumentException("未能找到 【" + configKey + "】节点的相关配置", innerException); } return(defaultValue); } return(defaultValue); } }
public Application() { peerCast.AgentName = AppSettingsReader.GetString("AgentName", "PeerCastStation"); LoadPlugins(); }