示例#1
0
        public HandleResult HandleEvent(
            Guid processInstanceId,
            Guid tokenId,
            object eventData
            )
        {
            var instance = InstancesStore.GetById(processInstanceId);

            if (instance == null)
            {
                throw new InvalidOperationException("Instance not found.");
            }

            var model = ModelsStore.GetById(Guid.Parse(instance.ProcessModelId));

            if (model == null)
            {
                throw new InvalidOperationException("Instance process model not found.");
            }

            var context = new ExecutionContext(this, model, instance, instance.Token.FindById(tokenId), null);

            var tokens = instance.HandleEvent(context, eventData);

            InstancesStore.Store(instance);

            return(new HandleResult(
                       Guid.Parse(model.Id),
                       Guid.Parse(instance.Id),
                       tokens.Select(token => token.Id).ToList()));
        }
示例#2
0
        public IEnumerable <HandleResult> HandleEvent(object e)
        {
            var models = ModelsStore.GetAll()
                         .Where(model =>
            {
                var context = new ExecutionContext(this, model, null, null, null);
                return(model.CanStartWith(context, e));
            });

            var result = new List <HandleResult>();

            foreach (var model in models)
            {
                var instance = ProcessInstance.Create(Guid.Parse(model.Id));
                var context  = new ExecutionContext(this, model, instance, instance.Token, null);

                var tokens = instance.HandleEvent(context, e);

                result.Add(new HandleResult(
                               Guid.Parse(model.Id),
                               Guid.Parse(instance.Id),
                               tokens.Select(token => token.Id).ToList()
                               ));

                // TODO: It can be late?
                InstancesStore.Store(instance);
            }
            return(result);
        }
示例#3
0
        public void Attach(ProcessInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (ModelsStore.GetById(Guid.Parse(instance.ProcessModelId)) == null)
            {
                throw new ArgumentException("Trying to attach an instance with an unrecognized model.", nameof(instance));
            }


            InstancesStore.Store(instance);
        }
示例#4
0
        private void InitializeModelsMetadata()
        {
            modelsStore.Clear();

            //ScottGu Model
            ModelMetadata metadata = new ModelMetadata()
            {
                ID                 = "polo",
                Name               = "T-Shirt",
                Description        = "Polo T-Shirt model",
                IsLocal            = true,
                IsContent          = true,
                DownloadProgress   = 100.0f,
                Assets             = new string[] { "polo" },
                World              = Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(0f, -0.15f, 0f),
                ViewMatrix         = Matrix.CreateLookAt(new Vector3(1.0f, 0f, 0f), Vector3.Zero, Vector3.Up),
                FieldOfViewDivisor = 2f,
                AspectRatio        = 2.0f,
                NearPlaneDistance  = 0.01f,
                FarPlaneDistance   = 1000f,
            };

            ModelsStore.Add(metadata.ID, metadata);

            //Tank Model
            metadata = new ModelMetadata()
            {
                ID                 = "tank",
                Name               = "Tank",
                Description        = "Tank model",
                IsLocal            = false,
                IsContent          = false,
                Assets             = new string[] { "tank", "engine_diff_tex_0", "turret_alt_diff_tex_0" },
                World              = Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(new Vector3(0f, -150f, 0f)),
                ViewMatrix         = Matrix.CreateLookAt(new Vector3(1500f, 1000f, 0f), Vector3.Zero, Vector3.Up),
                FieldOfViewDivisor = 1f,
                AspectRatio        = 1f,
                NearPlaneDistance  = 100f,
                FarPlaneDistance   = 2000f,
            };
            ModelsStore.Add(metadata.ID, metadata);

            //Spaceship Model
            metadata = new ModelMetadata()
            {
                ID                 = "spaceship",
                Name               = "Spaceship",
                Description        = "Alien spaceship model",
                IsLocal            = false,
                IsContent          = false,
                Assets             = new string[] { "spaceship", "enemy_0" },
                World              = Matrix.Identity,
                ViewMatrix         = Matrix.CreateLookAt(new Vector3(3500, 400, 0) + new Vector3(0, 250, 0), new Vector3(0, 250, 0), Vector3.Up),
                FieldOfViewDivisor = 1f,
                AspectRatio        = 1.66666663f,
                NearPlaneDistance  = 10f,
                FarPlaneDistance   = 20000f,
            };
            ModelsStore.Add(metadata.ID, metadata);

            //Marble Model
            metadata = new ModelMetadata()
            {
                ID                 = "marble",
                Name               = "Marble",
                Description        = "Marble model",
                IsLocal            = false,
                IsContent          = false,
                Assets             = new string[] { "marble" },
                World              = Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateRotationZ(MathHelper.Pi),
                ViewMatrix         = Matrix.CreateLookAt(new Vector3(50f, 0f, 0f), Vector3.Zero, Vector3.Up),
                FieldOfViewDivisor = 1f,
                AspectRatio        = 1.65f,
                NearPlaneDistance  = 0.01f,
                FarPlaneDistance   = 1000f,
            };
            ModelsStore.Add(metadata.ID, metadata);
        }