public PingMiddleware(IMiddleware next, PingPlugin pingPlugin) : base(next) { _pingPlugin = pingPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new []{ "/ping stop", "stop pinging me" }, Description = "Stops sending you pings", EvaluatorFunc = StopPingingHandler }, new HandlerMapping { ValidHandles = new []{ "/ping list", "ping list" }, Description = "Lists all of the people currently being pinged", EvaluatorFunc = ListPingHandler }, new HandlerMapping { ValidHandles = new []{ "ping me", "/ping" }, Description = "Sends you a ping about every second", EvaluatorFunc = PingHandler }, }; }
private static async Task RunMiddleware(IMiddleware[] middleware, IDictionary<string, object> context) { var environment = new Environment(context); for(int i =0;i< middleware.Length;i++) { var result = await middleware[i].Invoke(environment); if (result == MiddlewareInvocationEnum.StopChain) return; } }
public YieldTestMiddleware(IMiddleware next) : base(next) { HandlerMappings = new[] { new HandlerMapping { ValidHandles = new[] { "yield test" }, EvaluatorFunc = YieldTest, Description = "Just tests delayed messages" } }; }
public AboutMiddleware(IMiddleware next) : base(next) { HandlerMappings = new[] { new HandlerMapping { ValidHandles = new []{ "about" }, Description = "Tells you some stuff about this bot :-)", EvaluatorFunc = AboutHandler } }; }
public WelcomeMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next) { _statsPlugin = statsPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new []{"hi", "hey", "hello", "wuzzup"}, Description = "Try saying hi and see what happens", EvaluatorFunc = WelcomeHandler } }; }
public StatsMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next) { _statsPlugin = statsPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new []{ "stats" }, Description = "Returns interesting stats about your noobot installation", EvaluatorFunc = StatsHandler } }; }
public HelpMiddleware(IMiddleware next) : base(next) { HandlerMappings = new[] { new HandlerMapping { ValidHandles = new[] {"/help", "help", "yo tell me more"}, Description = "Returns supported commands and descriptions of how to use them", EvaluatorFunc = HelpHandler } }; }
public WelcomeMiddleware(IMiddleware next) : base(next) { HandlerMappings = new[] { new HandlerMapping { ValidHandles = new []{"hi", "hey", "hello", "wuzzup"}, Description = "Try saying hi and see what happens", EvaluatorFunc = TestHandler } }; }
public JokeMiddleware(IMiddleware next) : base(next) { HandlerMappings = new[] { new HandlerMapping { ValidHandles = new [] { "/joke", "joke", "tell me a joke"}, Description = "Tells a random joke", EvaluatorFunc = JokeHandler } }; }
public JokeMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next) { _statsPlugin = statsPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new [] { "joke", "tell me a joke"}, Description = "Tells a random joke", EvaluatorFunc = JokeHandler } }; }
public AutoResponderMiddleware(IMiddleware next) : base(next) { HandlerMappings = new [] { new HandlerMapping { ValidHandles = new [] { ""}, Description = "Annoys the heck out of everyone", EvaluatorFunc = AutoResponseHandler, MessageShouldTargetBot = false, ShouldContinueProcessing = true } }; }
public FlickrMiddleware(IMiddleware next, IConfigReader configReader) : base(next) { _configReader = configReader; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new [] { "/flickr", "flickr", "/pic", "pic"}, Description = "Finds a pics from flickr - usage: /flickr birds", EvaluatorFunc = FlickrHandler, } }; }
public AdminMiddleware(IMiddleware next, AdminPlugin adminPlugin, SchedulePlugin schedulePlugin, INoobotCore noobotCore, ILog log) : base(next) { _adminPlugin = adminPlugin; _schedulePlugin = schedulePlugin; _noobotCore = noobotCore; _log = log; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new []{ "admin pin" }, EvaluatorFunc = PinHandler, Description = "This function is used to authenticate a user as admin", VisibleInHelp = false }, new HandlerMapping { ValidHandles = new []{ "admin schedules list" }, EvaluatorFunc = SchedulesListHandler, Description = "[Requires authentication] Will return a list of all schedules.", VisibleInHelp = false }, new HandlerMapping { ValidHandles = new []{ "admin schedules delete" }, EvaluatorFunc = DeleteSchedulesHandler, Description = "[Requires authentication] This will delete all schedules.", VisibleInHelp = false }, new HandlerMapping { ValidHandles = new []{ "admin channels" }, EvaluatorFunc = ChannelsHandler, Description = "[Requires authentication] Will return all channels connected.", VisibleInHelp = false }, new HandlerMapping { ValidHandles = new []{"admin help", "admin list"}, EvaluatorFunc = AdminHelpHandler, Description = "[Requires authentication] Lists all available admin functions", VisibleInHelp = false } }; }
public ScheduleMiddleware(IMiddleware next, SchedulePlugin schedulePlugin, StatsPlugin statsPlugin) : base(next) { _schedulePlugin = schedulePlugin; _statsPlugin = statsPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new [] { "schedule hourly"}, Description = "Schedule a command to execute every hour on the current channel. Usage: `@{bot} schedule hourly @{bot} tell me a joke`", EvaluatorFunc = HourlyHandler, }, new HandlerMapping { ValidHandles = new [] { "schedule daily"}, Description = "Schedule a command to execute every day on the current channel. Usage: `@{bot} schedule daily @{bot} tell me a joke`", EvaluatorFunc = DayHandler, }, new HandlerMapping { ValidHandles = new [] { "schedule cronjob"}, Description = "Schedule a cron job for this channel. Usage: `@{bot} schedule cronjob '0 15 10 * * ?' @{bot} tell me a joke`", EvaluatorFunc = CronHandler, }, new HandlerMapping { ValidHandles = new [] { "schedule list"}, Description = "List all schedules on the current channel", EvaluatorFunc = ListHandlerForChannel, }, new HandlerMapping { ValidHandles = new [] { "schedule delete"}, Description = "Delete a schedule in this channel. You must enter a valid {guid}", EvaluatorFunc = DeleteHandlerForChannel, }, }; }
public CalculatorMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next) { _statsPlugin = statsPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new []{"calc"}, Description = "Calculate mathematical expressions - usage: calc ((1+2)*3)/4", EvaluatorFunc = CalculateHandler, MessageShouldTargetBot = false }, new HandlerMapping { ValidHandles = new []{""}, Description = "Try to calculate mathematical expressions without the 'calc' prefix - usage: ((1+2)*3)/4", EvaluatorFunc = CalculateHandler, MessageShouldTargetBot = false, ShouldContinueProcessing = true } }; }
/// <inheritdoc/> public void Release(IMiddleware middleware) { // The container owns the lifetime of the service }
public MiddlewareException(IMiddleware <TContext> middleware, TContext context, string message) : base(message) { Middleware = middleware; Context = context; }
public MiddlewareException(IMiddleware <TContext> middleware, TContext context) { Middleware = middleware; Context = context; }
public new TwitterAdapter Use(IMiddleware middleware) { MiddlewareSet.Use(middleware); return(this); }
public BeginMessageMiddleware(IMiddleware next) : base(next) { }
public BeginMessageMiddleware(IMiddleware next, StatsPlugin statsPlugin, ILog log) : base(next) { _statsPlugin = statsPlugin; _log = log; }
public StatsdFrontendEventProcessor(IMiddleware hostedMiddeMiddleware) { _hostedMiddeMiddleware = hostedMiddeMiddleware; }
public static IMiddleware UseMvc(this IMiddleware host, string viewroot, ServiceGroup services, bool checkPathCase = false) { return(host.InsertMiddleware(new MvcMiddleware(viewroot, services, checkPathCase))); }
public static IMiddleware UseRoute(this IMiddleware host, string sourcePath, string controllerName, string actionName) { return(host.InsertMiddleware(new RouteMiddleware(sourcePath, controllerName, actionName))); }
public static IMiddleware UseStaticFile(this IMiddleware host, string rootPath) { return(host.InsertMiddleware(new StaticFileMiddleware(rootPath))); }
public static IMiddleware UseDefaultFile(this IMiddleware host, string location, string pathMatch, string fileName = "index.html") { return(host.InsertMiddleware(new DefaultFileMiddleware(location, pathMatch, fileName))); }
public static IMiddleware UseHeaders(this IMiddleware host, string serverName = "Genji", bool keepAlive = true) { return(host.InsertMiddleware(new HeadersMiddleware(serverName, keepAlive))); }
public override void ConnectMiddleware(IMiddleware middleware) { this.connectedMiddleware.Add(middleware); }
public StatsdFrontendEventProcessorFactory(IMiddleware hostedMiddleware, EventHubFrontendConfiguration configuration) { _hostedMiddleware = hostedMiddleware; _configuration = configuration; }
public static IMiddleware UseNotFound(this IMiddleware host, string root, string errorPage) { return(host.InsertMiddleware(new NotFoundMiddleware(root, errorPage))); }
protected MiddlewareBase(IMiddleware next) { _next = next; HandlerMappings = HandlerMappings ?? new HandlerMapping[0]; }
/// <summary> /// Adds a middleware object to the end of the set. /// </summary> /// <param name="middleware">The middleware to add.</param> /// <returns>The updated middleware set.</returns> /// <see cref="BotAdapter.Use(IMiddleware)"/> public MiddlewareSet Use(IMiddleware middleware) { BotAssert.MiddlewareNotNull(middleware); _middleware.Add(middleware); return(this); }
protected MiddlewareBase(IMiddleware next) { Next = next; }
public void Release(IMiddleware middleware) { Released = middleware; }
/// <summary> /// Adds middleware to the adapter's pipeline. /// </summary> /// <param name="middleware">The middleware to add.</param> /// <returns>The updated adapter object.</returns> /// <remarks>Middleware is added to the adapter at initialization time. /// For each turn, the adapter calls middleware in the order in which you added it. /// </remarks> public new TestAdapter Use(IMiddleware middleware) { base.Use(middleware); return(this); }
public void Release(IMiddleware middleware) { }
/// <inheritdoc /> public virtual void Release(IMiddleware <TContext> middleware) { }
public BotFrameworkAdapter(string appId, string appPassword, HttpClient httpClient = null, IMiddleware middleware = null) : this(new SimpleCredentialProvider(appId, appPassword), httpClient, middleware) { }
public MiddlewareException(IMiddleware <TContext> middleware, TContext context, params Exception[] innerExceptions) : base(innerExceptions) { Middleware = middleware; Context = context; }
public IMiddlewareSetup AddMiddleWare(IMiddleware middleware) { Middleware.Add(middleware); return this; }
public MiddlewareException(IMiddleware <TContext> middleware, TContext context, string message, IEnumerable <Exception> innerExceptions) : base(message, innerExceptions) { Middleware = middleware; Context = context; }
public MiddlewareAdapter(IMiddleware <TAction> middleware) { _middleware = middleware; }
public void RegisterMiddleware(IMiddleware middleware) { _beforeView.Add(middleware); _afterView.Insert(0, middleware); }
/// <summary> /// Adds middleware to the adapter's pipeline. /// </summary> /// <param name="middleware">The middleware to add.</param> /// <returns>The updated adapter object.</returns> /// <remarks>Middleware is added to the adapter at initialization time. /// For each turn, the adapter calls middleware in the order in which you added it. /// </remarks> public BotAdapter Use(IMiddleware middleware) { MiddlewareSet.Use(middleware); return(this); }
public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger <BotFrameworkHttpAdapter> logger, IMiddleware middleware, ConversationState conversationState = null) : base(credentialProvider) { OnTurnError = async(turnContext, exception) => { // Log any leaked exception from the application. logger.LogError($"Exception caught : {exception.Message}"); // Send a catch-all apology to the user. await turnContext.SendActivityAsync("Sorry, it looks like something went wrong."); if (conversationState != null) { try { // Delete the conversationState for the current conversation to prevent the // bot from getting stuck in a error-loop caused by being in a bad state. // ConversationState should be thought of as similar to "cookie-state" in a Web pages. await conversationState.DeleteAsync(turnContext); } catch (Exception e) { logger.LogError($"Exception caught on attempting to Delete ConversationState : {e.Message}"); } } }; Use(middleware); Use(new ShowTypingMiddleware()); }
/// <summary> /// Initializes this object. /// </summary> private void Initialize() { if (!DIContainer.IsRegistered<IMiddleware>()) { throw new Exception("未在 DIContainer 中注册 IMiddleware 类型的实例!"); } if (!DIContainer.IsRegistered<ILog>()) { throw new Exception("未在 DIContainer 中注册 ILog 类型的实例!"); } _serviceObjects = new SortedList<string, ServiceObject>(); _logger = DIContainer.Resolve<ILog>(); _middleware = DIContainer.Resolve<IMiddleware>(); //通过注册的服务初始化_serviceObjects foreach (ApService aps in DIContainer.Resolves<ApService>()) { AddService(aps); } //初始化最大线程数 InitializeMaxThread(); _middleware.MessageReceived += (msg) => { if (!(msg is IBytesMessage)) return; //同步调用 //DoInvoke(msg); //异步调用 ThreadPool.QueueUserWorkItem(new WaitCallback(DoInvoke), msg); }; }
public TraceLogMiddleware(IMiddleware next) : base(next) { }
public UdpFrontend(IMiddleware hostedMiddleware, IPEndPoint serverEndpoint) { _hostedMiddleware = hostedMiddleware; _udpClient = new UdpClient(serverEndpoint); }
public TcpFrontend(IMiddleware hostedMiddleware, IPEndPoint serverEndpoint) { _hostedMiddleware = hostedMiddleware; _listener = new TcpListener(serverEndpoint); }
public RootReducerBuilder <TState> UseMiddleware(IMiddleware <TState> middleware) { _middleware.Add(middleware); return(this); }
public EventHubFrontend(IMiddleware hostedMiddleware, EventHubFrontendConfiguration configuration) { _eventProcessorFactory = new StatsdFrontendEventProcessorFactory(hostedMiddleware, configuration); _eventProcessorHost = new EventProcessorHost(configuration.EventProcessorName, configuration.EventHubName, EventHubConsumerGroup.DefaultGroupName, configuration.EventHubConnectionString, configuration.StorageConnectionString); }
/// <summary> /// Initializes a new instance of the <see cref="BotFrameworkAdapter"/> class, /// using an application ID and secret. /// </summary> /// <param name="appId">The application ID of the bot.</param> /// <param name="appPassword">The application secret for the bot.</param> /// <param name="connectorClientRetryPolicy">Retry policy for retrying HTTP operations.</param> /// <param name="httpClient">The HTTP client.</param> /// <param name="middleware">The middleware to initially add to the adapter.</param> /// <remarks>Use a <see cref="MiddlewareSet"/> object to add multiple middleware /// components in the conustructor. Use the <see cref="Use(IMiddleware)"/> method to /// add additional middleware to the adapter after construction. /// </remarks> public BotFrameworkAdapter(string appId, string appPassword, RetryPolicy connectorClientRetryPolicy = null, HttpClient httpClient = null, IMiddleware middleware = null) : this(new SimpleCredentialProvider(appId, appPassword), connectorClientRetryPolicy, httpClient, middleware) { }
public EventHubMiddleware(IMiddleware next, EventHubMiddlewareConfiguration config) : base(next) { _config = config; }
/// <summary> /// Adds middleware to the adapter's pipeline. /// </summary> /// <param name="middleware">The middleware to add.</param> /// <returns>The updated adapter object.</returns> /// <remarks>Middleware is added to the adapter at initialization time. /// For each turn, the adapter calls middleware in the order in which you added it. /// </remarks> public new BotFrameworkAdapter Use(IMiddleware middleware) { base._middlewareSet.Use(middleware); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="BotFrameworkAdapter"/> class, /// using a credential provider. /// </summary> /// <param name="credentialProvider">The credential provider.</param> /// <param name="connectorClientRetryPolicy">Retry policy for retrying HTTP operations.</param> /// <param name="httpClient">The HTTP client.</param> /// <param name="middleware">The middleware to initially add to the adapter.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="credentialProvider"/> is <c>null</c>.</exception> /// <remarks>Use a <see cref="MiddlewareSet"/> object to add multiple middleware /// components in the conustructor. Use the <see cref="Use(IMiddleware)"/> method to /// add additional middleware to the adapter after construction. /// </remarks> public BotFrameworkAdapter(ICredentialProvider credentialProvider, RetryPolicy connectorClientRetryPolicy = null, HttpClient httpClient = null, IMiddleware middleware = null) { _credentialProvider = credentialProvider ?? throw new ArgumentNullException(nameof(credentialProvider)); _httpClient = httpClient ?? new HttpClient(); _connectorClientRetryPolicy = connectorClientRetryPolicy; if (middleware != null) { this.Use(middleware); } }
public static void RegisterMiddleware <TPayload>(IMiddleware <TPayload> middleware) { CheckDefaultDipatcher(); s_DefaultDispatcher.RegisterMiddlewareImplementation(middleware); }
public new ConsoleAdapter Use(IMiddleware middleware) { base.Use(middleware); return(this); }
public WebSocketService(IServiceProvider serviceProvider, IOptions <ServerOptions> serverOptions, IChannelCreatorFactory channelCreatorFactory) : base(serviceProvider, serverOptions, channelCreatorFactory) { _sessionContainerMiddleware = Middlewares.FirstOrDefault(m => m is IAsyncSessionContainer || m is ISessionContainer); }
public void RegisterMiddleware(IMiddleware <TMetaPacket, TContext> middleware) { _middleware.Add(middleware); }
public SimpleHost(IMiddleware middleware, IList<IFrontend> fontends) { _middleware = middleware; _fontends = fontends; }