示例#1
0
        public static bool HasAccess(ISession session, DBlog.Data.Comment comment, string ticket)
        {
            if (comment.PostComments == null || comment.PostComments.Count == 0)
            {
                return(true);
            }

            foreach (PostComment pi in comment.PostComments)
            {
                if (TransitPost.GetAccess(session, pi.Post, ticket))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        public static bool HasAccess(ISession session, DBlog.Data.Image image, string ticket)
        {
            if (image.PostImages == null || image.PostImages.Count == 0)
            {
                return(true);
            }

            foreach (PostImage pi in image.PostImages)
            {
                if (TransitPost.GetAccess(session, pi.Post, ticket))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        protected override int UpdateFeedItems(ISession session)
        {
            string urlServicePost = ServicePostUrl;

            IList <Post> posts = session.CreateCriteria(typeof(Post))
                                 .Add(Expression.Ge("Modified", mFeed.Saved))
                                 .Add(Expression.Eq("Publish", true))
                                 .Add(Expression.Eq("Display", true))
                                 .AddOrder(Order.Desc("Modified"))
                                 .List <Post>();

            foreach (Post post in posts)
            {
                XmlDocument xmlEntry = new XmlDocument();
                xmlEntry.LoadXml(
                    "<?xml version=\"1.0\"?>" +
                    "<entry xmlns=\"" + AtomNamespace + "\">" +
                    "<title type=\"text/html\" />" +
                    "<created />" +
                    "<content type=\"text/html\" mode=\"escaped\" />" +
                    "</entry>");

                XmlNamespaceManager xmlnsmgr = new XmlNamespaceManager(xmlEntry.NameTable);
                xmlnsmgr.AddNamespace("ns", AtomNamespace);

                xmlEntry.SelectSingleNode("//ns:title", xmlnsmgr).InnerText   = Renderer.RenderEx(post.Title, ConfigurationManager.AppSettings["url"], null);
                xmlEntry.SelectSingleNode("//ns:created", xmlnsmgr).InnerText = post.Modified.ToString("s");
                xmlEntry.SelectSingleNode("//ns:content", xmlnsmgr).InnerText = TransitPost.RenderXHTML(session, post);

                HttpWebRequest FeedRequest = (HttpWebRequest)WebRequest.Create(urlServicePost);
                if (!string.IsNullOrEmpty(mFeed.Username))
                {
                    FeedRequest.Credentials = new NetworkCredential(mFeed.Username, mFeed.Password, null);
                }

                // from http://haacked.com/archive/2004/05/15/449.aspx
                System.Net.ServicePointManager.Expect100Continue = false;

                FeedRequest.AllowAutoRedirect            = false;
                FeedRequest.Method                       = "POST";
                FeedRequest.UserAgent                    = "DBlog.NET/2.0";
                FeedRequest.ContentType                  = "application/x.atom+xml;charset=utf-8";
                FeedRequest.Timeout                      = 5000;
                FeedRequest.KeepAlive                    = false;
                FeedRequest.MaximumAutomaticRedirections = 5;

                MemoryStream  utf8ms = new MemoryStream();
                XmlTextWriter utf8tw = new XmlTextWriter(utf8ms, new UTF8Encoding(false));
                xmlEntry.Save(utf8tw);

                byte[] byteData = utf8ms.ToArray();
                FeedRequest.ContentLength = byteData.Length;
                FeedRequest.GetRequestStream().Write(byteData, 0, byteData.Length);
                FeedRequest.GetRequestStream().Close();

                try
                {
                    StreamReader tx = new StreamReader(FeedRequest.GetResponse().GetResponseStream());
                    string       s  = tx.ReadToEnd();
                    mFeed.Saved = post.Modified;
                }
                catch (WebException ex)
                {
                    if (ex.Response != null)
                    {
                        StreamReader rx = new StreamReader(ex.Response.GetResponseStream());
                        string       s  = rx.ReadToEnd();
                        s += ("<br>" + urlServicePost);
                        throw new Exception(s);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }

            return(posts.Count);
        }
示例#4
0
 private AtomEntry GetPost(TransitPost post)
 {
     AtomEntry atomEntry = new AtomEntry();
     atomEntry.Title = new AtomTextConstruct(post.Title);
     foreach (TransitTopic topic in post.Topics)
     {
         atomEntry.Categories.Add(new AtomCategory(topic.Name));
     }
     atomEntry.Content = new AtomContent(post.BodyXHTML, "html");
     atomEntry.PublishedOn = post.Created;
     atomEntry.UpdatedOn = post.Modified;
     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}AtomBlog.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);
     return atomEntry;
 }
示例#5
0
 public TransitPostLogin(ISession session, DBlog.Data.PostLogin o)
     : base(o.Id)
 {
     Post = new TransitPost(session, o.Post, false);
     Login = new TransitLogin(o.Login);
 }
示例#6
0
 public TransitPostTopic(ISession session, DBlog.Data.PostTopic o)
     : base(o.Id)
 {
     Post = new TransitPost(session, o.Post, false);
     Topic = new TransitTopic(o.Topic);
 }
示例#7
0
 public TransitPostTopic(ISession session, DBlog.Data.PostTopic o)
     : base(o.Id)
 {
     Post  = new TransitPost(session, o.Post, false);
     Topic = new TransitTopic(o.Topic);
 }
示例#8
0
 public TransitPostLogin(ISession session, DBlog.Data.PostLogin o)
     : base(o.Id)
 {
     Post  = new TransitPost(session, o.Post, false);
     Login = new TransitLogin(o.Login);
 }
示例#9
0
 public TransitPostImage(ISession session, DBlog.Data.PostImage o, string ticket)
     : base(o.Id)
 {
     Post = new TransitPost(session, o.Post, ticket);
     Image = new TransitImage(session, o.Image, ticket);
 }
示例#10
0
 public TransitPostImage(ISession session, DBlog.Data.PostImage o, string ticket)
     : base(o.Id)
 {
     Post  = new TransitPost(session, o.Post, ticket);
     Image = new TransitImage(session, o.Image, ticket);
 }
示例#11
0
 public TransitPostComment(ISession session, DBlog.Data.PostComment o, string ticket)
     : base(session, o.Post.Id, o.Comment, TransitPost.GetAccess(session, o.Post, ticket))
 {
     AssociatedType = "Post";
 }
示例#12
0
 public int GeneratePostSlugs(string ticket)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CheckAdministrator(session, ticket);
         IList<Post> list = session.CreateCriteria(typeof(Post))
             .Add(Restrictions.IsNull("Slug"))
             .List<Post>();
         foreach(Post post in list)
         {
             TransitPost t_post = new TransitPost(session, post, true);
             t_post.GenerateSlug(session);
             post.Slug = t_post.Slug;
             session.Save(post);
             session.Flush();
         }
         return list.Count;
     }
 }
示例#13
0
        public int CreateOrUpdatePost(string ticket, TransitPost t_post)
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;
                CheckAdministrator(session, ticket);
                if (t_post.LoginId == 0) t_post.LoginId = ManagedLogin.GetLoginId(ticket);
                t_post.GenerateSlug(session);
                Post post = t_post.GetPost(session);
                post.Modified = DateTime.UtcNow;
                if (post.Id == 0) post.Created = post.Modified;
                session.SaveOrUpdate(post);

                if (t_post.Topics != null)
                {
                    foreach (TransitTopic t_topic in t_post.Topics)
                    {
                        if (t_topic.Id == 0)
                        {
                            Topic topic = t_topic.GetTopic(session);
                            session.SaveOrUpdate(topic);
                            t_topic.Id = topic.Id;
                        }
                    }
                }

                List<PostTopic> postTopicsToBeCreated = null;
                List<PostTopic> postTopicsToBeDeleted = null;
                TransitTopic.MergeTo(session, post, t_post.Topics, out postTopicsToBeCreated, out postTopicsToBeDeleted);
                foreach (PostTopic postTopic in postTopicsToBeCreated) session.Save(postTopic);
                foreach (PostTopic postTopic in postTopicsToBeDeleted) session.Delete(postTopic);
                session.Flush();
                return post.Id;
            }
        }
示例#14
0
 public TransitPost GetPostBySlug(string ticket, string slug)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         Post post = (Post)session.CreateCriteria(typeof(Post))
             .Add(Expression.Eq("Slug", slug))
             .UniqueResult<Post>();
         TransitPost t_post = new TransitPost(session, post, ticket);
         return t_post;
     }
 }
示例#15
0
 public TransitPost GetPostById(string ticket, int id)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         Post post = (Post)session.Load(typeof(Post), id);
         TransitPost t_post = new TransitPost(session, post, ticket);
         return t_post;
     }
 }