BaseExtensions.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Globalization;
  3. using System.Text.RegularExpressions;
  4. using MediaBrowser.Model.Cryptography;
  5. namespace MediaBrowser.Common.Extensions
  6. {
  7. /// <summary>
  8. /// Class BaseExtensions
  9. /// </summary>
  10. public static class BaseExtensions
  11. {
  12. public static ICryptoProvider CryptographyProvider { get; set; }
  13. /// <summary>
  14. /// Strips the HTML.
  15. /// </summary>
  16. /// <param name="htmlString">The HTML string.</param>
  17. /// <returns>System.String.</returns>
  18. public static string StripHtml(this string htmlString)
  19. {
  20. // http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
  21. const string pattern = @"<(.|\n)*?>";
  22. return Regex.Replace(htmlString, pattern, string.Empty).Trim();
  23. }
  24. /// <summary>
  25. /// Gets the M d5.
  26. /// </summary>
  27. /// <param name="str">The STR.</param>
  28. /// <returns>Guid.</returns>
  29. public static Guid GetMD5(this string str)
  30. {
  31. return CryptographyProvider.GetMD5(str);
  32. }
  33. /// <summary>
  34. /// Gets the MB id.
  35. /// </summary>
  36. /// <param name="str">The STR.</param>
  37. /// <param name="type">The type.</param>
  38. /// <returns>Guid.</returns>
  39. /// <exception cref="System.ArgumentNullException">type</exception>
  40. [Obsolete("Use LibraryManager.GetNewItemId")]
  41. public static Guid GetMBId(this string str, Type type)
  42. {
  43. if (type == null)
  44. {
  45. throw new ArgumentNullException("type");
  46. }
  47. var key = type.FullName + str.ToLower();
  48. return key.GetMD5();
  49. }
  50. }
  51. }