Skip to content

Commit

Permalink
Added on and off functionality in SocketClientWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthashw committed Mar 23, 2017
1 parent e825464 commit 433b0a7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 48 deletions.
Expand Up @@ -2,11 +2,6 @@
{
public interface IScrumRepository
{
/// <summary>
/// Method to turn off scrum bot
/// </summary>
void TurnOffScrumBot();

/// <summary>
/// Method to turn on scrum bot
/// </summary>
Expand Down
Expand Up @@ -18,12 +18,18 @@ public interface ISocketClientWrapper
/// Method to initialize scrum bot
/// </summary>
/// <param name="bottoken">scrum bot token</param>
void InitializeScrumBot(string bottoken);
void InitializeAndConnectScrumBot(string bottoken);

/// <summary>
/// Method to initialize task mail bot
/// </summary>
/// <param name="bottoken"></param>
void InitializeTaskBot(string bottoken);
void InitializeAndConnectTaskBot(string bottoken);

/// <summary>
/// Method to turn off bot by module name
/// </summary>
/// <param name="module">name of module</param>
void StopBotByModule(string module);
}
}
Expand Up @@ -2,11 +2,6 @@
{
public interface ITaskMailBotRepository
{
/// <summary>
/// Method to turn off task mail bot
/// </summary>
void TurnOffTaskMailBot();

/// <summary>
/// Method to turn on task mail bot
/// </summary>
Expand Down
Expand Up @@ -33,14 +33,6 @@ public class ScrumRepository : IScrumRepository
#endregion

#region Public Methods
/// <summary>
/// Method to turn off scrum bot
/// </summary>
public void TurnOffScrumBot()
{
_socketClientWrapper.ScrumBot.CloseSocket();
}

/// <summary>
/// Method to turn on scrum bot
/// </summary>
Expand All @@ -49,12 +41,11 @@ public void StartAndConnectScrumBot(string botToken)
{
if (!string.IsNullOrEmpty(botToken))
{
_socketClientWrapper.InitializeScrumBot(botToken);
_socketClientWrapper.InitializeAndConnectScrumBot(botToken);
// Creating a Action<MessageReceived> for Slack Socket Client to get connected.
MessageReceived messageReceive = new MessageReceived();
messageReceive.ok = true;
Action<MessageReceived> showMethod = (MessageReceived messageReceived) => new MessageReceived();
_socketClientWrapper.ScrumBot.Connect((connect) => { });
_socketClientWrapper.ScrumBot.OnMessageReceived += (message) =>
{
_scrumlogger.Debug("Scrum bot got message :" + message);
Expand Down
@@ -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
/// <summary>
/// Contain ScrumBot Client socket details
Expand All @@ -20,8 +25,9 @@ public class SocketClientWrapper : ISocketClientWrapper
/// <summary>
/// Constructor
/// </summary>
public SocketClientWrapper()
public SocketClientWrapper(IStringConstantRepository stringConstant)
{
_stringConstant = stringConstant;
}
#endregion

Expand All @@ -30,18 +36,32 @@ public SocketClientWrapper()
/// Method to initialize scrum bot
/// </summary>
/// <param name="bottoken">scrum bot token</param>
public void InitializeScrumBot(string bottoken)
public void InitializeAndConnectScrumBot(string bottoken)
{
ScrumBot = new SlackSocketClient(bottoken);
ScrumBot.Connect((connect) => { });
}

/// <summary>
/// Method to initialize task mail bot
/// </summary>
/// <param name="bottoken"></param>
public void InitializeTaskBot(string bottoken)
public void InitializeAndConnectTaskBot(string bottoken)
{
TaskBot = new SlackSocketClient(bottoken);
TaskBot.Connect((connect) => { });
}

/// <summary>
/// Method to turn off bot by module name
/// </summary>
/// <param name="module">name of module</param>
public void StopBotByModule(string module)
{
if (module == _stringConstant.TaskModule)
TaskBot.CloseSocket();
else if (module == _stringConstant.Scrum)
ScrumBot.CloseSocket();
}
#endregion
}
Expand Down
Expand Up @@ -30,14 +30,6 @@ public class TaskMailBotRepository : ITaskMailBotRepository
#endregion

#region Public Methods
/// <summary>
/// Method to turn off task mail bot
/// </summary>
public void TurnOffTaskMailBot()
{
_socketClientWrapper.TaskBot.CloseSocket();
}

/// <summary>
/// Method to turn on task mail bot
/// </summary>
Expand All @@ -46,7 +38,7 @@ public void StartAndConnectTaskMailBot(string botToken)
{
if (!string.IsNullOrEmpty(botToken))
{
_socketClientWrapper.InitializeTaskBot(botToken);
_socketClientWrapper.InitializeAndConnectTaskBot(botToken);
// Creating a Action<MessageReceived> for Slack Socket Client to get connected.
MessageReceived messageReceive = new MessageReceived();
messageReceive.ok = true;
Expand Down
Expand Up @@ -15,20 +15,18 @@ public class ConfigurationRepository : IConfigurationRepository
private readonly IRepository<Configuration> _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<Configuration> configurationDataRepository,
IStringConstantRepository stringConstant, IAppCredentialRepository appCredentialRepository,
ITaskMailBotRepository taskMailBotRepository, IScrumRepository scrumRepository)
ISocketClientWrapper socketClientWrapper)
{
_configurationDataRepository = configurationDataRepository;
_stringConstant = stringConstant;
_appCredentialRepository = appCredentialRepository;
_taskMailBotRepository = taskMailBotRepository;
_scrumRepository = scrumRepository;
_socketClientWrapper = socketClientWrapper;
}
#endregion

Expand Down Expand Up @@ -115,14 +113,7 @@ private async Task<bool> StatusOfModule(string module)
/// <returns></returns>
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
Expand Down
@@ -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;
Expand All @@ -18,6 +19,8 @@ public class ConfigurationRepositoryTest
private readonly IStringConstantRepository _stringConstant;
private readonly IRepository<Configuration> _configurationDataRepository;
private readonly IRepository<AppCredential> _appCredentialDataRepository;
private readonly ISocketClientWrapper _socketClientWrapper;
private readonly ITaskMailBotRepository _taskMailBotRepository;
private Configuration taskConfiguration = new Configuration();
private Configuration leaveConfiguration = new Configuration();
private Configuration scrumConfiguration = new Configuration();
Expand All @@ -31,6 +34,8 @@ public ConfigurationRepositoryTest()
_stringConstant = _componentContext.Resolve<IStringConstantRepository>();
_configurationDataRepository = _componentContext.Resolve<IRepository<Configuration>>();
_appCredentialDataRepository = _componentContext.Resolve<IRepository<AppCredential>>();
_socketClientWrapper = _componentContext.Resolve<ISocketClientWrapper>();
_taskMailBotRepository = _componentContext.Resolve<ITaskMailBotRepository>();
Initialize();
}
#endregion
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 433b0a7

Please sign in to comment.