コード例 #1
0
ファイル: Convert.cs プロジェクト: jjvdangelo/EventStore
        public static FeedElement ToStreamEventBackwardFeed(ClientMessage.ReadStreamEventsBackwardCompleted msg, Uri requestedUrl, EmbedLevel embedContent, bool headOfStream)
        {
            Ensure.NotNull(msg, "msg");

            string escapedStreamId = Uri.EscapeDataString(msg.EventStreamId);
            var self = HostName.Combine(requestedUrl, "/streams/{0}", escapedStreamId);
            var feed = new FeedElement();
            feed.SetTitle(string.Format("Event stream '{0}'", msg.EventStreamId));
            feed.StreamId = msg.EventStreamId;
            feed.SetId(self);
            feed.SetUpdated(msg.Events.Length > 0 ? msg.Events[0].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);

            var prevEventNumber = Math.Min(msg.FromEventNumber, msg.LastEventNumber) + 1;
            var nextEventNumber = msg.FromEventNumber - msg.MaxCount;

            feed.AddLink("self", self);
            feed.AddLink("first", HostName.Combine(requestedUrl, "/streams/{0}/head/backward/{1}", escapedStreamId, msg.MaxCount));
            if (!msg.IsEndOfStream)
            {
                if (nextEventNumber < 0) throw new Exception(string.Format("nextEventNumber is negative: {0} while IsEndOfStream", nextEventNumber));
                feed.AddLink("last", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", escapedStreamId, 0, msg.MaxCount));
                feed.AddLink("next", HostName.Combine(requestedUrl, "/streams/{0}/{1}/backward/{2}", escapedStreamId, nextEventNumber, msg.MaxCount));
            }
            feed.AddLink("previous", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", escapedStreamId, prevEventNumber, msg.MaxCount));
            feed.AddLink("metadata", HostName.Combine(requestedUrl, "/streams/{0}/metadata", escapedStreamId));
            for (int i = 0; i < msg.Events.Length; ++i)
            {
                feed.AddEntry(ToEntry(msg.Events[i], requestedUrl, embedContent));
            }

            return feed;
        }
コード例 #2
0
ファイル: Convert.cs プロジェクト: EventStore/EventStore
        public static FeedElement ToStreamEventForwardFeed(ClientMessage.ReadStreamEventsForwardCompleted msg, Uri requestedUrl, EmbedLevel embedContent)
        {
            Ensure.NotNull(msg, "msg");

            string escapedStreamId = Uri.EscapeDataString(msg.EventStreamId);
            var self = HostName.Combine(requestedUrl, "/streams/{0}", escapedStreamId);
            var feed = new FeedElement();
            feed.SetTitle(string.Format("Event stream '{0}'", msg.EventStreamId));
            feed.StreamId = msg.EventStreamId;
            feed.SetId(self);
            feed.SetUpdated(msg.Events.Length > 0 && msg.Events[0].Event != null ? msg.Events[0].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);
            feed.SetHeadOfStream(msg.IsEndOfStream);

            var prevEventNumber = Math.Min(msg.FromEventNumber + msg.MaxCount - 1, msg.LastEventNumber) + 1;
            var nextEventNumber = msg.FromEventNumber - 1;

            feed.AddLink("self", self);
            feed.AddLink("first", HostName.Combine(requestedUrl, "/streams/{0}/head/backward/{1}", escapedStreamId, msg.MaxCount));
            if (nextEventNumber >= 0)
            {
                feed.AddLink("last", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", escapedStreamId, 0, msg.MaxCount));
                feed.AddLink("next", HostName.Combine(requestedUrl, "/streams/{0}/{1}/backward/{2}", escapedStreamId, nextEventNumber, msg.MaxCount));
            }
            if (!msg.IsEndOfStream || msg.Events.Length > 0)
                feed.AddLink("previous", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", escapedStreamId, prevEventNumber, msg.MaxCount));
            if (!escapedStreamId.StartsWith("$$"))
                feed.AddLink("metadata", HostName.Combine(requestedUrl, "/streams/{0}/metadata", escapedStreamId));
            for (int i = msg.Events.Length - 1; i >= 0; --i)
            {
                feed.AddEntry(ToEntry(msg.Events[i], requestedUrl, embedContent));
            }

            return feed;
        }
コード例 #3
0
ファイル: Convert.cs プロジェクト: soto/EventStore
        public static FeedElement ToAllEventsBackwardFeed(ReadAllResult result,
                                                          Func<EventRecord, string, EntryElement> itemToEntry,
                                                          string userHostName)
        {
            var self = HostName.Combine(userHostName, "/streams/$all");
            var feed = new FeedElement();
            feed.SetTitle(String.Format("All events"));
            feed.SetId(self);

            var items = result.Records.Select(rer => rer.Event).ToList();

            feed.SetUpdated(items.Any() ? items.First().TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);

            feed.AddLink(self, "self", null);
            feed.AddLink(HostName.Combine(userHostName,
                                          "/streams/$all/{0}",
                                          result.MaxCount),
                         "first",
                         null);
            feed.AddLink(HostName.Combine(userHostName,
                                          "/streams/$all/after/{0}/{1}",
                                          new TFPos(0, 0).AsString(),
                                          result.MaxCount),
                         "last",
                         null);
            feed.AddLink(HostName.Combine(userHostName,
                                          "/streams/$all/after/{0}/{1}",
                                          result.PrevPos.AsString(),
                                          result.MaxCount),
                         "prev",
                         null);
            feed.AddLink(HostName.Combine(userHostName,
                                          "/streams/$all/before/{0}/{1}",
                                          result.NextPos.AsString(),
                                          result.MaxCount),
                         "next",
                         null);

            foreach (var item in items)
            {
                feed.AddEntry(itemToEntry(item, userHostName));
            }
            return feed;
        }
コード例 #4
0
ファイル: Convert.cs プロジェクト: EventStore/EventStore
        public static FeedElement ToAllEventsForwardFeed(ClientMessage.ReadAllEventsForwardCompleted msg, Uri requestedUrl, EmbedLevel embedContent)
        {
            var self = HostName.Combine(requestedUrl, "/streams/{0}", AllEscaped);
            var feed = new FeedElement();
            feed.SetTitle("All events");
            feed.SetId(self);
            feed.SetUpdated(msg.Events.Length > 0 && msg.Events[0].Event != null ? msg.Events[msg.Events.Length - 1].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);

            feed.AddLink("self", self);
            feed.AddLink("first", HostName.Combine(requestedUrl, "/streams/{0}/head/backward/{1}", AllEscaped, msg.MaxCount));
            if (msg.CurrentPos.CommitPosition != 0)
            {
                feed.AddLink("last", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllEscaped, new TFPos(0, 0).AsString(), msg.MaxCount));
                feed.AddLink("next", HostName.Combine(requestedUrl, "/streams/{0}/{1}/backward/{2}", AllEscaped, msg.PrevPos.AsString(), msg.MaxCount));
            }
            if (!msg.IsEndOfStream || msg.Events.Length > 0)
                feed.AddLink("previous", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllEscaped, msg.NextPos.AsString(), msg.MaxCount));
            feed.AddLink("metadata", HostName.Combine(requestedUrl, "/streams/{0}/metadata", AllEscaped));
            for (int i = msg.Events.Length - 1; i >= 0; --i)
            {
                feed.AddEntry(ToEntry(msg.Events[i].WithoutPosition(), requestedUrl, embedContent));
            }
            return feed;
        }
コード例 #5
0
ファイル: Convert.cs プロジェクト: EventStore/EventStore
        public static FeedElement ToNextNPersistentMessagesFeed(ClientMessage.ReadNextNPersistentMessagesCompleted msg, Uri requestedUrl, string streamId, string groupName, int count, EmbedLevel embedContent)
        {
            string escapedStreamId = Uri.EscapeDataString(streamId);
            string escapedGroupName = Uri.EscapeDataString(groupName);
            var self = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}", escapedStreamId, escapedGroupName);
            var feed = new FeedElement();
            feed.SetTitle(string.Format("Messages for '{0}/{1}'", streamId, groupName));
            feed.SetId(self);
            feed.SetUpdated(msg.Events.Length > 0 && msg.Events[0].Event != null ? msg.Events[msg.Events.Length - 1].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);

            if (msg.Events != null && msg.Events.Length > 0)
            {
                var ackAllQueryString = String.Format("?ids={0}", String.Join(",", msg.Events.Select(x => x.OriginalEvent.EventId)));
                var ackAll = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}/ack", escapedStreamId, escapedGroupName) + ackAllQueryString;
                feed.AddLink("ackAll", ackAll);

                var nackAllQueryString = String.Format("?ids={0}", String.Join(",", msg.Events.Select(x => x.OriginalEvent.EventId)));
                var nackAll = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}/nack", escapedStreamId, escapedGroupName) + nackAllQueryString;
                feed.AddLink("nackAll", nackAll);
            }

            var prev = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}/{2}", escapedStreamId, escapedGroupName, count);
            feed.AddLink("previous", prev);

            feed.AddLink("self", self);
            for (int i = msg.Events.Length - 1; i >= 0; --i)
            {
                var entry = ToEntry(msg.Events[i].WithoutPosition(), requestedUrl, embedContent);
                var ack = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}/ack/{2}", escapedStreamId, escapedGroupName, msg.Events[i].OriginalEvent.EventId);
                var nack = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}/nack/{2}", escapedStreamId, escapedGroupName, msg.Events[i].OriginalEvent.EventId);
                entry.AddLink("ack", ack);
                entry.AddLink("nack", nack);
                feed.AddEntry(entry);
            }
            return feed;
        }
