static void WatcherEvent(object sender, FileSystemEventArgs e) { var re = e as RenamedEventArgs; var dirChanged = scii(e.FullPath, cerebelloDebugPath) || re != null && scii(re.OldFullPath, cerebelloDebugPath); var fileChanged = scii(e.FullPath, cerebelloDebugConfigPath) || re != null && scii(re.OldFullPath, cerebelloDebugConfigPath); if (fileChanged || dirChanged) { lock (locker) { inst = new DebugConfig(); HttpRuntime.UnloadAppDomain(); } } }
static void WatcherEvent(object sender, FileSystemEventArgs e) { var re = e as RenamedEventArgs; var dirChanged = scii(e.FullPath, cerebelloDebugPath) || re != null && scii(re.OldFullPath, cerebelloDebugPath); var fileChanged = scii(e.FullPath, cerebelloDebugConfigPath) || re != null && scii(re.OldFullPath, cerebelloDebugConfigPath); if (fileChanged || dirChanged) lock (locker) { inst = new DebugConfig(); HttpRuntime.UnloadAppDomain(); } }
static DebugConfig() { #if DEBUG string uncommitedXml = "Uncommited.xml"; if (!File.Exists(uncommitedXml)) uncommitedXml = Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, "Uncommited.xml"); if (!File.Exists(uncommitedXml) && HttpContext.Current != null) uncommitedXml = HttpContext.Current.Server.MapPath(uncommitedXml); if (File.Exists(uncommitedXml)) { var ser = new XmlSerializer(typeof(UserSettings)); using (var reader = XmlReader.Create(uncommitedXml)) userSettings = (UserSettings)ser.Deserialize(reader); } else { userSettings = new UserSettings { CommonPath = @"C:\", DesktopPath = @"C:\", SolutionPath = @"C:\", }; } // reading the debug.config file placed in a common path var commonPath = userSettings.CommonPath; cerebelloDebugPath = Path.Combine(commonPath, "Cerebello.Debug"); cerebelloDebugConfigPath = Path.Combine(cerebelloDebugPath, "debug.config"); if (Directory.Exists(commonPath)) { { var watcher = new FileSystemWatcher(commonPath, "debug.config"); watcher.Created += WatcherEvent; watcher.Deleted += WatcherEvent; watcher.Changed += WatcherEvent; watcher.Renamed += WatcherEvent; watcher.Error += WatcherError; watcher.Disposed += WatcherDisposed; watcher.IncludeSubdirectories = true; watcher.EnableRaisingEvents = true; } { var watcher = new FileSystemWatcher(commonPath, "Cerebello.Debug"); watcher.Created += WatcherEvent; watcher.Deleted += WatcherEvent; watcher.Changed += WatcherEvent; watcher.Renamed += WatcherEvent; watcher.Error += WatcherError; watcher.Disposed += WatcherDisposed; watcher.EnableRaisingEvents = true; } inst = new DebugConfig(); } #endif }
static DebugConfig() { #if DEBUG string uncommitedXml = "Uncommited.xml"; if (!File.Exists(uncommitedXml)) { uncommitedXml = Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, "Uncommited.xml"); } if (!File.Exists(uncommitedXml) && HttpContext.Current != null) { uncommitedXml = HttpContext.Current.Server.MapPath(uncommitedXml); } if (File.Exists(uncommitedXml)) { var ser = new XmlSerializer(typeof(UserSettings)); using (var reader = XmlReader.Create(uncommitedXml)) userSettings = (UserSettings)ser.Deserialize(reader); } else { userSettings = new UserSettings { CommonPath = @"C:\", DesktopPath = @"C:\", SolutionPath = @"C:\", }; } // reading the debug.config file placed in a common path var commonPath = userSettings.CommonPath; cerebelloDebugPath = Path.Combine(commonPath, "Cerebello.Debug"); cerebelloDebugConfigPath = Path.Combine(cerebelloDebugPath, "debug.config"); if (Directory.Exists(commonPath)) { { var watcher = new FileSystemWatcher(commonPath, "debug.config"); watcher.Created += WatcherEvent; watcher.Deleted += WatcherEvent; watcher.Changed += WatcherEvent; watcher.Renamed += WatcherEvent; watcher.Error += WatcherError; watcher.Disposed += WatcherDisposed; watcher.IncludeSubdirectories = true; watcher.EnableRaisingEvents = true; } { var watcher = new FileSystemWatcher(commonPath, "Cerebello.Debug"); watcher.Created += WatcherEvent; watcher.Deleted += WatcherEvent; watcher.Changed += WatcherEvent; watcher.Renamed += WatcherEvent; watcher.Error += WatcherError; watcher.Disposed += WatcherDisposed; watcher.EnableRaisingEvents = true; } inst = new DebugConfig(); } #endif }
/// <summary> /// Sends an e-mail message using the default SmtpClient. /// The e-mail will be sent by either calling the DefaultSendEmailAction delegate or the DefaultSendEmail method. /// </summary> /// <param name="mailMessage">The MailMessage to send.</param> public static void SendEmail(MailMessage mailMessage) { #if DEBUG if (DebugConfig.IsDebug) { // saving e-mail to the file-system foreach (var storageEmailSavers in DebugConfig.StorageEmailSavers) { storageEmailSavers(mailMessage); } foreach (var addressToSendTo in DebugConfig.EmailAddressesToCopyEmailsTo) { // ReSharper disable AccessToForEachVariableInClosure foreach (var emailAddress in mailMessage.To.Select(x => new MailAddress(addressToSendTo, x.DisplayName))) { // ReSharper restore AccessToForEachVariableInClosure mailMessage.Bcc.Add(emailAddress); } } // removing all unallowed email addresses var notAllowed = mailMessage.To.Where(a => !DebugConfig.CanSendEmailToAddress(a.Address)).ToList(); foreach (var address in notAllowed) { mailMessage.To.Remove(address); } if (notAllowed.Any() && !mailMessage.To.Any()) { if (!mailMessage.Bcc.Any()) { // ReSharper disable EmptyGeneralCatchClause try { Debug.Print( "E-mail ignored: cannot send to the address ({0}) while in DEBUG mode.", notAllowed.First().Address); } catch { } // ReSharper restore EmptyGeneralCatchClause return; } mailMessage.To.Add(mailMessage.Bcc[0]); mailMessage.Bcc.RemoveAt(0); } // prepending "[TEST]" when in debug (this will help differentiate real messages from test messages) mailMessage.Subject = "[TEST] " + mailMessage.Subject; } #endif if (!mailMessage.To.Any()) { mailMessage.Subject = string.Format("WARNING: E-MAIL W/O DESTINATION: {0}", mailMessage.Subject); mailMessage.To.Add(new MailAddress("*****@*****.**", "Error report")); } (DefaultEmailSender ?? DefaultSendEmail)(mailMessage); }