public HttpResponseMessage Post(BlogRollItem item)
    {
        if (!Security.IsAdministrator)
            return Request.CreateResponse(HttpStatusCode.Unauthorized, item);

        BlogEngine.Core.Providers.BlogService.InsertBlogRoll(item);
        return Request.CreateResponse(HttpStatusCode.Created, item);
    }
示例#2
0
        /// <summary>
        /// Fills an unsorted list of BlogRolls.
        /// </summary>
        /// <returns>A List&lt;BlogRoll&gt; of all BlogRolls</returns>
        public override List<BlogRollItem> FillBlogRoll()
        {
            string fileName = _Folder + "blogroll.xml";
            if (!File.Exists(fileName))
                return null;

            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);
            List<BlogRollItem> blogRoll = new List<BlogRollItem>();

            int largestSortIndex = -1;
            bool isLegacyFormat = false;
            XmlNodeList nodes = doc.SelectNodes("blogRoll/item");
            if (nodes.Count == 0)
            {
                // legacy file format.
                nodes = doc.SelectNodes("opml/body/outline");
                isLegacyFormat = true;
            }
            foreach (XmlNode node in nodes)
            {
                BlogRollItem br = new BlogRollItem()
                {
                    Id = node.Attributes["id"] == null ? Guid.NewGuid() : new Guid(node.Attributes["id"].InnerText),
                    Title = node.Attributes["title"] == null ? null : node.Attributes["title"].InnerText,
                    Description = node.Attributes["description"] == null ? null : node.Attributes["description"].InnerText,
                    BlogUrl = node.Attributes["htmlUrl"] == null ? null : new Uri(node.Attributes["htmlUrl"].InnerText),
                    FeedUrl = node.Attributes["xmlUrl"] == null ? null : new Uri(node.Attributes["xmlUrl"].InnerText),
                    Xfn = node.Attributes["xfn"] == null ? null : node.Attributes["xfn"].InnerText,
                    SortIndex = node.Attributes["sortIndex"] == null ? (blogRoll.Count == 0 ? 0 : largestSortIndex + 1) : int.Parse(node.Attributes["sortIndex"].InnerText)
                };

                if (br.SortIndex > largestSortIndex)
                    largestSortIndex = br.SortIndex;

                blogRoll.Add(br);
                br.MarkOld();
            }

            if (isLegacyFormat && blogRoll.Count > 0)
            {
                // if we're upgrading from a legacy format, re-write the file to conform to the new format.
                writeBlogRollFile(blogRoll);
            }

            return blogRoll;
        }
    public HttpResponseMessage Post(BlogRollRowItem item)
    {
        BlogRollItem br = new BlogRollItem();
        br.Title = item.Title.Replace(@"\", "'");
        br.Description = item.Description;
        br.BlogUrl = new Uri(getUrl(item.BlogUrl));
        br.FeedUrl = new Uri(getUrl(item.FeedUrl));
        br.Xfn = item.Xfn.TrimEnd();

        int largestSortIndex = -1;
        foreach (BlogRollItem brExisting in BlogRollItem.BlogRolls)
        {
            if (brExisting.SortIndex > largestSortIndex)
                largestSortIndex = brExisting.SortIndex;
        }
        br.SortIndex = largestSortIndex + 1;
        br.Save();

        return Request.CreateResponse(HttpStatusCode.Created, br);
    }
示例#4
0
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        private static void AddBlog(BlogEngine.Core.BlogRollItem br)
        {
            blogRequest affected = null;

            foreach (blogRequest req in _Items)
            {
                if (req.RollItem.Equals(br))
                {
                    affected = req;
                    break;
                }
            }
            if (affected == null)
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(br.FeedUrl);
                req.Credentials = CredentialCache.DefaultNetworkCredentials;

                blogRequest bReq = new blogRequest(br, req);
                _Items.Add(bReq);
                req.BeginGetResponse(ProcessRespose, bReq);
            }
        }
