private void InvokeAfterRegister(MRegistrationListener listener)
 {
     if (listener != null)
     {
         listener.AfterRegister();
     }
 }
 private void InvokeBeforeRegister(MRegistrationListener listener, ManagedObjectName name)
 {
     if (listener != null)
     {
         listener.BeforeRegister(server, name);
     }
 }
        public void UnregisterManagedObject(ManagedObjectName name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            String domainName = name.Domain;

            try
            {
                Domain domain = FindDomain(domainName);
                Entry  entry  = domain[name];

                if (entry != null)
                {
                    MRegistrationListener listener = entry.Instance as MRegistrationListener;

                    InvokeBeforeDeregister(listener);

                    domain.Remove(name);

                    InvokeAfterDeregister(listener);
                }
            }
            catch (InvalidDomainException)
            {
            }
        }
 private void InvokeAfterDeregister(MRegistrationListener listener)
 {
     if (listener != null)
     {
         try
         {
             listener.AfterDeregister();
         }
         catch (Exception)
         {
             // An exception here shall not stop us from continue
         }
     }
 }
 private void InvokeBeforeRegister(MRegistrationListener listener, ManagedObjectName name)
 {
     if (listener != null)
     {
         listener.BeforeRegister(server, name);
     }
 }
 private void InvokeBeforeDeregister(MRegistrationListener listener)
 {
     if (listener != null)
     {
         try
         {
             listener.BeforeDeregister();
         }
         catch(Exception)
         {
             // An exception here shall not stop us from continue
         }
     }
 }
 private void InvokeAfterRegister(MRegistrationListener listener)
 {
     if (listener != null)
     {
         listener.AfterRegister();
     }
 }
        public ManagedInstance RegisterManagedObject(Object instance, ManagedObjectName name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            ComponentType   cType   = MInspector.Inspect(instance);
            MDynamicSupport dynamic = null;

            if (cType == ComponentType.None)
            {
                throw new InvalidComponentException("Component is not a managed component.");
            }

            if (cType == ComponentType.Standard)
            {
                dynamic = MDynamicSupportFactory.Create(instance);
            }
            else if (cType == ComponentType.Dynamic)
            {
                dynamic = (MDynamicSupport)instance;
            }

            String domainName = name.Domain;
            Domain domain     = null;

            lock (domains)
            {
                domain = domains[domainName];

                if (domain == null)
                {
                    domain = new Domain(domainName);
                    domains.Add(domain);
                }
            }

            Entry entry = new Entry(instance, dynamic);

            try
            {
                MRegistrationListener registration = instance as MRegistrationListener;

                InvokeBeforeRegister(registration, name);

                lock (domain)
                {
                    if (domain.Contains(name))
                    {
                        throw new InstanceAlreadyRegistredException(name.ToString());
                    }

                    domain.Add(name, entry);
                }

                InvokeAfterRegister(registration);
            }
            catch (Exception e)
            {
                domain.Remove(name);

                throw e;
            }

            return(new ManagedInstance(instance.GetType().FullName, name));
        }