public static void WriteBaseAddressToConfigFile(string manufacturer, string applicationName, bool isService, string baseAddress) { CleanupBaseAddressConfigFiles(manufacturer, applicationName); string[] relativePathItems; if (isService) { relativePathItems = new string[] { }; } else { relativePathItems = new string[] { Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) }; } // ReSharper disable LocalizableElement var configurationFile = ConfigurationFileSupport.GetConfigurationFileInfo(manufacturer, applicationName, @"WCF", true, false, relativePathItems, @"WcfBaseAddress.config", true); using (var fileStream = FileHandler.OpenFile(configurationFile.FullName, FileMode.Create, FileAccess.ReadWrite)) { using (var writer = new StreamWriter(fileStream)) { writer.Write(baseAddress); } } // ReSharper restore LocalizableElement }
/// <summary> /// Currents the domain unhandled exception. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param> /// <exception cref="System.ArgumentNullException">@ e</exception> protected void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { if (e == null) { throw new ArgumentNullException(@"e"); } // ReSharper disable LocalizableElement // put your tracing or logging code here (I put a message box as an example) var relativePathItems = new[] { @"SupportFiles", @"Crashs" }; var crashFileInfo = ConfigurationFileSupport.GetConfigurationFileInfo(@"Endress+Hauser", @"ImsOpcBridge", null, false, true, relativePathItems, string.Format(CultureInfo.CurrentUICulture, @"{0:yyyyMMddHHmmss}.crash", DateTime.Now), true); var systemInfo = new SystemInfo(crashFileInfo.Directory); // ReSharper restore LocalizableElement TextWriter textWriter = crashFileInfo.AppendText(); textWriter.WriteLine(e.ExceptionObject.ToString()); systemInfo.WriteInTextFile(systemInfo.HardwareInformationList, textWriter); systemInfo.WriteInTextFile(systemInfo.SoftwareInformationList, textWriter); textWriter.Close(); this.CleanCrashFiles(crashFileInfo.Directory); MessageBox.Show(e.ExceptionObject.ToString()); }
public static void CleanupBaseAddressConfigFile(string manufacturer, string applicationName, bool isService) { // ReSharper disable LocalizableElement string[] relativePathItems; if (isService) { relativePathItems = new string[] { }; var configurationFile = ConfigurationFileSupport.GetConfigurationFileInfo(manufacturer, applicationName, @"WCF", true, false, relativePathItems, @"WcfBaseAddress.config", true); configurationFile.Delete(); } else { relativePathItems = new string[] { Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) }; var configurationPath = ConfigurationFileSupport.GetConfigurationPath(manufacturer, applicationName, @"WCF", true, false, relativePathItems, true); try { configurationPath.Delete(true); } catch (Exception) { } } // ReSharper restore LocalizableElement }
public static void CleanupBaseAddressConfigFiles(string manufacturer, string applicationName) { var myOtherProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); var baseRelativePathItems = new string[] { }; var basePath = ConfigurationFileSupport.GetConfigurationPath(manufacturer, applicationName, @"WCF", true, false, baseRelativePathItems, true); try { foreach (var subDirectory in basePath.EnumerateDirectories()) { int subDirectoryNameAsInt; if (int.TryParse(subDirectory.Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out subDirectoryNameAsInt)) { if (myOtherProcesses.All(p => p.Id != subDirectoryNameAsInt)) { try { subDirectory.Delete(true); } catch (System.Exception) { } } } } } catch (System.Exception) { } }
/// <summary> /// Loads this instance. /// </summary> public void Load() { lock (SyncRoot) { var assembly = Assembly.GetEntryAssembly(); object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false); AssemblyProductAttribute attribute = null; if (attributes.Length > 0) { attribute = attributes[0] as AssemblyProductAttribute; } string productName = "unknown"; if (attribute != null) { productName = attribute.Product; } this.configFileInfo = ConfigurationFileSupport.GetConfigurationFileInfo(this.Manufacturer, productName, string.Empty, false, false, new string[] { }, "ImsOpcBridge.config", false); var xmlSettings = new ConfigStorage(); xmlSettings.Load(this.configFileInfo.FullName); this.Manufacturer = xmlSettings.GetValue(PathLabelingManufacturer, this.Manufacturer); this.WindowsPosLeft = xmlSettings.GetValue(PathWindowsPosLeft, this.WindowsPosLeft); this.WindowsPosTop = xmlSettings.GetValue(PathWindowsPosTop, this.WindowsPosTop); this.WindowsPosWidth = xmlSettings.GetValue(PathWindowsSizeWidth, this.WindowsPosWidth); this.WindowsPosHeight = xmlSettings.GetValue(PathWindowsSizeHeight, this.WindowsPosHeight); this.CultureName = xmlSettings.GetValue(PathCultureName, this.CultureName); this.AllowCultureChange = xmlSettings.GetValue(PathAllowCultureChange, (bool?)true); this.AllowExecutionOnMachine = xmlSettings.GetValue(ExecutionPolicyException, string.Empty); this.ShowDeviceCommands = xmlSettings.GetValue(PathLayoutShowDeviceCommands, this.ShowDeviceCommands); this.LoggingCommands = xmlSettings.GetValue(PathDoLoggingCommands, this.LoggingCommands); try { CommandAlignment temp; if (!Enum.TryParse(xmlSettings.GetValue(PathLayoutCommandAlignment, "Left"), out temp)) { temp = CommandAlignment.Left; } this.CommandAlignment = temp; } catch (ArgumentException) { this.CommandAlignment = CommandAlignment.Left; } xmlSettings.Save(); xmlSettings.Close(); } }
/// <summary> /// Contacts the support pressed. /// </summary> private void ContactSupportPressed() { // ReSharper disable LocalizableElement var relativePathItems = new[] { @"SupportFiles" }; var supportFiles = ConfigurationFileSupport.GetConfigurationPath(@"Endress+Hauser", @"DeviceCare", null, false, true, relativePathItems, true); var systemInfo = new SystemInfo(supportFiles); systemInfo.WriteInTextFiles(); //// // ReSharper restore LocalizableElement ////using (var zipFile = new ZipFile()) ////{ //// zipFile.AddDirectory(supportFiles.FullName); //// // ReSharper disable LocalizableElement //// zipFile.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\DC_SupportFiles.zip"); //// // ReSharper restore LocalizableElement ////} }
public static string ReadServiceBaseAddressFromConfigFile() { string[] relativePathItems = new string[] { }; // ReSharper disable LocalizableElement var configurationFile = ConfigurationFileSupport.GetConfigurationFileInfo(@"Endress+Hauser", @"EH.ImsOpcBridge.Service", @"WCF", true, false, relativePathItems, @"WcfBaseAddress.config", false); configurationFile.Refresh(); if (!configurationFile.Exists) { return(string.Empty); } using (var fileStream = FileHandler.OpenFile(configurationFile.FullName, FileMode.Open, FileAccess.Read)) { using (var reader = new StreamReader(fileStream)) { return(reader.ReadToEnd()); } } // ReSharper restore LocalizableElement }
public static void ConfigureLogging(IBaseHost host) { if (host == null) { throw new ArgumentNullException(@"host"); } var isService = host.IsService; var myOtherProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); var baseRelativePathItems = new[] { RelativeLoggingPath }; var basePath = ConfigurationFileSupport.GetConfigurationPath(host.Manufacturer, host.ApplicationName, @"ImsOpcBridge", isService, false, baseRelativePathItems, true); try { foreach (var subDirectory in basePath.EnumerateDirectories()) { int subDirectoryNameAsInt; if (int.TryParse(subDirectory.Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out subDirectoryNameAsInt)) { if (myOtherProcesses.All(p => p.Id != subDirectoryNameAsInt)) { try { subDirectory.Delete(true); } catch (Exception) { } } } } } catch (Exception) { } string[] relativePathItems; if (isService) { // relative path { "Logging" } leads to ...\Users\UserX\AppData\Local\<manufacturer>\<application>\ImsOpcBridge\Shared\Logging relativePathItems = new[] { RelativeLoggingPath }; } else { // relative path { "Logging" } leads to ...\Users\UserX\AppData\Local\<manufacturer>\<application>\ImsOpcBridge\Shared\Logging\<ProcessId> relativePathItems = new[] { RelativeLoggingPath, Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) }; } // ReSharper disable LocalizableElement Log4NetConfigurationFile = ConfigurationFileSupport.GetConfigurationFileInfo(host.Manufacturer, host.ApplicationName, @"ImsOpcBridge", isService, false, relativePathItems, Log4NetConfigurationFileName, false); // ReSharper restore LocalizableElement if (!Log4NetConfigurationFile.Exists) { InstallDefaultLog4NetConfiguration(Log4NetConfigurationFile); Log4NetConfigurationFile.Refresh(); } if (Log4NetConfigurationFile.Exists) { ConfigureLogging(Log4NetConfigurationFile, true); } }