Пример #1
0
        /// <summary> Processes the given marc file and creates an instance of <see cref="IPluginInfo"/>. </summary>
        /// <param name="bundle">Marc file to process</param>
        /// <returns>Instance of PluginInfo or null</returns>
        private IPluginInfo RegisterBundle(IBundle bundle)
        {
            _log.Debug($"Processing bundle '{bundle}'");
            try {
                Stream signatureFileStream = bundle.GetResourceAsStream("signature.mf");

                if (signatureFileStream == null)
                {
                    _log.Debug("No signature file found. Plug-in will not be available!");
                    return(null);
                }

                _log.Debug("Signature file found");
                IPluginSignature pluginSignature;

                using (signatureFileStream) {
                    pluginSignature = SignatureFactory.Instance.CreateSignature(signatureFileStream);
                    _log.Debug($"Resolved plug-in signature '{pluginSignature}'");
                }

                IPluginInfo pluginInfo = PluginFactory.Instance.CreatePluginInfo(bundle, pluginSignature);
                _log.Debug($"Resolved plug-in info '{pluginInfo}'");

                return(pluginInfo);
            } catch (Exception ex) {
                string message = $"Could not process marc file '{bundle}'. Plug-in will not be available!";
                _log.Error(message, ex);
            }
            return(null);
        }
Пример #2
0
        /// <summary> Will be invoked when the app domain cannot resolve an assembly on its own. </summary>
        private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            string assemblyName = args.Name;

            string[] nameSplit = assemblyName.Split(',');
            // Fully qualified name
            if (nameSplit.Length > 1)
            {
                assemblyName = nameSplit[0];
            }

            // Remove trailing '.dll'
            assemblyName = assemblyName.Replace(".dll", string.Empty);

            // Maybe the assembly has already been resolved
            if (_nameToAssemblyMap.TryGetValue(assemblyName, out Assembly assmbly))
            {
                return(assmbly);
            }

            Stream assemblyStream;
            // Maybe it's an included assembly?
            string         dllName = $"{assemblyName}.dll";
            IncludeMapping inclMap = _includeMappings.FirstOrDefault(x => x.Name == dllName);

            if (inclMap != null)
            {
                string  path   = inclMap.BundlePath;
                IBundle bundle = inclMap.Bundle;
                assemblyStream = bundle.GetResourceAsStream(path);
                using (assemblyStream) {
                    return(Unwrap(assemblyStream, assemblyName));
                }
            }

            // TODO Maybe a hash algorithmn would be faster
            // Looking for normal plugged assembly
            using (LinkedList <IPluginInfo> .Enumerator enmtor = _providedPlugins.GetEnumerator()) {
                while (enmtor.MoveNext())
                {
                    IPluginInfo plugin = enmtor.Current;
                    if (plugin == null)
                    {
                        continue;
                    }

                    IBundle bundle = plugin.Bundle;
                    if (bundle.Name != assemblyName)
                    {
                        continue;
                    }

                    string lookupName = $"{assemblyName}.dll";
                    assemblyStream = bundle.GetResourceAsStream(lookupName);
                    using (assemblyStream) {
                        return(Unwrap(assemblyStream, assemblyName));
                    }
                }
            }

            return(null);
        }