public void Init()
		{
			feed = new AtomFeed();
			testUri = new Uri("http://www.w3.org");
			feedspath = @"..\..\tests\feeds\";
			files = Directory.GetFiles(feedspath);
		}
        public static Atom.Core.Collections.AtomEntryCollection geadGMailEmail(string username, string password)
        {
            // source found at https://app.box.com/shared/ka7j7n5bzm
            Atom.Core.Collections.AtomEntryCollection entries = null;

            WebRequest webRequestGetUrl;

            try {
                // Create a new web-request instance
                webRequestGetUrl = WebRequest.Create(_gmailServerUri);

                byte[] bytes = Encoding.ASCII.GetBytes(username + ":" + password);

                // Add the headers for basic authentication.
                webRequestGetUrl.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(bytes));

                // Get the response feed
                Stream feedStream = webRequestGetUrl.GetResponse().GetResponseStream();

                // Load Feed into Atom DLL
                Atom.Core.AtomFeed gmailFeed = Atom.Core.AtomFeed.Load(feedStream);

                //Atom.Core.Collections.AtomEntryCollection entries = gmailFeed.Entries;
                entries = gmailFeed.Entries;



                //if (entries.Count > 0) {
                //Console.WriteLine(string.Format("Found {0} email(s)", entries.Count));
                //Console.WriteLine(Environment.NewLine);

                // Read the first email in the inbox only.
                // you can change this section to read all emails.
                //for (int i = 0; i < 1; i++) {
                //     AtomEntry email = entries[i];
                //     Console.WriteLine("Brief details of the first Email in the inbox:");
                //     Console.WriteLine("Title: " + email.Title.Content);
                //     Console.WriteLine("Author Name: " + email.Author.Name);
                //     Console.WriteLine("Author Email: " + email.Author.Email);
                //     Console.WriteLine(Environment.NewLine);
                //     Console.WriteLine("Email Content: " + Environment.NewLine);
                //     Console.WriteLine(email.Summary.Content);
                //     Console.WriteLine(Environment.NewLine);
                //     Console.WriteLine("Hit 'Enter' to exit");
                //     Console.ReadLine();
                //}
                //}
            }
            catch (Exception ex) {
            }

            return(entries);
        }
		public void TestNameIsNotEmail()
		{
			foreach(string file in files)
			{
				feed = AtomFeed.Load(file);
				if(feed.Author != null)
					Assert.IsFalse(AU.Utils.IsEmail(feed.Author.Name));
				foreach(AtomPersonConstruct contributor in feed.Contributors)
					Assert.IsFalse(AU.Utils.IsEmail(contributor.Name));
				foreach(AtomEntry entry in feed.Entries)
				{
					if(entry.Author != null)
						Assert.IsFalse(AU.Utils.IsEmail(entry.Author.Name));
					foreach(AtomPersonConstruct contributor in entry.Contributors)
						Assert.IsFalse(AU.Utils.IsEmail(contributor.Name));
				}
			}
		}
		public void TestXmlBaseFeedUri()
		{
			
			foreach(string file in files)
			{
				FileInfo info = new FileInfo(file);
				if(info.Name.ToLower() == "pilgrim.xml")
				{
					feed = AtomFeed.Load(file);
					Assert.IsNotNull(feed.XmlBase);
					Assert.AreEqual(feed.XmlBase.ToString(), "http://diveintomark.org/");
				}
			}
		}
		public void TestXmlFragment()
		{
			string filename = "test";
			for(int i = 0; i < files.Length; i++)
			{
				StreamReader reader = new StreamReader(files[i]);
				string content = reader.ReadToEnd();
				feed = AtomFeed.LoadXml(content);
				Assert.IsNotNull(feed);
				feed.Save(filename);
				File.Delete(filename);
			}
		}
		public void TestXmlReaderXmlWriter()
		{
			for(int i = 0; i < files.Length; i++)
			{
				XmlTextReader reader = new XmlTextReader(files[i]);
				feed = AtomFeed.Load(reader);
				Assert.IsNotNull(feed);
				MemoryStream stream = new MemoryStream();
				XmlTextWriter writer = new XmlTextWriter(stream,
					System.Text.Encoding.Default);
				feed.Save(writer);
				stream.Close();
			}
		}
		public void TestReaderWriter()
		{
			for(int i = 0; i < files.Length; i++)
			{
				StreamReader reader = new StreamReader(files[i]);
				feed = AtomFeed.Load(reader);
				Assert.IsNotNull(feed);
				MemoryStream stream = new MemoryStream();
				StreamWriter w = new StreamWriter(stream);
				feed.Save(w);
				stream.Close();
			}
		}
		public void TestStream()
		{
			for(int i = 0; i < files.Length; i++)
			{
				FileStream stream = File.OpenRead(files[i]);
				feed = AtomFeed.Load(stream);
				Assert.IsNotNull(feed);
				MemoryStream memStream = new MemoryStream();
				feed.Save(memStream);
				stream.Close();
			}
		}
		public void TestInvalidFeeds()
		{
			string filename = "test";
			feedspath = @"..\..\tests\invalidfeeds\";
			files = Directory.GetFiles(feedspath);
			for(int i = 0; i < files.Length; i++)
			{
				feed = AtomFeed.Load(files[i]);
				Assert.IsNotNull(feed);
				feed.Save(filename);
				File.Delete(filename);
			}
		}
		public void TestSaveToFile()
		{
			Init();
			string filename = "test";
			for(int i = 0; i < files.Length; i++)
			{
				feed = AtomFeed.Load(files[i]);
				Assert.IsNotNull(feed);
				feed.Save(filename);
				File.Delete(filename);
			}
		}
		public void TestUri()
		{
			for(int i = 0; i < files.Length; i++)
			{
				Console.WriteLine("{0}: {1}", i, files[i]);
				feed = AtomFeed.Load(files[i]);
				Assert.IsNotNull(feed.Uri);
				foreach(AtomEntry entry in feed.Entries)
					Assert.IsNotNull(entry.Uri);
			}
		}
