Ejemplo n.º 1
0
        protected async Task Over()
        {
            if (Snapshot.Base.IsOver)
            {
                throw new StateIsOverException(Snapshot.Base.StateId.ToString(), GrainType);
            }
            if (Snapshot.Base.Version != Snapshot.Base.DoingVersion)
            {
                throw new StateInsecurityException(Snapshot.Base.StateId.ToString(), GrainType, Snapshot.Base.DoingVersion, Snapshot.Base.Version);
            }
            if (ArchiveOptions.On && ArchiveOptions.ArchiveEventOnOver)
            {
                var versions = await ObserverUnit.GetAndSaveVersion(Snapshot.Base.StateId, Snapshot.Base.Version);

                if (versions.Any(v => v < Snapshot.Base.Version))
                {
                    throw new ObserverNotCompletedException(GrainType.FullName, Snapshot.Base.StateId.ToString());
                }
            }
            Snapshot.Base.IsOver   = true;
            Snapshot.Base.IsLatest = true;
            if (SnapshotEventVersion != Snapshot.Base.Version)
            {
                var saveTask = SaveSnapshotAsync(true, true);
                if (!saveTask.IsCompletedSuccessfully)
                {
                    await saveTask;
                }
            }
            else
            {
                await SnapshotStorage.Over(Snapshot.Base.StateId, true);
            }
            if (ArchiveOptions.On && ArchiveOptions.ArchiveEventOnOver)
            {
                await ArchiveStorage.DeleteAll(Snapshot.Base.StateId);

                if (ArchiveOptions.EventArchiveType == EventArchiveType.Delete)
                {
                    await EventStorage.DeletePrevious(Snapshot.Base.StateId, Snapshot.Base.Version, Snapshot.Base.StartTimestamp);
                }
                else
                {
                    await ArchiveStorage.EventArichive(Snapshot.Base.StateId, Snapshot.Base.Version, Snapshot.Base.StartTimestamp);
                }
            }
            else
            {
                await ArchiveStorage.Over(Snapshot.Base.StateId, true);
            }
        }