Guest User

Untitled

a guest
Jan 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using Telerik.Sitefinity.Abstractions;
  6. using Telerik.Sitefinity.Multisite;
  7. using Telerik.Sitefinity.Services;
  8. using Telerik.Sitefinity.Utilities.TypeConverters;
  9.  
  10. namespace SitefinityWebApp.Helpers
  11. {
  12. public static class MultisiteHelpers
  13. {
  14. /// <summary>
  15. /// Returns the provider name for the current site.
  16. /// </summary>
  17. /// <param name="moduleName">Name of the Sitefinity module you want to know the prover name.</param>
  18. /// <returns>The sites provider name of empty if not found or in single site mode.</returns>
  19. public static string GetCurrentProvider(string moduleName)
  20. {
  21. var context = SystemManager.CurrentContext;
  22. string providerName = string.Empty;
  23.  
  24. if (moduleName.Contains("DynamicTypes"))
  25. {
  26. moduleName = TypeResolutionService.ResolveType(moduleName).FullName;
  27. }
  28. try
  29. {
  30. if (context.IsMultisiteMode)
  31. {
  32. providerName = context.MultisiteContext.CurrentSite.GetProviders(moduleName).Select(p => p.ProviderName).FirstOrDefault();
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37. Log.Write("Provider not found for " + moduleName, System.Diagnostics.TraceEventType.Error);
  38. Log.Write(ex, System.Diagnostics.TraceEventType.Error);
  39. }
  40.  
  41. return providerName;
  42. }
  43.  
  44. /// <summary>
  45. /// Gets current site Id
  46. /// </summary>
  47. /// <returns>Guid or null</returns>
  48. public static Guid? GetCurrentSiteId()
  49. {
  50. var context = SystemManager.CurrentContext;
  51. Guid? siteId = null;
  52. try
  53. {
  54. if (context.IsMultisiteMode)
  55. {
  56. siteId = context.MultisiteContext.CurrentSite.Id;
  57. }
  58. else
  59. {
  60. siteId = context.CurrentSite.Id;
  61. }
  62. }
  63. catch (Exception ex)
  64. {
  65. Log.Write("Error retrieving site Id", System.Diagnostics.TraceEventType.Error);
  66. Log.Write(ex, System.Diagnostics.TraceEventType.Error);
  67. }
  68.  
  69. return siteId;
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment