public StreamActionMessage(StreamAction action, long position, long offset, long size) { this.Action = action; this.Position = position; this.Offset = offset; this.Size = size; }
public StreamAction Append(string stream, params object[] events) { var step = action(e => e.Append(stream, events)); if (events.Count() > 3) { step.Description = $"Append('{stream}', events)"; } else { step.Description = $"Append('{stream}', {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Append(_store.Events, stream, events)); }
public void Read(StreamAction action) { try { Stream input = GetInput(); try { action(input); } finally { if (input != null) { input.Close(); } } } catch (Exception) { } }
public StreamAction StartStream(string streamKey, params object[] events) { var step = action(e => e.StartStream(streamKey, events)); if (events.Count() > 3) { step.Description = $"StartStream(\"{streamKey}\", events)"; } else { step.Description = $"StartStream(\"{streamKey}\", {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Start(_store.Events, streamKey, events)); }
public StreamAction Append(Guid stream, IEnumerable <object> events) { var step = action(e => e.Append(stream, events)); if (events.Count() > 3) { step.Description = $"Append({stream}, events)"; } else { step.Description = $"Append({stream}, {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Append(_store.Events, stream, events)); }
public StreamAction StartStream(Guid id, params object[] events) { var step = action(e => e.StartStream(id, events)); if (events.Count() > 3) { step.Description = $"StartStream({id}, events)"; } else { step.Description = $"StartStream({id}, {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Start(_store.Events, id, events)); }
/// <inheritdoc /> protected override void OnNotifyWrite(StreamMonitor monitor, ArraySegment <byte> data) { lock (streamLock) { if (lastStreamMonitor != monitor || lastStreamAction != StreamAction.Write) { var tag = GetStreamTag(monitor, StreamAction.Write); //WriteLine(); DumpStream.Write(tag, 0, tag.Length); lastStreamMonitor = monitor; lastStreamAction = StreamAction.Write; } DumpStream.Write(data.Array, data.Offset, data.Count); } }
public StreamAction StartStream(params object[] events) { var streamId = Guid.NewGuid(); var step = action(e => e.StartStream(streamId, events)); if (events.Count() > 3) { step.Description = "StartStream(events)"; } else { step.Description = $"StartStream({events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Start(_store.Events, streamId, events)); }
public StreamAction StartStream(Type aggregateType, string streamKey, params object[] events) { var step = action(e => e.StartStream(aggregateType, streamKey, events)); if (events.Count() > 3) { step.Description = $"StartStream({aggregateType.FullNameInCode()}>(\"{streamKey}\", events)"; } else { step.Description = $"StartStream({aggregateType.FullNameInCode()}, \"{streamKey}\", {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Start(_store.Events, streamKey, events)); }
public StreamAction StartStream <TAggregate>(string streamKey, params object[] events) where TAggregate : class { var step = action(e => e.StartStream <TAggregate>(streamKey, events)); if (events.Count() > 3) { step.Description = $"StartStream<{typeof(TAggregate).FullNameInCode()}>(\"{streamKey}\", events)"; } else { step.Description = $"StartStream<{typeof(TAggregate).FullNameInCode()}>(\"{streamKey}\", {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Start(_store.Events, streamKey, events)); }
public StreamAction StartStream(Type aggregateType, Guid id, IEnumerable <object> events) { var step = action(e => e.StartStream(aggregateType, id, events)); if (events.Count() > 3) { step.Description = $"StartStream({aggregateType.FullNameInCode()}>({id}, events)"; } else { step.Description = $"StartStream({aggregateType.FullNameInCode()}, {id}, {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Start(_store.Events, id, events)); }
public void can_set_aggregator_through_extension_methods_and_strategy() { var theGraph = new EventGraph(new StoreOptions()); theGraph.UseAggregatorLookup(AggregationLookupStrategy.UsePublicApply); var aggregator = theGraph.AggregateFor <QuestParty>(); var stream = StreamAction.Start(Guid.NewGuid(), new object[] { new QuestStarted { Name = "Destroy the Ring" } }); var party = aggregator.Build(stream.Events, null); party.Name.ShouldBe("Destroy the Ring"); }
public StreamAction Append(Guid stream, long expectedVersion, params object[] events) { var step = action(e => e.Append(stream, expectedVersion, events)); if (events.Count() > 3) { step.Description = $"Append({stream}, {expectedVersion}, events)"; } else { step.Description = $"Append({stream}, {expectedVersion}, {events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Append(_store.Events, stream, events)); }
public void can_lookup_private_apply_methods() { var theGraph = new EventGraph(new StoreOptions()); theGraph.UseAggregatorLookup(new AggregatorLookup(type => typeof(AggregatorApplyPrivate <>).CloseAndBuildAs <IAggregator>(type))); var aggregator = theGraph.AggregateFor <AggregateWithPrivateEventApply>(); var stream = StreamAction.Append(Guid.NewGuid(), new[] { new QuestStarted { Name = "Destroy the Ring" } }); var party = aggregator.Build(stream.Events, null); party.Name.ShouldBe("Destroy the Ring"); }
public async Task find_when_stream_is_not_new_async() { var id = Guid.NewGuid(); var persisted = new QuestParty { Id = id }; theSession.Store(persisted); await theSession.SaveChangesAsync(); var finder = new AggregateFinder <QuestParty>(); (await finder.FindAsync(StreamAction.Append(id), theSession, new CancellationToken())) .ShouldBeTheSameAs(persisted); }
public void WriteElements <T, TContext>(TName elementName, IEnumerable <T> coll, TContext ctxt, StreamAction <T, TContext> action) { Contract.Requires(ValidateNameArg(elementName)); Contract.Requires <ArgumentNullException>(coll != null); Contract.Requires(action != null); foreach (var value in coll) { using (EnterCursorBookmark(elementName)) { var v = value; // can't pass a foreach value by ref action(this, ctxt, ref v); } } }
public void find_when_stream_is_not_new() { var session = Substitute.For <IDocumentSession>(); var id = Guid.NewGuid(); var persisted = new QuestParty { Id = id }; var finder = new AggregateFinder <QuestParty>(); session.Load <QuestParty>(id).Returns(persisted); finder.Find(StreamAction.Append(id), session) .ShouldBeTheSameAs(persisted); }
public void TestStreamUrl() { //Arrange var expected = "{\"streamUrl\":[\"https://www.example.com/waiting.mp3\"],\"action\":\"stream\"}"; var action = new StreamAction() { StreamUrl = new string[] { "https://www.example.com/waiting.mp3" } }; //Act var serialized = JsonConvert.SerializeObject(action, Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); //Assert Assert.AreEqual(expected, serialized); }
public StreamAction ToEventStream() { if (Store.Events.StreamIdentity == StreamIdentity.AsGuid) { var stream = StreamAction.Start(StreamId, new AEvent()); stream.TenantId = TenantId; return(stream); } else { var stream = StreamAction.Start(StreamId.ToString(), new AEvent()); stream.TenantId = TenantId; return(stream); } }
public StreamAction StartStream <TAggregate>(IEnumerable <object> events) where TAggregate : class { var streamId = Guid.NewGuid(); var step = action(e => e.StartStream <TAggregate>(streamId, events)); if (events.Count() > 3) { step.Description = $"StartStream<{typeof(TAggregate).FullNameInCode()}>(events)"; } else { step.Description = $"StartStream<{typeof(TAggregate).FullNameInCode()}>({events.Select(x => x.ToString()).Join(", ")})"; } return(StreamAction.Start(_store.Events, streamId, events)); }
public static void ToListener(this int port, StreamAction handler) { //Console.WriteLine("#1"); new Thread( delegate() { //Console.WriteLine("#2"); var r = new TcpListener(IPAddress.Loopback, port); //Console.WriteLine("#3"); r.TryStart( delegate { //Console.WriteLine("#4"); while (true) { var c = r.AcceptTcpClient(); //Console.WriteLine("#5"); var s = c.GetStream(); new Thread( delegate() { //Console.WriteLine("#6"); handler(s); } ) { IsBackground = true, }.Start(); //Console.WriteLine("#7"); } } ); } ) { IsBackground = true, }.Start(); }
public void StreamableElements <TKey, TValue, TContext>(TName elementName, IDictionary <TKey, TValue> dic, TContext ctxt, StreamAction <TKey, TContext> streamKey, Predicate <KeyValuePair <TKey, TValue> > shouldWritePredicate = null) where TValue : ITagElementStreamable <TName>, new() { Contract.Requires(ValidateNameArg(elementName)); Contract.Requires <ArgumentNullException>(dic != null); if (IsReading) { ReadStreamableElements(elementName, dic, ctxt, streamKey); } else if (IsWriting) { WriteStreamableElements(elementName, dic, ctxt, streamKey, shouldWritePredicate); } }
public async Task InlineProject(Action <TestEventScenario> action) { var scenario = new TestEventScenario(); action(scenario); var streams = scenario .Streams .ToDictionary() .Select(x => StreamAction.Append(x.Key, x.Value.Events().ToArray())) .ToArray(); var inline = _projection.BuildRuntime(theStore); await inline.ApplyAsync(theSession, streams, CancellationToken.None); await theSession.SaveChangesAsync(); }
public void StreamElements <T, TContext>(TName elementName, ICollection <T> coll, TContext ctxt, StreamAction <T, TContext> read, StreamAction <T, TContext> write) where T : new() { Contract.Requires(ValidateNameArg(elementName)); Contract.Requires <ArgumentNullException>(coll != null); Contract.Requires(read != null && write != null); if (IsReading) { ReadElements(elementName, coll, ctxt, read); } else if (IsWriting) { WriteElements(elementName, coll, ctxt, write); } }
public void ApplyServerVersion_for_existing_streams() { var action = StreamAction.Append(theEvents, Guid.NewGuid(), new AEvent(), new BEvent(), new CEvent(), new DEvent()); var queue = new Queue<long>(); queue.Enqueue(11); queue.Enqueue(12); queue.Enqueue(13); queue.Enqueue(14); action.PrepareEvents(5, theEvents, queue, theSession); action.ExpectedVersionOnServer.ShouldBe(5); action.Events[0].Version.ShouldBe(6); action.Events[1].Version.ShouldBe(7); action.Events[2].Version.ShouldBe(8); action.Events[3].Version.ShouldBe(9); }
public static Thread ToListener(this int port, StreamAction handler) { var t = new Thread( delegate() { var r = new TcpListener(IPAddress.Loopback, port); r.TryStart( delegate { while (true) { // http://stackoverflow.com/questions/365370/proper-way-to-stop-tcplistener var c = r.AcceptTcpClient(); // we wont be able to stop // this loop with current implementation var s = c.GetStream(); new Thread( delegate() { handler(s); } ) { IsBackground = true, }.Start(); } } ); } ) { IsBackground = true, }; t.Start(); return t; }
void ReadStreamableElements <TKey, TValue, TContext>(IEnumerable <TCursor> elements, IDictionary <TKey, TValue> dic, TContext ctxt, StreamAction <TKey, TContext> streamKey) where TValue : ITagElementStreamable <TName>, new() { foreach (var node in elements) { using (EnterCursorBookmark(node)) { var key = default(TKey); streamKey(this, ctxt, ref key); var value = new TValue(); value.Serialize(this); dic.Add(key, value); } } }
public void can_set_private_apply_aggregator_through_extension_methods_and_strategy() { var theGraph = new EventGraph(new StoreOptions()); // SAMPLE: register-custom-aggregator-lookup // Registering an aggregator lookup that provides aggregator supporting private Apply([Event Type]) methods theGraph.UseAggregatorLookup(AggregationLookupStrategy.UsePrivateApply); // ENDSAMPLE var aggregator = theGraph.AggregateFor <AggregateWithPrivateEventApply>(); var stream = StreamAction.Append(Guid.NewGuid(), new object[] { new QuestStarted { Name = "Destroy the Ring" } }); var party = aggregator.Build(stream.Events, null); party.Name.ShouldBe("Destroy the Ring"); }
void ReadElements <TKey, TValue, TContext>(IEnumerable <TCursor> elements, IDictionary <TKey, TValue> dic, TContext ctxt, StreamAction <TKey, TContext> streamKey, StreamAction <TValue, TContext> streamValue, Func <TContext, TValue> valueCtor) { foreach (var node in elements) { using (EnterCursorBookmark(node)) { var key = default(TKey); streamKey(this, ctxt, ref key); var value = valueCtor(ctxt); streamValue(this, ctxt, ref value); dic.Add(key, value); } } }
public void StreamElements <TKey, TValue, TContext>(TName elementName, IDictionary <TKey, TValue> dic, TContext ctxt, StreamAction <TKey, TContext> streamKey, StreamAction <TValue, TContext> streamValue, Func <TContext, TValue> valueCtor) { Contract.Requires(ValidateNameArg(elementName)); Contract.Requires <ArgumentNullException>(dic != null); Contract.Requires(streamKey != null); Contract.Requires(streamValue != null && valueCtor != null); if (IsReading) { ReadElements(elementName, dic, ctxt, streamKey, streamValue, valueCtor); } else if (IsWriting) { WriteElements(elementName, dic, ctxt, streamKey, streamValue); } }
public static Thread ToListener(this int port, StreamAction handler) { var t = new Thread( delegate() { var r = new TcpListener(IPAddress.Loopback, port); r.TryStart( delegate { while (true) { // http://stackoverflow.com/questions/365370/proper-way-to-stop-tcplistener var c = r.AcceptTcpClient(); // we wont be able to stop // this loop with current implementation var s = c.GetStream(); new Thread( delegate() { handler(s); } ) { IsBackground = true, }.Start(); } } ); } ) { IsBackground = true, }; t.Start(); return(t); }
public void for_determines_action_type_guid() { var events = new List<IEvent> { new Event<AEvent>(new AEvent()), new Event<AEvent>(new AEvent()), new Event<AEvent>(new AEvent()), new Event<AEvent>(new AEvent()), new Event<AEvent>(new AEvent()), }; events[0].Version = 5; StreamAction.For(Guid.NewGuid(), events) .ActionType.ShouldBe(StreamActionType.Append); events[0].Version = 1; StreamAction.For(Guid.NewGuid(), events) .ActionType.ShouldBe(StreamActionType.Start); }
public static Thread ToListener(this int port, StreamAction handler) { var t = new Thread( delegate() { var r = new TcpListener(IPAddress.Loopback, port); r.TryStart( delegate { while (true) { var c = r.AcceptTcpClient(); var s = c.GetStream(); new Thread( delegate() { handler(s); } ) { IsBackground = true, }.Start(); } } ); } ) { IsBackground = true, }; t.Start(); return t; }
public void Write(StreamAction action) { string tmpFile = null; try { tmpFile = CreateTempFile("config-", ".tmp", Path.GetDirectoryName(_configFile)); MD5 outputDigest = MD5.Create(); OutputFileStream output = new OutputFileStream(tmpFile, outputDigest); try { action(output); } finally { output.Close(); } if (inputDigest == null || !File.Exists(_configFile) || !ArraysAreEqual(inputDigest, output.ComputedHash)) { if (File.Exists(_configFile)) File.Delete(_configFile); File.Move(tmpFile, _configFile); } } catch (Exception e) { System.Console.Error.WriteLine("do not write config. Error occured: " + e); } finally { if (tmpFile != null) File.Delete(tmpFile); } }
public void Read(StreamAction action) { try { Stream input = GetInput(); try { action(input); } finally { if (input != null) input.Close(); } } catch (Exception) { } }
public static ToThreadedTcpListenerInfo ToThreadedTcpListener(this int port, StreamAction handler) { var ret = new ToThreadedTcpListenerInfo(); var t = new Thread( delegate() { var r = new TcpListener(IPAddress.Loopback, port); ret.Listener = r; r.TryStart( delegate { while (true) { // http://stackoverflow.com/questions/365370/proper-way-to-stop-tcplistener // + $exception {"A blocking operation was interrupted by a call to WSACancelBlockingCall"} System.Exception {System.Net.Sockets.SocketException} var c = r.AcceptTcpClient(); // we wont be able to stop // this loop with current implementation var s = c.GetStream(); new Thread( delegate() { handler(s); } ) { IsBackground = true, }.Start(); } } ); } ) { IsBackground = true, }; t.Start(); ret.Thread = t; return ret; }
public StreamActionMessage(StreamAction action) : this(action, 0, 0, 0) { }