private void SaveStreamCollectionItems(SQLiteConnection connection, StreamItemCollectionState collection) { using (var statement = connection.Prepare(@"INSERT OR REPLACE INTO STREAM_ITEM(ID, STREAM_ID, PUBLISHED, TITLE, WEB_URI, CONTENT, UNREAD, NEED_SET_READ_EXPLICITLY, IS_SELECTED, STARRED, SAVED) VALUES(@ID, @STREAM_ID, @PUBLISHED, @TITLE, @WEB_URI, @CONTENT, @UNREAD, @NEED_SET_READ_EXPLICITLY, @IS_SELECTED, @STARRED, @SAVED);")) { foreach (var item in collection.Items) { if (item is EmptySpaceStreamItem || item is HeaderSpaceStreamItem) { continue; } statement.Bind("@ID", item.Id); statement.Bind("@STREAM_ID", collection.StreamId); statement.Bind("@PUBLISHED", item.Published.ToString("O")); statement.Bind("@TITLE", item.Title); statement.Bind("@WEB_URI", item.WebUri); statement.Bind("@CONTENT", item.Content); statement.Bind("@UNREAD", item.Unread ? 1 : 0); statement.Bind("@NEED_SET_READ_EXPLICITLY", item.NeedSetReadExplicitly ? 1 : 0); statement.Bind("@IS_SELECTED", item.IsSelected ? 1 : 0); statement.Bind("@STARRED", item.Starred ? 1 : 0); statement.Bind("@SAVED", item.Saved ? 1 : 0); statement.Step(); // Resets the statement, to that it can be used again (with different parameters). statement.Reset(); statement.ClearBindings(); } } }
public Task SaveStreamCollectionAsync(StreamItemCollectionState collection) { if (collection == null) { throw new ArgumentNullException("collection"); } return(Task.Run(() => { SaveStreamCollectionInternal(collection); })); }
public StreamItemCollectionState GetSate() { var state = new StreamItemCollectionState(); state.StreamId = _streamId; state.Continuation = _continuation; state.Items = this.ToArray(); state.ShowNewestFirst = _showNewestFirst; state.StreamTimestamp = _streamTimestamp; state.Fault = _fault; return(state); }
private void SaveStreamCollection(SQLiteConnection connection, StreamItemCollectionState collection) { using (var statement = connection.Prepare(@"INSERT OR REPLACE INTO STREAM_COLLECTION(STREAM_ID, CONTINUATION, SHOW_NEWEST_FIRST, STREAM_TIMESTAMP, FAULT) VALUES(@STREAM_ID, @CONTINUATION, @SHOW_NEWEST_FIRST, @STREAM_TIMESTAMP, @FAULT);" )) { statement.Bind("@STREAM_ID", collection.StreamId); statement.Bind("@CONTINUATION", collection.Continuation); statement.Bind("@SHOW_NEWEST_FIRST", collection.ShowNewestFirst ? 1 : 0); statement.Bind("@STREAM_TIMESTAMP", collection.StreamTimestamp); statement.Bind("@FAULT", collection.Fault ? 1 : 0); statement.Step(); } }
private void SaveStreamCollectionInternal(StreamItemCollectionState collection) { try { using (var connection = new SQLiteConnection(DatabaseFilename)) { EnableForeignKeys(connection); BeginTransaction(connection); SaveStreamCollection(connection, collection); SaveStreamCollectionItems(connection, collection); CommitTransaction(connection); } } catch (Exception e) { _telemetryClient.TrackException(e); } }
public StreamItemCollection([NotNull] StreamItemCollectionState state, [NotNull] ApiClient apiClient, [NotNull] TelemetryClient telemetryClient, [NotNull] Action <bool> onBusy, int preloadItemsCount) : base(state.Items.Length) { if (state == null) { throw new ArgumentNullException("state"); } if (apiClient == null) { throw new ArgumentNullException("apiClient"); } if (telemetryClient == null) { throw new ArgumentNullException("telemetryClient"); } if (onBusy == null) { throw new ArgumentNullException("onBusy"); } _apiClient = apiClient; _telemetryClient = telemetryClient; _onBusy = onBusy; _streamId = state.StreamId; _showNewestFirst = state.ShowNewestFirst; _continuation = state.Continuation; _streamTimestamp = state.StreamTimestamp; _fault = state.Fault; AddRange(state.Items); _preloadItemsCount = preloadItemsCount; }