Example #1
0
        public AtomEntry createWebPage(String title, String html, String pageName)
        {
            SiteEntry    entry    = new SiteEntry();
            AtomCategory category = new AtomCategory(SitesService.WEBPAGE_TERM, SitesService.KIND_SCHEME);

            category.Label = "webpage";
            entry.Categories.Add(category);
            entry.Title.Text      = title;
            entry.Content.Type    = "xhtml";
            entry.Content.Content = html;
            entry.ExtensionElements.Add(makePageNameExtension(pageName));

            AtomEntry newEntry = null;

            try
            {
                newEntry = service.Insert(new Uri(makeFeedUri("content")), entry);
            }
            catch (GDataRequestException e)
            {
                Console.WriteLine(e.ResponseString);
            }

            return(newEntry);
        }
        public AtomEntry createWebPage(String originalUrl, String path, String title, String html, String pageName, DateTime lastModified, bool isIndexPage, string indexHtmlPath = "")
        {
            if (cancel())
            {
                return(null);
            }
            String parentUrl = originalUrl.Substring(0, originalUrl.LastIndexOf("/"));

            pageName = originalUrl.Substring(originalUrl.LastIndexOf("/") + 1);
            AtomEntry    parent   = m_service.Get(parentUrl);
            SiteEntry    entry    = new SiteEntry();
            AtomCategory category = new AtomCategory(SitesService.WEBPAGE_TERM, SitesService.KIND_SCHEME);

            category.Label = "webpage";
            entry.Categories.Add(category);
            AtomLink link = new AtomLink("application/atom+xml", "http://schemas.google.com/sites/2008#parent");

            link.HRef = parent.EditUri;
            entry.Links.Add(link);
            entry.Title.Text      = m_convertCase ? IndianBridge.Common.Utilities.ConvertCaseString(title) : title;
            entry.Content.Type    = "html";
            entry.Content.Content = m_replaceLinks ? replaceLinks(html, originalUrl, isIndexPage, indexHtmlPath) : html;
            entry.ExtensionElements.Add(makePageNameExtension(pageName));
            AtomEntry newEntry = null;
            String    url      = "https://sites.google.com/feeds/content/site/" + m_siteName;

            newEntry = m_service.Insert(new Uri(url), entry);
            m_lastRunTimes[originalUrl] = lastModified;
            printMessage("CREATED.");
            numberOfPagesAlreadyUploaded++;
            reportProgress(title);
            return(newEntry);
        }
