コード例 #1
0
 public UserConfiguration(IAppSettings appSettings, ISlackConfiguration slackConfiguration, ITeamConfiguration teamConfiguration, IZoomConfiguration zoomConfiguration)
 {
     m_appSettings      = appSettings;
     SlackConfiguration = slackConfiguration;
     TeamConfiguration  = teamConfiguration;
     ZoomConfiguration  = zoomConfiguration;
 }
コード例 #2
0
        public SlackChannelApi(ISlackConfiguration configuration)
        {
            _httpClient = new HttpClient
            {
                BaseAddress = new Uri("https://slack.com/")
            };

            _configuration = configuration;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Slack"/> class.
        /// </summary>
        /// <param name="slackConfiguration">The Slack configuration.</param>
        /// <param name="poster">The Slack message poster.</param>
        public Slack(ISlackConfiguration slackConfiguration, ISlackMessagePoster poster)
        {
            this.poster = poster;

            // Set default values...
            messageLevel = SlackMessageLevel.Info;

            pendingSlackMessage = new SlackMessage(slackConfiguration.DefaultChannel);
        }
コード例 #4
0
        public SlackBot(ISlackBotCommand[] commands, ISlackConfiguration configuration, IShutdown shutdown)
        {
            if (!configuration.Enabled)
            {
                return;
            }

            CancellationToken token = shutdown.Token;

            Worker = Task.Run(() =>
            {
                SlackConnector.SlackConnector connector = new SlackConnector.SlackConnector();

                ISlackConnection client = connector.Connect(configuration.BotUserToken).Result;

                client.OnMessageReceived += message =>
                {
                    var context = new SlackBotCommandContext(client.Say, message);

                    var tasks = new List <Task>();

                    Parallel.ForEach(commands, command =>
                    {
                        Task task;
                        if (command.TryHandle(context, token, out task))
                        {
                            tasks.Add(task);
                        }
                    });

                    // TODO: Implement various messages - randomly selected
                    //  - also implement a "/help" command type
                    if (tasks.Count == 0)
                    {
                        return(context.WriteText("Hey, you're cool, but I don't understand what you're trying to do."));
                    }

                    return(Task.WhenAll(tasks));
                };

                token.WaitHandle.WaitOne();

                client.Disconnect();
            }, token);
        }
コード例 #5
0
        public SlackMessageQueue(ISlackMessageHandlerFactory factory, IShutdown shutdown, ILogger logger, ISlackConfiguration configuration)
        {
            _factory = factory;
            _logger  = logger;

            if (!configuration.Enabled)
            {
                return;
            }

            _token = shutdown.Token;
            _queue = new BlockingCollection <Func <Task> >();

            Consumer = Task.Run(() =>
            {
                while (!_token.IsCancellationRequested)
                {
                    Func <Task> messageInvoker = null;

                    try
                    {
                        messageInvoker = _queue.Take(_token);
                    }
                    catch (OperationCanceledException)
                    {
                    }

                    Task task = messageInvoker?.Invoke();

                    if (task != null)
                    {
                        try
                        {
                            task.Wait(_token);
                        }
                        catch (OperationCanceledException)
                        {
                            // ignore if operation is cancelled.
                        }
                        catch (AggregateException ex)
                        {
                            foreach (Exception exception in ex.Flatten().InnerExceptions)
                            {
                                _logger.LogError(exception);
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError(ex);
                        }
                    }
                }
            }, _token);
        }
コード例 #6
0
 public SlackChangeNotifier(ISlackConfiguration configuration)
 {
     _configuration = configuration;
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SlackMessagePoster"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 public SlackMessagePoster(ISlackConfiguration configuration)
 {
     this.configuration = configuration;
 }
コード例 #8
0
 public SlackChangeNotifier(ISlackConfiguration configuration)
 {
     _configuration = configuration;
 }