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 != null ? 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, msg.Events[i].ResolveResult), requestedUrl, embedContent)); } return(feed); }
public static FeedElement ToFeed(string eventStreamId, int start, int count, DateTime updateTime, EventRecord[] items, Func <EventRecord, IPEndPoint, EntryElement> itemToEntry, IPEndPoint httpEndPoint) { if (string.IsNullOrEmpty(eventStreamId) || items == null || httpEndPoint == null) { return(null); } if (start == -1) { start = GetActualStart(items); } var self = httpEndPoint.ToHttpUrl("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(httpEndPoint.ToHttpUrl("/streams/{0}/range/{1}/{2}", eventStreamId, AtomSpecs.FeedPageSize - 1, AtomSpecs.FeedPageSize), "first", null); feed.AddLink(httpEndPoint.ToHttpUrl("/streams/{0}/range/{1}/{2}", eventStreamId, PrevStart(start), AtomSpecs.FeedPageSize), "prev", null); feed.AddLink(httpEndPoint.ToHttpUrl("/streams/{0}/range/{1}/{2}", eventStreamId, NextStart(start), AtomSpecs.FeedPageSize), "next", null); foreach (var item in items) { feed.AddEntry(itemToEntry(item, httpEndPoint)); } return(feed); }
public void FilterMismatch() { FeedElement.FilterMismatch(new EntryPoint()).Should().BeFalse(); FeedElement.FilterMismatch(new EntryPoint { IfZeroInstallVersion = new VersionRange("0..") }).Should().BeFalse(); FeedElement.FilterMismatch(new EntryPoint { IfZeroInstallVersion = new VersionRange("..!0") }).Should().BeTrue(); }
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 != null ? msg.Events[0].Event.TimeStamp : DateTime.MinValue.ToUniversalTime()); feed.SetAuthor(AtomSpecs.Author); feed.SetHeadOfStream(headOfStream); //TODO AN: remove this ? feed.SetSelfUrl(self); //TODO AN: remove this ? if (headOfStream) //NOTE: etag workaround - to be fixed with better http handling model { feed.SetETag(Configure.GetPositionETag(msg.LastEventNumber, ContentType.AtomJson)); } 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); }
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].ResolvedEvent.Event != null ? msg.Events[msg.Events.Length - 1].ResolvedEvent.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.ResolvedEvent.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.ResolvedEvent.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].ResolvedEvent.WithoutPosition(), requestedUrl, embedContent); var ack = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}/ack/{2}", escapedStreamId, escapedGroupName, msg.Events[i].ResolvedEvent.OriginalEvent.EventId); var nack = HostName.Combine(requestedUrl, "/subscriptions/{0}/{1}/nack/{2}", escapedStreamId, escapedGroupName, msg.Events[i].ResolvedEvent.OriginalEvent.EventId); entry.AddLink("ack", ack); entry.AddLink("nack", nack); entry.AddRetryCount(msg.Events[i].RetryCount); feed.AddEntry(entry); } return(feed); }
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); }
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); }
public static FeedElement ToAllEventsForwardFilteredFeed(ClientMessage.FilteredReadAllEventsForwardCompleted msg, Uri requestedUrl, EmbedLevel embedContent) { var self = HostName.Combine(requestedUrl, "/streams/{0}", AllFilteredEscaped); 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}", AllFilteredEscaped, msg.MaxCount)); if (msg.CurrentPos.CommitPosition != 0) { feed.AddLink("last", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllFilteredEscaped, new TFPos(0, 0).AsString(), msg.MaxCount)); feed.AddLink("next", HostName.Combine(requestedUrl, "/streams/{0}/{1}/backward/{2}", AllFilteredEscaped, msg.PrevPos.AsString(), msg.MaxCount)); } if (!msg.IsEndOfStream || msg.Events.Length > 0) { feed.AddLink("previous", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllFilteredEscaped, msg.NextPos.AsString(), msg.MaxCount)); } for (int i = msg.Events.Length - 1; i >= 0; --i) { feed.AddEntry(ToEntry(msg.Events[i].WithoutPosition(), requestedUrl, embedContent)); } return(feed); }
public static void Persist(List <Feed> feeds) { // save feed info try { //Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); Configuration configuration = OpenConfig(); FeedsSection section = (FeedsSection)configuration.GetSection(FEED_SETTINGS_SECTION_NAME); if (section == null) { section = new FeedsSection(); section.LockItem = false; section.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser; section.SectionInformation.ForceSave = true; configuration.Sections.Add(FEED_SETTINGS_SECTION_NAME, section); } section.Feeds.Clear(); foreach (Feed feed in feeds) { FeedElement fe = new FeedElement(); fe.Name = feed.ActualName; fe.Url = feed.Url; fe.PollInterval = feed.PollInterval; fe.CustomName = feed.CustomName; fe.Username = feed.Username; fe.Password = feed.Password; section.Feeds.Add(fe); } configuration.Save(); } catch { } }
public static void Persist(List<Feed> feeds) { // save feed info try { //Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); Configuration configuration = OpenConfig(); FeedsSection section = (FeedsSection) configuration.GetSection(FEED_SETTINGS_SECTION_NAME); if (section == null) { section = new FeedsSection(); section.LockItem = false; section.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser; section.SectionInformation.ForceSave = true; configuration.Sections.Add(FEED_SETTINGS_SECTION_NAME, section); } section.Feeds.Clear(); foreach (Feed feed in feeds) { FeedElement fe = new FeedElement(); fe.Name = feed.ActualName; fe.Url = feed.Url; fe.PollInterval = feed.PollInterval; fe.CustomName = feed.CustomName; fe.Username = feed.Username; fe.Password = feed.Password; section.Feeds.Add(fe); } configuration.Save(); } catch { } }
public void SetUp() { _feed = new FeedElement(); _writer = XmlWriter.Create(new MemoryStream()); }
public void Add(FeedElement feed) { this.BaseAdd(feed); }
void LoadData(bool forceFeeds) { // // Load the data // List<UserQuery> queries = null; List<UserFeed> feeds = null; using (var repo = new Repo ()) { queries = repo.GetQueries (Service); feeds = repo.GetFeeds (Service); feeds.Sort ((x, y) => x.Category.CompareTo (y.Category)); if (feeds.Count == 0 || Service.ShouldUpdateFeeds || forceFeeds) { BeginDownloadFeeds (); } } // // Update the UI // if (feeds.Count > 0) { RemoveLoading (); foreach (var f in _feeds) { Sections.Remove (f); } DialogSection feedSection = null; foreach (var f in feeds) { if (feedSection == null || feedSection.Header != f.Category) { feedSection = new DialogSection (f.Category); _feeds.Add (feedSection); Sections.Add (feedSection); } var e = new FeedElement (Service, f, UITableViewCellAccessory.DisclosureIndicator); e.Selected += delegate { PushDataViewController (e.Feed); }; feedSection.Add (e); } } _queries.Clear (); foreach (var q in queries) { var e = new QueryElement (q); _queries.Add (e); } if (queries.Count > 0 && !Sections.Contains (_queries)) { Sections.Insert (0, _queries); } TableView.ReloadData (); }
public void Add(FeedElement feed) { this.BaseAdd(feed); }