Exemplo n.º 1
0
        TimeSpan UpdateNextShare()
        {
            ShareMessage sh = null;
            Message m = null;

            using (var repo = new Repo()) {
                sh = repo.Table<ShareMessage>().Where(s => s.Status == ShareMessageStatus.Unsent).FirstOrDefault();
                if (sh != null) {
                    m = repo.Table<Message>().Where(mm => mm.Id == sh.MessageId).FirstOrDefault();
                }

                if (sh == null) {
                    // Nothing to do
                    return TimeSpan.FromMinutes(1);
                }

                if (sh != null && m == null) {
                    // Missing the message, must have been deleted
                    sh.Status = ShareMessageStatus.Abandoned;
                    repo.Update(sh);
                    return TimeSpan.FromSeconds(2);
                }
            }

            //
            // Ready to send!
            //
            var post = new Dictionary<string, string>();
            post["url"] = m.Url;
            post["title"] = m.Subject;
            post["from"] = sh.From;
            post["to"] = sh.To;

            try {
                Http.Post("http://lcarsreader.com/Share/Send", post);

                sh.Status = ShareMessageStatus.Sent;
                using (var repo = new Repo()) {
                    repo.Update(sh);
                }
                Console.WriteLine ("SU: Successfully posted share for " + m.Subject);
                return TimeSpan.FromSeconds(2);
            }
            catch (Exception ex) {
                Console.WriteLine ("SU: ERROR: " + ex.Message);
                return TimeSpan.FromMinutes(1);
            }
        }
Exemplo n.º 2
0
        TimeSpan Update()
        {
            GoogleReaderConfig info = null;

            var now = DateTime.UtcNow;

            var updateInterval = TimeSpan.FromHours(8);

            using (var repo = new Repo()) {
                info = repo.Table<GoogleReaderConfig>().FirstOrDefault();
            }

            if (info == null || !info.IsValid) {
                return TimeSpan.FromHours(10);
            }

            if ((now - info.LastUpdateTime) < updateInterval) {
                return updateInterval - (now - info.LastUpdateTime);
            }

            Console.WriteLine ("GU: Gathering subscriptions");

            LogIn(info);

            var subs = GetSubscriptions();

            Subscribe(subs);

            MarkRead();

            using (var repo = new Repo()) {
                info.LastUpdateTime = now;
                repo.Update(info);
            }

            return TimeSpan.FromHours(8);
        }
Exemplo n.º 3
0
        void SaveAccessTokens()
        {
            using (var repo = new Repo()) {

                var tokens = repo.Table<TwitterOAuthTokens>().Where(t => t.Account == _auth.ScreenName).FirstOrDefault();

                if (tokens == null) {
                    tokens = new TwitterOAuthTokens() {
                        Account = _auth.ScreenName,
                        Token = _auth.AccessToken,
                        TokenSecret = _auth.AccessTokenSecret,
                        UserId = _auth.UserId
                    };
                    repo.Insert(tokens);
                }
                else {
                    tokens.Token = _auth.AccessToken;
                    tokens.TokenSecret = _auth.AccessTokenSecret;
                    tokens.UserId = _auth.UserId;
                    repo.Update(tokens);
                }
            }
        }
Exemplo n.º 4
0
        void Run()
        {
            using (var repo = new Repo()) {
                var info = repo.Table<GoogleReaderConfig>().FirstOrDefault();
                if (info != null) {
                    info.Account = "";
                    info.Password = "";
                    repo.Update(info);
                }
            }

            /*

            var done = false;
            while (!done) {
                var sleepTime = TimeSpan.FromMinutes(1);

                try {
                    sleepTime = Update();
                }
                catch (Exception dataEx) {
                    Console.WriteLine (dataEx.ToString());
                }

                _wakeup.WaitOne(sleepTime);
            }
            */
        }