public bool AddIfNotExist(Algorithm.BTree.BTreeItemOnDisk item) { Locker.Lock(); var r = Collection.AddIfNotExist(item); Locker.Unlock(); return(r); }
public void Save(User user) { _synchronizer.Lock(() => { var allUsers = GetAll().ToList(); allUsers.Add(user); string serialized = _serializer.Serialize(allUsers); _writer.Write(_file, serialized); }); }
void Host_UserAccountActivity(object sender, UserAccountActivityEventArgs e) { if (e.Activity != UserAccountActivity.AccountActivated) { return; } _synchronizer.Lock(() => { var failed = false; User user = null; try { user = _registrationRepository.FindByUserName(e.User.Username); if (user == null) { return; } var pageInfo = _pageRepository.FindPage(_configuration.PageName); if (pageInfo == null) { _logger.Error(String.Format("The attendee page '{0}' does not exist.", _configuration.PageName), "SYSTEM"); throw new Exception("Attendee page does not exist."); } PageContent pageContent; try { pageContent = _host.GetPageContent(pageInfo); } catch (Exception ex) { _logger.Error(String.Format("The attendee page's content ('{0}') could not be loaded: {1}", _configuration.PageName, ex), "SYSTEM"); throw; } try { string entry = _entryFormatter.FormatUserEntry(user, _settings, _configuration.EntryTemplate); string newContent = _pageFormatter.AddEntry(pageContent.Content, entry, user, _configuration); _pageRepository.Save(pageInfo, pageContent.Title, user.UserName, _configuration.Comment, newContent); _logger.Info("User entry written successfully", user.UserName); } catch (Exception ex) { _logger.Error(String.Format("Could not add the user's entry to the attendee list: {0}", ex), "SYSTEM"); throw; } } catch { failed = true; } finally { if (user != null) { string message = LoadEmailTemplate(failed); message = FillTemplate(message, user); _notificationSender.SendMessage(e.User.Email, _configuration.Comment, message); _notificationSender.SendMessage(_settings.ContactEmail, _configuration.Comment, message); } } }); }