Пример #1
0
        /// <summary>
        /// Resolves an assembly not found by the system using the assembly
        /// cache.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">A <see cref="ResolveEventArgs" /> that contains the event data.</param>
        /// <returns>
        /// The loaded assembly, or <see langword="null" /> if not found.
        /// </returns>
        private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
        {
            Assembly assembly = DiscoverAssembly(sender, args);

            if (assembly != null)
            {
                ChoAssembly.AddToLoadedAssembly(assembly);
            }

            return(assembly);
        }
Пример #2
0
        public void Initialize()
        {
            //Load Default Assemblies
            foreach (Assembly assembly in ChoAssembly.GetLoadedAssemblies())
            {
                if (_loadedAssemblies.ContainsKey(assembly.FullName))
                {
                    continue;
                }
                _loadedAssemblies.Add(assembly.FullName, assembly);
            }

            LoadAssemblies(ChoCodeBase.Me.Paths);
        }
Пример #3
0
        public void LoadAssemblies(string[] directories)
        {
            if (!ChoGuard.IsArgumentNotNullOrEmpty(directories))
            {
                return;
            }

            foreach (Assembly assembly in ChoAssembly.GetAssemblies(directories))
            {
                if (_loadedAssemblies.ContainsKey(assembly.FullName))
                {
                    continue;
                }
                _loadedAssemblies.Add(assembly.FullName, assembly);
            }
        }
Пример #4
0
        public void LoadAssemblies(string[] directories)
        {
            if (!ChoGuard.IsArgumentNotNullOrEmpty(directories))
            {
                return;
            }

            lock (_padLock)
            {
                foreach (Assembly assembly in ChoAssembly.GetAssemblies(directories))
                {
                    if (_loadedAssemblies.ContainsKey(assembly.FullName))
                    {
                        continue;
                    }
                    _loadedAssemblies.Add(assembly.FullName, assembly);
                    AssemblyLoaded.Raise(null, new ChoEventArgs <Assembly>(assembly));
                }
            }
        }
Пример #5
0
        public bool Initialize(bool beforeFieldInit, object state)
        {
            if (beforeFieldInit)
            {
                return(false);
            }

            //Load Default Assemblies
            foreach (Assembly assembly in ChoAssembly.GetLoadedAssemblies())
            {
                if (_loadedAssemblies.ContainsKey(assembly.FullName))
                {
                    continue;
                }
                _loadedAssemblies.Add(assembly.FullName, assembly);
            }

            LoadAssemblies(ChoCodeBase.Me.Paths);

            return(false);
        }
Пример #6
0
        private static Assembly LoadAssemblyFromResource(string name)
        {
            //Assembly thisAssembly = Assembly.GetEntryAssembly();

            foreach (Assembly thisAssembly in ChoAssembly.GetLoadedAssemblies())
            {
                if (thisAssembly.IsDynamic)
                {
                    continue;
                }
                try
                {
                    //Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder
                    var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name));
                    if (resources.Count() > 0)
                    {
                        var resourceName = resources.First();
                        using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
                        {
                            if (stream == null)
                            {
                                return(null);
                            }
                            var block = new byte[stream.Length];
                            stream.Read(block, 0, block.Length);
                            return(Assembly.Load(block));
                        }
                    }
                }
                catch (Exception ex)
                {
                    ChoTrace.Error(ex);
                }
            }
            return(null);
        }
Пример #7
0
        public static string GetEntryAssemblyLocation()
        {
            HttpContext ctx = HttpContext.Current;

            if (ctx == null)
            {
                return(ChoAssembly.GetEntryAssembly().Location);
            }
            else if (!HttpContext.Current.Request.PhysicalApplicationPath.IsNullOrEmpty())
            {
                if (HttpContext.Current.Request.PhysicalApplicationPath.EndsWith(@"\"))
                {
                    return(HttpContext.Current.Request.PhysicalApplicationPath.Substring(0, HttpContext.Current.Request.PhysicalApplicationPath.Length - 1));
                }
                else
                {
                    return(HttpContext.Current.Request.PhysicalApplicationPath);
                }
            }
            else
            {
                return(Assembly.GetExecutingAssembly().Location);
            }
        }