/UniqueStudio.ComContent/BLL/AutoSaveManager.cs

http://uniquestudiocms.googlecode.com/ · C# · 144 lines · 107 code · 12 blank · 25 comment · 12 complexity · f07796dcd92971d56be51ac30f5bcf36 MD5 · raw file

  1. using System;
  2. using System.Data.Common;
  3. using UniqueStudio.ComContent.DAL;
  4. using UniqueStudio.ComContent.Model;
  5. using UniqueStudio.Common.ErrorLogging;
  6. using UniqueStudio.Common.Exceptions;
  7. using UniqueStudio.Common.Utilities;
  8. namespace UniqueStudio.ComContent.BLL
  9. {
  10. public class AutoSaveManager
  11. {
  12. //
  13. // !!! ??????????
  14. //
  15. private static AutoSaveProvider provider = new AutoSaveProvider();
  16. public AutoSaveManager()
  17. {
  18. }
  19. /// <summary>
  20. /// ??????
  21. /// </summary>
  22. /// <param name="userID">??ID</param>
  23. /// <param name="post">????</param>
  24. /// <returns>????????</returns>
  25. public bool AutoSavePost(Guid userID, PostInfo post)
  26. {
  27. if (post.Title == null)
  28. {
  29. post.Title = string.Empty;
  30. }
  31. if (post.SubTitle == null)
  32. {
  33. post.SubTitle = string.Empty;
  34. }
  35. if (post.Author == null)
  36. {
  37. post.Author = string.Empty;
  38. }
  39. if (post.AddUserName == null)
  40. {
  41. post.AddUserName = string.Empty;
  42. }
  43. if (post.Summary == null)
  44. {
  45. post.Summary = string.Empty;
  46. }
  47. if (post.Content.Trim().ToString() == "")
  48. {
  49. return false;
  50. }
  51. try
  52. {
  53. long userUri = Convert.ToInt64("6" + DateTime.Now.ToString("yyyyMMddHHmmss"));
  54. return provider.AutoSaveFile(userID, post, userUri);
  55. }
  56. catch (Exception ex)
  57. {
  58. ErrorLogger.LogError(ex);
  59. return false;
  60. }
  61. }
  62. /// <summary>
  63. /// ????????????????????
  64. /// </summary>
  65. /// <param name="userID">??ID</param>
  66. /// <returns>?????????</returns>
  67. public PostInfo GetAutoSavedPost(Guid userID)
  68. {
  69. Validator.CheckGuid(userID, "userID");
  70. try
  71. {
  72. return provider.GetAutoSavedPost(userID);
  73. }
  74. catch (DbException ex)
  75. {
  76. ErrorLogger.LogError(ex);
  77. throw new DatabaseException();
  78. }
  79. catch (Exception ex)
  80. {
  81. ErrorLogger.LogError(ex);
  82. throw new UnhandledException();
  83. }
  84. }
  85. /// <summary>
  86. ///
  87. /// </summary>
  88. /// <param name="userId"></param>
  89. /// <returns></returns>
  90. public bool IsPostSaved(Guid userId)
  91. {
  92. Validator.CheckGuid(userId, "userId");
  93. try
  94. {
  95. return provider.IsPostSaved(userId);
  96. }
  97. catch (DbException ex)
  98. {
  99. ErrorLogger.LogError(ex);
  100. throw new DatabaseException();
  101. }
  102. catch (Exception ex)
  103. {
  104. ErrorLogger.LogError(ex);
  105. throw new UnhandledException();
  106. }
  107. }
  108. /// <summary>
  109. /// ????????????
  110. /// </summary>
  111. /// <param name="userID">??ID</param>
  112. /// <param name="isEffictive">????</param>
  113. /// <returns>??????</returns>
  114. public bool SetAutoSaveFileEft(Guid userID, bool isEffictive)
  115. {
  116. try
  117. {
  118. return provider.SetAutoSavePostEft(userID, isEffictive);
  119. }
  120. catch (DbException ex)
  121. {
  122. ErrorLogger.LogError(ex);
  123. throw new DatabaseException();
  124. }
  125. catch (Exception ex)
  126. {
  127. ErrorLogger.LogError(ex);
  128. throw new UnhandledException();
  129. }
  130. }
  131. }
  132. }