예제 #1
0
 private void OnSyncBundleStateChanged(object sender, BundleStateChangedEventArgs e)
 {
     if (SyncBundleStateChanged != null)
     {
         SyncBundleStateChanged(sender, e);
     }
 }
예제 #2
0
        private void BundleEventHandler(object sender, BundleStateChangedEventArgs e)
        {
            bool flag = e.CurrentState == BundleState.Starting;
            IBundleInstallerService firstOrDefaultService = this._framework.ServiceContainer.GetFirstOrDefaultService <IBundleInstallerService>();
            BundleData bundleDataByName = firstOrDefaultService.GetBundleDataByName(e.Bundle.SymbolicName);

            if (bundleDataByName != null)
            {
                if (flag)
                {
                    this.AddExtensionPoint(e.Bundle, bundleDataByName.ExtensionPoints);
                    this.AddExtension(e.Bundle, bundleDataByName.Extensions);
                    Interface1 bundleByID = this._framework.FrameworkAdaptor.State.GetBundleByID(e.Bundle.BundleID) as Interface1;
                    if (bundleByID != null)
                    {
                        BundleData data2 = null;
                        foreach (IFragmentBundleMetadata metadata in bundleByID.Fragments)
                        {
                            data2 = firstOrDefaultService.GetBundleDataByName(metadata.SymbolicName);
                            this.AddExtensionPoint(e.Bundle, data2.ExtensionPoints);
                            this.AddExtension(e.Bundle, data2.Extensions);
                        }
                    }
                }
                else if (e.CurrentState == BundleState.Stopping)
                {
                    this.ReleaseExtension(e.Bundle);
                }
            }
        }
예제 #3
0
        private void BundleEventListener(object sender, BundleStateChangedEventArgs e)
        {
            Action <ServiceData> action = null;
            IBundle             bundle;
            Func <string, Type> loadClass;
            bool       flag             = e.CurrentState == BundleState.Starting;
            BundleData bundleDataByName = this._framework.ServiceContainer.GetFirstOrDefaultService <IBundleInstallerService>().GetBundleDataByName(e.Bundle.SymbolicName);

            if (bundleDataByName != null)
            {
                bundle = this._framework.GetBundleBySymbolicName(bundleDataByName.SymbolicName);
                AssertUtility.NotNull(bundle);
                loadClass = classType => bundle.LoadClass(classType);
                if (flag)
                {
                    if (action == null)
                    {
                        action = serviceData => this.AddService(bundle, serviceData, loadClass);
                    }
                    bundleDataByName.Services.ForEach(action);
                }
                else if (e.CurrentState == BundleState.Stopping)
                {
                    this.RemoveServiceByOwner(bundle);
                }
            }
        }
예제 #4
0
        private void context_BundleStateChanged(object sender, BundleStateChangedEventArgs e)
        {
            BundleRuntime runtime    = BundleRuntime.Instance;
            BundleData    bundleData = runtime.GetFirstOrDefaultService <IBundleInstallerService>()
                                       .GetBundleDataByName(e.Bundle.SymbolicName);

            if (bundleData == null)
            {
                return;
            }

            bool needLoad = e.CurrentState == BundleState.Active;

            if (needLoad)
            {
                RegisterBundle(e.Bundle);
            }
            else if (e.CurrentState == BundleState.Stopping)
            {
                //如果插件正在停止,就不需要更新ContainerBuilder了,因为这个服务即将不可用。
                if (BundleRuntime.Instance.State == BundleRuntimeState.Stopping)
                {
                    return;
                }
                Assembly[] assemblies;
                if (_registerHostory.TryGetValue(e.Bundle.BundleID, out assemblies))
                {
                    IServiceResolver newResolver = UnRegisterBundleAndGetControllerResolver(assemblies);
                    ServiceResolver = newResolver;
                }
            }
        }
예제 #5
0
 private void BundleEventListener(object sender, BundleStateChangedEventArgs args)
 {
     if (args.CurrentState == BundleState.Active)
     {
         AddViewEngine(args.Bundle);
     }
     else if (args.CurrentState == BundleState.Stopping)
     {
         RemoveViewEngine(args.Bundle);
     }
 }
예제 #6
0
 private void BundleEventListener(object sender, BundleStateChangedEventArgs e)
 {
     if (e.CurrentState == BundleState.Active)
     {
         AddViewEngine(e.Bundle);
         return;
     }
     if (e.CurrentState == BundleState.Stopping)
     {
         RemoveViewEngine(e.Bundle);
     }
 }
예제 #7
0
 private void BundleHandler(object sender, BundleStateChangedEventArgs bundleStateChangedEventArgs)
 {
     Dispatcher.Invoke(() =>
     {
         if (ProgressBar.Value < 80)
         {
             var msg = "Loding plugin " + bundleStateChangedEventArgs.Bundle.Name + ", version :" +
                       bundleStateChangedEventArgs.Bundle.Version;
             SetProgress((int)ProgressBar.Value + 1, msg);
         }
     });
 }
예제 #8
0
 public void DispatchBundleEvent(object sender, BundleStateChangedEventArgs e)
 {
     if (_bundleDispatcher != null)
     {
         List <EventHandler <BundleStateChangedEventArgs> > listeners = new List <EventHandler <BundleStateChangedEventArgs> >(_syncBundleListeners);
         List <EventHandler <BundleStateChangedEventArgs> > list2     = new List <EventHandler <BundleStateChangedEventArgs> >(_bundleListeners);
         if ((e.CurrentState != BundleState.Starting) && (e.CurrentState != BundleState.Stopping))
         {
             _bundleDispatcher.DispatchToAsyncListeners(sender, e, list2);
         }
         _bundleDispatcher.DispatchToSyncListeners(sender, e, listeners);
     }
 }
