コード例 #1
0
        /// <summary>
        /// Starts the request dispatcher.
        /// </summary>
        /// <param name="relayNamespace">The ServiceBus namespace that hosts this Relay. E.g. BCDemoAgent.servicebus.windows.net</param>
        /// <param name="hybridConnectionName"></param>
        /// <param name="keyName">The name of your Shared Access Policies key, which is RootManageSharedAccessKey by default</param>
        /// <param name="sharedAccessKey"></param>
        /// <param name="pluginFolder"></param>
        /// <param name="logger">Logger implementation</param>
        /// <param name="cancellationToken">Cancellation Tokan</param>
        public static async void Start(
            string relayNamespace,
            string hybridConnectionName,
            string keyName,
            string sharedAccessKey,
            string pluginFolder,
            ILogger logger,
            CancellationToken cancellationToken
            )
        {
            logger?.LogMessage(LogLevel.Verbose, $"Loading plugins from: {pluginFolder}");
            CompositionContext compositionContext             = CompositionHelper.CreateCompositionHost(pluginFolder);
            ImmutableDictionary <string, AgentPlugin> plugins = compositionContext.TryGetExports <IAgentPlugin, AgentPluginMetadata>()
                                                                .Select(exp => AgentPlugin.Create(exp.Metadata, exp.Value, logger))
                                                                .Where(p => p != null)
                                                                .ToImmutableDictionary(p => p.RootPath);

            if (plugins.IsEmpty)
            {
                logger?.LogMessage(LogLevel.Error, $"No valid plugins. Exiting...");
                return;
            }

            HybridConnectionListener listener = CreateHybridConnectionListener(relayNamespace, hybridConnectionName, keyName, sharedAccessKey, logger);

            await new RequestDispatcher(listener, plugins, logger).RunAsync(cancellationToken);
        }