Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. public class FeedStorage
  2. {
  3. public FeedStorage()
  4. {
  5. GroupStoryChildIdList = "";
  6. }
  7. [PrimaryKey]
  8. public string Id { get; set; }
  9. public DateTime FeedItemDateTime { get; set; }
  10. public string ItemType { get; set; }
  11. public bool IsNew { get; set; }
  12. public string Json { get; set; }
  13. public string GroupStoryChildIdList { get; set; }
  14.  
  15. }
  16.  
  17.  
  18.  
  19.  
  20. private SQLiteConnection Connection
  21. {
  22. get
  23. {
  24. CheckDatabaseExists ();
  25.  
  26. //SQLite3.Config(SQLite3.ConfigOption.MultiThread);
  27.  
  28. return new SQLiteConnection (DatabaseFilename, true);
  29. }
  30. }
  31.  
  32. private void ExecuteBlock (SQLiteConnection conn, Action<SQLiteConnection> func)
  33. {
  34. if (conn == null)
  35. {
  36. using (var localConn = Connection)
  37. {
  38. func (localConn);
  39. }
  40. } else
  41. {
  42. func (conn);
  43. }
  44. }
  45.  
  46.  
  47.  
  48. public List<FeedItem> GetStories (SQLiteConnection conn = null)
  49. {
  50. List<FeedItem> items = new List<FeedItem> ();
  51.  
  52. ExecuteBlock (conn, delegate(SQLiteConnection c) {
  53. var feedItems = from item in c.Table<FeedStorage> ()
  54. where (item.ItemType != "Message")
  55. orderby item.FeedItemDateTime descending select item;
  56.  
  57. foreach (var item in feedItems)
  58. {
  59. var feedItem = JsonSerializer.DeserializeFromString<FeedItem> (item.Json);
  60. items.Add (feedItem);
  61. }
  62.  
  63. BTLogger.Log ("GetStories: {0} items", items.Count);
  64.  
  65. });
  66.  
  67. return items;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement