Exemple #1
0
        public void SaveEvents(Guid aggregateId, IList <IAggregateEvent> events, int expectedVersion)
        {
            if (events.Count == 0)
            {
                return;
            }

            Console.WriteLine(aggregateId);

            var serializedEvents = events.Select(evt => new RemoteEvent {
                Version = evt.Version,
                Data    = this.serializer.SerializeToString(evt),
            }).ToList();

            //var newVersion = events[events.Count - 1].Version;
            //this.index.UpdateIndex(aggregateId, expectedVersion, newVersion);

            var x = new RemoteEventSaveRequest();

            x.Id = aggregateId.ToString();
            x.ExpectedVersion = expectedVersion;
            x.Events          = serializedEvents;

            var client = new HttpClient();

            using (client)
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var dataToSend = JsonConvert.SerializeObject(x);
                using (var content = new StringContent(dataToSend, Encoding.UTF8, "application/json"))
                {
                    var response = client.PostAsync(string.Format("http://helloservicestack.apphb.com/eventsx/{0}", aggregateId), content).Result;

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new HttpRequestException(response.StatusCode.ToString());
                    }
                }
            }
        }
Exemple #2
0
        public void SaveEvents(Guid aggregateId, IList<IAggregateEvent> events, int expectedVersion)
        {
            if (events.Count == 0)
            {
                return;
            }

            Console.WriteLine(aggregateId);

            var serializedEvents = events.Select(evt => new RemoteEvent{
                Version = evt.Version,
                Data = this.serializer.SerializeToString(evt),
            }).ToList();

            //var newVersion = events[events.Count - 1].Version;
            //this.index.UpdateIndex(aggregateId, expectedVersion, newVersion);

            var x = new RemoteEventSaveRequest();
            x.Id = aggregateId.ToString();
            x.ExpectedVersion = expectedVersion;
            x.Events = serializedEvents;

            var client = new HttpClient();
            using (client)
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var dataToSend = JsonConvert.SerializeObject(x);
                using (var content = new StringContent(dataToSend, Encoding.UTF8, "application/json"))
                {
                    var response = client.PostAsync(string.Format("http://helloservicestack.apphb.com/eventsx/{0}", aggregateId), content).Result;

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new HttpRequestException(response.StatusCode.ToString());
                    }
                }
            }
        }