Ejemplo n.º 1
0
        public void AtomNewImageTest()
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/DBlog/AtomImage.aspx");

            request.Method      = "POST";
            request.ContentType = "image/jpg";
            string usernamePassword   = string.Format("Administrator:");
            string basicAuthorization = string.Format("Basic {0}", Convert.ToBase64String(
                                                          Encoding.ASCII.GetBytes(usernamePassword)));

            request.Headers.Add("Authorization", basicAuthorization);
            byte[] postData = ThumbnailBitmap.GetBitmapDataFromText("x", 72, 100, 150);
            request.ContentLength = postData.Length;
            request.GetRequestStream().Write(postData, 0, postData.Length);
            request.GetRequestStream().Close();
            HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
            string          responseLocation = response.Headers["Location"];

            Assert.IsNotEmpty(responseLocation);
            Console.WriteLine(responseLocation);
            // atom entry returned
            AtomEntry atomEntry = new AtomEntry();

            atomEntry.Load(response.GetResponseStream());
            Console.WriteLine(atomEntry.Id.Uri);
            int id = int.Parse(atomEntry.Id.Uri.ToString().Substring(atomEntry.Id.Uri.ToString().LastIndexOf("/") + 1));

            Assert.IsTrue(id > 0);
            Console.WriteLine(string.Format("Id: {0}", id));
            Blog.DeleteImage(Ticket, id);
        }
        private static AtomEntry LoadEntryContent(Stream stream)
        {
            var entry = new AtomEntry();

            entry.Load(stream);
            return(entry);
        }
Ejemplo n.º 3
0
 public void TestUri()
 {
     for (int i = 0; i < files.Length; i++)
     {
         Console.WriteLine("{0}: {1}", i, files[i]);
         entry = AtomEntry.Load(files[i], new Uri("http://purl.org/atom/ns#"));
         Assert.IsNotNull(entry.Uri);
     }
 }
