コード例 #1
0
        /// <summary>
        /// This method is called whenever an actor is activated.
        /// An actor is activated the first time any of its methods are invoked.
        /// </summary>
        protected override async Task OnActivateAsync()
        {
            ActorEventSource.Current.ActorMessage(this, "Actor activated.");

            // The StateManager is this actor's private state store.
            // Data stored in the StateManager will be replicated for high-availability for actors that use volatile or persisted state storage.
            // Any serializable object can be saved in the StateManager.
            // For more information, see https://aka.ms/servicefabricactorsstateserialization

            var state = await StateManager.TryGetStateAsync <ActorState>(GameState);

            if (!state.HasValue)
            {
                var newState = new ActorState()
                {
                    Board           = new int[9],
                    Winner          = "",
                    Players         = new List <Tuple <long, string> >(),
                    NextPlayerIndex = 0,
                    NumberOfMoves   = 0
                };

                await StateManager.SetStateAsync <ActorState>(GameState, newState);
            }
        }
コード例 #2
0
        /// <summary>
        /// This method is called whenever an actor is activated.
        /// An actor is activated the first time any of its methods are invoked.
        /// </summary>
        protected override async Task OnActivateAsync()
        {
            ActorEventSource.Current.ActorMessage(this, "Actor activated.");

            ConditionalValue <ActorState> state = await StateManager.TryGetStateAsync <ActorState>(STATE_KEY);

            if (!state.HasValue)
            {
                var newState = new ActorState()
                {
                    Board           = new int[9],
                    Winner          = "",
                    Players         = new List <Tuple <long, string> >(),
                    NextPlayerIndex = 0,
                    NumberOfMoves   = 0
                };
                await StateManager.SetStateAsync <ActorState>(STATE_KEY, newState);
            }
        }