Beispiel #1
0
        /// <summary>
        /// 删除状态
        /// </summary>
        /// <returns></returns>
        protected async ValueTask DeleteSnapshot()
        {
            if (Snapshot.Base.IsOver)
            {
                throw new StateIsOverException(Snapshot.Base.StateId.ToString(), GrainType);
            }
            if (SnapshotEventVersion > 0)
            {
                await SnapshotStorage.Delete(GrainId);

                SnapshotEventVersion = 0;
            }
        }
Beispiel #2
0
        protected async Task Over(OverType overType)
        {
            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 (overType != OverType.None)
            {
                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 (overType == OverType.ArchivingEvent)
            {
                if (ArchiveOptions.On)
                {
                    await DeleteAllArchive();
                }
                await ArchiveStorage.EventArichive(Snapshot.Base.StateId, Snapshot.Base.Version, Snapshot.Base.StartTimestamp);
            }
            else if (overType == OverType.DeleteEvent)
            {
                if (ArchiveOptions.On)
                {
                    await DeleteAllArchive();
                }
                await EventStorage.DeletePrevious(Snapshot.Base.StateId, Snapshot.Base.Version, Snapshot.Base.StartTimestamp);
            }
            else if (overType == OverType.DeleteAll)
            {
                if (ArchiveOptions.On)
                {
                    await DeleteAllArchive();
                }
                await EventStorage.DeletePrevious(Snapshot.Base.StateId, Snapshot.Base.Version, Snapshot.Base.StartTimestamp);

                if (SnapshotEventVersion > 0)
                {
                    await SnapshotStorage.Delete(GrainId);

                    SnapshotEventVersion = 0;
                }
            }
            else if (ArchiveOptions.On && BriefArchiveList.Count > 0)
            {
                await ArchiveStorage.Over(Snapshot.Base.StateId, true);
            }
        }