/// <summary> /// Get the file event log writer. /// </summary> /// <returns>The event log writer.</returns> private static IEventLogWriter GetFileEventLogWriter() { DiagnosticsConfiguration diagnosticsConfiguration = ConfigurationSettings.GetDiagnosticsConfigurationSection(); LogSettings logSettings = diagnosticsConfiguration?.LogSettings; if (logSettings == null || !logSettings.IsEnabled) { return(null); } string folder = SpecialFolder.GetSpecialFolderPath(SpecialMachineFolders.Log); string fileName = String.IsNullOrEmpty(logSettings.Filename) ? "log.xml" : logSettings.Filename; return(new FileEventLogWriter(folder, fileName) { MaxSize = logSettings.MaxSize, MaxCount = logSettings.MaxCount, MaxRetention = logSettings.MaxRetention, TraceEnabled = logSettings.TraceEnabled, InformationEnabled = logSettings.InformationEnabled, WarningEnabled = logSettings.WarningEnabled, ErrorEnabled = logSettings.ErrorEnabled }); }
/// <summary> /// Initialize the ConfigurationSettings type. /// </summary> static ConfigurationSettings( ) { try { ///// // Setup a watcher so we can get notification when the configuration file changes rather than having to poll it continually. ///// _fileSystemWatcher = new FileSystemWatcher( ) { Path = SpecialFolder.GetSpecialFolderPath(SpecialMachineFolders.Configuration), NotifyFilter = NotifyFilters.LastWrite, Filter = PlatformConfigurationFile }; _fileSystemWatcher.Changed += FileSystemWatcher_Changed; _fileSystemWatcher.EnableRaisingEvents = true; } catch (Exception ex) { ///// // Will happen if the product is not installed. ///// Trace.WriteLine("Failed to setup file watcher. " + ex); } }
/// <summary> /// Loads the log entries from the active log file. /// </summary> /// <returns> /// A collection of the entries contained within the active log file. /// </returns> private static EventLogEntryCollection LoadActiveLog( ) { // Load the active log file string path = Path.Combine(SpecialFolder.GetSpecialFolderPath(SpecialMachineFolders.Log), "Log.xml"); EventLogEntryCollection eventLogEntries = LoadLog(path); return(eventLogEntries); }
private void SaveRecentServerLogs(string path) { var logsPath = SpecialFolder.GetSpecialFolderPath(SpecialMachineFolders.Log); var sortedFiles = new DirectoryInfo(logsPath).GetFiles().OrderBy(f => f.LastWriteTime).Reverse().Take(2).ToList(); foreach (var f in sortedFiles) { File.Copy(f.FullName, Path.Combine(path, f.Name)); } }
public void CheckDebugFlagIsOff( ) { string installPath = SpecialFolder.GetSpecialFolderPath(SpecialMachineFolders.Install); string configFile = Path.Combine(installPath, @"SpApi\Web.config"); Assert.That(File.Exists(configFile), Is.True, "Web.config not found at " + configFile); XmlDocument doc = new XmlDocument( ); doc.Load(configFile); XmlNode compilation; compilation = doc.SelectSingleNode("/configuration/system.web/compilation"); Assert.That(compilation, Is.Not.Null, "compilation element should be present"); compilation = doc.SelectSingleNode("/configuration/system.web/compilation[@debug='true']"); Assert.That(compilation, Is.Null, "compilation debug attribute should be off"); }
/// <summary> /// Handle binding events /// </summary> /// <remarks> /// The problem: Autofac.Extras.Attributed.dll refers to ver 3.4.0.0 of Autofac.dll /// However, the published version is Autofac is 3.5.0.0 /// The NuGet package lays down assembly redirects in app.config, which are annoying /// (and more specifically, don't work when we try to access the Entity model in the MSI Custom Action package). /// So catch all bindings for Autofac.dll and redirect them to the version that EDC.ReadiNow.Common references. /// </remarks> private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { var name = new AssemblyName(args.Name); if (name.Name == "Autofac") { return(typeof(ContainerBuilder).Assembly); } var installPath = SpecialFolder.GetSpecialFolderPath(SpecialMachineFolders.Install); ///// // Probe the tests folder (if found) ///// var assembly = ProbeAssembly(Path.Combine(installPath, "Tests"), name); if (assembly != null) { return(assembly); } ///// // Probe the tools folder (if found) ///// assembly = ProbeAssembly(Path.Combine(installPath, "Tools"), name); if (assembly != null) { return(assembly); } ///// // Probe the spapi bin folder (if found) ///// assembly = ProbeAssembly(Path.Combine(installPath, "SpApi\\Bin"), name); return(assembly); }
private static MethodInfo GetDeserializeMethod( ) { if (_genericDeserializeMethod == null) { string install = SpecialFolder.GetSpecialFolderPath(SpecialMachineFolders.Install); string jilPath = Path.Combine(install, @"SpApi\bin\Jil.dll"); Assembly assembly = Assembly.LoadFrom(jilPath); Type jsonType = assembly.GetType("Jil.JSON"); Type optionsType = assembly.GetType("Jil.Options"); _genericDeserializeMethod = jsonType.GetMethod("Deserialize", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, new Type [] { typeof(string), optionsType }, null); if (_genericDeserializeMethod == null) { throw new Exception("Could not access Jil.JSON.Deserialize"); } } return(_genericDeserializeMethod); }