PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/settings/WebCache.cs

https://github.com/moscrif/ide
C# | 73 lines | 60 code | 13 blank | 0 comment | 10 complexity | c78bb16e60c411dbf7688a28d5737a45 MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using System.Xml;
  4. using System.Xml.Serialization;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using Moscrif.IDE.Iface.Entities;
  8. namespace Moscrif.IDE.Option
  9. {
  10. public class WebCache
  11. {
  12. [XmlIgnore]
  13. public string FilePath
  14. {
  15. get;
  16. set;
  17. }
  18. public WebCache()
  19. {
  20. FilePath = System.IO.Path.Combine(MainClass.Paths.SettingDir, ".webcache");
  21. if (ListRss == null) ListRss = new List<WebObject>();
  22. if (ListTweet == null) ListTweet = new List<WebObject>();
  23. }
  24. public WebCache(string filePath)
  25. {
  26. FilePath = filePath;
  27. if (ListRss == null) ListRss = new List<WebObject>();
  28. if (ListTweet == null) ListTweet = new List<WebObject>();
  29. }
  30. public void SaveWebCache()
  31. {
  32. using (FileStream fs = new FileStream(FilePath, FileMode.Create)) {
  33. XmlSerializer serializer = new XmlSerializer(typeof(WebCache));
  34. serializer.Serialize(fs, this);
  35. }
  36. }
  37. static public WebCache OpenWebCache(string filePath)
  38. {
  39. if (System.IO.File.Exists(filePath)) {
  40. try {
  41. using (FileStream fs = File.OpenRead(filePath)) {
  42. XmlSerializer serializer = new XmlSerializer(typeof(WebCache));
  43. WebCache s = (WebCache)serializer.Deserialize(fs);
  44. return s;
  45. }
  46. } catch {//(Exception ex) {
  47. return new WebCache();
  48. }
  49. } else {
  50. return new WebCache();
  51. }
  52. }
  53. [XmlArrayAttribute("rss")]
  54. [XmlArrayItem("item")]
  55. public List<WebObject> ListRss;
  56. [XmlArrayAttribute("twitter")]
  57. [XmlArrayItem("tweet")]
  58. public List<WebObject> ListTweet;
  59. }
  60. }