void View_UserCreated(object sender, EventArgs e)
		{
			if (!_view.AutoRegisterUser)
			{
				_logger.Info("User opted-out of auto registration", _view.UserName);
				return;
			}

			try
			{
				var user = new User(_view.UserName)
				           {
				           	Data =
				           		{
				           			Xing = _view.Xing,
				           			Twitter = _view.Twitter,
				           			Name = _view.Name,
				           			Blog = _view.Blog,
				           			Email = _view.Email,
				           			Picture = _view.Picture,
				           			Sponsoring = _view.Sponsoring,
				           			InvoiceAddress = _view.InvoiceAddress,
				           			RegisteredAt = DateTime.Now
				           		}
				           };

				_repository.Save(user);
				_logger.Info("Saved registration data", _view.UserName);
			}
			catch (Exception ex)
			{
				_logger.Error(String.Format("Saving registration data failed: {0}", ex), _view.UserName);
			}
		}
Exemplo n.º 2
0
		public void Save(User user)
		{
			_synchronizer.Lock(() =>
				{
					var allUsers = GetAll().ToList();
					allUsers.Add(user);

					string serialized = _serializer.Serialize(allUsers);
					_writer.Write(_file, serialized);
				});
		}
		public string FormatUserEntry(User user, ISettings settings, string template)
		{
			var context = new VelocityContext();
			context.Put("user", user);
			context.Put("settings", settings);

			using (StringWriter writer = new StringWriter())
			{
				template = PrepareTemplate(template);
				_engine.Evaluate(context, writer, null, template);

				return writer.ToString();
			}
		}
Exemplo n.º 4
0
		public string AddEntry(string content, string entry, User user, IPluginConfiguration configuration)
		{
			var entryMatcher = NewRegex(configuration.EntryPattern);
			var listStartMatcher = NewRegex(configuration.ListStartPattern);
			var listEndMatcher = NewRegex(configuration.ListEndPattern);
			var waitingListEndMatcher = NewRegex(configuration.WaitingListEndPattern);

			int listStart = AssertMatchesOnce(content, listStartMatcher, "list start");
			int listEnd = AssertMatchesOnce(content, listEndMatcher, "list end");
			int waitingListEnd = AssertMatchesOnce(content, waitingListEndMatcher, "waiting list end");
			if (listEnd == -1 || listEnd == -1 || waitingListEnd == -1)
			{
				throw new InvalidOperationException(
					"The list and/or waiting list regular expressions did not match once. See previous errors.");
			}

			if (listEnd < listStart)
			{
				_logger.Error(String.Format("The list end position ({0}) is before the list start position ({1})",
				                            listEnd,
				                            listStart),
				              "SYSTEM");
				throw new InvalidOperationException("The list start and end positions are not sanitized. See previous error.");
			}

			int numberOfAttendees = CountNumberOfEntries(content.Substring(listStart, listEnd - listStart), entryMatcher);

			int addAtIndex = _opinionEvaluator.Evaluate(new EvaluationContext
				                           {
				                           	NumberOfAttendees = numberOfAttendees,
				                           	ListEnd = listEnd,
				                           	WaitingListEnd = waitingListEnd,
				                           	Configuration = configuration,
				                           	User = user,
				                           	Logger = _logger
				                           });

			return content.Insert(addAtIndex, entry);
		}
Exemplo n.º 5
0
		string FillTemplate(string template, User user)
		{
			return _entryFormatter.FormatUserEntry(user, _settings, template);
		}