Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            foreach (var entityId in _addedEntities)
            {
                _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
                ActiveCount++;
                EntityAdded?.Invoke(entityId);
            }

            foreach (var entityId in _changedEntities)
            {
                _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
                EntityChanged?.Invoke(entityId);
            }

            foreach (var entityId in _removedEntities)
            {
                // we must notify subscribers before removing it from the pool
                // otherwise an entity system could still be using the entity when the same id is obtained.
                EntityRemoved?.Invoke(entityId);

                var entity = _entityBag[entityId];
                _entityBag[entityId] = null;
                _componentManager.Destroy(entityId);
                _entityToComponentBits[entityId] = default(BitVector32);
                ActiveCount--;
                _entityPool.Free(entity);
            }

            _addedEntities.Clear();
            _removedEntities.Clear();
            _changedEntities.Clear();
        }
Ejemplo n.º 2
0
        private async Task OnEntityChangedAsync(EntityChanged entityChanged, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (entityChanged == null)
            {
                return;
            }

            var appEntityChanged = AppEntityChanged.Create(entityChanged);

            if (appEntityChanged.Type == typeof(User).Name)
            {
                foreach (var connectionId in await _connectionMapping.GetConnectionsAsync(appEntityChanged.Id))
                {
                    await Context.Connection.TypedSendAsync(connectionId, appEntityChanged);
                }

                return;
            }

            if (!String.IsNullOrEmpty(appEntityChanged.OrganizationId))
            {
                await GroupSendAsync(appEntityChanged.OrganizationId, appEntityChanged);
            }

            if (appEntityChanged.Type == "Organization")
            {
                await GroupSendAsync(appEntityChanged.Id, appEntityChanged);
            }
        }
Ejemplo n.º 3
0
        private void LandingSiteCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            LandingSite editedLandingSite = new LandingSite();

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int newIndex = e.NewStartingIndex;
                editedLandingSite = LandingSiteCollection[newIndex];
                LandingSites.Add(editedLandingSite);
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <LandingSite> tempListOfRemovedItems = e.OldItems.OfType <LandingSite>().ToList();
                editedLandingSite = tempListOfRemovedItems[0];
                LandingSites.Delete(editedLandingSite.LandingSiteID);
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <LandingSite> tempListOfLandingSites = e.NewItems.OfType <LandingSite>().ToList();
                editedLandingSite = tempListOfLandingSites[0];
                LandingSites.Update(editedLandingSite);              // As the IDs are unique, only one row will be effected hence first index only
            }
            break;
            }
            EntityChangedEventArgs args = new EntityChangedEventArgs(editedLandingSite.GetType().Name, editedLandingSite);

            EntityChanged?.Invoke(this, args);
        }
Ejemplo n.º 4
0
        protected EntityChanged CreateEntityChanged(ChangeType changeType, string organizationId = null, string projectId = null, string stackId = null, string id = null, IDictionary <string, object> data = null)
        {
            var model = new EntityChanged {
                ChangeType = changeType,
                Type       = EntityTypeName,
                Id         = id
            };

            if (data != null)
            {
                foreach (var kvp in data)
                {
                    model.Data[kvp.Key] = kvp.Value;
                }
            }

            if (organizationId != null)
            {
                model.Data[ExtendedEntityChanged.KnownKeys.OrganizationId] = organizationId;
            }

            if (projectId != null)
            {
                model.Data[ExtendedEntityChanged.KnownKeys.ProjectId] = projectId;
            }

            if (stackId != null)
            {
                model.Data[ExtendedEntityChanged.KnownKeys.StackId] = stackId;
            }

            return(model);
        }
Ejemplo n.º 5
0
        protected virtual void PublishMessage(ChangeType changeType, IEnumerable <T> documents)
        {
            if (_isOwnedByOrganization && _isOwnedByProject)
            {
                foreach (var projectDocs in documents.Cast <IOwnedByOrganizationAndProjectWithIdentity>().GroupBy(d => d.ProjectId))
                {
                    var firstDoc = projectDocs.FirstOrDefault();
                    if (firstDoc == null)
                    {
                        continue;
                    }

                    int count   = projectDocs.Count();
                    var message = new EntityChanged {
                        ChangeType     = changeType,
                        OrganizationId = firstDoc.OrganizationId,
                        ProjectId      = projectDocs.Key,
                        Id             = count == 1 ? firstDoc.Id : null,
                        Type           = _entityType
                    };

                    PublishMessage(message, TimeSpan.FromSeconds(1.5));
                }
            }
            else if (_isOwnedByOrganization)
            {
                foreach (var orgDocs in documents.Cast <IOwnedByOrganizationWithIdentity>().GroupBy(d => d.OrganizationId))
                {
                    var firstDoc = orgDocs.FirstOrDefault();
                    if (firstDoc == null)
                    {
                        continue;
                    }

                    int count   = orgDocs.Count();
                    var message = new EntityChanged {
                        ChangeType     = changeType,
                        OrganizationId = orgDocs.Key,
                        Id             = count == 1 ? firstDoc.Id : null,
                        Type           = _entityType
                    };

                    PublishMessage(message, TimeSpan.FromSeconds(1.5));
                }
            }
            else
            {
                foreach (var doc in documents)
                {
                    var message = new EntityChanged {
                        ChangeType = changeType,
                        Id         = doc.Id,
                        Type       = _entityType
                    };

                    PublishMessage(message, TimeSpan.FromSeconds(1.5));
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Removes a component from the entity with the given ID. Notifies all systems that the entity has changed.
 /// </summary>
 /// <param name="entityId">The entity to remove the component from.</param>
 /// <param name="component">The component to remove from the entity.</param>
 public void RemoveComponent(uint entityId, IComponent component)
 {
     entityTable[componentIndices[component.GetType()], entityId] = null;
     if (entityInWorld[entityId])
     {
         EntityChanged?.Invoke(this, new EntityEventArgs(entityId, GetEntityBitmask(entityId)));
     }
 }
Ejemplo n.º 7
0
        protected virtual void OnEntityChanged(object oldValue, object newValue)
        {
            EntityChanged?.Invoke(this, isUserInteraction, oldValue, newValue);

            AutomationProperties.SetItemStatus(this, Common.GetEntityStringAndHashCode(newValue));

            UpdateVisibility();
        }
Ejemplo n.º 8
0
        private void OnEntityChanged(EntityChanged entityChanged)
        {
            if (String.IsNullOrEmpty(entityChanged.OrganizationId))
            {
                return;
            }

            Clients.Group(entityChanged.OrganizationId).entityChanged(entityChanged);
        }
Ejemplo n.º 9
0
        private Task OnEntityChangedAsync(EntityChanged entityChanged, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (entityChanged != null)
            {
                Clients.All.entityChanged(entityChanged);
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 10
0
        private Task <int> GetNumberOfListeners(EntityChanged message)
        {
            var entityChanged = ExtendedEntityChanged.Create(message, false);

            if (String.IsNullOrEmpty(entityChanged.OrganizationId))
            {
                return(Task.FromResult(1)); // Return 1 as we have no idea if people are listening.
            }
            return(_connectionMapping.GetGroupConnectionCountAsync(entityChanged.OrganizationId));
        }
Ejemplo n.º 11
0
        public T PopAt(Key i)
        {
            T val;

            if (DataSet.TryRemove(i, out val))
            {
                EntityChanged.Invoke(this, new DSChangedArgs <Key, T>(i, NotifyCollectionChangedAction.Remove, val, default(T)));//this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new KeyValuePair<int, T>(i, val)));
                return(val);
            }
            return(default(T));
        }
        protected virtual void PublishMessage(EntityChangeType changeType, T document)
        {
            var orgEntity = document as IOwnedByOrganization;
            var message   = new EntityChanged {
                ChangeType     = changeType,
                Id             = document.Id,
                OrganizationId = orgEntity != null ? orgEntity.OrganizationId : null,
                Type           = _entityType
            };

            PublishMessage(message);
        }
Ejemplo n.º 13
0
        private void OnEntityChanged(EntityChanged entityChanged)
        {
            if (entityChanged.Type == typeof(User).Name && Clients.User(entityChanged.Id) != null)
            {
                Clients.User(entityChanged.Id).entityChanged(entityChanged);
                return;
            }

            if (String.IsNullOrEmpty(entityChanged.OrganizationId))
            {
                return;
            }

            Clients.Group(entityChanged.OrganizationId).entityChanged(entityChanged);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Работа с сущностью при нажатии ОК.
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="ec"></param>
 public override void ApplyChanged(EntityBase entity, EntityController ec)
 {
     if (entity as Hierarchy != null)
     {
         var entities = ec.AddRangeHierarchy(entity as Hierarchy, countCopy).ToArray();
         ec.SaveChanges();
         HierarchyChangedRange?.Invoke(entities);
     }
     else
     {
         ec.AddEntity(entity);
         ec.SaveChanges();
         EntityChanged?.Invoke(entity);
     }
 }
Ejemplo n.º 15
0
        void ChangeTracker_EntityPropertyChanged(object sender, EntityEntryPropertyChangedEventArgs e)
        {
            #region Trigger entity set validation if ValidateOnPropertyChanged is set to true

            var entitySet = e.EntityEntry.EntitySet;

            var validationResults = new Collection <ValidationResultWithSeverityLevel>();
            if (entitySet.ValidateOnPropertyChanged)
            {
                entitySet.ValidateProperty(e.EntityEntry.Entity, e.PropertyName, validationResults);
            }

            #endregion Trigger entity set validation if ValidateOnPropertyChanged is set to true

            EntityChanged?.Invoke(this, e);
        }
Ejemplo n.º 16
0
        private IObservable <ITransition> getCorrectTransitionFromResults(
            IEnumerable <IConflictResolutionResult <TThreadsafeModel> > results,
            TThreadsafeModel originalEntity)
        {
            foreach (var result in results)
            {
                switch (result)
                {
                case UpdateResult <TThreadsafeModel> u when u.OriginalId == originalEntity.Id:
                    return(Observable.Return(Done.Transition(extractFrom(result))));

                case IgnoreResult <TThreadsafeModel> i when i.Id == originalEntity.Id:
                    return(Observable.Return(EntityChanged.Transition(originalEntity)));
                }
            }
            throw new ArgumentException("Results must contain result with one of the specified ids.");
        }
Ejemplo n.º 17
0
        private void ProjectSettings_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            ProjectSetting editedEntity = new ProjectSetting();

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int newIndex = e.NewStartingIndex;
                editedEntity = ProjectSettingCollection[newIndex];

                if (ProjectSettings.Add(editedEntity))
                {
                    EditedEntity = new EditedEntity(EditAction.Add, editedEntity);
                }
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <ProjectSetting> tempListOfRemovedItems = e.OldItems.OfType <ProjectSetting>().ToList();
                editedEntity = tempListOfRemovedItems[0];

                if (ProjectSettings.Delete(editedEntity.ProjectID))
                {
                    EditedEntity = new EditedEntity(EditAction.Delete, editedEntity);
                }
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <ProjectSetting> tempListOfProjectSettings = e.NewItems.OfType <ProjectSetting>().ToList();
                editedEntity = tempListOfProjectSettings[0];

                if (ProjectSettings.Update(tempListOfProjectSettings[0]))              // As the IDs are unique, only one row will be effected hence first index only
                {
                    EditedEntity = new EditedEntity(EditAction.Update, editedEntity);
                }
            }
            break;
            }
            EntityChangedEventArgs args = new EntityChangedEventArgs(editedEntity.GetType().Name, editedEntity);

            EntityChanged?.Invoke(this, args);
        }
        // Component removed observable
        public IObservable <EntityChangedEventArgs <T> > OnComponentRemovedAsObservable <T>()
        {
            var componentRemoved = Observable.FromEvent <EntityChanged, EntityChangedEventArgs <T> >(handler => {
                EntityChanged componentRemovedHandler = (entity, index, component) => {
                    if (component is T)
                    {
                        var args       = new EntityChangedEventArgs <T>();
                        args.entity    = entity;
                        args.index     = index;
                        args.component = (T)component;
                        handler(args);
                    }
                };
                return(componentRemovedHandler);
            },
                                                                                                     componentRemovedHandler => OnComponentRemoved += componentRemovedHandler,
                                                                                                     componentRemovedHandler => OnComponentRemoved -= componentRemovedHandler);

            return(componentRemoved);
        }
Ejemplo n.º 19
0
 public T this[Key i]
 {
     get
     {
         return(DataSet[i]);//DataSet.GetOrAdd(i,default(T));
     }
     set
     {
         if (!DataSet.ContainsKey(i))
         {
             DataSet[i] = value;
             EntityChanged.Invoke(this, new DSChangedArgs <Key, T>(i, NotifyCollectionChangedAction.Add, default(T), value));
         }
         else if (!EqualityComparer <T> .Default.Equals(DataSet[i], value))
         {
             DataSet[i] = value;
             EntityChanged.Invoke(this, new DSChangedArgs <Key, T>(i, NotifyCollectionChangedAction.Replace, default(T), value));//(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, new KeyValuePair<int, T>(i, value)));
         }
     }
 }
Ejemplo n.º 20
0
        protected override async Task PublishMessageAsync(EntityChangeType changeType, User user)
        {
            if (user.OrganizationIds.Any())
            {
                foreach (var organizationId in user.OrganizationIds)
                {
                    var message = new EntityChanged {
                        ChangeType     = changeType,
                        Id             = user.Id,
                        OrganizationId = organizationId,
                        Type           = _entityType
                    };

                    await _messagePublisher.PublishAsync(message);
                }
            }
            else
            {
                await base.PublishMessageAsync(changeType, user);
            }
        }
Ejemplo n.º 21
0
        protected override void PublishMessage(EntityChangeType changeType, User user)
        {
            if (user.OrganizationIds.Any())
            {
                foreach (var organizationId in user.OrganizationIds)
                {
                    var message = new EntityChanged {
                        ChangeType     = changeType,
                        Id             = user.Id,
                        OrganizationId = organizationId,
                        Type           = _entityType
                    };

                    _messagePublisher.Publish(message);
                }
            }
            else
            {
                base.PublishMessage(changeType, user);
            }
        }
Ejemplo n.º 22
0
        private async Task OnEntityChangedAsync(EntityChanged entityChanged, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (entityChanged == null)
            {
                return;
            }

            if (entityChanged.Type == typeof(User).Name)
            {
                foreach (var connectionId in _userIdConnections.GetConnections(entityChanged.Id))
                {
                    await Context.Connection.TypedSend(connectionId, entityChanged);
                }

                return;
            }

            if (!String.IsNullOrEmpty(entityChanged.OrganizationId))
            {
                await Context.Groups.TypedSend(entityChanged.OrganizationId, entityChanged);
            }
        }
Ejemplo n.º 23
0
    public static ExtendedEntityChanged Create(EntityChanged entityChanged, bool removeWhenSettingProperties = true)
    {
        var model = new ExtendedEntityChanged {
            Id         = entityChanged.Id,
            Type       = entityChanged.Type,
            ChangeType = entityChanged.ChangeType,
            Data       = entityChanged.Data
        };

        if (model.Data.TryGetValue(KnownKeys.OrganizationId, out object organizationId))
        {
            model.OrganizationId = organizationId.ToString();
            if (removeWhenSettingProperties)
            {
                model.Data.Remove(KnownKeys.OrganizationId);
            }
        }

        if (model.Data.TryGetValue(KnownKeys.ProjectId, out object projectId))
        {
            model.ProjectId = projectId.ToString();
            if (removeWhenSettingProperties)
            {
                model.Data.Remove(KnownKeys.ProjectId);
            }
        }

        if (model.Data.TryGetValue(KnownKeys.StackId, out object stackId))
        {
            model.StackId = stackId.ToString();
            if (removeWhenSettingProperties)
            {
                model.Data.Remove(KnownKeys.StackId);
            }
        }

        return(model);
    }
Ejemplo n.º 24
0
        public static AppEntityChanged Create(EntityChanged entityChanged)
        {
            var appEntityChanged = new AppEntityChanged {
                Id         = entityChanged.Id,
                Type       = entityChanged.Type,
                ChangeType = entityChanged.ChangeType,
                Data       = entityChanged.Data
            };

            if (appEntityChanged.Data.ContainsKey(KnownKeys.OrganizationId))
            {
                appEntityChanged.OrganizationId = appEntityChanged.Data[KnownKeys.OrganizationId].ToString();
                appEntityChanged.Data.Remove(KnownKeys.OrganizationId);
            }

            if (appEntityChanged.Data.ContainsKey(KnownKeys.ContactId))
            {
                appEntityChanged.ContactId = appEntityChanged.Data[KnownKeys.ContactId].ToString();
                appEntityChanged.Data.Remove(KnownKeys.ContactId);
            }

            return(appEntityChanged);
        }
Ejemplo n.º 25
0
        private void OnEntityChanged(EntityChanged entityChanged)
        {
            if (entityChanged == null)
            {
                return;
            }

            if (entityChanged.Type == typeof(User).Name && Clients.User(entityChanged.Id) != null)
            {
                try {
                    Clients.User(entityChanged.Id).entityChanged(entityChanged);
                } catch (NullReferenceException) { } // TODO: Remove this when SignalR bug is fixed.
                return;
            }

            if (String.IsNullOrEmpty(entityChanged.OrganizationId))
            {
                return;
            }

            try {
                Clients.Group(entityChanged.OrganizationId).entityChanged(entityChanged);
            } catch (NullReferenceException) {} // TODO: Remove this when SignalR bug is fixed.
        }
Ejemplo n.º 26
0
 protected async Task SetSelectedValue(string value)
 {
     SetValue(value);
     FilteredValues = null;
     await EntityChanged.InvokeAsync(Entity).ConfigureAwait(false);
 }
Ejemplo n.º 27
0
 private void OnComponentsChanged(int entityId)
 {
     _changedEntities.Add(entityId);
     _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
     EntityChanged?.Invoke(entityId);
 }
Ejemplo n.º 28
0
 void ChangeTracker_EntityChanged(object sender, EntityEntryEventArgs e)
 {
     EntityChanged?.Invoke(this, e);
 }
Ejemplo n.º 29
0
 protected void InvokeEntityChanged(T entity)
 {
     EntityChanged?.Invoke(entity);
 }
Ejemplo n.º 30
0
    private async Task OnEntityChangedAsync(EntityChanged ec, CancellationToken cancellationToken = default)
    {
        if (ec == null)
        {
            return;
        }

        var entityChanged = ExtendedEntityChanged.Create(ec);

        if (UserTypeName == entityChanged.Type)
        {
            // It's pointless to send a user added message to the new user.
            if (entityChanged.ChangeType == ChangeType.Added)
            {
                _logger.LogTrace("Ignoring {UserTypeName} message for added user: {user}.", UserTypeName, entityChanged.Id);
                return;
            }

            var userConnectionIds = await _connectionMapping.GetUserIdConnectionsAsync(entityChanged.Id);

            _logger.LogTrace("Sending {UserTypeName} message to user: {user} (to {UserConnectionCount} connections)", UserTypeName, entityChanged.Id, userConnectionIds.Count);
            foreach (string connectionId in userConnectionIds)
            {
                await TypedSendAsync(connectionId, entityChanged);
            }

            return;
        }

        // Only allow specific token messages to be sent down to the client.
        if (TokenTypeName == entityChanged.Type)
        {
            string userId = entityChanged.Data.GetValueOrDefault <string>(ExtendedEntityChanged.KnownKeys.UserId);
            if (userId != null)
            {
                var userConnectionIds = await _connectionMapping.GetUserIdConnectionsAsync(userId);

                _logger.LogTrace("Sending {TokenTypeName} message for added user: {user} (to {UserConnectionCount} connections)", TokenTypeName, userId, userConnectionIds.Count);
                foreach (string connectionId in userConnectionIds)
                {
                    await TypedSendAsync(connectionId, entityChanged);
                }

                return;
            }

            if (entityChanged.Data.GetValueOrDefault <bool>(ExtendedEntityChanged.KnownKeys.IsAuthenticationToken))
            {
                _logger.LogTrace("Ignoring {TokenTypeName} Authentication Token message: {user}.", TokenTypeName, entityChanged.Id);
                return;
            }

            entityChanged.Data.Clear();
        }

        if (!String.IsNullOrEmpty(entityChanged.OrganizationId))
        {
            _logger.LogTrace("Sending {MessageType} message to organization: {organization}", entityChanged.Type, entityChanged.OrganizationId);
            await GroupSendAsync(entityChanged.OrganizationId, entityChanged);
        }
    }