コード例 #1
0
        /// <inheritdoc/>
        public async void LoadExtensionsFromZipArchive(IList <string> extensions, ZipArchive archive)
        {
            foreach (var dll in archive.Entries.Where(x =>
                                                      x.FullName.StartsWith("extension\\") &&
                                                      x.FullName.ToLower().EndsWith(".dll")))
            {
                using (var filestream = new FileStream($"{ExtensionHelper.GetTempPath()}\\{dll.Name}", FileMode.Create))
                {
                    dll.Open().CopyTo(filestream);
                    filestream.Close();
                }
            }

            foreach (var extension in extensions)
            {
                var dll = archive.Entries.FirstOrDefault(x => x.Name == extension);

                if (ExtensionHelper.LoadedExtensions.Contains(extension))
                {
                    await logService.WriteAsync($"Extension '{extension}' already contained in loaded extensions",
                                                LogLevel.Debug);

                    continue;
                }

                Assembly assembly = null;

                try
                {
                    assembly = Assembly.Load(ReadStream(dll.Open()));
                    await logService.WriteAsync($"Assembly loaded from {extension}", LogLevel.Info);
                }
                catch
                {
                    await logService.WriteAsync($"Could not load extension at: " +
                                                $"{extension}", LogLevel.Error);

                    continue;
                }

                if (assembly == null)
                {
                    continue;
                }

                LoadExtension(assembly, extension);
            }
        }
コード例 #2
0
        /// <inheritdoc/>
        public async void LoadExtensions(IList <string> extensions)
        {
            //load all assemblies in extension folder.

            foreach (var dll in Directory.GetFiles($"{Environment.CurrentDirectory}\\extension")
                     .Where(x => x.ToLower().EndsWith(".dll")))
            {
                File.Copy(dll, $"{ExtensionHelper.GetTempPath()}\\{Path.GetFileName(dll)}");
            }

            foreach (var extension in extensions)
            {
                if (ExtensionHelper.LoadedExtensions.Contains(extension))
                {
                    await logService.WriteAsync($"Extension '{extension}' already contained in loaded extensions",
                                                LogLevel.Debug);

                    continue;
                }

                Assembly assembly = null;

                try
                {
                    assembly = Assembly.LoadFile($"{Environment.CurrentDirectory}\\extension\\{extension}");
                    await logService.WriteAsync($"Assembly loaded from \\extension\\{extension}", LogLevel.Info);
                }
                catch
                {
                    await logService.WriteAsync($"Could not load extension at: " +
                                                $"{Path.GetFullPath($"\\extension\\{extension}")}", LogLevel.Error);

                    continue;
                }


                if (assembly == null)
                {
                    continue;
                }

                LoadExtension(assembly, extension);
            }
        }