Esempio n. 1
0
        public async Task InitializeAsync(CoreTypes.FamilyId?familyId = null)
        {
            if (SynchronizationStatus == SynchronizationStatus.Synchronizing)
            {
                return;
            }
            if (State == null)
            {
                if (familyId == null)
                {
                    throw new InvalidOperationException("Can't initialize the service without an existing familyId.");
                }
                else
                {
                    State                 = StateModule.createDefault(familyId.Value, UserIdModule.anonymous);
                    _hasSynchronized      = false;
                    SynchronizationStatus = HasChanges();
                    await SyncEverythingAsync();
                }
            }
            else
            {
                if (familyId == null || State.FamilyId.Equals(familyId.Value))
                {
                    if (!_hasSynchronized)
                    {
                        await SyncEverythingAsync();
                    }
                }
                else
                {
                    switch (SynchronizationStatus)
                    {
                    case SynchronizationStatus.Synchronizing:
                        break;

                    case SynchronizationStatus.HasChanges:
                        await SyncIncrementalAsync();

                        _hasSynchronized = false;
                        await InitializeAsync(familyId);

                        break;

                    case SynchronizationStatus.NoChanges:
                        State = StateModule.createDefault(familyId.Value, UserIdModule.anonymous);
                        await SyncEverythingAsync();

                        break;
                    }
                }
            }
        }
Esempio n. 2
0
 public StateService(ICosmosConnector cosmos) : this(StateModule.createDefault(FamilyIdModule.anonymous, UserIdModule.anonymous), cosmos)
 {
 }