Exemplo n.º 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}");
            }
        }
Exemplo n.º 2
0
 protected override void Go(string[] args)
 {
     _log.Info("ID".PadRight(16) + "Next Time");
     foreach (var task in _tasks.Get())
     {
         _log.Info(task.Id.ToString().PadRight(16) + task.ScheduledOperations[task.CompletedOperations].Time);
     }
 }
        public async Task <Result> Execute(string[] args)
        {
            var credentials = _credentials.Get();
            var username    = credentials.AreValid ? credentials.Username : "******";

            _log.Info($"{nameof(credentials.Username)}: {username}");
            _log.Info("");
            return(await _inner.Execute(args));
        }
Exemplo n.º 4
0
        public void Update(TimeSpan delta)
        {
            if (!_data.Get().IsEnabled)
            {
                return;
            }

            _timeTilNextUpdate -= delta;
            if (_timeTilNextUpdate <= TimeSpan.Zero)
            {
                Update();
                _timeTilNextUpdate = TimeSpan.FromSeconds(60);
            }
        }
Exemplo n.º 5
0
        public void Execute(string[] args)
        {
            while (true)
            {
                var targets   = _targets.Get();
                var processes = Process.GetProcesses();
                processes
                .Where(x => targets.Contains(x.ProcessName))
                .OrderBy(x => x.ProcessName)
                .ToList()
                .ForEach(Kill);

                Thread.Sleep(2000);
            }
        }
        protected override void Go(string[] args)
        {
            var credentials = _credentials.Get();

            if (!credentials.AreValid)
            {
                _log.Error("No Credentials are set.");
            }
            else
            {
                _log.Info($"{nameof(credentials.Username)}: {credentials.Username}");
                _log.Info($"{nameof(credentials.ConsumerKey)}: {credentials.ConsumerKey}");
                _log.Info($"{nameof(credentials.ConsumerKeySecret)}: {credentials.ConsumerKeySecret}");
                _log.Info($"{nameof(credentials.AccessToken)}: {credentials.AccessToken}");
                _log.Info($"{nameof(credentials.AccessTokenSecret)}: {credentials.AccessTokenSecret}");
            }
        }
Exemplo n.º 7
0
        private async Task <Result <JObject> > SendRequest(
            string method, string relativeUrl, Dictionary <string, string> query, IHttpKeyValuePairs data)
        {
            var credentials = _credentials.Get();

            if (!credentials.AreValid)
            {
                return(Result <JObject> .Errored(ResultStatus.ClientError, "Credentials have not been setup. Use 'SaveCredentials' to initialize."));
            }

            var client = new OAuthClient("https://api.twitter.com/1.1/", credentials);

            var result = JObject.Parse(await client.SendRequest(method, relativeUrl, query, data));

            return(result.ContainsKey("errors")
                ? Result <JObject> .Errored(ResultStatus.DependencyFailure, ToErrorMessage(result))
                : result);
        }
Exemplo n.º 8
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);
            }
        }