示例#1
0
        // add event id to event list
        public async Task AddAnEvent(SummaryEventInfo eventInfo)
        {
            Console.WriteLine($"** AggregatorGrain AddAnEvent() for event id {eventInfo.id}, title {eventInfo.title}");

            // ensure allevent List is constructed ok
            if (State.allevents == null)
            {
                State.allevents = new List <SummaryEventInfo>();
            }


            // check to see if event already exists, and if so, removed, before inserting new event info
            int index = State.allevents.FindIndex(item => item.id == eventInfo.id);

            if (index >= 0)
            {
                State.allevents.RemoveAt(index);
            }

            // add this event key to our active list
            State.allevents.Add(eventInfo);

            Console.WriteLine($"** AggregatorGrain AddAnEvent() about to write WriteStateAsync for new event id {eventInfo.id}");
            await base.WriteStateAsync();

            return;
        }
示例#2
0
        // create / update an event
        //  the system doesn't really distinguish between the two, just to keep the logic simple
        //  scenarios include changing the start or end date, changing the list of topics for that event, etc
        public async Task Update(string title, string type, string start, string end, TopicApiData[] topics)
        {
            string id = this.GetPrimaryKeyString();  // rmember - the grain key is the event id

            Console.WriteLine($"** EventGrain Update()for event id = {id}, with title {title}");

            // update interal grain state

            State.title    = title;
            State.type     = type;
            State.start    = start;
            State.end      = end;
            State.topics   = topics;
            State.feedback = new List <FeedbackGrainState>();  //  lets clear all feedback, just to keep things simple

            Console.WriteLine($"** EventGrain Update() about to write WriteStateAsync");
            await base.WriteStateAsync();

            // update aggregator about this new event

            SummaryEventInfo eventInfo = new SummaryEventInfo();

            eventInfo.id    = id;
            eventInfo.title = title;
            eventInfo.start = start;
            eventInfo.end   = end;

            IAggregatorGrain aggregator = GrainFactory.GetGrain <IAggregatorGrain>(Guid.Empty);  // the aggregator grain is a singleton - Guid.Empty is convention to indicate this
            //await aggregator.DeleteAnEvent(id);
            await aggregator.AddAnEvent(eventInfo);

            return;
        }