Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var groupList = GroupMeApi.GetGroupListAsync().Result;

            var tasks = new List <Task>();

            groupList.ForEach(group => {
                NpgSqlApi.AsyncAddOrUpdateGroup(group).Wait();

                var getAllMessagesTask = CollectData.GetAllMessagesAsync(group);
                tasks.Add(getAllMessagesTask);
            });

            tasks.ForEach(task => task.Wait());
        }
Ejemplo n.º 2
0
        public static Task GetAllMessagesAsync(Group group)
        {
            var task = new Task(() => {
                var startId          = NpgSqlApi.GetNewestGroupMessageAsync(group).Result;
                Task newMessagesTask = null;
                if (startId != null && startId != group.MessageInfo.LastMessageId)
                {
                    // Get all messages after startId
                    newMessagesTask = new Task(() => {
                        var newMsgs = GroupMeApi.GetMessagesAfterIdAsync(group.Id, startId).Result;
                        while (newMsgs.Count != 0)
                        {
                            NpgSqlApi.AddMessagesToDatabaseAsync(group, newMsgs);
                            var lastMessageId = newMsgs.Last().Id;
                            newMsgs           = GroupMeApi.GetMessagesAfterIdAsync(group.Id, lastMessageId).Result;
                        }
                    });
                    newMessagesTask.Start();
                }

                var oldId = NpgSqlApi.GetOldestGroupMessageAsync(group).Result;
                if (oldId == null)
                {
                    oldId = "";
                }
                var oldMsgs = GroupMeApi.GetMessagesBeforeIdAsync(group.Id, oldId).Result;

                while (oldMsgs.Count != 0)
                {
                    NpgSqlApi.AddMessagesToDatabaseAsync(group, oldMsgs);
                    oldId   = oldMsgs.Last().Id;
                    oldMsgs = GroupMeApi.GetMessagesBeforeIdAsync(group.Id, oldId).Result;
                }

                if (newMessagesTask != null)
                {
                    newMessagesTask.Wait();
                }
            });

            task.Start();
            return(task);
        }