NotificationDefinition.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using Abp.Application.Features;
  4. using Abp.Authorization;
  5. using Abp.Collections.Extensions;
  6. using Abp.Localization;
  7. namespace Abp.Notifications
  8. {
  9. /// <summary>
  10. /// Definition for a notification.
  11. /// </summary>
  12. public class NotificationDefinition
  13. {
  14. /// <summary>
  15. /// Unique name of the notification.
  16. /// </summary>
  17. public string Name { get; private set; }
  18. /// <summary>
  19. /// Related entity type with this notification (optional).
  20. /// </summary>
  21. public Type EntityType { get; private set; }
  22. /// <summary>
  23. /// Display name of the notification.
  24. /// Optional.
  25. /// </summary>
  26. public ILocalizableString DisplayName { get; set; }
  27. /// <summary>
  28. /// Description for the notification.
  29. /// Optional.
  30. /// </summary>
  31. public ILocalizableString Description { get; set; }
  32. /// <summary>
  33. /// A permission dependency. This notification will be available to a user if this dependency is satisfied.
  34. /// Optional.
  35. /// </summary>
  36. public IPermissionDependency PermissionDependency { get; set; }
  37. /// <summary>
  38. /// A feature dependency. This notification will be available to a tenant if this feature is enabled.
  39. /// Optional.
  40. /// </summary>
  41. public IFeatureDependency FeatureDependency { get; set; }
  42. /// <summary>
  43. /// Gets/sets arbitrary objects related to this object.
  44. /// Gets null if given key does not exists.
  45. /// This is a shortcut for <see cref="Attributes"/> dictionary.
  46. /// </summary>
  47. /// <param name="key">Key</param>
  48. public object this[string key]
  49. {
  50. get { return Attributes.GetOrDefault(key); }
  51. set { Attributes[key] = value; }
  52. }
  53. /// <summary>
  54. /// Arbitrary objects related to this object.
  55. /// These objects must be serializable.
  56. /// </summary>
  57. public IDictionary<string, object> Attributes { get; private set; }
  58. /// <summary>
  59. /// Initializes a new instance of the <see cref="NotificationDefinition"/> class.
  60. /// </summary>
  61. /// <param name="name">Unique name of the notification.</param>
  62. /// <param name="entityType">Related entity type with this notification (optional).</param>
  63. /// <param name="displayName">Display name of the notification.</param>
  64. /// <param name="description">Description for the notification</param>
  65. /// <param name="permissionDependency">A permission dependency. This notification will be available to a user if this dependency is satisfied.</param>
  66. /// <param name="featureDependency">A feature dependency. This notification will be available to a tenant if this feature is enabled.</param>
  67. public NotificationDefinition(string name, Type entityType = null, ILocalizableString displayName = null, ILocalizableString description = null, IPermissionDependency permissionDependency = null, IFeatureDependency featureDependency = null)
  68. {
  69. if (string.IsNullOrWhiteSpace(name))
  70. {
  71. throw new ArgumentNullException("name", "name can not be null, empty or whitespace!");
  72. }
  73. Name = name;
  74. EntityType = entityType;
  75. DisplayName = displayName;
  76. Description = description;
  77. PermissionDependency = permissionDependency;
  78. FeatureDependency = featureDependency;
  79. Attributes = new Dictionary<string, object>();
  80. }
  81. }
  82. }