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