コード例 #1
0
        /// <summary>
        /// Hub method. Called when client requests to pull his/her history message.
        /// </summary>
        /// <param name="username">The username of the client</param>
        /// <param name="untilTime">The earliest message stored on the client. Any message
        /// after the untilTime will not be pulled</param>
        /// <returns></returns>
        public async Task OnPullHistoryMessagesReceived(string username, long untilTime)
        {
            _logger.LogInformation(string.Format("OnPullHistoryMessageReceived username: {0}; until: {1}", username, untilTime));

            //  Convert java base client time to C# DateTime object
            var untilDateTime = JavaLongToCSharpDateTime(untilTime);

            //  Fetch history from message storage. After done, send them back with a callback method SendHistoryMessages.
            List <Message> historyMessages = new List <Message>();
            bool           success         = await _messageStorage.TryFetchHistoryMessageAsync(username, untilDateTime, historyMessages);

            //  Only send messages out when storage was a success
            if (success)
            {
                await SendHistoryMessages(historyMessages);
            }
        }