示例#1
0
 public void UnregisterAsAChildOf(IPeripheral peripheralParent, IRegistrationPoint registrationPoint)
 {
     lock (collectionSync)
     {
         CollectGarbageStamp();
         try
         {
             var         parentNode        = registeredPeripherals.GetNode(peripheralParent);
             IPeripheral removedPeripheral = null;
             parentNode.RemoveChild(registrationPoint, p =>
             {
                 IPeripheralsGroup group;
                 if (PeripheralsGroups.TryGetActiveGroupContaining(p, out group))
                 {
                     throw new RegistrationException(string.Format("Given peripheral is a member of '{0}' peripherals group and cannot be directly removed.", group.Name));
                 }
                 removedPeripheral = p;
                 return(true);
             });
             CollectGarbage();
             if (removedPeripheral != null && registeredPeripherals.TryGetNode(removedPeripheral) == null)
             {
                 EmulationManager.Instance.CurrentEmulation.BackendManager.HideAnalyzersFor(removedPeripheral);
             }
         }
         catch (RegistrationException)
         {
             CollectGarbage();
             throw;
         }
     }
 }
示例#2
0
        private void InnerUnregisterFromParent(IPeripheral peripheral)
        {
            using (ObtainPausedState())
            {
                lock (collectionSync)
                {
                    var parents = GetParents(peripheral);
                    if (parents.Count > 1)
                    {
                        throw new RegistrationException(string.Format("Given peripheral is connected to more than one different parent, at least '{0}' and '{1}'.",
                                                                      parents.Select(x => GetAnyNameOrTypeName(x)).Take(2).ToArray()));
                    }

                    IPeripheralsGroup group;
                    if (PeripheralsGroups.TryGetActiveGroupContaining(peripheral, out group))
                    {
                        throw new RegistrationException(string.Format("Given peripheral is a member of '{0}' peripherals group and cannot be directly removed.", group.Name));
                    }

                    var parent = parents.FirstOrDefault();
                    if (parent == null)
                    {
                        throw new RecoverableException(string.Format("Cannot unregister peripheral {0} since it does not have any parent.", peripheral));
                    }
                    ((dynamic)parent).Unregister((dynamic)peripheral);
                    EmulationManager.Instance.CurrentEmulation.BackendManager.HideAnalyzersFor(peripheral);
                }
            }
        }
示例#3
0
        public void UnregisterAsAChildOf(IPeripheral peripheralParent, IPeripheral peripheralChild)
        {
            lock (collectionSync)
            {
                CollectGarbageStamp();
                IPeripheralsGroup group;
                if (PeripheralsGroups.TryGetActiveGroupContaining(peripheralChild, out group))
                {
                    throw new RegistrationException(string.Format("Given peripheral is a member of '{0}' peripherals group and cannot be directly removed.", group.Name));
                }

                var parentNode = registeredPeripherals.GetNode(peripheralParent);
                parentNode.RemoveChild(peripheralChild);
                EmulationManager.Instance.CurrentEmulation.BackendManager.HideAnalyzersFor(peripheralChild);
                CollectGarbage();
            }
        }