示例#5
0
        private void AddBlog()
        {
            BlogRollItem br = new BlogRollItem();
            br.Title = txtTitle.Text.Replace(@"\", "'");
            br.Description = txtDescription.Text;
            br.BlogUrl = new Uri(getUrl(txtWebUrl.Text));
            br.FeedUrl = new Uri(getUrl(txtFeedUrl.Text));
            br.Xfn = string.Empty;

            foreach (ListItem item in cblXfn.Items)
            {
                if (item.Selected)
                    br.Xfn += item.Text + " ";
            }
            if (br.Xfn.Length > 0)
            {
                br.Xfn = br.Xfn.Substring(0, br.Xfn.Length - 1);
            }

            int largestSortIndex = -1;
            foreach (BlogRollItem brExisting in BlogRollItem.BlogRolls)
            {
                if (brExisting.SortIndex > largestSortIndex)
                    largestSortIndex = brExisting.SortIndex;
            }

            br.SortIndex = largestSortIndex + 1;
            br.Save();
        }
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        /// <param name="br">
        /// The blogroll item.
        /// </param>
        private static void AddBlog(BlogRollItem br)
        {
            var affected = items.FirstOrDefault(r => r.RollItem.Equals(br));
            if (affected != null)
            {
                return;
            }

            var req = (HttpWebRequest)WebRequest.Create(br.FeedUrl);
            req.Credentials = CredentialCache.DefaultNetworkCredentials;

            var blogRequest = new BlogRequest(br, req);
            items.Add(blogRequest);
            req.BeginGetResponse(ProcessResponse, blogRequest);
        }
示例#7
0
    public HttpResponseMessage Post(BlogRollRowItem item)
    {
        try
        {
            BlogRollItem br = new BlogRollItem();
            br.Title = item.Title.Replace(@"\", "'");
            br.Description = item.Description;
            br.BlogUrl = new Uri(getUrl(item.BlogUrl));
            br.FeedUrl = new Uri(getUrl(item.FeedUrl));
            br.Xfn = item.Xfn.TrimEnd();

            int largestSortIndex = -1;
            foreach (BlogRollItem brExisting in BlogRollItem.BlogRolls)
            {
                if (brExisting.SortIndex > largestSortIndex)
                    largestSortIndex = brExisting.SortIndex;
            }
            br.SortIndex = largestSortIndex + 1;
            br.Save();

            if (br == null)
                return Request.CreateResponse(HttpStatusCode.NotFound);

            return Request.CreateResponse(HttpStatusCode.Created, br);
        }
        catch (UnauthorizedAccessException)
        {
            return Request.CreateResponse(HttpStatusCode.Unauthorized, Resources.labels.notAuthorized);
        }
        catch (Exception ex)
        {
            return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
        }
    }
示例#8
0
 internal blogRequest(BlogEngine.Core.BlogRollItem rollItem, HttpWebRequest request)
 {
     this.RollItem = rollItem;
     this.Request = request;
 }
示例#9
0
 internal blogRequest(BlogEngine.Core.BlogRollItem rollItem, HttpWebRequest request)
 {
     this.RollItem = rollItem;
     this.Request  = request;
 }
示例#10
0
 /// <summary>
 /// Updates an existing BlogRoll in the data store specified by the provider.
 /// </summary>
 public abstract void UpdateBlogRollItem(BlogRollItem blogRollItem);
示例#11
0
 /// <summary>
 /// Deletes a BlogRoll from the data store specified by the provider.
 /// </summary>
 public abstract void DeleteBlogRollItem(BlogRollItem blogRollItem);
示例#12
0
        /// <summary>
        /// Inserts a BlogRoll
        /// </summary>
        /// <param name="blogRoll">Must be a valid BlogRoll object.</param>
        public override void InsertBlogRollItem(BlogRollItem blogRollItem)
        {
            List<BlogRollItem> blogRolls = BlogRollItem.BlogRolls;
            blogRolls.Add(blogRollItem);

            writeBlogRollFile(blogRolls);
        }
示例#13
0
 /// <summary>
 /// Deletes a BlogRoll
 /// </summary>
 /// <param name="blogRoll">Must be a valid BlogRoll object.</param>
 public override void DeleteBlogRollItem(BlogRollItem blogRollItem)
 {
     List<BlogRollItem> blogRoll = BlogRollItem.BlogRolls;
     blogRoll.Remove(blogRollItem);
     writeBlogRollFile(blogRoll);
 }
示例#14
0
 /// <summary>
 /// Updates a BlogRoll
 /// </summary>
 /// <param name="blogRoll">Must be a valid BlogRoll object.</param>
 public override void UpdateBlogRollItem(BlogRollItem blogRollItem)
 {
     List<BlogRollItem> blogRolls = BlogRollItem.BlogRolls;
     blogRolls.Remove(blogRollItem);
     blogRolls.Add(blogRollItem);
     writeBlogRollFile(blogRolls);
 }
示例#15
0
 /// <summary>
 /// Gets a BlogRoll based on a Guid.
 /// </summary>
 /// <param name="id">The BlogRoll's Guid.</param>
 /// <returns>A matching BlogRoll</returns>
 public override BlogRollItem SelectBlogRollItem(Guid id)
 {
     BlogRollItem blogRoll = BlogRollItem.BlogRolls.Find(br => br.Id == id);
     if (blogRoll == null)
     {
         blogRoll = new BlogRollItem();
     }
     blogRoll.MarkOld();
     return blogRoll;
 }
示例#16
0
文件: Blogroll.cs 项目: Cycli/Cycli
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        /// <param name="br">
        /// The blogroll item.
        /// </param>
        private static void AddBlog(BlogRollItem br)
        {
            var affected = Items.FirstOrDefault(r => r.RollItem.Equals(br));
            if (affected != null)
            {
                return;
            }

            var req = (HttpWebRequest)WebRequest.Create(br.FeedUrl);
            req.Credentials = CredentialCache.DefaultNetworkCredentials;

            var blogRequest = new BlogRequest(br, req);
            Items.Add(blogRequest);

            GetRequestData data = new GetRequestData()
            {
                BlogInstanceId = Blog.CurrentInstance.Id,
                BlogRequest = blogRequest
            };

            req.BeginGetResponse(ProcessResponse, data);
        }
示例#17
0
文件: Blogroll.cs 项目: Cycli/Cycli
 /// <summary>
 /// Initializes a new instance of the <see cref="BlogRequest"/> class.
 /// </summary>
 /// <param name="rollItem">
 /// The roll item.
 /// </param>
 /// <param name="request">
 /// The request.
 /// </param>
 internal BlogRequest(BlogRollItem rollItem, HttpWebRequest request)
 {
     this.ItemTitles = new List<string>();
     this.ItemLinks = new List<string>();
     this.RollItem = rollItem;
     this.Request = request;
 }
示例#18
0
 /// <summary>
 /// Inserts a new BlogRoll into the data store specified by the provider.
 /// </summary>
 public abstract void InsertBlogRollItem(BlogRollItem blogRollItem);