PageRenderTime 70ms CodeModel.GetById 12ms RepoModel.GetById 5ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Providers/XmlProvider/PingServices.cs

#
C# | 79 lines | 51 code | 11 blank | 17 comment | 3 complexity | 82a61b3bc9df6041280d739b2da7fb56 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace BlogEngine.Core.Providers
  2. {
  3. using System;
  4. using System.Collections.Specialized;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Xml;
  9. /// <summary>
  10. /// A storage provider for BlogEngine that uses XML files.
  11. /// <remarks>
  12. /// To build another provider, you can just copy and modify
  13. /// this one. Then add it to the web.config's BlogEngine section.
  14. /// </remarks>
  15. /// </summary>
  16. public partial class XmlBlogProvider : BlogProvider
  17. {
  18. #region Public Methods
  19. /// <summary>
  20. /// Loads the ping services.
  21. /// </summary>
  22. /// <returns>A StringCollection.</returns>
  23. public override StringCollection LoadPingServices()
  24. {
  25. var fileName = this.Folder + "pingservices.xml";
  26. if (!File.Exists(fileName))
  27. {
  28. return new StringCollection();
  29. }
  30. var col = new StringCollection();
  31. var doc = new XmlDocument();
  32. doc.Load(fileName);
  33. foreach (XmlNode node in
  34. doc.SelectNodes("services/service").Cast<XmlNode>().Where(node => !col.Contains(node.InnerText)))
  35. {
  36. col.Add(node.InnerText);
  37. }
  38. return col;
  39. }
  40. /// <summary>
  41. /// Saves the ping services.
  42. /// </summary>
  43. /// <param name="services">
  44. /// The services.
  45. /// </param>
  46. public override void SavePingServices(StringCollection services)
  47. {
  48. if (services == null)
  49. {
  50. throw new ArgumentNullException("services");
  51. }
  52. var fileName = this.Folder + "pingservices.xml";
  53. using (var writer = new XmlTextWriter(fileName, Encoding.UTF8))
  54. {
  55. writer.Formatting = Formatting.Indented;
  56. writer.Indentation = 4;
  57. writer.WriteStartDocument(true);
  58. writer.WriteStartElement("services");
  59. foreach (var service in services)
  60. {
  61. writer.WriteElementString("service", service);
  62. }
  63. writer.WriteEndElement();
  64. }
  65. }
  66. #endregion
  67. }
  68. }