Exemplo n.º 1
0
        //============================================================
        //	CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the AtomLogo class.
        /// </summary>
        public static void ClassExample()
        {
            #region AtomLogo
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            //  Provide visual identification for the feed
            feed.Logo = new AtomLogo(new Uri("/logo.jpg"));

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            feed.AddEntry(entry);
            #endregion
        }
        /// <summary>
        /// Provides example code for the AtomContent class.
        /// </summary>
        public static void ClassExample()
        {
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            //  Define the complete content of the entry
            entry.Content = new AtomContent("Powered by <b>Argotic</b>!", "xhtml");

            feed.AddEntry(entry);
        }
        /// <summary>
        /// Provides example code for the AtomLink class.
        /// </summary>
        public static void ClassExample()
        {
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));

            //  Identify a related web resource for the feed
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            //  Identify a related web resource for the entry
            entry.Links.Add(new AtomLink(new Uri("/blog/1234"), "alternate"));

            feed.AddEntry(entry);
        }
Exemplo n.º 4
0
        //============================================================
        //	CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the AtomTextConstruct class.
        /// </summary>
        public static void ClassExample()
        {
            #region AtomTextConstruct
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            //  Provide summary as entity escaped html
            AtomTextConstruct summary = new AtomTextConstruct();
            summary.Content  = "AT&amp;amp;T bought &lt;b&gt;by SBC&lt;/b&gt;!";
            summary.TextType = AtomTextConstructType.Html;
            entry.Summary    = summary;

            feed.AddEntry(entry);
            #endregion
        }
Exemplo n.º 5
0
    private void GetPosts(object sender, EventArgs e)
    {
        TransitPostQueryOptions options = new TransitPostQueryOptions();

        options.PageNumber     = 0;
        options.PageSize       = 25;
        options.SortDirection  = WebServiceQuerySortDirection.Descending;
        options.SortExpression = "Created";
        options.PublishedOnly  = true;
        options.DisplayedOnly  = true;

        Response.ContentType = "application/atom+xml;charset=\"utf-8\"";

        AtomFeed feed = new AtomFeed();

        feed.Title = new AtomTextConstruct(SessionManager.GetSetting("title", "Untitled"));

        List <TransitPost> posts = SessionManager.GetCachedCollection <TransitPost>(
            "GetPosts", SessionManager.PostTicket, options);

        foreach (TransitPost post in posts)
        {
            AtomEntry atomEntry = GetPost(post);
            feed.AddEntry(atomEntry);
        }

        feed.Save(Response.OutputStream);
        Response.End();
    }
Exemplo n.º 6
0
        /// <summary>
        /// Provides example code for the AtomCategory class.
        /// </summary>
        public static void ClassExample()
        {
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            // Categorize the feed
            feed.Categories.Add(new AtomCategory("sports"));

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            //  Categorize the feed entry
            AtomCategory entryCategory = new AtomCategory();

            entryCategory.Label  = "Baseball";
            entryCategory.Scheme = new Uri("http://example.org/scheme/category");
            entryCategory.Term   = "baseball";

            entry.Categories.Add(entryCategory);

            feed.AddEntry(entry);
        }
Exemplo n.º 7
0
        public void FeedWithEntryIsPassedThroughFromPhabricator()
        {
            var entry = new AtomEntry(
                new AtomId(),
                new AtomTextConstruct("test entry"),
                DateTime.Now);
            var expectedFeed = new AtomFeed();

            expectedFeed.AddEntry(entry);

            var kernel = new MoqMockingKernel();

            IoC.ReplaceKernel(kernel);
            kernel.Unbind <IPhabricator>();
            var mock = kernel.GetMock <IPhabricator>();

            mock.Setup(m => m.GetFeed("1")).Returns(expectedFeed);
            var controller = kernel.Get <HomeController>();
            var result     = controller.Index();

            Assert.IsType <ViewResult>(result);
            var viewResult = result as ViewResult;

            Assert.IsType <FeedViewModel>(viewResult.Model);
            Assert.NotNull(((FeedViewModel)viewResult.Model).Feed);
            var feedObj = ((FeedViewModel)viewResult.Model).Feed;

            Assert.IsType <AtomFeed>(feedObj);
            var actualFeed = feedObj as AtomFeed;

            Assert.True(actualFeed.Entries.Count() == 1);
            Assert.True(actualFeed.Entries.First().Title.Content == "test entry");
            Assert.Equal(actualFeed, expectedFeed);
        }
