示例#1
0
        public async Task <IStateMachine <TState, TInput> > CreateMachineAsync(
            Schematic <TState, TInput> schematic,
            string machineId,
            IDictionary <string, string> metadata = null,
            CancellationToken cancellationToken   = default)
        {
            var response = await _stateMachineService
                           .WithCancellationToken(cancellationToken)
                           .CreateMachineFromSchematicAsync(new CreateMachineFromSchematicRequest
            {
                SchematicBytes = LZ4MessagePackSerializer.Serialize(schematic, ContractlessStandardResolver.Instance),
                Metadata       = metadata,
                MachineId      = machineId
            });

            return(new GrpcStateMachine <TState, TInput>(_stateMachineService, response.MachineId));
        }
示例#2
0
        public async Task <ISchematic <TState, TInput> > GetSchematicAsync(CancellationToken cancellationToken = default)
        {
            if (_machineSchematic != null)
            {
                return(_machineSchematic);
            }

            var response = await _stateMachineService
                           .WithCancellationToken(cancellationToken)
                           .GetMachineSchematicAsync(new GetMachineSchematicRequest
            {
                MachineId = MachineId
            });

            _machineSchematic = LZ4MessagePackSerializer
                                .Deserialize <Schematic <TState, TInput> >(
                response.SchematicBytes,
                ContractlessStandardResolver.Instance);

            return(_machineSchematic);
        }