Ejemplo n.º 4
0
 public void TestUri()
 {
     for (int i = 0; i < files.Length; i++)
     {
         Console.WriteLine("{0}: {1}", i, files[i]);
         entry = AtomEntry.Load(files[i]);
         Assert.IsNotNull(entry.Uri);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Provides example code for the Load(Uri, ICredentials, IWebProxy) method
        /// </summary>
        public static void LoadUriExample()
        {
            AtomEntry entry  = new AtomEntry();
            Uri       source = new Uri("http://example.org/blog/1234");

            entry.Load(source, CredentialCache.DefaultNetworkCredentials, null);

            if (entry.UpdatedOn >= DateTime.Today)
            {
                //  Perform some processing on the entry
            }
        }
Ejemplo n.º 6
0
        public void TestSaveToFile()
        {
            string filename = "test";

            for (int i = 0; i < files.Length; i++)
            {
                entry = AtomEntry.Load(files[i], new Uri("http://purl.org/atom/ns#"));
                Assert.IsNotNull(entry);
                entry.Save(filename);
                File.Delete(filename);
            }
        }
Ejemplo n.º 7
0
        public void TestSaveToFile()
        {
            string filename = "test";

            for (int i = 0; i < files.Length; i++)
            {
                entry = AtomEntry.Load(files[i]);
                Assert.IsNotNull(entry);
                entry.Save(filename);
                File.Delete(filename);
            }
        }
Ejemplo n.º 8
0
 public void TestStream()
 {
     for (int i = 0; i < files.Length; i++)
     {
         FileStream stream = File.OpenRead(files[i]);
         entry = AtomEntry.Load(stream);
         Assert.IsNotNull(entry);
         MemoryStream memStream = new MemoryStream();
         entry.Save(memStream);
         stream.Close();
     }
 }
Ejemplo n.º 9
0
 public void TestTextReaderWriter()
 {
     for (int i = 0; i < files.Length; i++)
     {
         StreamReader reader = new StreamReader(files[i]);
         entry = AtomEntry.Load(reader);
         Assert.IsNotNull(entry);
         MemoryStream stream = new MemoryStream();
         StreamWriter w      = new StreamWriter(stream);
         entry.Save(w);
         stream.Close();
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Provides example code for the Load(IXPathNavigable) method
        /// </summary>
        public static void LoadIXPathNavigableExample()
        {
            XPathDocument source = new XPathDocument("http://example.org/blog/1234");

            AtomEntry entry = new AtomEntry();

            entry.Load(source);

            if (entry.UpdatedOn >= DateTime.Today)
            {
                //  Perform some processing on the entry
            }
        }
Ejemplo n.º 11
0
 public void TestXmlReaderXmlWriter()
 {
     for (int i = 0; i < files.Length; i++)
     {
         XmlTextReader reader = new XmlTextReader(files[i]);
         entry = AtomEntry.Load(reader);
         Assert.IsNotNull(entry);
         MemoryStream  stream = new MemoryStream();
         XmlTextWriter writer = new XmlTextWriter(stream,
                                                  System.Text.Encoding.Default);
         entry.Save(writer);
         stream.Close();
     }
 }
Ejemplo n.º 12
0
        public void TestInvalidEntries()
        {
            string filename = "test";

            entriespath = @"..\..\tests\invalidentries\";
            files       = Directory.GetFiles(entriespath);
            for (int i = 0; i < files.Length; i++)
            {
                entry = AtomEntry.Load(files[i]);
                Assert.IsNotNull(entry);
                entry.Save(filename);
                File.Delete(filename);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Provides example code for the Load(Stream) method
        /// </summary>
        public static void LoadStreamExample()
        {
            AtomEntry entry = new AtomEntry();

            using (Stream stream = new FileStream("AtomEntryDocument.xml", FileMode.Open, FileAccess.Read))
            {
                entry.Load(stream);

                if (entry.UpdatedOn >= DateTime.Today)
                {
                    //  Perform some processing on the entry
                }
            }
        }
Ejemplo n.º 14
0
 public void TestNameIsNotEmail()
 {
     foreach (string file in files)
     {
         entry = AtomEntry.Load(file);
         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));
         }
     }
 }
Ejemplo n.º 15
0
        public void AtomNewPostTest()
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/DBlog/AtomPost.aspx");

            request.Method      = "POST";
            request.ContentType = "application/atom+xml;type=entry";
            string usernamePassword   = string.Format("Administrator:");
            string basicAuthorization = string.Format("Basic {0}", Convert.ToBase64String(
                                                          Encoding.ASCII.GetBytes(usernamePassword)));

            request.Headers.Add("Authorization", basicAuthorization);
            XmlDocument postXml = new XmlDocument();

            postXml.LoadXml(
                "<?xml version=\"1.0\"?>" +
                "<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
                "<title>Atom-Powered Robots Run Amok</title>" +
                "<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>" +
                "<updated>2003-12-13T18:30:02Z</updated>" +
                "<author><name>John Doe</name></author>" +
                "<content>Some text.</content>" +
                "</entry>");
            byte[] postData = Encoding.UTF8.GetBytes(postXml.OuterXml);
            request.ContentLength = postData.Length;
            request.GetRequestStream().Write(postData, 0, postData.Length);
            request.GetRequestStream().Close();
            HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
            string          responseLocation = response.Headers["Location"];

            Assert.IsNotEmpty(responseLocation);
            Console.WriteLine(responseLocation);
            // atom entry returned
            AtomEntry atomEntry = new AtomEntry();

            atomEntry.Load(response.GetResponseStream());
            Console.WriteLine(atomEntry.Id.Uri);
            int id = int.Parse(atomEntry.Id.Uri.ToString().Substring(atomEntry.Id.Uri.ToString().LastIndexOf("/") + 1));

            Assert.IsTrue(id > 0);
            Console.WriteLine(string.Format("Id: {0}", id));
            Blog.DeletePost(Ticket, id);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Provides example code for the Load(XmlReader) method
        /// </summary>
        public static void LoadXmlReaderExample()
        {
            AtomEntry entry = new AtomEntry();

            using (Stream stream = new FileStream("AtomEntryDocument.xml", FileMode.Open, FileAccess.Read))
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments   = true;
                settings.IgnoreWhitespace = true;

                using (XmlReader reader = XmlReader.Create(stream, settings))
                {
                    entry.Load(reader);

                    if (entry.UpdatedOn >= DateTime.Today)
                    {
                        //  Perform some processing on the entry
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public void Typical_Entry()
        {
            var xml   = @"<entry xmlns=""http://www.w3.org/2005/Atom""
                               xmlns:sync=""http://schemas.sage.com/sdata/sync/2008/1"">
                          <sync:syncState>
                            <sync:endpoint>http://www.example.com/sdata/myApp1/myContract/-/accounts</sync:endpoint>
                            <sync:tick>5</sync:tick>
                            <sync:stamp>2008-10-30T14:55:43Z</sync:stamp>
                          </sync:syncState>
                        </entry>";
            var entry = new AtomEntry();

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                entry.Load(stream);
            }

            var syncState = entry.GetSDataSyncState();

            Assert.That(syncState.EndPoint, Is.EqualTo("http://www.example.com/sdata/myApp1/myContract/-/accounts"));
            Assert.That(syncState.Tick, Is.EqualTo(5L));
            Assert.That(syncState.Stamp, Is.EqualTo(new DateTime(2008, 10, 30, 14, 55, 43)));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Instantiates a <see cref="ISyndicationResource"/> that conforms to the specified <see cref="SyndicationContentFormat"/> using the supplied <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> used to load the syndication resource.</param>
        /// <param name="format">A <see cref="SyndicationContentFormat"/> enumeration value that indicates the type syndication resource the <paramref name="stream"/> represents.</param>
        /// <returns>
        ///     An <see cref="ISyndicationResource"/> object that conforms to the specified <paramref name="format"/>, initialized using the supplied <paramref name="stream"/>.
        ///     If the <paramref name="format"/> is not supported by the provider, returns a <b>null</b> reference.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception>
        private static ISyndicationResource BuildResource(SyndicationContentFormat format, Stream stream)
        {
            Guard.ArgumentNotNull(stream, "stream");

            if (format == SyndicationContentFormat.Apml)
            {
                ApmlDocument document = new ApmlDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Atom)
            {
                XPathDocument  document  = new XPathDocument(stream);
                XPathNavigator navigator = document.CreateNavigator();
                navigator.MoveToRoot();
                navigator.MoveToChild(XPathNodeType.Element);

                if (String.Compare(navigator.LocalName, "entry", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomEntry entry = new AtomEntry();
                    entry.Load(navigator);
                    return(entry);
                }
                else if (String.Compare(navigator.LocalName, "feed", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomFeed feed = new AtomFeed();
                    feed.Load(navigator);
                    return(feed);
                }
                else
                {
                    return(null);
                }
            }
            else if (format == SyndicationContentFormat.BlogML)
            {
                BlogMLDocument document = new BlogMLDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Opml)
            {
                OpmlDocument document = new OpmlDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Rsd)
            {
                RsdDocument document = new RsdDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Rss)
            {
                RssFeed feed = new RssFeed();
                feed.Load(stream);
                return(feed);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 19
0
    private void CreateOrUpdatePost(object sender, EventArgs e)
    {
        SessionManager.BasicAuth();

        if (!SessionManager.IsAdministrator)
        {
            throw new ManagedLogin.AccessDeniedException();
        }

        AtomEntry atomEntry = new AtomEntry();

        atomEntry.Load(Request.InputStream);

        TransitPost post = (RequestId > 0)
            ? SessionManager.BlogService.GetPostById(SessionManager.Ticket, RequestId)
            : new TransitPost();

        post.Title = atomEntry.Title.Content;

        List <TransitTopic> topics = new List <TransitTopic>();

        foreach (AtomCategory category in atomEntry.Categories)
        {
            TransitTopic topic = SessionManager.BlogService.GetTopicByName(SessionManager.Ticket, category.Term);
            if (topic == null)
            {
                topic      = new TransitTopic();
                topic.Name = category.Term;
            }
            topics.Add(topic);
        }

        post.Topics  = topics.ToArray();
        post.Body    = atomEntry.Content.Content;
        post.Publish = true;
        post.Display = true;
        post.Sticky  = false;
        post.Export  = false;

        if (atomEntry.PublishedOn != DateTime.MinValue)
        {
            post.Created = atomEntry.PublishedOn;
        }
        if (atomEntry.UpdatedOn != DateTime.MinValue)
        {
            post.Modified = atomEntry.UpdatedOn;
        }

        post.Id = SessionManager.BlogService.CreateOrUpdatePost(SessionManager.Ticket, post);

        Response.ContentType       = "application/atom+xml;type=entry;charset=\"utf-8\"";
        Response.StatusCode        = 201;
        Response.StatusDescription = "Created";
        string location = string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id);

        Response.Headers.Add("Location", location);
        Response.Headers.Add("Content-Location", location);
        Response.Headers.Add("ETag", string.Format("\"{0}\"", Guid.NewGuid().ToString()));

        atomEntry.Id = new AtomId(new Uri(string.Format("{0}Post/{1}", SessionManager.WebsiteUrl, post.Id)));
        atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id))));
        atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)), "edit"));
        AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri)), "alternate");

        atomEntryUri.ContentType = "text/html";
        atomEntry.Links.Add(atomEntryUri);
        atomEntry.Save(Response.OutputStream);

        Response.End();
    }