private async Task MigrateConversation( Conversation conversation, CancellationToken cancellationToken) { Logger.Debug("Getting messages ..."); using (AsyncEnumerator <Message> messageEnumerator = await input.GetMessages(conversation.Id, filter)) { while (await messageEnumerator.Move()) { // Read message. Message message = await messageEnumerator.Read(); Logger.Trace("Read message: {0}", message); if (message.MessageType == Enums.InternalMessageType.Unknown) { Logger.Warn("Skip message."); continue; } // Get message group and open new group if necessary. Group group = await grouper.GetGroup(input, conversation, message); Logger.Trace("Group: {0}", group); if (!group.Equals(output.CurrentGroup)) { output.EndGroup(); output.BeginGroup(group); } // Insert message. await output.InsertMessage(message); // Check cancellation token. cancellationToken.ThrowIfCancellationRequested(); } } }
public async Task Migrate(CancellationToken cancellationToken) { Logger.Debug("Starting migration ..."); using (AsyncEnumerator <Conversation> conversationEnumerator = await input.GetConversationsAsync()) { while (await conversationEnumerator.Move()) { Conversation conversation = await conversationEnumerator.Read(); Logger.Debug("Read conversation: {0}", conversation); await MigrateConversation(conversation, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); } } Logger.Debug("Finished."); }