コード例 #6
0
ファイル: atom_specs.cs プロジェクト: jpierson/EventStore
 public void SetUp()
 {
     _feed = new FeedElement();
     _writer = XmlWriter.Create(new MemoryStream());
 }
コード例 #7
0
        public static FeedElement ToReadStreamFeed(
            ClientMessage.ReadStreamEventsBackwardCompleted msg, string userHostName, EmbedLevel embedContent,
            bool headOfStream)
        {
            Ensure.NotNull(msg, "msg");

            string escapedStreamId = Uri.EscapeDataString(msg.EventStreamId);
            var self = HostName.Combine(userHostName, "/streams/{0}", escapedStreamId);
            var feed = new FeedElement();
            feed.SetTitle(string.Format("Event stream '{0}'", msg.EventStreamId));
            feed.SetId(self);
            feed.SetUpdated(msg.Events.Length > 0 ? msg.Events[0].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);
            feed.SetHeadOfStream(headOfStream);
            if (headOfStream)
                //NOTE: etag workaround - to be fixed with better http handling model
                feed.SetETag(msg.LastEventNumber.ToString(CultureInfo.InvariantCulture) + ";" + "application/json".GetHashCode());
            feed.SetSelfUrl(self);

            feed.AddLink("self", self);
            feed.AddLink("first", HostName.Combine(userHostName, "/streams/{0}", escapedStreamId)); // TODO AN: should account for msg.MaxCount
            feed.AddLink("last", HostName.Combine(userHostName, "/streams/{0}/range/{1}/{2}", escapedStreamId, msg.MaxCount - 1, msg.MaxCount));
            feed.AddLink("previous", HostName.Combine(userHostName, 
                                                      "/streams/{0}/range/{1}/{2}", 
                                                      escapedStreamId, 
                                                      Math.Min(msg.FromEventNumber, msg.LastEventNumber) + msg.MaxCount, 
                                                      msg.MaxCount));

            if (msg.FromEventNumber - msg.MaxCount >= 0)
            {
                feed.AddLink("next", HostName.Combine(userHostName,
                                                      "/streams/{0}/range/{1}/{2}",
                                                      escapedStreamId,
                                                      msg.FromEventNumber - msg.MaxCount,
                                                      msg.MaxCount));
            }

            for (int i = 0; i < msg.Events.Length; ++i)
            {
                feed.AddEntry(ToEntry(msg.Events[i], userHostName, embedContent));
            }

            return feed;
        }
