Guest User

Untitled

a guest
Jan 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using System.IO;
  7. using EPiServer.Common;
  8. using System.Web.Configuration;
  9.  
  10. using EPiServer.Common.Sorting;
  11. using EPiServer.Common.Reporting;
  12.  
  13. using EPiServer.Community.Blog;
  14.  
  15. using EPiServer.Common.Security;
  16. using EPiServer.Community;
  17. using EPiServer.Common.Cache;
  18. using EPiServer.Common.Categories;
  19. using EPiServer.Common.Data;
  20.  
  21. namespace RelateBugTesting
  22. {
  23.  
  24. class Program
  25. {
  26.  
  27. private class FrameworkFactoryBaseWrapper : FrameworkFactoryBase
  28. {
  29. public static void DoStuff(IEntity e, int id)
  30. {
  31. // need to do it this way as FrameworkFactoryBase.UpdateEntity is protected.
  32. UpdateEntity(e, id);
  33. }
  34. }
  35.  
  36. static void Main(string[] args)
  37. {
  38. // Initialize Community
  39. Initialize();
  40.  
  41. // fetch the bug reports about the first blog
  42. Blog blog = BlogHandler.Instance.GetBlog(4);
  43.  
  44. int totalItems;
  45. foreach (var reportCase in ReportHandler.Instance.GetReportCases(ReportCaseStatus.New, blog, EntityStatus.Approved, null, 1, 10, out totalItems, new ReportCaseSortOrder[] { new ReportCaseSortOrder(ReportCaseSortField.Created, SortingDirection.Ascending) }))
  46. {
  47. Console.WriteLine(reportCase.Comment);
  48. Console.WriteLine("hi");
  49. }
  50.  
  51. // Create Report about the first blog
  52. UserAuthor user = (UserAuthor)AuthorHandler.Instance.GetAuthor(3);
  53.  
  54. IReport r = new Report(blog, user, "testing" + DateTime.Now);
  55.  
  56. // save the report
  57. r = ReportHandler.Instance.AddReport(r);
  58.  
  59. // add a category
  60. ICategory category = new Category("Urban" + DateTime.Now.Minute);
  61.  
  62. // Add it if it doesn't exist
  63. ICategory rootCategory = CategoryHandler.Instance.AddCategory(category);
  64.  
  65. // Add the category to the report
  66. Report reportClone = (Report)r.Clone();
  67. reportClone.Categories.Add(rootCategory);
  68.  
  69. // Haxx to update the categories and attributes
  70. FrameworkFactoryBaseWrapper.DoStuff(reportClone, r.ID);
  71.  
  72. foreach (var reportCase in ReportHandler.Instance.GetReportCases(ReportCaseStatus.New, blog, EntityStatus.Approved, null, 1, 10, out totalItems, new ReportCaseSortOrder[] { new ReportCaseSortOrder(ReportCaseSortField.Created, SortingDirection.Ascending) }))
  73. {
  74. Console.WriteLine(reportCase.Comment);
  75. Console.WriteLine("hello");
  76. //ReportCase rCase = (ReportCase)reportCase.Clone();
  77. //rCase.Categories.Add(rootCategory);
  78. //ReportHandler.Instance.UpdateReportCase(rCase);
  79.  
  80. }
  81. }
  82.  
  83. private static void Initialize()
  84. {
  85. new EPiServer.Framework.Initialization.SiteMappingConfiguration().Initialize(null);
  86. EPiServer.Framework.Initialization.SiteMappingConfiguration.Instance.SiteId = "MyRelateSite";
  87.  
  88. EPiServer.Data.Configuration.EPiServerDataStoreSection.ConfigurationInstance = GetConfigurationFromFile();
  89.  
  90. EPiServer.Common.Configuration.EPiServerCommonSection.ConfigurationInstance = GetConfigurationFromFile();
  91. EPiServer.Community.Configuration.EPiServerCommunitySection.ConfigurationInstance = GetConfigurationFromFile();
  92.  
  93. EPiServer.Common.Settings.LoadSettings();
  94. }
  95.  
  96. private static System.Configuration.Configuration GetConfigurationFromFile()
  97. {
  98. if (System.Web.Hosting.HostingEnvironment.IsHosted)
  99. {
  100. return WebConfigurationManager.OpenWebConfiguration("~/");
  101. }
  102. else
  103. {
  104. WebConfigurationFileMap cfm = new WebConfigurationFileMap();
  105. cfm.VirtualDirectories.Add("/", new VirtualDirectoryMapping(Environment.CurrentDirectory, true));
  106. return WebConfigurationManager.OpenMappedWebConfiguration(cfm, "/");
  107. }
  108. }
  109.  
  110. }
  111.  
  112.  
  113. }
Add Comment
Please, Sign In to add comment