Ejemplo n.º 1
0
        public void TestEncodeAndDecode()
        {
            var eid1    = new EntityIdentifier(EntityType.Organization, _testGuid);
            var eid1Str = eid1.ToString();
            var eid2    = EntityIdentifier.FromString(eid1Str);

            Assert.AreEqual(eid1, eid2);
        }
Ejemplo n.º 2
0
 public async Task UnsubscribeAsync(long userId, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     await _notificationStore.DeleteSubscriptionAsync(
         userId,
         notificationName,
         entityIdentifier?.Type.FullName,
         entityIdentifier?.Id.ToJsonString());
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Gets all subscribtions for given notification.
 ///     TODO: Can work only for single database approach!
 /// </summary>
 /// <param name="notificationSubscriptionManager">Notification subscription manager</param>
 /// <param name="notificationName">Name of the notification.</param>
 /// <param name="entityIdentifier">entity identifier</param>
 public static List <NotificationSubscription> GetSubscriptions(
     this INotificationSubscriptionManager notificationSubscriptionManager, string notificationName,
     EntityIdentifier entityIdentifier = null)
 {
     return
         (AsyncHelper.RunSync(
              () => notificationSubscriptionManager.GetSubscriptionsAsync(notificationName, entityIdentifier)));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NotificationSubscriptionInfo"/> class.
 /// </summary>
 public NotificationSubscriptionInfo(long userId, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     NotificationName = notificationName;
     UserId           = userId;
     EntityTypeName   = entityIdentifier == null ? null : entityIdentifier.Type.FullName;
     EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName;
     EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString();
 }
Ejemplo n.º 5
0
        public async Task UnSubscribeTenantToEditionChanges(Tenant tenant, Edition tenantPrevEdition, User tenantOwner)
        {
            var entityIdentifier = new EntityIdentifier(typeof(Edition), tenantPrevEdition.Id);
            var userIdentifier   = new UserIdentifier(tenant.Id, tenantOwner.Id);
            await _notificationSubscriptionManager.UnsubscribeAsync(userIdentifier, NotificationNames.EditionEdited, entityIdentifier);

            await _notificationSubscriptionManager.UnsubscribeAsync(userIdentifier, NotificationNames.EditionDeleted, entityIdentifier);
        }
Ejemplo n.º 6
0
        public string PrintHierarchy(EntityIdentifier entityId)
        {
            StringBuilder stringBuilder = new StringBuilder();

            PrintHierarchyRecursive(entityId, stringBuilder, 0);

            return(stringBuilder.ToString());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Maps the specified source system entity ID (of the specified type) to its
 /// destination system counterpart.
 /// </summary>
 /// <param name="entityTypeId">The ID of the entity type.</param>
 /// <param name="sourceSystemEntityId">
 /// The ID that uniquely identifies the entity in the current source system.
 /// </param>
 /// <returns>
 /// The ID that uniquely identifies the entity in the destination system; if the
 /// specified source system entity ID isn't mapped, null will be returned.
 /// </returns>
 public EntityIdentifier GetDestinationSystemEntityId(
     Guid entityTypeId,
     EntityIdentifier sourceSystemEntityId)
 {
     return(this.GetDestinationSystemEntityId(
                entityTypeId,
                this.context.SourceSystem.Id,
                sourceSystemEntityId));
 }
 /// <inheritdoc />
 public Task <bool> IsSubscribedAsync(long userId, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     return(_notificationRepository.IsSubscribedAsync(
                userId,
                notificationName,
                entityIdentifier?.Type.FullName,
                entityIdentifier?.Id.ToJsonString()
                ));
 }
Ejemplo n.º 9
0
        private EntityIdentifier getKMEntityIdentifier(string scopingEntityId, string businessId, string version)
        {
            EntityIdentifier kmEntityIdentifier = new EntityIdentifier();

            kmEntityIdentifier.scopingEntityId = scopingEntityId;
            kmEntityIdentifier.version         = version;
            kmEntityIdentifier.businessId      = businessId;
            return(kmEntityIdentifier);
        }
Ejemplo n.º 10
0
 public async Task NotifyAddedAsLeader(Project project, long userId)
 {
     var message          = _localizationManager.GetString(SapConsts.LocalizationSourceName, "AddedToProjectAsLeader");
     var formatedMessage  = string.Format(message, project.Name);
     var entityIdentifier = new EntityIdentifier(typeof(Project), project.Id);
     await
     _notificationPublisher.PublishAsync(TodoNotificationTypes.AddedAsProjectLeader,
                                         new GenericTodoNotification(0, 0, project.Id, formatedMessage, ""), entityIdentifier, userIds : new[] { new UserIdentifier(1, userId), });
 }
Ejemplo n.º 11
0
        private EntityIdentifier getIIEntityIdentifier(string businessId)
        {
            EntityIdentifier iiEntityIdentifier = new EntityIdentifier();

            iiEntityIdentifier.scopingEntityId = "gov.nyc.health";
            iiEntityIdentifier.version         = "1.0.0.0";
            iiEntityIdentifier.businessId      = businessId + "Data";
            return(iiEntityIdentifier);
        }
Ejemplo n.º 12
0
 public SourceSystemEntityIdentity(
     Guid entityTypeId,
     Guid sourceSystemId,
     EntityIdentifier sourceSystemEntityId)
 {
     this.entityTypeId         = entityTypeId;
     this.sourceSystemId       = sourceSystemId;
     this.sourceSystemEntityId = sourceSystemEntityId;
 }
Ejemplo n.º 13
0
 public async Task SilentChatNotification(DiscussionDto discussionDto, Project project)
 {
     //var singleIdentifier = new UserIdentifier(AppConstants.DefaultTenantId, discussionDto.Member.Id);
     //var userIdentifier = new[] { singleIdentifier };
     var entityIdentifier = new EntityIdentifier(typeof(Project), project.Id);
     await
     _notificationPublisher.PublishAsync(TodoNotificationTypes.DiscussionMessage,
                                         new DiscussionMessage(discussionDto), entityIdentifier);
 }
 public Task <bool> IsSubscribedAsync(long userId, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     return(_store.IsSubscribedAsync(
                userId,
                notificationName,
                entityIdentifier == null ? null : entityIdentifier.Type.FullName,
                entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString()
                ));
 }
 public bool IsSubscribed(UserIdentifier user, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     return(_store.IsSubscribed(
                user,
                notificationName,
                entityIdentifier == null ? null : entityIdentifier.Type.FullName,
                entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString()
                ));
 }
Ejemplo n.º 16
0
        public virtual async Task PublishAsync(
            string notificationName,
            NotificationData data             = null,
            EntityIdentifier entityIdentifier = null,
            NotificationSeverity severity     = NotificationSeverity.Info,
            UserIdentifier[] userIds          = null,
            UserIdentifier[] excludedUserIds  = null,
            int?[] tenantIds = null)
        {
            if (notificationName.IsNullOrEmpty())
            {
                throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName");
            }

            if (!tenantIds.IsNullOrEmpty() && !userIds.IsNullOrEmpty())
            {
                throw new ArgumentException("tenantIds can be set only if userIds is not set!", "tenantIds");
            }

            if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty())
            {
                tenantIds = new[] { CodeZeroSession.TenantId };
            }

            var notificationInfo = new NotificationInfo(_guidGenerator.Create())
            {
                NotificationName = notificationName,
                EntityTypeName   = entityIdentifier == null ? null : entityIdentifier.Type.FullName,
                EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName,
                EntityId        = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(),
                Severity        = severity,
                UserIds         = userIds.IsNullOrEmpty() ? null : userIds.Select(uid => uid.ToUserIdentifierString()).JoinAsString(","),
                ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.Select(uid => uid.ToUserIdentifierString()).JoinAsString(","),
                TenantIds       = tenantIds.IsNullOrEmpty() ? null : tenantIds.JoinAsString(","),
                Data            = data == null ? null : data.ToJsonString(),
                DataTypeName    = data == null ? null : data.GetType().AssemblyQualifiedName
            };

            await _store.InsertNotificationAsync(notificationInfo);

            await CurrentUnitOfWork.SaveChangesAsync(); //To get Id of the notification

            if (userIds != null && userIds.Length <= MaxUserCountToDirectlyDistributeANotification)
            {
                //We can directly distribute the notification since there are not much receivers
                await _notificationDistributer.DistributeAsync(notificationInfo.Id);
            }
            else
            {
                //We enqueue a background job since distributing may get a long time
                await _backgroundJobManager.EnqueueAsync <NotificationDistributionJob, NotificationDistributionJobArgs>(
                    new NotificationDistributionJobArgs(
                        notificationInfo.Id
                        )
                    );
            }
        }
 /// <summary>
 /// Update the data
 /// </summary>
 public override EntityIdentifier UpdateInternal(DataContext context, EntityIdentifier data)
 {
     if (data.Authority != null)
     {
         data.Authority = data.Authority.EnsureExists(context) as AssigningAuthority;
     }
     data.AuthorityKey = data.Authority?.Key ?? data.AuthorityKey;
     return(base.UpdateInternal(context, data));
 }
 public void Unsubscribe(UserIdentifier user, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     _store.DeleteSubscription(
         user,
         notificationName,
         entityIdentifier == null ? null : entityIdentifier.Type.FullName,
         entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString()
         );
 }
Ejemplo n.º 19
0
 private static EntityIdentifier Normalize(EntityIdentifier entity)
 {
     entity = new EntityIdentifier()
     {
         Type       = entity.Type.Trim(),
         Identifier = entity.Identifier.Trim()
     };
     return(entity);
 }
Ejemplo n.º 20
0
 public async Task NotifyTodoDeleted(Todo todo, int todoListId, Project project)
 {
     var message          = _localizationManager.GetString(SapConsts.LocalizationSourceName, "TodoDeleted");
     var formatedMessage  = string.Format(message, todo.TodoName);
     var entityIdentifier = new EntityIdentifier(typeof(Project), project.Id);
     await _notificationPublisher.PublishAsync(
         TodoNotificationTypes.TodoDeleted,
         new GenericTodoNotification(todo.Id, todoListId, 0, formatedMessage, todo.TodoName), entityIdentifier);
 }
Ejemplo n.º 21
0
        private EntityIdentifier getSPEntityIdentifier()
        {
            EntityIdentifier spEntityIdentifier = new EntityIdentifier();

            spEntityIdentifier.businessId      = "VMR";
            spEntityIdentifier.scopingEntityId = "org.opencds.vmr";
            spEntityIdentifier.version         = "1.0";
            return(spEntityIdentifier);
        }
 /// <summary>
 /// Insert the entity identifier
 /// </summary>
 public override EntityIdentifier InsertInternal(DataContext context, EntityIdentifier data, IPrincipal principal)
 {
     if (data.Authority != null)
     {
         data.Authority = data.Authority.EnsureExists(context, principal) as AssigningAuthority;
     }
     data.AuthorityKey = data.Authority?.Key ?? data.AuthorityKey;
     return(base.InsertInternal(context, data, principal));
 }
Ejemplo n.º 23
0
 public async Task NotifyTodoStatusChange(Todo todo, Project project, StatusTypes.Status statusType)
 {
     var message          = _localizationManager.GetString(SapConsts.LocalizationSourceName, "StatusChanged");
     var formatedMessage  = string.Format(message, todo.TodoName, _statusResolver.GetStatusName(statusType));
     var entityIdentifier = new EntityIdentifier(typeof(Project), project.Id);
     await _notificationPublisher.PublishAsync(
         TodoNotificationTypes.TodoChangeStatusForAllInProject,
         new ChangedStatusNotificationMessage(todo.Id, todo.TodoList.Id, formatedMessage, statusType), entityIdentifier);
 }
Ejemplo n.º 24
0
        public EntityIdentifier GetParent(EntityIdentifier entityId)
        {
            if (!_engine.TryGetComponent(entityId, out Hierarchical hierarchical))
            {
                return(EntityIdentifier.None);
            }

            return(hierarchical.Parent);
        }
Ejemplo n.º 25
0
        public EntityIdentifier GetRootEntity(EntityIdentifier entityId)
        {
            while (_parentCache.ContainsKey(entityId))
            {
                entityId = _parentCache[entityId];
            }

            return(entityId);
        }
Ejemplo n.º 26
0
 private DeduplicationResult(
     DeduplicationStatus status,
     EntityIdentifier duplicateId,
     IEnumerable <Duplicate> candidateDuplicates)
 {
     this.Status              = status;
     this.DuplicateId         = duplicateId;
     this.CandidateDuplicates = candidateDuplicates;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same
        /// type. The comparison is based on EntityIdentifier.
        ///
        /// If the local EntityIdentifier is empty, then return false.
        /// </summary>
        /// <param name="other">An object to compare with this object</param>
        /// <returns></returns>
        public bool IsEquatable(IIdentifiable other)
        {
            if (EntityIdentifier == default(Guid))
            {
                return(false);
            }

            return(EntityIdentifier.Equals(other.EntityIdentifier));
        }
Ejemplo n.º 28
0
        public virtual async Task PublishAsync(
            string pushRequestName,
            PushRequestData data = null,
            EntityIdentifier entityIdentifier = null,
            PushRequestPriority priority      = PushRequestPriority.Normal,
            IUserIdentifier[] userIds         = null,
            IUserIdentifier[] excludedUserIds = null,
            int?[] tenantIds = null)
        {
            if (pushRequestName.IsNullOrEmpty())
            {
                throw new ArgumentException("PushRequestName can not be null or whitespace!", nameof(pushRequestName));
            }

            if (!tenantIds.IsNullOrEmpty() && !userIds.IsNullOrEmpty())
            {
                throw new ArgumentException("tenantIds can be set only if userIds is not set!", nameof(tenantIds));
            }

            if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty())
            {
                tenantIds = new[] { AbpSession.TenantId };
            }

            var pushRequest = new PushRequest(GuidGenerator.Create())
            {
                Name           = pushRequestName,
                EntityTypeName = entityIdentifier?.Type.FullName,
                EntityTypeAssemblyQualifiedName = entityIdentifier?.Type.AssemblyQualifiedName,
                EntityId        = entityIdentifier?.Id.ToJsonString(),
                Priority        = priority,
                UserIds         = userIds.IsNullOrEmpty() ? null : userIds.Select(uid => uid.ToUserIdentifier().ToUserIdentifierString()).JoinAsString(","),
                ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.Select(uid => uid.ToUserIdentifier().ToUserIdentifierString()).JoinAsString(","),
                TenantIds       = PushRequest.ToTenantIds(tenantIds),
                Data            = data?.ToJsonString(),
                DataTypeName    = data?.GetType().AssemblyQualifiedName
            };

            await RequestStore.InsertRequestAsync(pushRequest);

            await CurrentUnitOfWork.SaveChangesAsync(); //To get Id of the push request

            if (userIds != null && userIds.Length <= Configuration.MaxUserCountForForegroundDistribution)
            {
                //We can directly distribute the push request since there are not much receivers
                await RequestDistributor.DistributeAsync(pushRequest.Id);
            }
            else
            {
                //We enqueue a background job since distributing may get a long time
                await BackgroundJobManager.EnqueueAsync <PushRequestDistributionJob, PushRequestDistributionJobArgs>(
                    new PushRequestDistributionJobArgs(
                        pushRequest.Id
                        )
                    );
            }
        }
Ejemplo n.º 29
0
        public RevolutionEntity CreateIdentEntityInChunk <TIdentity>(TIdentity identity, RevolutionChunk chunk)
        {
            var ent = CreateEntityInChunk(chunk);
            var id  = new EntityIdentifier();

            id.Set(identity);
            identifierToEntity.Set(id, ent.Raw);

            return(ent);
        }
Ejemplo n.º 30
0
        /// <summary>
        ///     Get an entity from an identifier
        /// </summary>
        /// <param name="identity"></param>
        /// <typeparam name="TIdentity"></typeparam>
        /// <returns></returns>
        public RevolutionEntity GetEntityFromIdentifier <TIdentity>(TIdentity identity)
        {
            var id = new EntityIdentifier();

            id.Set(identity);
            if (identifierToEntity.TryGetValue(id, out var entity))
            {
                return(new RevolutionEntity(this, entity));
            }
            return(default);
 private EntityIdentifier getIIEntityIdentifier(string businessId)
 {
     EntityIdentifier iiEntityIdentifier = new EntityIdentifier();
     iiEntityIdentifier.scopingEntityId = "gov.nyc.health";
     iiEntityIdentifier.version = "1.0.0.0";
     iiEntityIdentifier.businessId = businessId + "Data";
     return iiEntityIdentifier;
 }
Ejemplo n.º 32
0
 protected EntityGetEvent(EntityIdentifier entityIdentifier)
     : base(entityIdentifier)
 {
 }
 protected InternalEntityUpdate(EntityIdentifier entityIdentifier)
     : base(entityIdentifier)
 {
 }
Ejemplo n.º 34
0
 protected EntityPostEvent(Xml xmlContent, EntityIdentifier entityIdentifier)
     : base(entityIdentifier)
 {
     Xml = xmlContent;
 }
 private EntityIdentifier getKMEntityIdentifier(string scopingEntityId, string businessId, string version)
 {
     EntityIdentifier kmEntityIdentifier = new EntityIdentifier();
     kmEntityIdentifier.scopingEntityId = scopingEntityId;
     kmEntityIdentifier.version = version;
     kmEntityIdentifier.businessId = businessId;
     return kmEntityIdentifier;
 }
 private EntityIdentifier getSPEntityIdentifier()
 {
     EntityIdentifier spEntityIdentifier = new EntityIdentifier();
     spEntityIdentifier.businessId = "VMR";
     spEntityIdentifier.scopingEntityId = "org.opencds.vmr";
     spEntityIdentifier.version = "1.0";
     return spEntityIdentifier;
 }