diff --git a/BotMessageRouting/BotMessageRouting.csproj b/BotMessageRouting/BotMessageRouting.csproj
index 5d6a3a5..7d04309 100644
--- a/BotMessageRouting/BotMessageRouting.csproj
+++ b/BotMessageRouting/BotMessageRouting.csproj
@@ -14,8 +14,8 @@
-
-
+
+
diff --git a/BotMessageRouting/MessageRouting/DataStore/Azure/AzureStorageHelper.cs b/BotMessageRouting/MessageRouting/DataStore/Azure/AzureStorageHelper.cs
index 1a6c949..96e9bc6 100644
--- a/BotMessageRouting/MessageRouting/DataStore/Azure/AzureStorageHelper.cs
+++ b/BotMessageRouting/MessageRouting/DataStore/Azure/AzureStorageHelper.cs
@@ -38,6 +38,31 @@ public static CloudTable GetTable(string connectionString, string tableName)
return cloudTableClient?.GetTableReference(tableName);
}
+ ///
+ /// Tries to insert the given entry into the given table.
+ ///
+ /// TableEntity derivative.
+ /// The destination table.
+ /// The entry to insert into the table.
+ /// True, if the given entry was inserted successfully. False otherwise.
+ public static async Task ReplaceAsync(CloudTable cloudTable, T entryToInsert) where T : ITableEntity
+ {
+ TableOperation replaceOperation = TableOperation.InsertOrReplace(entryToInsert);
+ TableResult replaceResult = null;
+
+ try
+ {
+ replaceResult = await cloudTable.ExecuteAsync(replaceOperation);
+ }
+ catch (Exception e)
+ {
+ System.Diagnostics.Debug.WriteLine($"Failed to replace the given entity into table '{cloudTable.Name}': {e.Message}");
+ return false;
+ }
+
+ return (replaceResult?.Result != null);
+ }
+
///
/// Tries to insert the given entry into the given table.
///
diff --git a/BotMessageRouting/MessageRouting/DataStore/Azure/AzureTableRoutingDataStore.cs b/BotMessageRouting/MessageRouting/DataStore/Azure/AzureTableRoutingDataStore.cs
index 931efad..88f4d64 100644
--- a/BotMessageRouting/MessageRouting/DataStore/Azure/AzureTableRoutingDataStore.cs
+++ b/BotMessageRouting/MessageRouting/DataStore/Azure/AzureTableRoutingDataStore.cs
@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
+using Underscore.Bot.MessageRouting.Logging;
using Underscore.Bot.MessageRouting.Models;
using Underscore.Bot.MessageRouting.Models.Azure;
@@ -24,7 +25,7 @@ public class AzureTableRoutingDataStore : IRoutingDataStore
protected const string TableNameAggregationChannels = "AggregationChannels";
protected const string TableNameConnectionRequests = "ConnectionRequests";
protected const string TableNameConnections = "Connections";
-
+ protected readonly ILogger _logger;
protected CloudTable _botInstancesTable;
protected CloudTable _usersTable;
protected CloudTable _aggregationChannelsTable;
@@ -35,13 +36,15 @@ public class AzureTableRoutingDataStore : IRoutingDataStore
/// Constructor.
///
/// The connection string associated with an Azure Table Storage.
- public AzureTableRoutingDataStore(string connectionString)
+ public AzureTableRoutingDataStore(string connectionString, ILogger logger)
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException("The connection string cannot be null or empty");
}
+ _logger = logger;
+
_botInstancesTable = AzureStorageHelper.GetTable(connectionString, TableNameBotInstances);
_usersTable = AzureStorageHelper.GetTable(connectionString, TableNameUsers);
_aggregationChannelsTable = AzureStorageHelper.GetTable(connectionString, TableNameAggregationChannels);
@@ -216,11 +219,11 @@ protected virtual async void MakeSureTablesExistAsync()
try
{
await cloudTable.CreateIfNotExistsAsync();
- Debug.WriteLine($"Table '{cloudTable.Name}' created or did already exist");
+ _logger.LogInformation($"Table '{cloudTable.Name}' created or did already exist");
}
catch (StorageException e)
{
- Debug.WriteLine($"Failed to create table '{cloudTable.Name}' (perhaps it already exists): {e.Message}");
+ _logger.LogError($"Failed to create table '{cloudTable.Name}' (perhaps it already exists): {e.Message}");
}
}
}
diff --git a/BotMessageRouting/MessageRouting/DataStore/RoutingDataManager.cs b/BotMessageRouting/MessageRouting/DataStore/RoutingDataManager.cs
index 2205b4b..1b29d86 100644
--- a/BotMessageRouting/MessageRouting/DataStore/RoutingDataManager.cs
+++ b/BotMessageRouting/MessageRouting/DataStore/RoutingDataManager.cs
@@ -366,11 +366,11 @@ public virtual bool IsAssociatedWithAggregation(ConversationReference conversati
return (conversationReference != null
&& aggregationParties != null
- && aggregationParties.Count() > 0
+ && aggregationParties.Count > 0
&& aggregationParties.Where(aggregationChannel =>
- aggregationChannel.Conversation.Id == conversationReference.Conversation.Id
- && aggregationChannel.ServiceUrl == conversationReference.ServiceUrl
- && aggregationChannel.ChannelId == conversationReference.ChannelId).Count() > 0);
+ aggregationChannel.Conversation.Id.Equals(conversationReference.Conversation.Id, StringComparison.OrdinalIgnoreCase)
+ && aggregationChannel.ServiceUrl.Equals(conversationReference.ServiceUrl)
+ && aggregationChannel.ChannelId.Equals(conversationReference.ChannelId)).Any());
}
///
diff --git a/BotMessageRouting/MessageRouting/Logging/ConsoleLogger.cs b/BotMessageRouting/MessageRouting/Logging/ConsoleLogger.cs
new file mode 100644
index 0000000..bcc430c
--- /dev/null
+++ b/BotMessageRouting/MessageRouting/Logging/ConsoleLogger.cs
@@ -0,0 +1,44 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+namespace Underscore.Bot.MessageRouting.Logging
+{
+ public class ConsoleLogger : Bot.MessageRouting.Logging.ILogger
+ {
+ private readonly Microsoft.Extensions.Logging.ILogger _logger;
+
+ public ConsoleLogger(Microsoft.Extensions.Logging.ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ public void Log(string message, [CallerMemberName] string methodName = "")
+ {
+ _logger.LogDebug(BuildMessage(message, methodName));
+ }
+
+ public void LogError(string message, [CallerMemberName] string methodName = "")
+ {
+ _logger.LogError(BuildMessage(message, methodName));
+ }
+
+ public void LogInformation(string message, [CallerMemberName] string methodName = "")
+ {
+ _logger.LogInformation(BuildMessage(message, methodName));
+ }
+
+ private string BuildMessage(string message, string methodName)
+ {
+ var msg = $"{DateTime.Now}> ";
+ if (!string.IsNullOrWhiteSpace(methodName))
+ msg += $"{methodName}: {message}";
+ else
+ msg += message;
+
+ return msg;
+ }
+ }
+}
diff --git a/BotMessageRouting/MessageRouting/Logging/DebugLogger.cs b/BotMessageRouting/MessageRouting/Logging/DebugLogger.cs
index d79346e..a99f2ac 100644
--- a/BotMessageRouting/MessageRouting/Logging/DebugLogger.cs
+++ b/BotMessageRouting/MessageRouting/Logging/DebugLogger.cs
@@ -15,5 +15,15 @@ public void Log(string message, [CallerMemberName] string methodName = "")
Debug.WriteLine($"{DateTime.Now}> {message}");
}
+
+ public void LogError(string message, [CallerMemberName] string methodName = "")
+ {
+ Log(message, methodName);
+ }
+
+ public void LogInformation(string message, [CallerMemberName] string methodName = "")
+ {
+ Log(message, methodName);
+ }
}
}
\ No newline at end of file
diff --git a/BotMessageRouting/MessageRouting/Logging/ILogger.cs b/BotMessageRouting/MessageRouting/Logging/ILogger.cs
index d6334ea..e1b8ab1 100644
--- a/BotMessageRouting/MessageRouting/Logging/ILogger.cs
+++ b/BotMessageRouting/MessageRouting/Logging/ILogger.cs
@@ -10,5 +10,20 @@ public interface ILogger
/// The message to log.
/// Resolved by the [CallerMemberName] attribute. No value required.
void Log(string message, [CallerMemberName] string methodName = "");
+
+ ///
+ /// Logs the given message.
+ ///
+ /// The message to log.
+ /// Resolved by the [CallerMemberName] attribute. No value required.
+ void LogInformation(string message, [CallerMemberName] string methodName = "");
+
+ ///
+ /// Logs the given message.
+ ///
+ /// The message to log.
+ /// Resolved by the [CallerMemberName] attribute. No value required.
+ void LogError(string message, [CallerMemberName] string methodName = "");
+
}
}
\ No newline at end of file