Ejemplo n.º 1
0
        public async Task RemoveBehaviourAsync(string reference)
        {
            var found = Behaviours.Where(b => b.UniqueReference == reference).ToList();

            Behaviours.RemoveAll(b => b.UniqueReference == reference);
            UpdateFrameProcessors();
            if (Connection == ConnectedState.Connected)
            {
                foreach (var behaviour in found)
                {
                    if (behaviour.ActionOnRemoved != null)
                    {
                        EnqueueAction(behaviour.ActionOnRemoved);
                    }
                }
                await ActOnAnyBehaviourPermanentRequirements();
                await UnregisterBehavioursAsync(found);
            }

            OnBehaviourEvent?.Invoke(Behaviours, BehaviourEvent.Remove);
        }
Ejemplo n.º 2
0
        public async Task AddBehaviourAsync(IVectorBehaviourPlus behaviour)
        {
            if (!Behaviours.Any(b => b.UniqueReference == behaviour.UniqueReference))
            {
                Behaviours.Add(behaviour);
                UpdateFrameProcessors();

                if (Connection == ConnectedState.Connected)
                {
                    await ActOnAnyBehaviourPermanentRequirements();
                    await RegisterBehavioursAsync(new[] { behaviour });
                }

                if (behaviour.ActionOnAdded != null)
                {
                    EnqueueAction(behaviour.ActionOnAdded);
                }

                OnBehaviourEvent?.Invoke(Behaviours, BehaviourEvent.Add);
            }
        }