예제 #9
0
 private void BundleStateChangedHandler(object sender, BundleStateChangedEventArgs e)
 {
     if (e.CurrentState == BundleState.Installed)
     {
         _loading.AddMessage(string.Format("安装插件'{0}'......", e.Bundle.SymbolicName));
     }
     else if (e.CurrentState == BundleState.Starting)
     {
         _loading.AddMessage(string.Format("正在启动插件'{0}'......", e.Bundle.SymbolicName));
     }
     else if (e.CurrentState == BundleState.Active)
     {
         _loading.AddMessage(string.Format("插件'{0}'启动完成......", e.Bundle.SymbolicName));
     }
 }
예제 #10
0
        void context_BundleStateChanged(object sender, BundleStateChangedEventArgs args)
        {
            var bundleData = BundleRuntime.Instance.GetFirstOrDefaultService <IBundleInstallerService>().GetBundleDataByName(args.Bundle.SymbolicName);

            if (bundleData == null)
            {
                return;
            }
            if (bundleData.SymbolicName == _context.Bundle.SymbolicName)
            {
                //sometimes autofac can't load itself assemblies for unknown reason.
                return;
            }
            bool needLoad = (args.CurrentState == BundleState.Active);

            if (needLoad)
            {
                //register bundle assemblies to BuildManager.
                var service    = BundleRuntime.Instance.GetFirstOrDefaultService <IRuntimeService>();
                var assemblies = service.LoadBundleAssembly(bundleData.SymbolicName);
                if (assemblies != null && assemblies.Count > 0)
                {
                    var builderContainer = BundleRuntime.Instance.GetFirstOrDefaultService <ContainerBuilder>();
                    if (builderContainer != null)
                    {
                        RegisterBundleAssemblies(args.Bundle.BundleID, builderContainer, assemblies);
                    }
                }
            }
            else if (args.CurrentState == BundleState.Stopping)
            {
                //如果是Stopping,就不再需要更新ContainerBuilder,因为这个服务即将不可用。
                if (BundleRuntime.Instance.State != BundleRuntimeState.Stopping)
                {
                    var builderContainer = BundleRuntime.Instance.GetFirstOrDefaultService <ContainerBuilder>();
                    if (builderContainer != null)
                    {
                        List <Assembly> assemblies;
                        if (_registerHistory.TryGetValue(args.Bundle.BundleID, out assemblies))
                        {
                            builderContainer.UnRegisterControllers(assemblies.ToArray());
                        }
                    }
                }
            }
        }
예제 #11
0
        private void BundleEventListener(object sender, BundleStateChangedEventArgs args)
        {
            // This is in another domain, thus the HttpContext.Current is always null.
            // Just comment it.
            //if (HttpContext.Current == null)
            //{
            //    return;
            //}

            //check if this bundle still exist.
            BundleData bundleData = BundleRuntime.Instance.GetFirstOrDefaultService <IBundleInstallerService>()
                                    .GetBundleDataByName(args.Bundle.SymbolicName);

            if (bundleData == null)
            {
                return;
            }
            bool needLoad = (args.CurrentState == BundleState.Active);

            if (needLoad)
            {
                //already registered its assemblies
                using (ReaderWriterLockHelper.CreateReaderLock(CacheLock))
                {
                    if (RegisteredBunldeCache.ContainsKey(bundleData))
                    {
                        return;
                    }
                    //register bundle assemblies to BuildManager.
                    ICollection <Assembly> assemblies = AddReferencedAssemblies(bundleData.SymbolicName);
                    FileLogUtility.Debug(
                        string.Format("Add the assemblies of bundle '{0}' to top level referenced assemblies since the bundle is active.",
                                      args.Bundle.SymbolicName));
                    if (assemblies != null && assemblies.Count > 0)
                    {
                        using (ReaderWriterLockHelper.CreateWriterLock(CacheLock))
                        {
                            RegisteredBunldeCache[bundleData] = assemblies;
                        }
                    }
                }
            }
            else if (args.CurrentState == BundleState.Stopping)
            {
                //unregister when stopping.
                using (ReaderWriterLockHelper.CreateReaderLock(CacheLock))
                {
                    if (RegisteredBunldeCache.ContainsKey(bundleData))
                    {
                        RemoveReferencedAssemblies(RegisteredBunldeCache[bundleData]);
                        //remove from cache.
                        using (ReaderWriterLockHelper.CreateWriterLock(CacheLock))
                        {
                            RegisteredBunldeCache.Remove(bundleData);
                        }
                        FileLogUtility.Debug(
                            string.Format("Remove the assemblies of bundle '{0}' from top level referenced assemblies since the bundle is stopping.",
                                          args.Bundle.SymbolicName));
                    }
                }
            }
        }
예제 #12
0
        public static void RefreshBundleTopLevelReferencedAssembliesByEvent(object sender, BundleStateChangedEventArgs e)
        {
            BundleData bundleDataByName =
                BundleRuntime.Instance.GetFirstOrDefaultService <IBundleInstallerService>().GetBundleDataByName(e.Bundle.SymbolicName);

            if (bundleDataByName == null)
            {
                return;
            }
            if (e.CurrentState == BundleState.Active)
            {
                AddReferencedAssemblies(bundleDataByName);
                return;
            }
            if (e.CurrentState == BundleState.Stopping)
            {
                RemoveReferencedAssemblies(bundleDataByName);
            }
        }