Skip to content

Instantly share code, notes, and snippets.

@nicwise
Last active March 7, 2017 02:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nicwise/5636318 to your computer and use it in GitHub Desktop.
Save nicwise/5636318 to your computer and use it in GitHub Desktop.
public class FeedStorage
{
public FeedStorage()
{
GroupStoryChildIdList = "";
}
[PrimaryKey]
public string Id { get; set; }
public DateTime FeedItemDateTime { get; set; }
public string ItemType { get; set; }
public bool IsNew { get; set; }
public string Json { get; set; }
public string GroupStoryChildIdList { get; set; }
}
private SQLiteConnection Connection
{
get
{
CheckDatabaseExists ();
//SQLite3.Config(SQLite3.ConfigOption.MultiThread);
return new SQLiteConnection (DatabaseFilename, true);
}
}
private void ExecuteBlock (SQLiteConnection conn, Action<SQLiteConnection> func)
{
if (conn == null)
{
using (var localConn = Connection)
{
func (localConn);
}
} else
{
func (conn);
}
}
public List<FeedItem> GetStories (SQLiteConnection conn = null)
{
List<FeedItem> items = new List<FeedItem> ();
ExecuteBlock (conn, delegate(SQLiteConnection c) {
var feedItems = from item in c.Table<FeedStorage> ()
where (item.ItemType != "Message")
orderby item.FeedItemDateTime descending select item;
foreach (var item in feedItems)
{
var feedItem = JsonSerializer.DeserializeFromString<FeedItem> (item.Json);
items.Add (feedItem);
}
BTLogger.Log ("GetStories: {0} items", items.Count);
});
return items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment