Пример #1
0
        /// <summary>
        /// 停止
        /// </summary>
        public void Stop()
        {
            log.Debug(string.Format("模块{0}停止开始!", this.GetBundleAssemblyFileName()));

            if (this.state == BundleStateConst.ACTIVE)
            {
                this.state = BundleStateConst.STOPPING;
                if (bundleActivator != null)
                {
                    var frameworkFireEvent = (IFrameworkFireEvent)framework;
                    frameworkFireEvent.FireBundleEvent(new BundleEventArgs(BundleEventArgs.STOPPING, this));

                    log.Debug("卸载扩展点数据!");
                    UnLoadExtensions();

                    log.Debug("激活器停止");
                    bundleActivator.Stop(bundleContext);

                    ((BundleContext)bundleContext).Stop();

                    frameworkFireEvent.FireBundleEvent(new BundleEventArgs(BundleEventArgs.STOPPED, this));

                    bundleActivator = null;
                }
                this.state = BundleStateConst.RESOLVED;
            }

            log.Debug(string.Format("模块{0}停止结束!", this.GetBundleAssemblyFileName()));
        }
Пример #2
0
 public BundleContextImpl(BundleHost bundle)
 {
     this.bundle    = bundle;
     this.framework = bundle.Framework;
     this.valid     = true;
     lock (contextLock)
     {
         servicesInUse = null;
     }
     activator = null;
 }
Пример #3
0
        /// <summary>
        /// 启动
        /// </summary>
        public void Start()
        {
            log.Debug(string.Format("模块{0}启动开始!", this.GetBundleAssemblyFileName()));

            if (this.state == BundleStateConst.INSTALLED)
            {
                try
                {
                    Resolve();
                }
                catch (Exception ex)
                {
                    this.state = BundleStateConst.INSTALLED;
                    log.Debug(string.Format("模块{0}启动失败!", this.GetBundleAssemblyFileName()));
                    throw ex;
                }
            }
            if (this.state == BundleStateConst.RESOLVED)
            {
                this.state = BundleStateConst.STARTING;

                try
                {
                    var frameworkFireEvent = (IFrameworkFireEvent)framework;
                    frameworkFireEvent.FireBundleEvent(new BundleEventArgs(BundleEventArgs.STARTING, this));

                    if (this.activatorClass != null)
                    {
                        log.Debug("激活器启动!");
                        bundleActivator = Activator.CreateInstance(activatorClass) as IBundleActivator;
                        //启动激活器
                        bundleActivator.Start(bundleContext);

                        log.Debug("加载扩展点数据!");
                        //初始化扩展信息
                        LoadExtensions();
                    }
                    this.state = BundleStateConst.ACTIVE;

                    frameworkFireEvent.FireBundleEvent(new BundleEventArgs(BundleEventArgs.STARTED, this));
                }
                catch (Exception ex)
                {
                    this.state = BundleStateConst.RESOLVED;
                    log.Debug(string.Format("模块{0}启动失败!", this.GetBundleAssemblyFileName()));
                    throw ex.InnerException;
                }
            }

            log.Debug(string.Format("模块{0}启动结束!", this.GetBundleAssemblyFileName()));
        }