Exemplo n.º 8
0
        //============================================================
        //	CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the AtomId class.
        /// </summary>
        public static void ClassExample()
        {
            #region AtomId
            AtomFeed feed = new AtomFeed();

            //  Identifies the feed using a universally unique and permanent URI
            feed.Id = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));

            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            AtomEntry entry = new AtomEntry();

            //  Identifies the entry using a universally unique and permanent URI
            entry.Id = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));

            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            feed.AddEntry(entry);
            #endregion
        }
        /// <summary>
        /// Provides example code for the AtomSource class.
        /// </summary>
        public static void ClassExample()
        {
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            //  Entry was copied from another feed, so preserve source meta-data
            AtomSource source = new AtomSource();

            source.Id        = new AtomId(new Uri("http://example2.org/"));
            source.Title     = new AtomTextConstruct("Fourty-Two");
            source.UpdatedOn = new DateTime(2003, 11, 13, 18, 30, 2);
            source.Rights    = new AtomTextConstruct("© 2003 Example, Inc.");
            entry.Source     = source;

            feed.AddEntry(entry);
        }
Exemplo n.º 10
0
        //============================================================
        //	CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the AtomGenerator class.
        /// </summary>
        public static void ClassExample()
        {
            #region AtomGenerator
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            //  Identify the software used to generate the feed
            AtomGenerator generator = new AtomGenerator("Example Toolkit");
            generator.Uri     = new Uri("/myblog.php");
            generator.Version = "1.0";
            feed.Generator    = generator;

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            feed.AddEntry(entry);
            #endregion
        }
Exemplo n.º 11
0
        private RequestOperation CreateBatchOperation()
        {
            var uri = new SDataUri(Uri);

            if (uri.PathSegments.Length != 4)
            {
                throw new InvalidOperationException("Batch requests can only be made on collection end points");
            }

            var feed    = new AtomFeed();
            var batchOp = new RequestOperation(HttpMethod.Post, feed);

            foreach (var op in _operations)
            {
                AtomEntry entry;

                if (op.Resource == null)
                {
                    if (op.Method != HttpMethod.Post)
                    {
                        throw new InvalidOperationException("A predicate must be specified for GET, PUT and DELETE batch requests");
                    }

                    var entryUri = new SDataUri(uri)
                    {
                        CollectionPredicate = op.Predicate
                    };
                    entry = new AtomEntry {
                        Id = new AtomId(entryUri.Uri)
                    };
                }
                else
                {
                    entry = op.Resource as AtomEntry;

                    if (entry == null)
                    {
                        throw new InvalidOperationException("Only atom entry resources can be submitted in batch requests");
                    }
                }

                entry.SetSDataHttpMethod(op.Method);

                if (!string.IsNullOrEmpty(op.ETag))
                {
                    entry.SetSDataHttpIfMatch(op.ETag);
                }

                feed.AddEntry(entry);

                foreach (var file in op.Files)
                {
                    batchOp.Files.Add(file);
                }
            }

            return(batchOp);
        }
        public void verify_can_handle_AtomFeed_response_for_create_entry()
        {
            var mock = new Mock<ISDataResponse>(MockBehavior.Strict);
            var feed = new AtomFeed();
            feed.AddEntry(new AtomEntry());

            mock.SetupGet(r => r.Content).Returns(feed);
            mock.SetupGet(r => r.ETag).Returns(String.Empty);

            var service = new MockService(mock);
            var result = service.CreateEntry(new SDataServiceOperationRequest(service) { OperationName = "computePrice" }, new AtomEntry());
            Expect(result, Is.InstanceOf<AtomEntry>());
        }
        public void verify_can_handle_AtomFeed_response_for_create_entry()
        {
            var mock = new Mock <ISDataResponse>(MockBehavior.Strict);
            var feed = new AtomFeed();

            feed.AddEntry(new AtomEntry());

            mock.SetupGet(r => r.Content).Returns(feed);
            mock.SetupGet(r => r.ETag).Returns(String.Empty);

            var service = new MockService(mock);
            var result  = service.CreateEntry(new SDataServiceOperationRequest(service)
            {
                OperationName = "computePrice"
            }, new AtomEntry());

            Expect(result, Is.InstanceOf <AtomEntry>());
        }
