public async Task Process() { while (IsEnabled) { using (var db = new InstaBotContext()) { var activeQueues = await db.Queues .Where(x => x.LastActivity < DateTime.UtcNow - TimeSpan.FromSeconds(x.DelayInSeconds) && x.QueueState == QueueState.InProgress && x.IsActive) .Include(x => x.LoginData) .ToListAsync(); foreach (var queue in activeQueues) { try { IInstaApi instaApi = await InstagramApiFactory.GetInstaApiAsync(new InstagramUser(queue.LoginData.Name, queue.LoginData.Password)); IInstagramExecutor instagramExecutor = InstagramServiceFactory.CreateExecutor(queue.QueueType, instaApi); await instagramExecutor.Execute(queue, db); Console.WriteLine(DateTime.Now); } catch (Exception e) { Console.WriteLine(e); //throw; } } } } }
public static IInstagramExecutor CreateExecutor(QueueType queueType, IInstaApi instaApi) { IInstagramExecutor executor = null; switch (queueType) { case QueueType.LikePhoto: executor = new LikeExecutor(instaApi); break; case QueueType.PostMedia: executor = new PostMediaExecutor(instaApi); break; case QueueType.FollowUsers: executor = new FollowUserExecutor(instaApi); break; default: break; } return(executor); }