Beispiel #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.DeleteStart(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);
            }
        }
Beispiel #2
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 (CoreOptions.ClearEventWhenOver)
            {
                var versions = await Task.WhenAll(FollowUnit.GetAndSaveVersionFuncs().Select(func => func(Snapshot.Base.StateId, Snapshot.Base.Version)));

                if (versions.Any(v => v < Snapshot.Base.Version))
                {
                    throw new FollowNotCompletedException(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 (CoreOptions.ClearEventWhenOver)
            {
                await ArchiveStorage.DeleteAll(Snapshot.Base.StateId);

                await EventStorage.Delete(Snapshot.Base.StateId, Snapshot.Base.Version, Snapshot.Base.StartTimestamp);
            }
            else
            {
                await ArchiveStorage.Over(Snapshot.Base.StateId, true);
            }
        }
Beispiel #3
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);
            }
        }