コード例 #8
0
        public static FeedElement ToAllEventsBackwardFeed(ReadAllResult result, string userHostName, EmbedLevel embedContent)
        {
            var self = HostName.Combine(userHostName, "/streams/{0}", AllEscaped);
            var feed = new FeedElement();
            feed.SetTitle(string.Format("All events"));
            feed.SetId(self);

            feed.SetUpdated(result.Events.Length > 0 ? result.Events[0].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);

            feed.AddLink("self", self);
            feed.AddLink("first", HostName.Combine(userHostName, "/streams/{0}/{1}", AllEscaped, result.MaxCount));
            feed.AddLink("last", HostName.Combine(userHostName, "/streams/{0}/after/{1}/{2}", AllEscaped, new TFPos(0, 0).AsString(), result.MaxCount));
            feed.AddLink("previous", HostName.Combine(userHostName, "/streams/{0}/after/{1}/{2}", AllEscaped, result.PrevPos.AsString(), result.MaxCount));
            feed.AddLink("next", HostName.Combine(userHostName, "/streams/{0}/before/{1}/{2}", AllEscaped, result.NextPos.AsString(), result.MaxCount));

            for (int i = 0; i < result.Events.Length; ++i)
            {
                feed.AddEntry(ToEntry(new ResolvedEvent(result.Events[i].Event, result.Events[i].Link), userHostName, embedContent));
            }
            return feed;
        }
