private async Task <int?> PushCoreAsync() { if (_familyId == null) { throw new InvalidOperationException("No familyId has been specified; the service must be initialized first with a valid familyId."); } var pushRequest = Dto.pushRequest(State); if (pushRequest.IsSome()) { var pushResponse = await _cosmos.PushAsync(_familyId, pushRequest.Value); var import = Dto.changesAsImport(pushResponse); if (import.IsSome()) { var message = StateTypes.StateMessage.NewImport(import.Value); State = StateModule.updateUsingStandardClock(message, State); OnChange?.Invoke(); return(import.Value.EarliestTimestamp.AsNullable()); } else { return(null); } } else { return(null); } }
public StateService(StateTypes.State state, ICosmosConnector cosmos) { _cosmos = cosmos; _hasSynchronized = false; State = state; SynchronizationStatus = HasChanges(); }
private async Task PullCoreAsync(int?after, int?before) { if (_familyId == null) { throw new InvalidOperationException("No familyId has been specified; the service must be initialized first with a valid familyId."); } var pullResponse = (after is null && before is null) ? await _cosmos.PullEverythingAsync(_familyId) : await _cosmos.PullIncrementalAsync(_familyId, after ?? int.MinValue, before); var import = Dto.changesAsImport(pullResponse); if (import.IsSome()) { var message = StateTypes.StateMessage.NewImport(import.Value); State = StateModule.updateUsingStandardClock(message, State); OnChange?.Invoke(); } }
public async Task UpdateAsync(StateTypes.StateMessage message) { State = StateModule.updateUsingStandardClock(message, State); OnChange?.Invoke(); await SyncCoreAsync(isIncremental : true, ignoreIfSynchronizing : false); }