Example #1
0
        public void PutState(PD_State item, int id, int sid, int stid)
        {
            var _p = _db.PD_Processes.Find(id);

            if (User.Identity.Name.Equals(_p.LockedBy))
            {
                var state = _db.PD_States.Find(id, sid, stid);

                if (state != null)
                {
                    if (item.Name != null)
                    {
                        state.Name = item.Name;
                    }
                    state.PositionTop  = item.PositionTop;
                    state.PositionLeft = item.PositionLeft;
                    _db.SaveChanges();
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
        }
Example #2
0
        public HttpResponseMessage PostTransition(PD_TransitionDTO item, int id, int sid)
        {
            var _p = _db.PD_Processes.Find(id);

            if (User.Identity.Name.Equals(_p.LockedBy))
            {
                var           subject       = _db.PD_Subjects.Find(id, sid);
                PD_Transition newTransition = null;
                if (item.Type == PD_TransitionTypes.RegularTransition)
                {
                    var from = _db.PD_States.Find(id, sid, item.Source);
                    var to   = _db.PD_States.Find(id, sid, item.Target);
                    if (from.Type == PD_StateTypes.SendState && to.Type == PD_StateTypes.ReceiveState)
                    {
                        var state    = _db.PD_SendStates.Find(id, sid, item.Source);
                        var messages = _db.PD_Messages.Where(result => result.PD_Process_Id == id && result.From == sid).ToList();
                        foreach (var message in messages)
                        {
                            if (state.Message == message.Id)
                            {
                                newTransition = new PD_RegularTransition()
                                {
                                    Name = message.PD_MessageType.Name.ToString()
                                };
                            }
                        }
                        if (newTransition == null)
                        {
                            newTransition = new PD_RegularTransition()
                            {
                                Name = "No message used"
                            };
                        }
                    }
                    else
                    {
                        PD_State s = _db.PD_States.Find(id, sid, item.Source);
                        if (s.Type == PD_StateTypes.SendState)
                        {
                            var state = _db.PD_SendStates.Find(id, sid, item.Source);

                            var messages = _db.PD_Messages.Where(result => result.PD_Process_Id == id && result.From == sid).ToList();
                            if (messages.Count() > 0)
                            {
                                var name = messages.Find(result => result.Id == state.Message).PD_MessageType.Name;
                                newTransition = new PD_RegularTransition()
                                {
                                    Name = name
                                };
                            }
                            else
                            {
                                newTransition = new PD_RegularTransition()
                                {
                                    Name = "Transition"
                                };
                            }
                        }
                        else
                        {
                            newTransition = new PD_RegularTransition()
                            {
                                Name = "Transition"
                            };
                        }
                    }
                }
                if (item.Type == PD_TransitionTypes.ReceiveTransition)
                {
                    newTransition = new PD_ReceiveTransition()
                    {
                        Message = -1
                    };
                }
                if (item.Type == PD_TransitionTypes.TimeoutTransition)
                {
                    newTransition = new PD_TimeoutTransition()
                    {
                        TimeSpan = "dd:hh:mm"
                    };
                }

                newTransition.Id = IdHelper.getTransitionId(_db, id, sid);

                newTransition.Source        = item.Source;
                newTransition.Target        = item.Target;
                newTransition.LabelPosition = item.LabelPosition;
                subject.Transitions.Add(newTransition);
                _db.SaveChanges();
                var response = Request.CreateResponse <PD_TransitionDTO>(HttpStatusCode.Created, new PD_TransitionDTO()
                {
                    Id = newTransition.Id, Source = newTransition.Source, Target = newTransition.Target, Type = newTransition.Type, Label = "Transition" + newTransition.Type
                });

                string uri = Url.Content("Designer" + id + "/Subjects/" + sid + "/States/" + newTransition.Id);
                response.Headers.Location = new Uri(uri);
                return(response);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        public HttpResponseMessage PostState(PD_State item, int id, int sid)
        {
            var _p = _db.PD_Processes.Find(id);

            if (User.Identity.Name.Equals(_p.LockedBy))
            {
                var      subject  = _db.PD_Subjects.Find(id, sid);
                PD_State newState = null;
                if (item.Type == PD_StateTypes.FunctionState)
                {
                    newState = new PD_FunctionState()
                    {
                        Name = "Function State", EndState = false
                    };
                }
                if (item.Type == PD_StateTypes.SendState)
                {
                    newState = new PD_SendState()
                    {
                        Name = "Send State", EndState = false
                    };
                }
                if (item.Type == PD_StateTypes.ReceiveState)
                {
                    newState = new PD_ReceiveState()
                    {
                        Name = "Receive State", EndState = false
                    };
                }
                if (item.Type == PD_StateTypes.RefinementState)
                {
                    newState = new PD_RefinementState()
                    {
                        Name = "Refinement State", EndState = false
                    };
                }
                newState.Id = IdHelper.getStateId(_db, id, sid);

                newState.PositionLeft = item.PositionLeft;
                newState.PositionTop  = item.PositionTop;

                newState.StartState = false;
                if (subject.States.Count == 0)
                {
                    newState.StartState = true;
                }

                subject.States.Add(newState);
                _db.SaveChanges();
                var response = Request.CreateResponse <PD_StateDTO>(HttpStatusCode.Created, new PD_StateDTO {
                    Id = newState.Id, Name = newState.Name, PositionLeft = newState.PositionLeft, PositionTop = newState.PositionTop, Type = newState.Type
                });

                string uri = Url.Content("Designer" + id + "/Subjects/" + sid + "/States/" + newState.Id);
                response.Headers.Location = new Uri(uri);
                return(response);
            }
            else
            {
                return(null);
            }
        }