diff --git a/Slack.Automation/Promact.Core.Repository/BotRepository/IScrumRepository.cs b/Slack.Automation/Promact.Core.Repository/BotRepository/IScrumRepository.cs index fc1cd160..552b7b02 100644 --- a/Slack.Automation/Promact.Core.Repository/BotRepository/IScrumRepository.cs +++ b/Slack.Automation/Promact.Core.Repository/BotRepository/IScrumRepository.cs @@ -2,11 +2,6 @@ { public interface IScrumRepository { - /// - /// Method to turn off scrum bot - /// - void TurnOffScrumBot(); - /// /// Method to turn on scrum bot /// diff --git a/Slack.Automation/Promact.Core.Repository/BotRepository/ISocketClientWrapper.cs b/Slack.Automation/Promact.Core.Repository/BotRepository/ISocketClientWrapper.cs index 52bb3d55..043db259 100644 --- a/Slack.Automation/Promact.Core.Repository/BotRepository/ISocketClientWrapper.cs +++ b/Slack.Automation/Promact.Core.Repository/BotRepository/ISocketClientWrapper.cs @@ -18,12 +18,18 @@ public interface ISocketClientWrapper /// Method to initialize scrum bot /// /// scrum bot token - void InitializeScrumBot(string bottoken); + void InitializeAndConnectScrumBot(string bottoken); /// /// Method to initialize task mail bot /// /// - void InitializeTaskBot(string bottoken); + void InitializeAndConnectTaskBot(string bottoken); + + /// + /// Method to turn off bot by module name + /// + /// name of module + void StopBotByModule(string module); } } diff --git a/Slack.Automation/Promact.Core.Repository/BotRepository/ITaskMailBotRepository.cs b/Slack.Automation/Promact.Core.Repository/BotRepository/ITaskMailBotRepository.cs index e97b537c..567e7ad2 100644 --- a/Slack.Automation/Promact.Core.Repository/BotRepository/ITaskMailBotRepository.cs +++ b/Slack.Automation/Promact.Core.Repository/BotRepository/ITaskMailBotRepository.cs @@ -2,11 +2,6 @@ { public interface ITaskMailBotRepository { - /// - /// Method to turn off task mail bot - /// - void TurnOffTaskMailBot(); - /// /// Method to turn on task mail bot /// diff --git a/Slack.Automation/Promact.Core.Repository/BotRepository/ScrumRepository.cs b/Slack.Automation/Promact.Core.Repository/BotRepository/ScrumRepository.cs index 838d666f..064cca64 100644 --- a/Slack.Automation/Promact.Core.Repository/BotRepository/ScrumRepository.cs +++ b/Slack.Automation/Promact.Core.Repository/BotRepository/ScrumRepository.cs @@ -33,14 +33,6 @@ public class ScrumRepository : IScrumRepository #endregion #region Public Methods - /// - /// Method to turn off scrum bot - /// - public void TurnOffScrumBot() - { - _socketClientWrapper.ScrumBot.CloseSocket(); - } - /// /// Method to turn on scrum bot /// @@ -49,12 +41,11 @@ public void StartAndConnectScrumBot(string botToken) { if (!string.IsNullOrEmpty(botToken)) { - _socketClientWrapper.InitializeScrumBot(botToken); + _socketClientWrapper.InitializeAndConnectScrumBot(botToken); // Creating a Action for Slack Socket Client to get connected. MessageReceived messageReceive = new MessageReceived(); messageReceive.ok = true; Action showMethod = (MessageReceived messageReceived) => new MessageReceived(); - _socketClientWrapper.ScrumBot.Connect((connect) => { }); _socketClientWrapper.ScrumBot.OnMessageReceived += (message) => { _scrumlogger.Debug("Scrum bot got message :" + message); diff --git a/Slack.Automation/Promact.Core.Repository/BotRepository/SocketClientWrapper.cs b/Slack.Automation/Promact.Core.Repository/BotRepository/SocketClientWrapper.cs index 0d74a6ac..1c25134c 100644 --- a/Slack.Automation/Promact.Core.Repository/BotRepository/SocketClientWrapper.cs +++ b/Slack.Automation/Promact.Core.Repository/BotRepository/SocketClientWrapper.cs @@ -1,9 +1,14 @@ -using SlackAPI; +using Promact.Erp.Util.StringConstants; +using SlackAPI; namespace Promact.Core.Repository.BotRepository { public class SocketClientWrapper : ISocketClientWrapper { + #region Private Variable + private readonly IStringConstantRepository _stringConstant; + #endregion + #region Public property /// /// Contain ScrumBot Client socket details @@ -20,8 +25,9 @@ public class SocketClientWrapper : ISocketClientWrapper /// /// Constructor /// - public SocketClientWrapper() + public SocketClientWrapper(IStringConstantRepository stringConstant) { + _stringConstant = stringConstant; } #endregion @@ -30,18 +36,32 @@ public SocketClientWrapper() /// Method to initialize scrum bot /// /// scrum bot token - public void InitializeScrumBot(string bottoken) + public void InitializeAndConnectScrumBot(string bottoken) { ScrumBot = new SlackSocketClient(bottoken); + ScrumBot.Connect((connect) => { }); } /// /// Method to initialize task mail bot /// /// - public void InitializeTaskBot(string bottoken) + public void InitializeAndConnectTaskBot(string bottoken) { TaskBot = new SlackSocketClient(bottoken); + TaskBot.Connect((connect) => { }); + } + + /// + /// Method to turn off bot by module name + /// + /// name of module + public void StopBotByModule(string module) + { + if (module == _stringConstant.TaskModule) + TaskBot.CloseSocket(); + else if (module == _stringConstant.Scrum) + ScrumBot.CloseSocket(); } #endregion } diff --git a/Slack.Automation/Promact.Core.Repository/BotRepository/TaskMailBotRepository.cs b/Slack.Automation/Promact.Core.Repository/BotRepository/TaskMailBotRepository.cs index 32078f54..9e065f87 100644 --- a/Slack.Automation/Promact.Core.Repository/BotRepository/TaskMailBotRepository.cs +++ b/Slack.Automation/Promact.Core.Repository/BotRepository/TaskMailBotRepository.cs @@ -30,14 +30,6 @@ public class TaskMailBotRepository : ITaskMailBotRepository #endregion #region Public Methods - /// - /// Method to turn off task mail bot - /// - public void TurnOffTaskMailBot() - { - _socketClientWrapper.TaskBot.CloseSocket(); - } - /// /// Method to turn on task mail bot /// @@ -46,7 +38,7 @@ public void StartAndConnectTaskMailBot(string botToken) { if (!string.IsNullOrEmpty(botToken)) { - _socketClientWrapper.InitializeTaskBot(botToken); + _socketClientWrapper.InitializeAndConnectTaskBot(botToken); // Creating a Action for Slack Socket Client to get connected. MessageReceived messageReceive = new MessageReceived(); messageReceive.ok = true; diff --git a/Slack.Automation/Promact.Core.Repository/ConfigurationRepository/ConfigurationRepository.cs b/Slack.Automation/Promact.Core.Repository/ConfigurationRepository/ConfigurationRepository.cs index e37e7960..626e332c 100644 --- a/Slack.Automation/Promact.Core.Repository/ConfigurationRepository/ConfigurationRepository.cs +++ b/Slack.Automation/Promact.Core.Repository/ConfigurationRepository/ConfigurationRepository.cs @@ -15,20 +15,18 @@ public class ConfigurationRepository : IConfigurationRepository private readonly IRepository _configurationDataRepository; private readonly IAppCredentialRepository _appCredentialRepository; private readonly IStringConstantRepository _stringConstant; - private readonly ITaskMailBotRepository _taskMailBotRepository; - private readonly IScrumRepository _scrumRepository; + private readonly ISocketClientWrapper _socketClientWrapper; #endregion #region Constructor public ConfigurationRepository(IRepository configurationDataRepository, IStringConstantRepository stringConstant, IAppCredentialRepository appCredentialRepository, - ITaskMailBotRepository taskMailBotRepository, IScrumRepository scrumRepository) + ISocketClientWrapper socketClientWrapper) { _configurationDataRepository = configurationDataRepository; _stringConstant = stringConstant; _appCredentialRepository = appCredentialRepository; - _taskMailBotRepository = taskMailBotRepository; - _scrumRepository = scrumRepository; + _socketClientWrapper = socketClientWrapper; } #endregion @@ -115,14 +113,7 @@ private async Task StatusOfModule(string module) /// private async Task StopBotByModuleAsync(string module) { - if (module == _stringConstant.TaskModule) - { - _taskMailBotRepository.TurnOffTaskMailBot(); - } - if (module == _stringConstant.Scrum) - { - _scrumRepository.TurnOffScrumBot(); - } + _socketClientWrapper.StopBotByModule(module); await _appCredentialRepository.ClearBotTokenByModule(module); } #endregion diff --git a/Slack.Automation/Promact.Core.Test/ConfigurationRepositoryTest.cs b/Slack.Automation/Promact.Core.Test/ConfigurationRepositoryTest.cs index 6511f2f8..c36f5994 100644 --- a/Slack.Automation/Promact.Core.Test/ConfigurationRepositoryTest.cs +++ b/Slack.Automation/Promact.Core.Test/ConfigurationRepositoryTest.cs @@ -1,4 +1,5 @@ using Autofac; +using Promact.Core.Repository.BotRepository; using Promact.Core.Repository.ConfigurationRepository; using Promact.Erp.DomainModel.DataRepository; using Promact.Erp.DomainModel.Models; @@ -18,6 +19,8 @@ public class ConfigurationRepositoryTest private readonly IStringConstantRepository _stringConstant; private readonly IRepository _configurationDataRepository; private readonly IRepository _appCredentialDataRepository; + private readonly ISocketClientWrapper _socketClientWrapper; + private readonly ITaskMailBotRepository _taskMailBotRepository; private Configuration taskConfiguration = new Configuration(); private Configuration leaveConfiguration = new Configuration(); private Configuration scrumConfiguration = new Configuration(); @@ -31,6 +34,8 @@ public ConfigurationRepositoryTest() _stringConstant = _componentContext.Resolve(); _configurationDataRepository = _componentContext.Resolve>(); _appCredentialDataRepository = _componentContext.Resolve>(); + _socketClientWrapper = _componentContext.Resolve(); + _taskMailBotRepository = _componentContext.Resolve(); Initialize(); } #endregion @@ -97,6 +102,7 @@ public async Task GetAppCredentialsByConfigurationIdAsync() [Fact, Trait("Category", "Required")] public async Task DisableAppByConfigurationIdAsync() { + _taskMailBotRepository.StartAndConnectTaskMailBot(_stringConstant.AccessTokenForTest); await AddConfigurationAsync(); var configurationId = (await _configurationDataRepository.FirstAsync(x => x.Module == _stringConstant.TaskModule)).Id; await _configurationRepository.DisableAppByConfigurationIdAsync(configurationId);