Ejemplo n.º 1
0
        public void Handle(SmsReceived sms)
        {
            BaseInstance instance = instanceRepository.Peek(sms.PhoneNumber);

            if (instance != null)
            {
                if (this.mapper.MappingExists(sms.Body) && !(instance is ForkInstance))
                {
                    ForkInstance fork = new ForkInstance()
                    {
                        ForkingFromInstance = instance,
                        ForkingFromWorkflow = this.mapper.GetStateMachine(instance.GetType()),
                        ForkingToKeyword    = sms.Body,
                        PhoneNumber         = sms.PhoneNumber
                    };

                    var stateMachine = this.mapper.GetStateMachine(fork.GetType());

                    stateMachine.RaiseAnEvent(fork, stateMachine.Start, sms.PhoneNumber);

                    instanceRepository.Push(sms.PhoneNumber, fork);
                }
                else
                {
                    //then raise the SMS received event
                    var stateMachine = this.mapper.GetStateMachine(instance.GetType());

                    stateMachine.RaiseAnEvent(instance, stateMachine.SMSReceived, sms.Body);

                    if (instance.CurrentState == stateMachine.Final)
                    {
                        instanceRepository.Pop(sms.PhoneNumber);
                    }
                }
            }
            else if (this.mapper.MappingExists(sms.Body))
            {
                //make a new state machine instance
                instance = this.mapper.GetStateMachineInstance(sms.Body);
                IWorkflow stateMachine = this.mapper.GetStateMachine(sms.Body);

                stateMachine.RaiseAnEvent(instance, stateMachine.Start, sms.PhoneNumber);
                instanceRepository.Push(sms.PhoneNumber, instance);
            }
            else
            {
                bus.Publish(new SendSms()
                {
                    PhoneNumber = sms.PhoneNumber, Body = "That command was not recognized."
                });
            }
        }
Ejemplo n.º 2
0
        internal void Handle(ForkFinished msg)
        {
            if (msg.Abort)
            {
                //start new
                instanceRepository.Pop(msg.PhoneNumber);
                var wf       = mapper.GetStateMachine(msg.ForkToKeyword);
                var instance = mapper.GetStateMachineInstance(msg.ForkToKeyword);

                wf.RaiseAnEvent(instance, wf.Start, msg.PhoneNumber);

                instanceRepository.Push(msg.PhoneNumber, instance);
            }
        }