Ejemplo n.º 1
0
#pragma warning restore 649

        public async Task <FindPluginsResult> FindPluginsAsync(string directoryName, CancellationToken cancellationToken)
        {
            return(await Task.Run(() =>
            {
                Plugins = new List <ZvsPlugin>();
                var catalog = new SafeDirectoryCatalog(directoryName);
                var compositionContainer = new CompositionContainer(catalog);

                try
                {
                    compositionContainer.ComposeParts(this);
                }
                catch (CompositionException compositionException)
                {
                    return new FindPluginsResult(compositionException.Message);
                }

                var msg = "All plugins loaded.";
                if (catalog.LoadErrors.Count > 0)
                {
                    msg =
                        $@"The following plug-ins could not be loaded: {
                            string.Join(", " + Environment.NewLine, catalog.LoadErrors)}";
                }
                return new FindPluginsResult(Plugins, msg);
            }, cancellationToken));
        }
Ejemplo n.º 2
0
#pragma warning restore 649

        public async Task<FindAdaptersResult> FindAdaptersAsync(string directoryName, CancellationToken cancellationToken)
        {
            return await Task.Run(() =>
            {
                Adapters = new List<ZvsAdapter>();
                var catalog = new SafeDirectoryCatalog(directoryName);
                var compositionContainer = new CompositionContainer(catalog);

                try
                {
                    compositionContainer.ComposeParts(this);
                }
                catch (CompositionException compositionException)
                {
                    return new FindAdaptersResult(compositionException.Message);
                }

                var msg = "All adapters loaded.";
                if (catalog.LoadErrors.Count > 0)
                    msg =
                        $@"The following plug-ins could not be loaded: {
                            string.Join(", " + Environment.NewLine, catalog.LoadErrors)}";
                return new FindAdaptersResult(Adapters, msg);
            }, cancellationToken);
        }