Example #3
0
        /// <summary>
        /// Create a new folder with the name folderName inside parent folder with ID destFolderId
        /// </summary>
        /// <param name="folderName"> new folder's name </param>
        /// <param name="destFolderId"> destination folder's ID </param>
        /// <returns> The ID of the newly created folder </returns>
        public String CreateFolder(String folderName, String destFolderId)
        {
            AtomCategory category = new AtomCategory("http://schemas.google.com/docs/2007#folder", new AtomUri("http://schemas.google.com/g/2005#kind"));

            category.Label = "folder";

            AtomEntry folder = new AtomEntry();

            folder.Categories.Add(category);
            folder.Title = new AtomTextConstruct(AtomTextConstructElementType.Title, folderName);

            Uri       feedUri;
            AtomEntry newFolderEntry;

            if (destFolderId.Equals(""))
            {
                feedUri        = new Uri("http://docs.google.com/feeds/documents/private/full");
                newFolderEntry = this.service.Insert(feedUri, folder);               // send request
            }
            else
            { // !! PROBLEM, "Can not update a read-only feed"; URI: "http://docs.google.com/feeds/documents/private/full/folder:0B5S1An4gAziBNGYxOWI1M2ItYzVjNC00MDViLWFiZWYtM2VhZGUzZDRkZmZl/contents"
                feedUri = new Uri("http://docs.google.com/feeds/documents/private/full/folder" + "%3A" + destFolderId + "/contents");
                Console.WriteLine(feedUri.ToString());
                AtomFeed feed = new AtomFeed(feedUri, this.service);
                newFolderEntry = this.service.Insert(feed, folder);              // send request
            }

            //Console.WriteLine(FolderQuery.DocumentId(newFolderEntry.Id.AbsoluteUri));
            // String folderId = FolderQuery.DocumentID( newFolderEntry.Id.AbsoluteUri );
            String folderId = newFolderEntry.Id.AbsoluteUri;

            Console.WriteLine(folderId);
            return(folderId);
        }
        public void ShouldBePersistedTest()
        {
            AtomCategory target = new AtomCategory(); // TODO: Initialize to an appropriate value

            target.Label = "new label";
            Assert.IsTrue(target.ShouldBePersisted());
        }
 /// <summary>Removes a category.</summary>
 /// <param name="category">The <see cref="AtomCategory"/> to remove.</param>
 public void Remove(AtomCategory category)
 {
   if(category == null) throw new ArgumentNullException("category");
   XElement element = (XElement)category;
   if(element.Parent == this.Element)
     element.Remove();
 }
        /// <summary>
        /// Modifies the <see cref="AtomEntry"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillEntryCollections(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            Guard.ArgumentNotNull(entry, "entry");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            XPathNodeIterator authorIterator      = source.Select("atom:author", manager);
            XPathNodeIterator categoryIterator    = source.Select("atom:category", manager);
            XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager);
            XPathNodeIterator linkIterator        = source.Select("atom:link", manager);

            if (authorIterator != null && authorIterator.Count > 0)
            {
                while (authorIterator.MoveNext())
                {
                    AtomPersonConstruct author = new AtomPersonConstruct();
                    if (author.Load(authorIterator.Current, settings))
                    {
                        entry.Authors.Add(author);
                    }
                }
            }

            if (categoryIterator != null && categoryIterator.Count > 0)
            {
                while (categoryIterator.MoveNext())
                {
                    AtomCategory category = new AtomCategory();
                    if (category.Load(categoryIterator.Current, settings))
                    {
                        entry.Categories.Add(category);
                    }
                }
            }

            if (contributorIterator != null && contributorIterator.Count > 0)
            {
                while (contributorIterator.MoveNext())
                {
                    AtomPersonConstruct contributor = new AtomPersonConstruct();
                    if (contributor.Load(contributorIterator.Current, settings))
                    {
                        entry.Contributors.Add(contributor);
                    }
                }
            }

            if (linkIterator != null && linkIterator.Count > 0)
            {
                while (linkIterator.MoveNext())
                {
                    AtomLink link = new AtomLink();
                    if (link.Load(linkIterator.Current, settings))
                    {
                        entry.Links.Add(link);
                    }
                }
            }
        }
        public void AtomCategoryConstructorTest1()
        {
            string       term   = "Test";
            AtomCategory target = new AtomCategory(term);

            Assert.AreEqual(target.Term, term);
        }
Example #8
0
    public static AtomCategory GetCategoryFromGroup(int group)
    {
        AtomCategory category;

        if (group == 1)
        {
            category = AtomCategory.ALKALI_METAL;
        }
        else if (group == 2)
        {
            category = AtomCategory.ALKALINE_EARTH_METAL;
        }
        else if (group == 18)
        {
            category = AtomCategory.NOBLE_GAS;
        }
        else if (group == 17)
        {
            category = AtomCategory.HALOGEN;
        }
        else if (group >= 13)
        {
            category = AtomCategory.POST_TRANSTION_METAL;
        }
        else
        {
            category = AtomCategory.TRANSITION_METAL;
        }
        return(category);
    }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>compares a category</summary>
        /// <param name="theOne">the One category </param>
        /// <param name="theOther">the Other category</param>
        /// <returns>true if identical </returns>
        //////////////////////////////////////////////////////////////////////
        public static bool IsCategoryIdentical(AtomCategory theOne, AtomCategory theOther)
        {
            if (theOne == null && theOther == null)
            {
                return(true);
            }


            if (!ObjectModelHelper.IsBaseIdentical(theOne, theOther))
            {
                return(false);
            }

            if (String.Compare(theOne.Label, theOther.Label) != 0)
            {
                return(false);
            }
            if (String.Compare(theOne.Term, theOther.Term) != 0)
            {
                return(false);
            }
            if (AtomUri.Compare(theOne.Scheme, theOther.Scheme) != 0)
            {
                return(false);
            }

            return(true);
        }
        //////////////////////////////////////////////////////////////////////
        /// <summary>creates a new, in memory atom entry</summary>
        /// <returns>the new AtomEntry </returns>
        //////////////////////////////////////////////////////////////////////
        public static AtomEntry CreateAtomEntry(int iCount)
        {
            AtomEntry entry = new AtomEntry();

            // some unicode chars
            Char[] chars = new Char[] {
                '\u0023', // #
                '\u0025', // %
                '\u03a0', // Pi
                '\u03a3', // Sigma
                '\u03d1', // beta
                '&',
            };

            AtomPerson author = new AtomPerson(AtomPersonType.Author);

            author.Name  = "John Doe" + chars[0] + chars[1] + chars[2] + chars[3] + chars[4] + chars[5];
            author.Email = "*****@*****.**";
            entry.Authors.Add(author);

            AtomCategory cat = new AtomCategory();

            cat.Label = "Default";
            cat.Term  = "Default" + chars[4] + " Term";
            entry.Categories.Add(cat);

            entry.Content.Content = "this is the default text & entry";
            entry.Content.Type    = "html";
            entry.Published       = new DateTime(2001, 11, 20, 22, 30, 0);
            entry.Title.Text      = "This is a entry number: " + iCount;
            entry.Updated         = DateTime.Now;

            return(entry);
        }
