PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/CBR/CBR.Core/Services/BookServiceFactory.cs

#
C# | 83 lines | 50 code | 10 blank | 23 comment | 4 complexity | d6d036193235343c163db000990bcbfe MD5 | raw file
  1. using System;
  2. using System.IO;
  3. using CBR.Core.Files;
  4. using CBR.Core.Models;
  5. using CBR.Core.Helpers;
  6. namespace CBR.Core.Services
  7. {
  8. public class BookServiceFactory
  9. {
  10. #region ----------------SINGLETON----------------
  11. public static readonly BookServiceFactory Instance = new BookServiceFactory();
  12. /// <summary>
  13. /// Private constructor for singleton pattern
  14. /// </summary>
  15. private BookServiceFactory()
  16. {
  17. }
  18. #endregion
  19. public BookServiceBase GetService(Book bk)
  20. {
  21. if (bk == null)
  22. return new BookServiceBase();
  23. else
  24. return GetService(bk.FilePath);
  25. }
  26. public BookServiceBase GetService(string filePath)
  27. {
  28. return (BookServiceBase)Activator.CreateInstance(
  29. FileService.Instance.FindBookFilterByExt(Path.GetExtension(filePath)).Service
  30. );
  31. }
  32. //public ViewModelBase GetViewModel(Book bk)
  33. //{
  34. // try
  35. // {
  36. // return GetViewModel(bk.FilePath);
  37. // }
  38. // catch (Exception err)
  39. // {
  40. // ExceptionHelper.Manage("BookServiceFactory:GetViewModel", err);
  41. // return null;
  42. // }
  43. //}
  44. //public ViewModelBase GetViewModel(string filePath)
  45. //{
  46. // FileExtension fe = FileExtensionManager.Instance.FindBookFilterByExt(Path.GetExtension(filePath));
  47. // if (fe != null)
  48. // return (ViewModelBase)new ReflectionHelper().CreateInstance(fe.ViewModel);
  49. // else
  50. // return null;
  51. //}
  52. public string GetViewModel(Book bk)
  53. {
  54. try
  55. {
  56. return GetViewModel(bk.FilePath);
  57. }
  58. catch (Exception err)
  59. {
  60. ExceptionHelper.Manage("BookServiceFactory:GetViewModel", err);
  61. return string.Empty;
  62. }
  63. }
  64. public string GetViewModel(string filePath)
  65. {
  66. FileExtension fe = FileService.Instance.FindBookFilterByExt(Path.GetExtension(filePath));
  67. if (fe != null)
  68. return fe.ViewModel;
  69. else
  70. return string.Empty;
  71. }
  72. }
  73. }