Beispiel #12
0
        internal static AtomFeed Parse(XPathNavigator navigator)
        {
            AtomFeed feed = new AtomFeed();

            XPathNavigator    nav  = navigator.Clone();
            XPathNodeIterator iter = nav.SelectChildren(XPathNodeType.All);

            do
            {
                string name = iter.Current.Name.ToLower();
                int    idx  = name.IndexOf(":");
                if (idx != -1)
                {
                    name = name.Split(new char[] { ':' }, 2)[1];
                }

                switch (name)
                {
                case "feed":
                {
                    try
                    {
                        XPathNavigatorReader reader = new XPathNavigatorReader(nav);
                        string baseUri = reader.GetAttribute("base", XmlNamespaces.Xml);
                        if (baseUri != null && baseUri.Length > 0)
                        {
                            feed.XmlBase = new Uri(baseUri);
                        }
                    }
                    catch {}

                    try
                    {
                        feed.Uri = FindAlternateUri(iter.Current);
                    }
                    catch {}

                    try
                    {
                        feed.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                    }
                    catch {}

                    XPathNodeIterator attrIterator = nav.Select("@*");
                    while (attrIterator.MoveNext())
                    {
                        if (attrIterator.Current.Name.ToLower() == "version")
                        {
                            if (attrIterator.Current.Value != DefaultValues.AtomVersion)
                            {
                                string msg = String.Format("Atom {0} version is not supported!", attrIterator.Current.Value);
                                throw new InvalidOperationException(msg);
                            }
                        }
                    }
                    break;
                }

                case "title":
                    AtomContentConstruct content = AtomContentConstruct.Parse(iter.Current);
                    feed.Title = content;
                    break;

                case "link":
                    feed.Links.Add(AtomLink.Parse(iter.Current));
                    break;

                case "author":
                    feed.Author = AtomPersonConstruct.Parse(iter.Current);
                    break;

                case "contributor":
                    feed.Contributors.Add(AtomPersonConstruct.Parse(iter.Current));
                    break;

                case "tagline":
                    feed.Tagline = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "id":
                    feed.Id = new Uri(iter.Current.Value);
                    break;

                case "copyright":
                    feed.Copyright = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "info":
                    feed.Info = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "modified":
                    feed.Modified = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "entry":
                    feed.Entries.Add(AtomEntry.Parse(iter.Current));
                    break;
                }
            } while(iter.MoveNext());

            return(feed);
        }
