예제 #1
0
        private void Update()
        {
            var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            try
            {
                var followeesResp = _twitter.GetFriendIds().GetAwaiter().GetResult();
                followeesResp.OnSuccess(ids =>
                {
                    var updatedTasks = _tasks.Get();
                    _data.Update(d =>
                    {
                        if (d.LastUpdatedTimestamp < now - now % (SecondsPerHour * 24))
                        {
                            d.LikesGivenPerFollowee = d.LikesGivenPerFollowee.ToDictionary(kvp => kvp.Key, kvp => 0);
                        }
                        ScheduleLikesForFollowees(now, ids, d, updatedTasks).GetAwaiter().GetResult();
                        d.LastUpdatedTimestamp = now;
                        return(d);
                    });
                    _tasks.Update(t => updatedTasks);
                });
            }
            catch (TwitterException x)
            {
                _log.Error($"Twitter error! {x}");
            }
            catch (Exception x)
            {
                _log.Error($"Network error! {x}");
            }
        }
예제 #2
0
 private void UpdateMaxLikesForFollowee(string userId, int amount)
 {
     _data.Update(d =>
     {
         d.MaxLikesPerFollowee[userId] = amount;
         return(d);
     });
 }
예제 #3
0
        protected override void Go(string[] args)
        {
            var time  = DateTimeOffsetConverter.ParseFutureTime(args[0]);
            var tweet = args[1];

            _tasks.Update(tasks =>
            {
                var task = new ScheduledTask(tasks.NextId, new ScheduledOperation(time, _like.Name, tweet));
                tasks.Add(task);
                _log.Info($"Added Task '{task.Id}' - {task.ScheduledOperations[0].Time}");
                return(tasks);
            });
        }
 public void Execute(string[] args)
 {
     if (args.Length < 1)
     {
         _log.Error("Missing Target Process Name");
     }
     else
     {
         _targets.Update(t =>
         {
             t.Remove(args[0]);
             t.OutputTo(_log);
             return(t);
         });
     }
 }
예제 #5
0
 protected override void Go(string[] args)
 {
     _tasks.Update(tasks =>
     {
         foreach (var arg in args)
         {
             if (tasks.Any(t => t.Id.ToString() == arg))
             {
                 tasks.RemoveAll(t => t.Id.ToString() == arg);
             }
             else
             {
                 _log.Error("Task with id " + arg + " doesn't exist.");
             }
         }
         return(tasks);
     });
 }
예제 #6
0
        protected override void Go(string[] args)
        {
            var shouldRunContinuously = args.Length == 0 || !args[0].Equals("once", StringComparison.InvariantCultureIgnoreCase);

            _lastUpdate = DateTimeOffset.Now;
            _log.Info($"Running. Currently, there are {_tweetTasks.Get().Count} scheduled tasks.");
            while (true)
            {
                var time = DateTimeOffset.Now;
                _tweetTasks.Update(RunScheduledTasks(time));
                _likeTasks.Update(RunScheduledTasks(time));
                _automaton.Update(time - _lastUpdate);
                _lastUpdate = time;
                if (!shouldRunContinuously)
                {
                    return;
                }
                Thread.Sleep(1000);
            }
        }
예제 #7
0
 protected override void Go(string[] args)
 {
     _credentials.Update(_ => new Credentials(args[0], args[1], args[2], args[3], args[4]));
     _log.Info($"Saved Credentials for {args[0]}");
 }