Ejemplo n.º 1
0
            /// <summary>
            /// Resolve o assembly informado.
            /// </summary>
            /// <param name="args"></param>
            /// <param name="assembly"></param>
            /// <param name="error">Erro ocorrido</param>
            /// <returns></returns>
            public bool Resolve(ResolveEventArgs args, out System.Reflection.Assembly assembly, out Exception error)
            {
                var libraryName = new System.Reflection.AssemblyName(args.Name).Name;

                if (!libraryName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
                {
                    libraryName = string.Concat(libraryName, ".dll");
                }
                if (_assemblies.TryGetValue(libraryName, out assembly))
                {
                    error = null;
                    return(true);
                }
                var part = _deploymentParts.Where(f => string.Compare(System.IO.Path.GetFileName(f), libraryName, true) == 0).FirstOrDefault();

                if (part != null)
                {
                    try
                    {
                        var name = System.Reflection.AssemblyName.GetAssemblyName(part);
                        assembly = _appDomain.Load(name);
                        assembly.GetTypes();
                    }
                    catch (Exception ex)
                    {
                        error = ex;
                        return(false);
                    }
                    _assemblies.Add(libraryName, assembly);
                    error = null;
                    return(true);
                }
                error = null;
                return(false);
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Resolve o assembly informado.
            /// </summary>
            /// <param name="args"></param>
            /// <param name="assembly"></param>
            /// <param name="error">Erro ocorrido</param>
            /// <returns></returns>
            public bool Resolve(ResolveEventArgs args, out System.Reflection.Assembly assembly, out Exception error)
            {
                var libraryName = new System.Reflection.AssemblyName(args.Name).Name;

                if (!libraryName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
                {
                    libraryName = string.Concat(libraryName, ".dll");
                }
                if (_assemblies.TryGetValue(libraryName, out assembly))
                {
                    error = null;
                    return(true);
                }
                var part = _deploymentParts.Where(f => string.Compare(f.Source, libraryName, true) == 0).FirstOrDefault();

                if (part != null)
                {
                    try
                    {
                        if (_packageDirectory == null)
                        {
                            var fileInfo = _zipArchive.Files.Where(f => f.Name == part.Source).FirstOrDefault();
                            var buffer   = new byte[fileInfo.Length];
                            using (var file = _zipArchive.OpenRead(part.Source))
                                file.Read(buffer, 0, buffer.Length);
                            assembly = part.Load(_appDomain, buffer);
                        }
                        else
                        {
                            assembly = part.Load(_appDomain, System.IO.Path.Combine(_packageDirectory, part.Source));
                        }
                        assembly.GetTypes();
                    }
                    catch (Exception ex)
                    {
                        error = ex;
                        return(false);
                    }
                    _assemblies.Add(libraryName, assembly);
                    error = null;
                    return(true);
                }
                error = null;
                return(false);
            }