Example #1
0
        public static Addin GetAddin(string addinFile)
        {
            var addin = new Addin {
                AddinFile = addinFile
            };

            addin.AddinTempFile = GetTempAddin(addin.AddinFile);
            addin.Resolvers     = DllResolve.GetDllResolve(Path.GetDirectoryName(addin.AddinTempFile),
                                                           SearchOption.AllDirectories, ".dll", ".exe");
            Resolvers = addin.Resolvers;
            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            var addinAsm = Assembly.LoadFile(addin.AddinTempFile);

            addin.Commands = GetCommandMethods(addinAsm, addin);
            return(addin);
        }
Example #2
0
        private Assembly?CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                if (dllsResolve == null)
                {
                    // Сборки в основной папке dll
                    dllsResolve = DllResolve.GetDllResolve(CurDllDir, SearchOption.AllDirectories);

                    // Все сборки из папки Script\NET
                    dllsResolve.AddRange(DllResolve.GetDllResolve(
                                             Path.Combine(PikSettings.LocalSettingsFolder, @"Script\NET"),
                                             SearchOption.AllDirectories));

                    // Оставить только сборки под текущую версию автокада
                    dllsResolve = FilterDllResolveVersions(dllsResolve);
                }

                Debug.WriteLine($"AcadLib AssemblyResolve {args.Name}");
                var dllResolver = dllsResolve.FirstOrDefault(f => f.IsResolve(args.Name));
                if (dllResolver == null)
                {
                    var fmAssembly = ResolveFmAssembly(args.Name);
                    if (fmAssembly != null)
                    {
                        Logger.Log.Info($"resolve fm assembly - {fmAssembly.FullName}");
                        return(fmAssembly);
                    }

                    Debug.WriteLine("AcadLib dllResolver == null");
                    return(null);
                }

                var asm = dllResolver.LoadAssembly();
                Logger.Log.Info($"resolve assembly - {asm.FullName}");
                return(asm);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, $"Ошибка AssemblyResolve - {args.Name}.");
            }

            return(null);
        }
Example #3
0
        private static List <DllResolve> GetResolvers()
        {
            var dir = Path.GetDirectoryName(typeof(Commands).Assembly.Location);

            return(DllResolve.GetDllResolve(dir, SearchOption.TopDirectoryOnly));
        }