示例#1
0
        private protected async Task PreActivate(Grain grain, Func <Task <IndexedGrainStateWrapper <TGrainState> > > readGrainStateFunc, Func <Task> writeGrainStateFunc)
        {
            if (this.grain != null) // Already called
            {
                return;
            }
            this.grain               = grain;
            this.iIndexableGrain     = this.grain.AsReference <IIndexableGrain>(this.SiloIndexManager);
            this.readGrainStateFunc  = readGrainStateFunc;
            this.writeGrainStateFunc = writeGrainStateFunc;

            await this.ReadAsync();

            if (!GrainIndexes.CreateInstance(this.SiloIndexManager.IndexRegistry, this.grain.GetType(), out this._grainIndexes) ||
                !this._grainIndexes.HasAnyIndexes)
            {
                throw new InvalidOperationException("IndexedState should not be used for a Grain class with no indexes");
            }

            if (!this.wrappedState.AreNullValuesInitialized)
            {
                IndexUtils.SetNullValues(this.wrappedState.UserState, this._grainIndexes.PropertyNullValues);
                this.wrappedState.AreNullValuesInitialized = true;
            }

            this._hasAnyUniqueIndex = this._grainIndexes.HasAnyUniqueIndex;
            this._grainIndexes.AddMissingBeforeImages(this.wrappedState.UserState);
        }
示例#2
0
        private Task Initialize(Grain grain)
        {
            if (this.grain == null) // If not already called
            {
                this.grain           = grain;
                this.iIndexableGrain = this.grain.AsReference <IIndexableGrain>(this.SiloIndexManager);

                if (!GrainIndexes.CreateInstance(this.SiloIndexManager.IndexRegistry, this.grain.GetType(), out this._grainIndexes) ||
                    !this._grainIndexes.HasAnyIndexes)
                {
                    throw new InvalidOperationException("IndexedState should not be used for a Grain class with no indexes");
                }
                this._hasAnyUniqueIndex = this._grainIndexes.HasAnyUniqueIndex;
            }
            return(Task.CompletedTask);
        }