public static void TestInsert() { var r = new Repo<Country>(new DbContextFactory()); var c = new Country { Name = "Asaaa" }; r.Insert(c); r.Save(); var o = r.Get(c.Id); Assert.AreEqual(c.Name, o.Name); }
public static void TestRemove() { var r = new Repo<Country>(new DbContextFactory()); var c = new Country { Name = "AsaaaRemove" }; r.Insert(c); r.Save(); r.Delete(c); r.Save(); var o = r.Get(c.Id); Assert.IsTrue(o.IsDeleted); }
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); } }
XDocument Api(string method, Uri uri) { if (_tokens == null) { using (var repo = new Repo()) { _tokens = repo.Table<TwitterOAuthTokens>().Where(t=>t.Account == Account).FirstOrDefault(); } } if (_tokens == null) { throw new InvalidOperationException("Cannot access Twitter APIs without tokens"); } var wc = new WebClient(); OAuthAuthorizer.AuthorizeRequest(OAuthConfig, wc, _tokens.Token, _tokens.TokenSecret, method, uri, ""); var res = ""; if (method == "GET") { res = wc.DownloadString(uri); } else { res = wc.UploadString(uri, ""); } return XDocument.Parse(res); }
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); } } }
public void ConvertDBValueToPinYinCorrectly() { var r = new Repo<Vendor>(new DbContextFactory()); Assert.AreEqual("(ken3) (de2) (ji1)", us.ConvertChsToPinYin(r.Get(6).Name)); }
public void Update(Repo r, Action<Source> act) { _lastUpdateActTime = DateTime.UtcNow.AddHours(-1); repo = r; _act = act; DoUpdate(); }
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); }
void Subscribe(Dictionary<string, string> subs) { var sourceType = typeof(Blog); using (var repo = new Repo()) { var sources = repo.GetActiveSources(sourceType); var existingSources = new Dictionary<string, Blog>(); foreach (Blog s in sources) { existingSources.Add(s.Url, s); } foreach (var s in subs) { var url = s.Value; if (!existingSources.ContainsKey(url)) { var source = new Blog(); source.Url = url; repo.Insert(source); Console.WriteLine ("GU: Subscribed to " + url); } } } SourceUpdater.SetSourcesChanged(); App.RunUI(delegate { App.Inst.RefreshInfo(); }); }
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); } */ }