Example #11
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);
        }
Example #12
0
        public SitesEntry VerifySite(string url, SitesEntry entry = null)
        {
            if (entry == null)
            {
                entry = GetSite(url);
            }

            VerificationMethod method = new VerificationMethod("metatag", "true");
            var siteid = CreateSiteID(url);

            entry.VerificationMethod = method;
            var category = new AtomCategory("http://schemas.google.com/webmasters/tools/2007#site-info",
                                            "http://schemas.google.com/g/2005#kind");

            entry.Categories.Add(category);
            entry.Id           = new AtomId(string.Concat(SiteQueryUrl, siteid));
            entry.Content.Type = "";
            try
            {
                return(service.Update(entry));
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
            }
            return(null);
        }
        public void QueryCategoryConstructorTest1()
        {
            AtomCategory  category = new AtomCategory("term");
            QueryCategory target   = new QueryCategory(category);

            Assert.IsNotNull(target);
            Assert.AreEqual(target.Category, category);
        }
Example #14
0
        public void AddTest()
        {
            AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value
            AtomCategory           value  = new AtomCategory("test");

            target.Add(value);
            Assert.IsTrue(target.Contains(value));
        }
        public void AtomCategoryConstructorTest()
        {
            string       term   = "term";
            AtomUri      scheme = new AtomUri("scheme");
            AtomCategory target = new AtomCategory(term, scheme);

            Assert.AreEqual(target.Term, term);
            Assert.AreEqual(target.Scheme.ToString(), "scheme");
        }
        public void AtomCategoryConstructorTest2()
        {
            AtomCategory target = new AtomCategory();

            Assert.IsNotNull(target);
            Assert.IsTrue(String.IsNullOrEmpty(target.Label));
            Assert.IsTrue(String.IsNullOrEmpty(target.Term));
            Assert.IsNull(target.Scheme);
        }
        public void CategoryTest()
        {
            AtomCategory  category = new AtomCategory("term");
            QueryCategory target   = new QueryCategory(category); // TODO: Initialize to an appropriate value
            AtomCategory  actual;

            target.Category = category;
            actual          = target.Category;
            Assert.AreEqual(category, actual);
        }
        public void SchemeTest()
        {
            AtomCategory target   = new AtomCategory(); // TODO: Initialize to an appropriate value
            AtomUri      expected = new AtomUri("scheme");
            AtomUri      actual;

            target.Scheme = expected;
            actual        = target.Scheme;
            Assert.AreEqual(expected, actual);
        }
Example #19
0
        public void InsertTest()
        {
            AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value
            AtomCategory           value  = new AtomCategory("test");
            int index = 0;

            Assert.IsTrue(target.Count == 0);
            target.Insert(index, value);
            Assert.IsTrue(target.Count == 1);
        }
        public void ToggleCategoryTest()
        {
            AbstractEntry target = CreateAbstractEntry();
            AtomCategory  cat    = new AtomCategory("testcat");

            target.ToggleCategory(cat, true);
            Assert.IsTrue(target.Categories.Contains(cat), "Category should now be part of it");
            target.ToggleCategory(cat, false);
            Assert.IsFalse(target.Categories.Contains(cat), "Category should be gone");
        }
        public void TermTest()
        {
            AtomCategory target   = new AtomCategory(); // TODO: Initialize to an appropriate value
            string       expected = "TestValue";
            string       actual;

            target.Term = expected;
            actual      = target.Term;
            Assert.AreEqual(expected, actual);
        }