Пример #4
0
        /// <summary>
        /// 启动激活器
        /// </summary>
        /// <param name="bundleActivator"></param>
        internal void StartActivator(IBundleActivator bundleActivator)
        {
            try
            {
                if (bundleActivator != null)
                {
                    bundleActivator.Start(this);
                }
            }
            catch (Exception ex)
            {
                string clazz = null;
                clazz = bundleActivator.GetType().FullName;

                throw new BundleException(string.Format("Activator Start Exception. [Clazz:{0}] - [Method:{1}] -[Bundle:{2}] ", new object[] { clazz, "start", string.IsNullOrEmpty(bundle.SymbolicName) ? "" + bundle.BundleId : bundle.SymbolicName }), ex, BundleExceptionType.ACTIVATOR_ERROR); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
Пример #5
0
        /// <summary>
        /// 启动操作
        /// </summary>
        public void Start()
        {
            activator = bundle.LoadBundleActivator();

            if (activator != null)
            {
                try
                {
                    StartActivator(activator);
                }
                catch (BundleException be)
                {
                    activator = null;
                    throw be;
                }
            }
        }
Пример #6
0
        public void Stop()
        {
            try
            {
                this.state = BundleState.Stopping;
                IBundleActivator activator = this.Activator;
                if (activator == null)
                {
                    throw new Exception("No activator for: " + this.Location);
                }

                activator.Stop(this.Context);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.state = BundleState.Installed;
        }
Пример #7
0
        public void Stop()
        {
            try
            {
                this.state = BundleState.Stopping;
                IBundleActivator activator = this.Activator;
                if (activator == null)
                {
                    throw new Exception("No activator for: " + this.Location);
                }

                activator.Stop(this.Context);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.state = BundleState.Installed;
            EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Stopped, this));
        }
Пример #8
0
        public void StartActivator(IBundleContext context)
        {
            var path = AppDomain.CurrentDomain.SetupInformation.ApplicationName;
            var name = AssemblyName.GetAssemblyName(path);

            context.ChangeBundleState(name.Name, BundleState.Starting);

            // load the assembly in the AppDomain
            var assembly = AppDomain.CurrentDomain.Load(name);

            // get the meta-data of the bundle
            var activatorAttribute = (BundleActivatorAttribute)assembly.GetCustomAttributes(typeof(BundleActivatorAttribute), false).FirstOrDefault();
            var dependencyAttributes = assembly.GetCustomAttributes(typeof(BundleDependencyAttribute), false).Cast<BundleDependencyAttribute>();

            // if there's some dependencies, load them
            if (dependencyAttributes != null)
            {
                foreach (var bundle in dependencyAttributes)
                {
                    var existingBundle = context.GetBundle(bundle.Name);
                    if (existingBundle == null)
                    {
                        throw new BundleNotFoundException(bundle.Name, bundle.Version);
                    }
                    else
                    {
                        if (existingBundle.Version != bundle.Version)
                        {
                            throw new InvalidBundleVersionException(bundle.Name, bundle.Version, existingBundle.Version);
                        }
                        else if (existingBundle.State == BundleState.Installed)
                        {
                            BundleController.Start(context, bundle.Name);
                        }
                        else if (existingBundle.State == BundleState.Resolved)
                        {
                            BundleController.Start(context, bundle.Name);
                        }
                        else if (existingBundle.State == BundleState.Starting)
                        {
                            BundleController.WaitFor(context, bundle.Name, BundleState.Active);
                        }
                        else if (existingBundle.State == BundleState.Stopping)
                        {
                            BundleController.WaitFor(context, bundle.Name, BundleState.Resolved);
                            BundleController.Start(context, bundle.Name);
                        }
                        else if (existingBundle.State == BundleState.Uninstalled)
                            throw new BundleIsBeingUninstalledException(existingBundle.Name, existingBundle.Version);

                        logger.InfoFormat("Loading dependency: {0}", bundle);
                    }
                }
            }

            // create a new instance of the activator
            var activatorType = Type.GetType(activatorAttribute.Activator.AssemblyQualifiedName);
            var ctor = activatorType.GetConstructor(new Type[0]);
            this.instance = (IBundleActivator)ctor.Invoke(new object[0]);

            // start the bundle
            ThreadPool.QueueUserWorkItem(new WaitCallback((o) => ((IBundleActivator)o).Start()), this.instance);

            context.ChangeBundleState(name.Name, BundleState.Active);
        }
Пример #9
0
        //////////////////////////////////////////////////////////////////////////
        protected virtual void PreStart()
        {
            m_state = BundleState.STARTING;
            m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STARTING, this));

            m_activator = null;

            try
            {
                m_assembly = m_systemBundle.getBundleRepository().LoadBundleAssembly(this);

                Type[] exports = m_assembly.GetExportedTypes();
                foreach (Type t in exports)
                {
                    TypeAttributes attrs = t.Attributes;
                    if ((attrs & TypeAttributes.Interface) == TypeAttributes.Interface ||
                        (attrs & TypeAttributes.Abstract) == TypeAttributes.Abstract)
                        continue;

                    if (t.GetInterface(typeof(IBundleActivator).FullName) != null)
                    {
                        m_activator = m_assembly.CreateInstance(t.FullName) as IBundleActivator;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                m_state = BundleState.RESOLVED;
                throw new BundleException("Failed to load bundle assembly", BundleException.ErrorCode.STATECHANGE_ERROR, ex);
            }

            m_context = new CBundleContext(this, m_systemBundle);
        }