Beispiel #13
0
		public void TestSaveToFile()
		{
			Init();
			string filename = "test";
			for(int i = 0; i < files.Length; i++)
			{
                feed = AtomFeed.Load(files[i], new Uri("http://purl.org/atom/ns#"));
				Assert.IsNotNull(feed);
				feed.Save(filename);
				File.Delete(filename);
			}
		}
Beispiel #14
0
        internal static AtomFeed Parse(XPathNavigator navigator, Uri ns)
        {
            AtomFeed feed = new AtomFeed(ns);

            XPathNavigator nav = navigator.Clone();
            XPathNodeIterator iter = nav.SelectChildren(XPathNodeType.All);

            do
            {
                string name = iter.Current.Name.ToLower();
                int idx = name.IndexOf(":");
                if (idx != -1)
                    name = name.Split(new char[] { ':' }, 2)[1];

                switch (name)
                {
                    case "feed":
                        {
                            try
                            {
                                XPathNavigatorReader reader = new XPathNavigatorReader(nav);
                                string baseUri = reader.GetAttribute("base", XmlNamespaces.Xml);
                                if (baseUri != null && baseUri.Length > 0)
                                    feed.XmlBase = new Uri(baseUri);
                            }
                            catch { }

                            try
                            {
                                feed.Uri = FindAlternateUri(iter.Current, ns);
                            }
                            catch { }

                            try
                            {
                                feed.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                            }
                            catch { }

                            XPathNodeIterator attrIterator = nav.Select("@*");
                            while (attrIterator.MoveNext())
                            {
                                if (attrIterator.Current.Name.ToLower() == "version")
                                {
                                    if ((attrIterator.Current.Value != DefaultValues.Atom03Version) &&
                                        (attrIterator.Current.Value != DefaultValues.Atom10Version))
                                    {
                                        string msg = String.Format("Atom {0} version is not supported!", attrIterator.Current.Value);
                                        throw new InvalidOperationException(msg);
                                    }
                                }
                            }
                            break;
                        }

                    case "title":
                        AtomContentConstruct titlecontent = AtomContentConstruct.Parse(iter.Current, ns);
                        feed.Title = titlecontent;
                        break;

                    case "subtitle":
                        feed.SubTitle = new AtomContentConstruct("subtitle", iter.Current.Value, ns);
                        break;

                    case "link":
                        feed.Links.Add(AtomLink.Parse(iter.Current, ns));
                        break;

                    case "author":
                        feed.Author = AtomPersonConstruct.Parse(iter.Current, ns);
                        break;

                    case "contributor":
                        feed.Contributors.Add(AtomPersonConstruct.Parse(iter.Current, ns));
                        break;

                    case "tagline":
                        feed.Tagline = AtomContentConstruct.Parse(iter.Current, ns);
                        break;

                    case "id":
                        feed.Id = new Uri(iter.Current.Value);
                        break;

                    case "copyright":
                        feed.Copyright = AtomContentConstruct.Parse(iter.Current, ns);
                        break;

                    case "info":
                        feed.Info = AtomContentConstruct.Parse(iter.Current, ns);
                        break;

                    case "modified":
                        feed.Modified = AtomDateConstruct.Parse(iter.Current, ns);
                        break;

                    case "entry":
                        feed.Entries.Add(AtomEntry.Parse(iter.Current, ns));
                        break;

                }
            } while (iter.MoveNext());

            return feed;
        }
Beispiel #15
0
		/// <summary>
		/// Writes the Atom feed body.
		/// </summary>
		private void WriteFeed(AtomFeed feed)
		{
			if(this._writer == null)
			 throw new InvalidOperationException("AtomWriter has been closed, and can not be written to.");


			this.WriteHeader();

			if(feed == null)
				throw new RequiredElementNotFoundException("AtomFeed cannot be null.");

			this._writer.WriteRaw(feed.ToString());

			// finalize the writer
			this._writer.Flush();
			this._writer.Close();
			this._writer = null;
		}
Beispiel #16
0
		internal void Write(AtomFeed feed)
		{
			this.WriteFeed(feed);
		}