Exemplo n.º 1
0
        private AssemblyEntry FindCacheByPath(string path)
        {
            AssemblyEntry entry3;

            using (ReaderWriterLockHelper.CreateReaderLock(this._lock))
            {
                AssemblyEntry entry = null;
                using (Dictionary <string, AssemblyEntry> .ValueCollection.Enumerator enumerator = this.Cache.Values.GetEnumerator())
                {
                    AssemblyEntry current;
                    while (enumerator.MoveNext())
                    {
                        current = enumerator.Current;
                        if ((current != null) && (current.AssemblyPath == path))
                        {
                            goto Label_0046;
                        }
                    }
                    goto Label_0058;
Label_0046:
                    entry = current;
                }
Label_0058:
                entry3 = entry;
            }
            return(entry3);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将插件本地程序集添加到ASP.NET页面预编译引用程序集列表。这个方法一般是内部使用。
        /// </summary>
        /// <param name="bundleSymbolicName">插件唯一名称。</param>
        /// <returns>返回插件所有本地程序集。</returns>
        public virtual ICollection <Assembly> AddReferencedAssemblies(string bundleSymbolicName)
        {
            //Check if this bundle still exist or not.
            BundleData bundleData = BundleRuntime.Instance.GetFirstOrDefaultService <IBundleInstallerService>().GetBundleDataByName(bundleSymbolicName);

            if (bundleData == null)
            {
                FileLogUtility.Debug(string.Format("Bundle '{0}' does not exist when trying to add its assemblies to referenced assemblies.",
                                                   bundleSymbolicName));
                return(new List <Assembly>());
            }

            using (ReaderWriterLockHelper.CreateReaderLock(CacheLock))
            {
                //already registered its assembiles
                ICollection <Assembly> registeredItems;
                if (RegisteredBunldeCache.TryGetValue(bundleData, out registeredItems))
                {
                    return(registeredItems);
                }

                IServiceManager serviceContainer = BundleRuntime.Framework.ServiceContainer;
                IRuntimeService service          = serviceContainer.GetFirstOrDefaultService <IRuntimeService>();
                List <Assembly> assemlbies       = service.LoadBundleAssembly(bundleSymbolicName);
                FileLogUtility.Debug(string.Format("Add the assemblies of bundle '{0}' to top level referenced assemblies.", bundleSymbolicName));
                assemlbies.ForEach(AddReferencedAssembly);
                //cache the assemblies
                using (ReaderWriterLockHelper.CreateWriterLock(CacheLock))
                {
                    RegisteredBunldeCache[bundleData] = assemlbies;
                }

                return(assemlbies);
            }
        }
Exemplo n.º 3
0
 public List <ExtensionPoint> GetExtensionPoints()
 {
     using (ReaderWriterLockHelper.CreateReaderLock(this._locker))
     {
         List <ExtensionPoint> list = new List <ExtensionPoint>();
         list.AddRange(this.ExtensionPoints);
         return(list);
     }
 }
Exemplo n.º 4
0
 public Assembly ResolveAssembly(IAssemblyMetadata metadata, AssemblyName assemblyName)
 {
     using (ReaderWriterLockHelper.CreateReaderLock(this._lock))
     {
         AssemblyEntry entry;
         if ((assemblyName != null) && this.Cache.TryGetValue(assemblyName.FullName, out entry))
         {
             return(entry.Assembly);
         }
     }
     return(this.ResolveAssembly(metadata, assembly => StringUtility.IsAssemblyFullNameMatch(assembly, assemblyName, true), true));
 }
Exemplo n.º 5
0
 public List <Extension> GetExtensions(string extensionPoint)
 {
     using (ReaderWriterLockHelper.CreateReaderLock(this._locker))
     {
         List <Extension> list2;
         List <Extension> list = new List <Extension>();
         if (this.Extensions.TryGetValue(extensionPoint, out list2))
         {
             list.AddRange(list2);
         }
         return(list);
     }
 }
Exemplo n.º 6
0
 public List <ExtensionPoint> GetExtensionPoints(IBundle bundle)
 {
     using (ReaderWriterLockHelper.CreateReaderLock(this._locker))
     {
         List <ExtensionPoint> list = new List <ExtensionPoint>();
         foreach (ExtensionPoint point in this.ExtensionPoints)
         {
             if (point.Owner == bundle)
             {
                 list.Add(point);
             }
         }
         return(list);
     }
 }
Exemplo n.º 7
0
 protected bool TryGetCachedType(string className, out Type type)
 {
     type = null;
     if (BundleRuntime.Instance.EnableBundleClassLoaderCache)
     {
         using (ReaderWriterLockHelper.CreateReaderLock(_cacheLock))
         {
             if (_classAssemblyNameCache.Contains(className))
             {
                 type = _classAssemblyNameCache[className] as Type;
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 8
0
 public static void RemoveReferencedAssemblies(BundleData bundleData)
 {
     using (ReaderWriterLockHelper.CreateReaderLock(_cacheLock))
     {
         if (_registeredBunldeCache.ContainsKey(bundleData))
         {
             IList <Assembly> removedAssemblies = _registeredBunldeCache[bundleData];
             using (ReaderWriterLockHelper.CreateWriterLock(_cacheLock))
             {
                 _registeredBunldeCache.Remove(bundleData);
             }
             ResetTopLevelReferencedAssemblies(removedAssemblies);
             FileLogUtility.Debug(
                 string.Format("Remove the assemblies of bundle '{0}' from top level referenced assemblies since the bundle is stopping.",
                               bundleData.SymbolicName));
         }
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// 当启动/停止插件时,需要对TopLevelAssemblies重新处理确保同一个程序集的只有最高版本出现在列表中。
 /// 详细请查看“模块层与类加载设计规范的2.7小节”。
 /// </summary>
 /// <param name="removedAssemblies"></param>
 public static void ResetTopLevelReferencedAssemblies(IList <Assembly> removedAssemblies)
 {
     using (ReaderWriterLockHelper.CreateReaderLock(_cacheLock))
     {
         if (removedAssemblies != null)
         {
             foreach (Assembly current in removedAssemblies)
             {
                 RemoveReferencedAssemlby(current);
             }
         }
         List <Assembly> list = new List <Assembly>();
         foreach (IList <Assembly> current2 in _registeredBunldeCache.Values)
         {
             list.AddRange(current2);
         }
         list.Sort(new AssemblyComparer());
         list.ForEach(AddReferencedAssembly);
     }
 }
Exemplo n.º 10
0
 public static void AddReferencedAssemblies(BundleData bundleData)
 {
     using (ReaderWriterLockHelper.CreateReaderLock(_cacheLock))
     {
         if (!_registeredBunldeCache.ContainsKey(bundleData))
         {
             IList <Assembly> list = AddReferencedAssemblies(bundleData.SymbolicName);
             FileLogUtility.Debug(
                 string.Format("Add the assemblies of bundle '{0}' to top level referenced assemblies since the bundle is active.",
                               bundleData.SymbolicName));
             if (list != null && list.Count > 0)
             {
                 using (ReaderWriterLockHelper.CreateWriterLock(_cacheLock))
                 {
                     _registeredBunldeCache[bundleData] = list;
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
        public Assembly ResolveAssembly(AssemblyName assebmlyFullName)
        {
            Func <AssemblyName, bool> stopWhen = null;

            using (ReaderWriterLockHelper.CreateReaderLock(this._lock))
            {
                AssemblyEntry entry;
                if (this.Cache.TryGetValue(assebmlyFullName.FullName, out entry))
                {
                    return(entry.Assembly);
                }
            }
            IAssemblyMetadataNode node = this.Resolver.ResolvedAssemblyMetadataNodes.Find(delegate(IAssemblyMetadataNode resolvedAssemblyNode) {
                IAssemblyMetadata metadata = resolvedAssemblyNode.Metadata as IAssemblyMetadata;
                AssertUtility.NotNull(metadata);
                if (assebmlyFullName.Version == null)
                {
                    if (!metadata.MultipleVersions)
                    {
                        return(assebmlyFullName.Name.Equals(metadata.AssemblyName.Name));
                    }
                }
                else if (StringUtility.IsAssemblyFullNameMatch(metadata.AssemblyName, assebmlyFullName, true))
                {
                    return(true);
                }
                return(false);
            });

            if (node == null)
            {
                return(null);
            }
            if (stopWhen == null)
            {
                stopWhen = assembly => StringUtility.IsAssemblyFullNameMatch(assembly, assebmlyFullName, true);
            }
            return(this.ResolveAssembly((IAssemblyMetadata)node.Metadata, stopWhen, false));
        }
Exemplo n.º 12
0
 public ExtensionPoint GetExtensionPoint(string extensionPoint)
 {
     extensionPoint = extensionPoint.Trim();
     using (ReaderWriterLockHelper.CreateReaderLock(this._locker))
     {
         foreach (ExtensionPoint point in this.ExtensionPoints)
         {
             if (point.Point == extensionPoint)
             {
                 return(point);
             }
         }
         if (this.GetExtensions(extensionPoint).Count > 0)
         {
             return(new ExtensionPoint(this)
             {
                 Point = extensionPoint
             });
         }
     }
     return(null);
 }
Exemplo n.º 13
0
        /// <summary>
        /// 将插件本地程序集添加到ASP.NET页面预编译引用程序集列表。这个方法一般是内部使用。
        /// </summary>
        /// <param name="bundleSymbolicName">插件唯一名称。</param>
        /// <returns>返回插件所有本地程序集。</returns>
        public static IList <Assembly> AddReferencedAssemblies(string bundleSymbolicName)
        {
            BundleData bundleDataByName =
                BundleRuntime.Instance.GetFirstOrDefaultService <IBundleInstallerService>().GetBundleDataByName(bundleSymbolicName);

            if (bundleDataByName == null)
            {
                FileLogUtility.Debug(string.Format("Bundle '{0}' does not exist when trying to add its assemblies to referenced assemblies.",
                                                   bundleSymbolicName));
                return(new List <Assembly>());
            }
            IList <Assembly> result;

            using (ReaderWriterLockHelper.CreateReaderLock(_cacheLock))
            {
                IList <Assembly> list;
                if (_registeredBunldeCache.TryGetValue(bundleDataByName, out list))
                {
                    result = list;
                }
                else
                {
                    IServiceManager serviceContainer      = BundleRuntime.Instance.Framework.ServiceContainer;
                    IRuntimeService firstOrDefaultService = serviceContainer.GetFirstOrDefaultService <IRuntimeService>();
                    List <Assembly> list2 = firstOrDefaultService.LoadBundleAssembly(bundleSymbolicName);
                    FileLogUtility.Debug(string.Format("Add the assemblies of bundle '{0}' to top level referenced assemblies.", bundleSymbolicName));
                    using (ReaderWriterLockHelper.CreateWriterLock(_cacheLock))
                    {
                        _registeredBunldeCache[bundleDataByName] = list2;
                    }
                    ResetTopLevelReferencedAssemblies(null);
                    result = list2;
                }
            }
            return(result);
        }
Exemplo n.º 14
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));
                    }
                }
            }
        }