Exemplo n.º 1
0
        public async Task SetColor(GrainInformation grainInformation)
        {
            //// Initialize state if no record is present.
            if (this.State.GrainInformation == null)
            {
                this.State.GrainInformation = new List <GrainInformation>();
            }

            //// Don't add more than 20 requests in queue. If grain request is already present, delete and add it.
            var existingGrain =
                this.State.GrainInformation.FirstOrDefault(element => element.DeviceId == grainInformation.DeviceId);

            if (null != existingGrain)
            {
                this.State.GrainInformation.Remove(existingGrain);
            }

            this.State.GrainInformation.Add(grainInformation);
            if (this.State.GrainInformation.Count > 20)
            {
                this.State.GrainInformation.RemoveRange(0, this.State.GrainInformation.Count - 20);
            }

            //// Persist state.
            await this.WriteStateAsync();
        }
Exemplo n.º 2
0
        public async Task SetColor(string colorName)
        {
            //// This will save color to state and persist it to storage on executing WriteStateAsync.
            this.State.Color = colorName;
            await this.WriteStateAsync();

            //// We'll invoke Aggregator grain now so that we can collect all different grain requests.
            var aggregatorGrain = this.GrainFactory.GetGrain <IAggregatorGrain>("aggregator");

            //// Set information that aggregator grain would use.
            var grainInformation = new GrainInformation
            {
                DeviceId = this.GetPrimaryKeyString(),
                Time     = DateTime.Now,
                Value    = colorName
            };
            await aggregatorGrain.SetColor(grainInformation);
        }