<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading;
using Totem.Runtime.Map;
using Totem.Runtime.Map.Timeline;

namespace Totem.Runtime.Timeline
{
	/// <summary>
	/// A call to a Before or When method of a <see cref="Flow"/>
	/// </summary>
	public class FlowCall : Notion
	{
		private readonly List<Event> _newEvents = new List<Event>();

		public FlowCall(
			FlowType flowType,
			IDependencySource dependencies,
			Event e,
			EventType eventType,
			TimelinePosition cause,
			ClaimsPrincipal principal,
			CancellationToken cancellationToken)
		{
			FlowType = flowType;
			Dependencies = dependencies;
			Event = e;
			EventType = eventType;
			Cause = cause;
			Principal = principal;
			CancellationToken = cancellationToken;
		}

		public readonly FlowType FlowType;
		public readonly IDependencySource Dependencies;
		public readonly Event Event;
		public readonly EventType EventType;
		public readonly TimelinePosition Cause;
		public readonly ClaimsPrincipal Principal;
		public readonly CancellationToken CancellationToken;

		public IReadOnlyList<Event> NewEvents { get { return _newEvents; } }
		public bool IsDone { get; private set; }

		public void Publish(Flow flow, Event e)
		{
			Flow.Traits.ForwardRequestId(Event, e);

			_newEvents.Add(e);
		}

		public void Publish(Flow flow, IEnumerable<Event> events)
		{
			foreach(var e in events)
			{
				Publish(flow, e);
			}
		}

		public void Publish(Flow flow, params Event[] events)
		{
			Publish(flow, events as IEnumerable<Event>);
		}

		public void OnDone()
		{
			Expect(IsDone).IsFalse("Flow is already done");

			IsDone = true;
		}
	}<commit_msg>Use Many<> instead of IReadOnlyList<> for new events<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading;
using Totem.Runtime.Map;
using Totem.Runtime.Map.Timeline;

namespace Totem.Runtime.Timeline
{
	/// <summary>
	/// A call to a Before or When method of a <see cref="Flow"/>
	/// </summary>
	public class FlowCall : Notion
	{
		public FlowCall(
			FlowType flowType,
			IDependencySource dependencies,
			Event e,
			EventType eventType,
			TimelinePosition cause,
			ClaimsPrincipal principal,
			CancellationToken cancellationToken)
		{
			FlowType = flowType;
			Dependencies = dependencies;
			Event = e;
			EventType = eventType;
			Cause = cause;
			Principal = principal;
			CancellationToken = cancellationToken;

			NewEvents = new Many<Event>();
		}

		public readonly FlowType FlowType;
		public readonly IDependencySource Dependencies;
		public readonly Event Event;
		public readonly EventType EventType;
		public readonly TimelinePosition Cause;
		public readonly ClaimsPrincipal Principal;
		public readonly CancellationToken CancellationToken;
		public readonly Many<Event> NewEvents;
		public bool IsDone { get; private set; }

		public void Publish(Flow flow, Event e)
		{
			Flow.Traits.ForwardRequestId(Event, e);

			NewEvents.Write.Add(e);
		}

		public void Publish(Flow flow, IEnumerable<Event> events)
		{
			foreach(var e in events)
			{
				Publish(flow, e);
			}
		}

		public void Publish(Flow flow, params Event[] events)
		{
			Publish(flow, events as IEnumerable<Event>);
		}

		public void OnDone()
		{
			Expect(IsDone).IsFalse("Flow is already done");

			IsDone = true;
		}
	}
{'fraction_non_alphanumeric': 0.09056271981242672, 'fraction_numerical': 0.0, 'mean_word_length': 3.903735632183908, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1067845', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1022, 'n_words': 304}