protected override bool ExecuteRemovePendingRequest(Party requestorParty)
 {
     return(AzureStorageHelper.DeleteEntryAsync <PartyEntity>(
                _pendingRequestsTable,
                PartyEntity.CreatePartitionKey(requestorParty, PartyEntityType.PendingRequest),
                PartyEntity.CreateRowKey(requestorParty)).Result);
 }
        public bool RemoveAggregationChannel(ConversationReference aggregationChannel)
        {
            string rowKey = aggregationChannel.Conversation.Id;

            return(AzureStorageHelper.DeleteEntryAsync <RoutingDataEntity>(
                       _aggregationChannelsTable, DefaultPartitionKey, rowKey).Result);
        }
        public bool RemoveConnectionRequest(ConnectionRequest connectionRequest)
        {
            string rowKey = connectionRequest.Requestor.Conversation.Id;

            return(AzureStorageHelper.DeleteEntryAsync <RoutingDataEntity>(
                       _connectionRequestsTable, DefaultPartitionKey, rowKey).Result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableQuery"></param>
        /// <returns></returns>
        protected virtual async Task <IEnumerable <ConnectionEntity> > GetConnectionEntitiesAsync(TableQuery <ConnectionEntity> tableQuery = null)
        {
            Dictionary <Party, Party> connectedParties = new Dictionary <Party, Party>();

            tableQuery = tableQuery ?? new TableQuery <ConnectionEntity>();
            return(await AzureStorageHelper.ExecuteTableQueryAsync(_connectionsTable, tableQuery));
        }
 protected override bool ExecuteRemoveAggregationParty(Party aggregationPartyToRemove)
 {
     return(AzureStorageHelper.DeleteEntryAsync <PartyEntity>(
                _aggregationPartiesTable,
                PartyEntity.CreatePartitionKey(aggregationPartyToRemove, PartyEntityType.Aggregation),
                PartyEntity.CreateRowKey(aggregationPartyToRemove)).Result);
 }
 protected override bool ExecuteRemoveParty(Party partyToRemove, bool isUser)
 {
     return(AzureStorageHelper.DeleteEntryAsync <PartyEntity>(
                isUser ? _userPartiesTable : _botPartiesTable,
                PartyEntity.CreatePartitionKey(partyToRemove, isUser ? PartyEntityType.User : PartyEntityType.Bot),
                PartyEntity.CreateRowKey(partyToRemove)).Result);
 }
 private static bool InsertEntityToTable(string rowKey, string body, CloudTable table)
 {
     return(AzureStorageHelper.InsertAsync <RoutingDataEntity>(table,
                                                               new RoutingDataEntity()
     {
         Body = body, PartitionKey = DefaultPartitionKey, RowKey = rowKey
     }).Result);
 }
        public bool RemoveConnection(Connection connection)
        {
            string rowKey = connection.ConversationReference1.Conversation.Id +
                            connection.ConversationReference2.Conversation.Id;

            return(AzureStorageHelper.DeleteEntryAsync <RoutingDataEntity>(
                       _connectionsTable, DefaultPartitionKey, rowKey).Result);
        }
 protected override bool ExecuteAddConnection(Party conversationOwnerParty, Party conversationClientParty)
 {
     return(AzureStorageHelper.InsertAsync <ConnectionEntity>(_connectionsTable, new ConnectionEntity()
     {
         PartitionKey = conversationClientParty.ConversationAccount.Id,
         RowKey = conversationOwnerParty.ConversationAccount.Id,
         Client = JsonConvert.SerializeObject(new PartyEntity(conversationClientParty, PartyEntityType.Client)),
         Owner = JsonConvert.SerializeObject(new PartyEntity(conversationOwnerParty, PartyEntityType.Owner))
     }).Result);
 }
        protected override bool ExecuteRemoveAggregationParty(Party aggregationPartyToRemove)
        {
            var partyEntitiesToRemove = GetPartyEntitiesByPropertyNameAndValue(
                PartitionKey,
                PartyEntity.CreatePartitionKey(aggregationPartyToRemove, PartyEntityType.Aggregation))
                                        .FirstOrDefault();

            return(AzureStorageHelper.DeleteEntry <PartyEntity>(
                       _partiesTable, partyEntitiesToRemove.PartitionKey, partyEntitiesToRemove.RowKey));
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="connectionString">The connection string associated with an Azure Table Storage.</param>
        /// <param name="globalTimeProvider">The global time provider for providing the current
        /// time for various events such as when a connection is requested.</param>
        public AzureTableStorageRoutingDataManager(string connectionString, GlobalTimeProvider globalTimeProvider = null)
            : base(globalTimeProvider)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("The connection string cannot be null or empty");
            }

            _partiesTable     = AzureStorageHelper.GetTable(connectionString, TableNameParties);
            _connectionsTable = AzureStorageHelper.GetTable(connectionString, TableNameConnections);

            MakeSureTablesExist();
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="connectionString">The connection string associated with an Azure Table Storage.</param>
        public AzureTableRoutingDataStore(string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("The connection string cannot be null or empty");
            }

            _botInstancesTable        = AzureStorageHelper.GetTable(connectionString, TableNameBotInstances);
            _usersTable               = AzureStorageHelper.GetTable(connectionString, TableNameUsers);
            _aggregationChannelsTable = AzureStorageHelper.GetTable(connectionString, TableNameAggregationChannels);
            _connectionRequestsTable  = AzureStorageHelper.GetTable(connectionString, TableNameConnectionRequests);
            _connectionsTable         = AzureStorageHelper.GetTable(connectionString, TableNameConnections);

            MakeSureTablesExistAsync();
        }
        public override void DeleteAll()
        {
            base.DeleteAll();

            try
            {
                var partyEntities = _partiesTable.ExecuteQuery(new TableQuery <PartyEntity>());

                foreach (var partyEntity in partyEntities)
                {
                    AzureStorageHelper.DeleteEntry <PartyEntity>(
                        _partiesTable, partyEntity.PartitionKey, partyEntity.RowKey);
                }
            }
            catch (StorageException e)
            {
                System.Diagnostics.Debug.WriteLine($"Failed to delete entries: {e.Message}");
                return;
            }

            var connectionEntities = _connectionsTable.ExecuteQuery(new TableQuery <ConnectionEntity>());

            foreach (var connectionEntity in connectionEntities)
            {
                AzureStorageHelper.DeleteEntry <ConnectionEntity>(
                    _connectionsTable, connectionEntity.PartitionKey, connectionEntity.RowKey);
            }

            /*
             * try
             * {
             *  _partiesTable.Delete();
             * }
             * catch (Exception e)
             * {
             *  System.Diagnostics.Debug.WriteLine($"An error occured while trying to delete the parties table: {e.Message}");
             * }
             *
             * try
             * {
             *  _connectionsTable.Delete();
             * }
             * catch (Exception e)
             * {
             *  System.Diagnostics.Debug.WriteLine($"An error occured while trying to delete the connections table: {e.Message}");
             * }
             */
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="connectionString">The connection string associated with an Azure Table Storage.</param>
        /// <param name="globalTimeProvider">The global time provider for providing the current
        /// time for various events such as when a connection is requested.</param>
        public AzureTableStorageRoutingDataManager(string connectionString, GlobalTimeProvider globalTimeProvider = null)
            : base(globalTimeProvider)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("The connection string cannot be null or empty");
            }

            _botPartiesTable         = AzureStorageHelper.GetTable(connectionString, TableNameBotParties);
            _userPartiesTable        = AzureStorageHelper.GetTable(connectionString, TableNameUserParties);
            _aggregationPartiesTable = AzureStorageHelper.GetTable(connectionString, TableNameAggregationParties);
            _pendingRequestsTable    = AzureStorageHelper.GetTable(connectionString, TableNamePendingRequests);
            _connectionsTable        = AzureStorageHelper.GetTable(connectionString, TableNameConnections);

            MakeSureTablesExistAsync();
        }
        protected override bool ExecuteRemoveConnection(Party conversationOwnerParty)
        {
            Dictionary <Party, Party> connectedParties = GetConnectedParties();

            if (connectedParties != null && connectedParties.Remove(conversationOwnerParty))
            {
                Party conversationClientParty = GetConnectedCounterpart(conversationOwnerParty);

                return(AzureStorageHelper.DeleteEntryAsync <ConnectionEntity>(
                           _connectionsTable,
                           conversationClientParty.ConversationAccount.Id,
                           conversationOwnerParty.ConversationAccount.Id).Result);
            }

            return(false);
        }
        public bool RemoveConversationReference(ConversationReference conversationReference)
        {
            CloudTable table = null;

            if (conversationReference.Bot != null)
            {
                table = _botInstancesTable;
            }
            else
            {
                table = _usersTable;
            }

            string rowKey = conversationReference.Conversation.Id;

            return(AzureStorageHelper.DeleteEntryAsync <RoutingDataEntity>(
                       table, DefaultPartitionKey, rowKey).Result);
        }
        public override async void DeleteAll()
        {
            base.DeleteAll();

            CloudTable[] cloudTables =
            {
                _botPartiesTable,
                _userPartiesTable,
                _aggregationPartiesTable,
                _connectionsTable
            };

            foreach (CloudTable cloudTable in cloudTables)
            {
                try
                {
                    var partyEntities = await GetPartyEntitiesAsync(cloudTable);

                    foreach (var partyEntity in partyEntities)
                    {
                        await AzureStorageHelper.DeleteEntryAsync <PartyEntity>(
                            cloudTable, partyEntity.PartitionKey, partyEntity.RowKey);
                    }
                }
                catch (StorageException e)
                {
                    System.Diagnostics.Debug.WriteLine($"Failed to delete entries from table '{cloudTable.Name}': {e.Message}");
                    return;
                }
            }

            var connectionEntities = await GetConnectionEntitiesAsync();

            foreach (var connectionEntity in connectionEntities)
            {
                await AzureStorageHelper.DeleteEntryAsync <ConnectionEntity>(
                    _connectionsTable, connectionEntity.PartitionKey, connectionEntity.RowKey);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cloudTable"></param>
 /// <param name="tableQuery"></param>
 /// <returns></returns>
 protected virtual async Task <IEnumerable <PartyEntity> > GetPartyEntitiesAsync(
     CloudTable cloudTable, TableQuery <PartyEntity> tableQuery = null)
 {
     tableQuery = tableQuery ?? new TableQuery <PartyEntity>();
     return(await AzureStorageHelper.ExecuteTableQueryAsync <PartyEntity>(cloudTable, tableQuery));
 }
 protected override bool ExecuteAddParty(Party partyToAdd, bool isUser)
 {
     return(AzureStorageHelper.InsertAsync <PartyEntity>(
                isUser ? _userPartiesTable : _botPartiesTable,
                new PartyEntity(partyToAdd, isUser ? PartyEntityType.User : PartyEntityType.Bot)).Result);
 }
 protected override bool ExecuteAddParty(Party partyToAdd, bool isUser)
 {
     return(AzureStorageHelper.Insert <PartyEntity>(
                _partiesTable,
                new PartyEntity(partyToAdd, isUser ? PartyEntityType.User : PartyEntityType.Bot)));
 }
 protected override bool ExecuteAddPendingRequest(Party requestorParty)
 {
     return(AzureStorageHelper.InsertAsync <PartyEntity>(
                _pendingRequestsTable, new PartyEntity(requestorParty, PartyEntityType.PendingRequest)).Result);
 }
 protected override bool ExecuteAddAggregationParty(Party aggregationPartyToAdd)
 {
     return(AzureStorageHelper.InsertAsync <PartyEntity>(
                _aggregationPartiesTable, new PartyEntity(aggregationPartyToAdd, PartyEntityType.Aggregation)).Result);
 }