Example #22
0
        public void RemoveTest()
        {
            AtomCategoryCollection target   = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value
            AtomCategory           expected = new AtomCategory("test");

            Assert.IsTrue(target.Count == 0);
            target.Add(expected);
            Assert.IsTrue(target.Count == 1);
            target.Remove(expected);
            Assert.IsTrue(target.Count == 0);
        }
        public void OperatorTest()
        {
            AtomCategory          category = new AtomCategory("term");
            QueryCategory         target   = new QueryCategory(category); // TODO: Initialize to an appropriate value
            QueryCategoryOperator expected = QueryCategoryOperator.AND;
            QueryCategoryOperator actual;

            target.Operator = expected;
            actual          = target.Operator;
            Assert.AreEqual(expected, actual);
        }
        public void ExcludedTest()
        {
            AtomCategory  category = new AtomCategory("term");
            QueryCategory target   = new QueryCategory(category); // TODO: Initialize to an appropriate value
            bool          expected = false;                       // TODO: Initialize to an appropriate value
            bool          actual;

            target.Excluded = expected;
            actual          = target.Excluded;
            Assert.AreEqual(expected, actual);
        }
Example #25
0
        public void FindTest()
        {
            AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value
            AtomCategory           value  = new AtomCategory("test");

            target.Add(value);
            string       term = "test";
            AtomCategory actual;

            actual = target.Find(term);
            Assert.AreEqual(value, actual);
        }
Example #26
0
        public void ItemTest()
        {
            AtomCategoryCollection target = new AtomCategoryCollection();
            int          index            = 0;
            AtomCategory expected         = new AtomCategory("test");
            AtomCategory actual;

            target.Add(expected);
            target[index] = expected;
            actual        = target[index];
            Assert.AreEqual(expected, actual);
        }
Example #27
0
        public void IndexOfTest()
        {
            AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value
            AtomCategory           value  = new AtomCategory("test");

            target.Add(value);
            int expected = 0; // TODO: Initialize to an appropriate value
            int actual;

            actual = target.IndexOf(value);
            Assert.AreEqual(expected, actual);
        }
        //////////////////////////////////////////////////////////////////////
        /// <summary>[Test] public QueryObjectTest()</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void QueryObjectTest()
        {
            Tracing.TraceInfo("Entering QueryObject Test");

            FeedQuery query = new FeedQuery();

            query.Uri = new Uri(this.defaultHost);

            AtomCategory  aCat = new AtomCategory("Test", new AtomUri("urn:test.com"));
            QueryCategory qCat = new QueryCategory(aCat);

            query.Categories.Add(qCat);

            aCat          = new AtomCategory("TestNotAndOr", new AtomUri("urn:test.com"));
            qCat          = new QueryCategory(aCat);
            qCat.Operator = QueryCategoryOperator.OR;
            qCat.Excluded = true;

            query.Categories.Add(qCat);


            aCat = new AtomCategory("ANDTHISONE", new AtomUri(""));
            qCat = new QueryCategory(aCat);
            query.Categories.Add(qCat);

            aCat          = new AtomCategory("AnotherOrWithoutCategory");
            qCat          = new QueryCategory(aCat);
            qCat.Operator = QueryCategoryOperator.OR;
            qCat.Excluded = true;
            query.Categories.Add(qCat);

            query.Query            = "Hospital";
            query.NumberToRetrieve = 20;
            Tracing.TraceInfo("query: " + query.Uri);

            Uri uri = query.Uri;

            Tracing.TraceInfo("Uri: query= " + uri.Query);
            query.Uri = uri;
            Tracing.TraceInfo("Parsed Query URI: " + query.Uri);
            Assert.IsTrue(uri.AbsolutePath.Equals(query.Uri.AbsolutePath), "both query URIs should be identical, uri: " + uri.AbsolutePath + " compared to query: " + query.Uri.AbsolutePath);

            query.CategoryQueriesAsParameter = true;

            uri = query.Uri;
            Tracing.TraceInfo("Uri: query= " + uri.Query);
            query.Uri = uri;
            Tracing.TraceInfo("Parsed Query URI: " + query.Uri.AbsoluteUri);
            Assert.IsTrue(uri.AbsolutePath.Equals(query.Uri.AbsolutePath), "both query URIs should be identical, uri: " + uri.AbsolutePath + " compared to query: " + query.Uri.AbsolutePath);
        }