コード例 #9
0
ファイル: Convert.cs プロジェクト: bmavity/EventStore
        public static FeedElement ToFeed(string eventStreamId, 
                                            int start, 
                                            int count, 
                                            DateTime updateTime,
                                            EventRecord[] items, 
                                            Func<EventRecord, string, EntryElement> itemToEntry,
                                            string userHostName)
        {
            if (string.IsNullOrEmpty(eventStreamId) || items == null || userHostName == null)
                return null;

            if (start == -1)
                start = GetActualStart(items);

            var self = HostName.Combine(userHostName, "/streams/{0}", eventStreamId);

            var feed = new FeedElement();

            feed.SetTitle(String.Format("Event stream '{0}'", eventStreamId));
            feed.SetId(self);

            feed.SetUpdated(updateTime);
            feed.SetAuthor(AtomSpecs.Author);

            feed.AddLink(self, "self", null);

            feed.AddLink(HostName.Combine(userHostName,
                                     "/streams/{0}/range/{1}/{2}",
                                     eventStreamId,
                                     AtomSpecs.FeedPageSize - 1,
                                     AtomSpecs.FeedPageSize),
                         "first",
                         null);

            feed.AddLink(HostName.Combine(userHostName,
                                     "/streams/{0}/range/{1}/{2}",
                                     eventStreamId,
                                     PrevStart(start),
                                     AtomSpecs.FeedPageSize),
                         "prev",
                         null);
            feed.AddLink(HostName.Combine(userHostName,
                                     "/streams/{0}/range/{1}/{2}",
                                     eventStreamId,
                                     NextStart(start),
                                     AtomSpecs.FeedPageSize),
                         "next",
                         null);

            foreach (var item in items)
            {
                feed.AddEntry(itemToEntry(item, userHostName));
            }

            return feed;
        }
コード例 #10
0
ファイル: Convert.cs プロジェクト: jjvdangelo/EventStore
        public static FeedElement ToAllEventsBackwardFeed(ClientMessage.ReadAllEventsBackwardCompleted msg, Uri requestedUrl, EmbedLevel embedContent)
        {
            var self = HostName.Combine(requestedUrl, "/streams/{0}", AllEscaped);
            var feed = new FeedElement();
            feed.SetTitle(string.Format("All events"));
            feed.SetId(self);
            feed.SetUpdated(msg.Events.Length > 0 ? msg.Events[0].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);

            feed.AddLink("self", self);
            feed.AddLink("first", HostName.Combine(requestedUrl, "/streams/{0}/head/backward/{1}", AllEscaped, msg.MaxCount));
            if (!msg.IsEndOfStream)
            {
                feed.AddLink("last", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllEscaped, new TFPos(0, 0).AsString(), msg.MaxCount));
                feed.AddLink("next", HostName.Combine(requestedUrl, "/streams/{0}/{1}/backward/{2}", AllEscaped, msg.NextPos.AsString(), msg.MaxCount));
            }
            feed.AddLink("previous", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllEscaped, msg.PrevPos.AsString(), msg.MaxCount));
            feed.AddLink("metadata", HostName.Combine(requestedUrl, "/streams/{0}/metadata", AllEscaped));
            for (int i = 0; i < msg.Events.Length; ++i)
            {
                feed.AddEntry(ToEntry(new ResolvedEvent(msg.Events[i].Event, msg.Events[i].Link), requestedUrl, embedContent));
            }
            return feed;
        }