Esempio n. 1
0
    private void CreateOrUpdateImage(object sender, EventArgs e)
    {
        SessionManager.BasicAuth();

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

        TransitImage image = (RequestId > 0)
            ? SessionManager.BlogService.GetImageById(SessionManager.Ticket, RequestId)
            : new TransitImage();

        image.Name = string.Format("{0}.jpg", Request.Headers["Slug"]);
        image.Data = new byte[Request.InputStream.Length];
        Request.InputStream.Read(image.Data, 0, (int)Request.InputStream.Length);

        image.Id = SessionManager.BlogService.CreateOrUpdateImage(SessionManager.Ticket, image);

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

        Response.Headers.Add("Location", location);

        AtomEntry atomEntry = GetImage(image);

        atomEntry.Save(Response.OutputStream);
        Response.End();
    }
Esempio n. 2
0
    private void GetPost(object sender, EventArgs e)
    {
        Response.ContentType = "application/atom+xml;type=entry;charset=\"utf-8\"";
        TransitPost post      = SessionManager.BlogService.GetPostById(SessionManager.Ticket, RequestId);
        AtomEntry   atomEntry = GetPost(post);

        atomEntry.Save(Response.OutputStream);
        Response.End();
    }
Esempio n. 3
0
        /// <summary>
        /// Provides example code for the Save(Stream) method
        /// </summary>
        public static void SaveStreamExample()
        {
            AtomEntry entry = new AtomEntry();

            //  Modify entry state using public properties and methods

            using (Stream stream = new FileStream("AtomEntryDocument.xml", FileMode.Create, FileAccess.Write))
            {
                entry.Save(stream);
            }
        }
Esempio n. 4
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();
     }
 }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
    public void GetImage(object sender, EventArgs e)
    {
        TransitImage image = SessionManager.BlogService.GetImageById(SessionManager.Ticket, RequestId);

        Response.ContentType = "application/atom+xml;type=entry;charset=\"utf-8\"";
        Response.Headers.Add("ETag", string.Format("\"{0}\"", Guid.NewGuid().ToString()));

        AtomEntry atomEntry = GetImage(image);

        atomEntry.Save(Response.OutputStream);
        Response.End();
    }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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();
     }
 }
Esempio n. 9
0
        public void TestXmlFragment()
        {
            string filename = "test";

            for (int i = 0; i < files.Length; i++)
            {
                StreamReader reader  = new StreamReader(files[i]);
                string       content = reader.ReadToEnd();
                entry = AtomEntry.LoadXml(content);
                Assert.IsNotNull(entry);
                entry.Save(filename);
                File.Delete(filename);
            }
        }
Esempio n. 10
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();
     }
 }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            using (var xw = XmlWriter.Create(sb, new XmlWriterSettings()
            {
                Indent = true
            })) {
                entry.Save(xw, new SyndicationResourceSaveSettings()
                {
                    CharacterEncoding = Encoding.UTF8
                });
            }

            return(sb.ToString());
        }
Esempio n. 13
0
        /// <summary>
        /// Provides example code for the Save(XmlWriter) method
        /// </summary>
        public static void SaveXmlWriterExample()
        {
            AtomEntry entry = new AtomEntry();

            //  Modify entry state using public properties and methods

            using (Stream stream = new FileStream("AtomEntryDocument.xml", FileMode.Create, FileAccess.Write))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    entry.Save(writer);
                }
            }
        }
Esempio n. 14
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();
    }