Example #29
0
        public AtomEntry updloadAttachment(String filename, String contentType, AtomEntry parent, String title, String description)
        {
            SiteEntry entry = new SiteEntry();

            AtomCategory category = new AtomCategory(SitesService.ATTACHMENT_TERM, SitesService.KIND_SCHEME);

            category.Label = "attachment";
            entry.Categories.Add(category);

            AtomLink parentLink = new AtomLink(AtomLink.ATOM_TYPE, SitesService.PARENT_REL);

            parentLink.HRef = parent.SelfUri;
            entry.Links.Add(parentLink);

            entry.MediaSource  = new MediaFileSource(filename, contentType);
            entry.Content.Type = contentType;

            if (title == "")
            {
                entry.Title.Text = entry.MediaSource.Name;
            }
            else
            {
                entry.Title.Text = title;
            }

            entry.Summary.Text = description;

            AtomEntry newEntry = null;

            try
            {
                newEntry = service.Insert(new Uri(makeFeedUri("content")), entry);
            }
            catch (GDataRequestException e)
            {
                Console.WriteLine(e.ResponseString);
            }

            return(newEntry);
        }
Example #30
0
        /// <summary>
        /// Searches YouTube for tracks matching a certain query
        /// </summary>
        /// <param name="query">The query to search for</param>
        /// <returns>An observable collection of TrackData with all YouTube tracks that match query</returns>
        public static ObservableCollection <TrackData> Search(string query)
        {
            ObservableCollection <TrackData> tracks = new ObservableCollection <TrackData>();

            try
            {
                string filter = SettingsManager.YouTubeFilter;

                YouTubeQuery q = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
                q.OrderBy = "relevance";
                q.Query   = query;
                q.Formats.Add(YouTubeQuery.VideoFormat.Embeddable);
                q.NumberToRetrieve = 50;
                q.SafeSearch       = YouTubeQuery.SafeSearchValues.None;

                if (!String.IsNullOrWhiteSpace(filter) && filter != "None")
                {
                    AtomCategory category = new AtomCategory(filter, YouTubeNameTable.CategorySchema);
                    q.Categories.Add(new QueryCategory(category));
                }

                YouTubeRequest request = new YouTubeRequest(settings);

                Feed <Video> videoFeed = request.Get <Video>(q);
                foreach (Video entry in videoFeed.Entries)
                {
                    tracks.Add(YouTubeManager.CreateTrack(entry));
                }
            }
            catch (Exception exc)
            {
                U.L(LogLevel.Error, "YOUTUBE", "Error while performing search: " + exc.Message);
                VerifyConnectivity();
            }

            TrackSource = tracks;

            return(tracks);
        }
Example #31
0
        public void AddSitemap(string url, string sitemapurl)
        {
            var sitemap = new SitemapsEntry();

            sitemap.Id          = new AtomId(sitemapurl);
            sitemap.SitemapType = "WEB";
            var category = new AtomCategory("http://schemas.google.com/webmasters/tools/2007#sitemap-regular",
                                            "http://schemas.google.com/g/2005#kind");

            sitemap.Categories.Add(category);
            var siteid   = CreateSiteID(url);
            var queryurl = string.Format(sitemapQueryUrl, siteid);

            try
            {
                service.Insert(new Uri(queryurl), sitemap);
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
            }
        }
 /// <summary>Adds a category that can be applied to the members of an Atom Publishing Collection.</summary>
 /// <param name="category">An <see cref="AtomCategory"/> representing a category that can be applied to the members of an Atom Publishing Collection.</param>
 public void Add(AtomCategory category)
 {
   if(category == null) throw new ArgumentNullException("category");
   this.Element.Add((XElement)category);
 }