Exemple #1
0
        public void Restore(object keyValue, TState state)
        {
            var key = (TKey)keyValue;

            if (!states.TryGetValue(key, out var instance))
            {
                states[key] = instance = new StateContext <TState, TAffinity, TKey>(process, key);
            }
            instance.Restore(state);
        }
Exemple #2
0
        bool IStateInfoWithKey <TKey> .TryGetInstance(TKey key, out IStateInstance instance, bool createIfNotExist, ulong parent)
        {
            if (states.TryGetValue(key, out var entry))
            {
                instance = entry;
                return(true);
            }
            else
            {
                if (createIfNotExist)
                {
                    instance = states[key] = new StateContext <TState, TAffinity, TKey>(process, key);

                    if (!HasInitializer)
                    {
                        return(true);
                    }
                    else
                    {
                        var initialization = new Initialization <TState, TKey>()
                        {
                            PartitionKey = keyInfo.MakePartitionKey(key),
                            Singleton    = keyInfo.Singleton,
                        };

                        var orchestrationInfo =
                            (OrchestrationInfo <Initialization <TState, TKey>, UnitType>)
                            process.Orchestrations[typeof(Initialization <TState, TKey>)];
                        var clock = process.OperationCounter;
                        var orchestrationState =
                            new OrchestrationState <Initialization <TState, TKey>, UnitType>(
                                process,
                                orchestrationInfo,
                                process.NextOpid,
                                initialization,
                                OrchestrationType.Initialize,
                                true,
                                parent,
                                clock);

                        return(false);
                    }
                }
                else
                {
                    instance = null;
                    return(false);
                }
            }
        }