Exemplo n.º 14
0
        public void IndexContainsContentWhenFeedHasTitleAndEntryHasContent()
        {
            var feed = new AtomFeed();

            feed.Title = new AtomTextConstruct("My Feed");
            var entry = new AtomEntry(
                new AtomId(),
                new AtomTextConstruct("Entry Title"),
                DateTime.Now);

            entry.Content = new AtomContent("Entry Content");
            feed.AddEntry(entry);

            var html = RazorHelper <FeedViewModel> .GenerateAndExecuteTemplate(
                this.GetIndexView(),
                new FeedViewModel { Feed = feed });

            Assert.Contains("Entry Content", html.Text);
        }
Exemplo n.º 15
0
        public void IndexCrashesWhenEntryHasNoTitle()
        {
            var feed = new AtomFeed();

            feed.Title = new AtomTextConstruct("My Feed");
            var entry = new AtomEntry(
                new AtomId(),
                new AtomTextConstruct("Entry Title"),
                DateTime.Now);

            feed.AddEntry(entry);

            Assert.Throws <NullReferenceException>(() =>
                                                   RazorHelper <FeedViewModel> .GenerateAndExecuteTemplate(
                                                       this.GetIndexView(),
                                                       new FeedViewModel {
                Feed = feed
            }));
        }
Exemplo n.º 16
0
        public void IndexRendersWhenFeedHasTitleAndEntryHasContent()
        {
            var feed = new AtomFeed();

            feed.Title = new AtomTextConstruct("My Feed");
            var entry = new AtomEntry(
                new AtomId(),
                new AtomTextConstruct("Entry Title"),
                DateTime.Now);

            entry.Content = new AtomContent("Entry Content");
            feed.AddEntry(entry);

            Assert.DoesNotThrow(() =>
                                RazorHelper <FeedViewModel> .GenerateAndExecuteTemplate(
                                    this.GetIndexView(),
                                    new FeedViewModel {
                Feed = feed
            }));
        }
Exemplo n.º 17
0
        private AtomFeed GetFeed()
        {
            var feed = new AtomFeed
            {
                Title     = new AtomTextConstruct("Batch"),
                Id        = new AtomId(new Uri(ToString())),
                UpdatedOn = DateTime.Now
            };

            foreach (var item in Items)
            {
                var entry = item.Entry ?? new AtomEntry {
                    Id = new AtomId(new Uri(item.Url))
                };
                entry.SetSDataHttpMethod(item.Method);
                entry.SetSDataHttpIfMatch(item.ETag);
                feed.AddEntry(entry);
            }

            return(feed);
        }
Exemplo n.º 18
0
        //============================================================
        //	CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the AtomPersonConstruct class.
        /// </summary>
        public static void ClassExample()
        {
            #region AtomPersonConstruct
            AtomFeed feed = new AtomFeed();

            feed.Id        = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title     = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            //  Identify the author of the feed
            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            //  Identify the contributors to the feed
            feed.Contributors.Add(new AtomPersonConstruct("Jane Doe"));

            AtomPersonConstruct contributor = new AtomPersonConstruct();
            contributor.EmailAddress = "*****@*****.**";
            contributor.Name         = "Some Person";
            contributor.Uri          = new Uri("http://example.org/somePerson");
            feed.Contributors.Add(contributor);

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            entry.Summary = new AtomTextConstruct("Some text.");

            //  Identify the author of the entry
            entry.Authors.Add(new AtomPersonConstruct("Jane Doe"));

            feed.AddEntry(entry);
            #endregion
        }
