示例#1
0
        private void LocalPost(Messages msg)
        {
            // post return message straight away to the channel
            LastChannelMessages[msg.channel] = msg.id;

            // write to textbox
            DVH.WriteToTextBox(new List <Messages> {
                msg
            });
        }
示例#2
0
        /// <summary>
        /// Message updating logic
        /// </summary>
        private async void GetMessagesAsync()
        {
            if (MessagesIsPolling == true)
            {
                return;
            }

            MessagesIsPolling = true;

            try
            {
                // get messages for all channels
                foreach (var c in Channels)
                {
                    // get last id from channel message ids dictionary
                    int lastId = 0;

                    if (LastChannelMessages.ContainsKey(c.id))
                    {
                        lastId = LastChannelMessages[c.id];
                    }

                    // get messages frm API
                    if (lastId == 0)
                    {
                        // no local messageId - get all messages using the timeframe specified
                        var inc = (await Client.Channels.GetChannelMessagesFrom(c.id, DateTime.Now.AddMinutes(-3000))).ToList();

                        var t = inc.OrderBy(a => a.id).ToList().LastOrDefault();
                        if (t != null)
                        {
                            LastChannelMessages[c.id] = t.id;
                        }

                        // write to textbox
                        DVH.WriteToTextBox(inc.OrderBy(a => a.id).ToList());

                        // save to database
                        //SaveToLoggingDatabase(inc);
                    }
                    else
                    {
                        var inc = (await Client.Channels.GetChannelMessagesAfterMessageId(c.id, lastId)).ToList();
                        MessagesIsPolling = false;
                        var t = inc.OrderBy(a => a.id).ToList().LastOrDefault();
                        if (t != null)
                        {
                            LastChannelMessages[c.id] = t.id;
                        }

                        // write to textbox
                        DVH.WriteToTextBox(inc.OrderBy(a => a.id).ToList());

                        // save to database
                        //SaveToLoggingDatabase(inc);
                    }

                    MessagesIsPolling = false;
                }
            }
            catch (Exception ex) { APIDisconnected(ex); return; }

            MessagesIsPolling = false;
        }