Exemplo n.º 19
0
        public override void ExecuteItemSequence(string groupByValue, IEnumerable <Tuple <ITaskItem, ITaskItem, ITaskItem> > items)
        {
            var feed = new AtomFeed
            {
                Id        = new AtomId(new Uri(FeedId)),
                Title     = new AtomTextConstruct(FeedTitle ?? ""),
                UpdatedOn = DateTime.Now,
            };

            if (!string.IsNullOrWhiteSpace(FeedRights))
            {
                feed.Rights = new AtomTextConstruct(FeedRights);
            }

            if (!string.IsNullOrWhiteSpace(FeedIcon))
            {
                feed.Icon = new AtomIcon(new Uri(FeedIcon));
            }

            if (!string.IsNullOrWhiteSpace(FeedLogo))
            {
                feed.Logo = new AtomLogo(new Uri(FeedLogo));
            }

            if (!string.IsNullOrWhiteSpace(FeedSubtitle))
            {
                feed.Subtitle = new AtomTextConstruct(FeedSubtitle);
            }


            if (!string.IsNullOrWhiteSpace(FeedAuthors))
            {
                foreach (string author in FeedAuthors.Split(';').Select(item => item.Trim()))
                {
                    feed.Authors.Add(new AtomPersonConstruct(author));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedContributors))
            {
                foreach (string contributor in FeedContributors.Split(';').Select(item => item.Trim()))
                {
                    feed.Contributors.Add(new AtomPersonConstruct(contributor));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedCategories))
            {
                foreach (string category in FeedCategories.Split(';').Select(item => item.Trim()))
                {
                    feed.Categories.Add(new AtomCategory(category));
                }
            }

            if (FeedLinkRelationSelf != null)
            {
                var selfLink = new AtomLink
                {
                    Relation = "self",
                    Uri      = new Uri(FeedLinkRelationSelf)
                };
                feed.Links.Add(selfLink);
            }

            foreach (Tuple <ITaskItem, ITaskItem, ITaskItem> tuple in items.OrderByDescending(item => item.Item2.GetTimestamp()))
            {
                ITaskItem modelInput   = tuple.Item1;
                ITaskItem receiptInput = tuple.Item2;
                ITaskItem contentInput = tuple.Item3;

                modelInput.LoadCustomMetadata();

                DateTime receiptModified = receiptInput.GetTimestamp();
                var      entry           = new AtomEntry
                {
                    Id        = new AtomId(new Uri(modelInput.GetMetadata(EntryIdSelector ?? "Uri"))),
                    Title     = new AtomTextConstruct(modelInput.GetMetadata(EntryTitleSelector ?? "Title")),
                    UpdatedOn = receiptModified,
                    Summary   = new AtomTextConstruct(modelInput.GetMetadata(EntrySummarySelector ?? "Summary")),
                };

                if (string.IsNullOrWhiteSpace(entry.Title.Content))
                {
                    entry.Title.Content = tuple.Item1.ItemSpec;
                }
                if (string.IsNullOrWhiteSpace(entry.Summary.Content))
                {
                    entry.Summary.Content = entry.Title.Content;
                }

                if (contentInput.Exists())
                {
                    if (string.IsNullOrWhiteSpace(EntryContentEncoding))
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText());
                    }
                    else
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText(), EntryContentEncoding);
                    }

                    if (!string.IsNullOrWhiteSpace(EntryContentType))
                    {
                        entry.Content.ContentType = EntryContentType;
                    }
                }

                var alternateLink = new AtomLink
                {
                    Relation = "alternate",
                    Uri      = new Uri(modelInput.GetMetadata(EntryLinkAlternateSelector ?? "Uri"))
                };
                entry.Links.Add(alternateLink);
                feed.AddEntry(entry);
            }
            using (FileStream stream = File.OpenWrite(Output.ItemSpec))
            {
                SyndicationResourceSaveSettings s = new SyndicationResourceSaveSettings()
                {
                    CharacterEncoding = Encoding.UTF8
                };
                feed.Save(stream, s);
            }
        }