예제 #1
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);
            }
        }
예제 #2
0
        public int copyModel(int PD_ProcessId)
        {
            var process = _pdesignerDB.PD_Processes.Find(PD_ProcessId);

            PD_Process newProcess = new PD_Process()
            {
                Name = process.Name
            };

            _pdesignerDB.PD_Processes.Add(newProcess);
            _pdesignerDB.SaveChanges();

            foreach (var p in process.Parameters)
            {
                PD_Parameter par = new PD_Parameter()
                {
                    PD_Process_Id = newProcess.Id, Name = p.Name, Config = p.Config
                };
                _pdesignerDB.PD_Parameters.Add(par);
                _pdesignerDB.SaveChanges();
            }

            foreach (var mt in process.MessageTypes)
            {
                PD_MessageType newMessageType = new PD_MessageType()
                {
                    Id = mt.Id, Name = mt.Name, Parameters = mt.Parameters, PD_Process_Id = newProcess.Id
                };
                _pdesignerDB.PD_MessageTypes.Add(newMessageType);
                _pdesignerDB.SaveChanges();
            }

            foreach (var m in process.Messages)
            {
                PD_Message newMessage = new PD_Message()
                {
                    Id = m.Id, From = m.From, To = m.To, PD_MessageType_Id = m.PD_MessageType_Id, PD_MessageType_Process_Id = newProcess.Id, PD_Process_Id = newProcess.Id
                };
                _pdesignerDB.PD_Messages.Add(newMessage);
                _pdesignerDB.SaveChanges();
            }

            foreach (var s in process.Subjects)
            {
                PD_Subject newSubject = new PD_Subject()
                {
                    Id = s.Id, CanBeStarted = s.CanBeStarted, ExternalSubject = s.ExternalSubject, GlobalParameters = s.GlobalParameters, MultiSubject = s.MultiSubject, Name = s.Name, PD_Process_Id = newProcess.Id, PositionLeft = s.PositionLeft, PositionTop = s.PositionTop
                };
                _pdesignerDB.PD_Subjects.Add(newSubject);
                _pdesignerDB.SaveChanges();

                foreach (var st in s.States)
                {
                    if (st.Type == PD_StateTypes.FunctionState)
                    {
                        var oS = (PD_FunctionState)st;
                        PD_FunctionState newS = new PD_FunctionState()
                        {
                            EditableParameters = oS.EditableParameters, EndState = oS.EndState, Id = oS.Id, Name = oS.Name, PD_Process_Id = newProcess.Id, PD_Subject_Id = newSubject.Id, PositionLeft = oS.PositionLeft, PositionTop = oS.PositionTop, ReadableParameters = oS.ReadableParameters, StartState = oS.StartState, Type = oS.Type
                        };
                        _pdesignerDB.PD_FunctionStates.Add(newS);
                        _pdesignerDB.SaveChanges();
                    }
                    if (st.Type == PD_StateTypes.SendState)
                    {
                        var          oS   = (PD_SendState)st;
                        PD_SendState newS = new PD_SendState()
                        {
                            EditableParameters = oS.EditableParameters, EndState = oS.EndState, Id = oS.Id, Name = oS.Name, PD_Process_Id = newProcess.Id, PD_Subject_Id = newSubject.Id, PositionLeft = oS.PositionLeft, PositionTop = oS.PositionTop, ReadableParameters = oS.ReadableParameters, StartState = oS.StartState, Type = oS.Type, Message = oS.Message
                        };
                        _pdesignerDB.PD_SendStates.Add(newS);
                        _pdesignerDB.SaveChanges();
                    }
                    if (st.Type == PD_StateTypes.ReceiveState)
                    {
                        var             oS   = (PD_ReceiveState)st;
                        PD_ReceiveState newS = new PD_ReceiveState()
                        {
                            EndState = oS.EndState, Id = oS.Id, Name = oS.Name, PD_Process_Id = newProcess.Id, PD_Subject_Id = newSubject.Id, PositionLeft = oS.PositionLeft, PositionTop = oS.PositionTop, StartState = oS.StartState, Type = oS.Type
                        };
                        _pdesignerDB.PD_ReceiveStates.Add(newS);
                        _pdesignerDB.SaveChanges();
                    }
                }

                foreach (var t in s.Transitions)
                {
                    if (t.Type == PD_TransitionTypes.RegularTransition)
                    {
                        var oT = (PD_RegularTransition)t;
                        PD_RegularTransition newT = new PD_RegularTransition()
                        {
                            Id = oT.Id, Name = oT.Name, PD_Process_Id = newProcess.Id, PD_Subject_Id = newSubject.Id, Source = oT.Source, Target = oT.Target, Type = oT.Type
                        };
                        _pdesignerDB.PD_RegularTransitions.Add(newT);
                        _pdesignerDB.SaveChanges();
                    }
                    if (t.Type == PD_TransitionTypes.ReceiveTransition)
                    {
                        var oT = (PD_ReceiveTransition)t;
                        PD_ReceiveTransition newT = new PD_ReceiveTransition()
                        {
                            Id = oT.Id, PD_Process_Id = newProcess.Id, PD_Subject_Id = newSubject.Id, Source = oT.Source, Target = oT.Target, Type = oT.Type, Message = oT.Message
                        };
                        _pdesignerDB.PD_ReceiveTransitions.Add(newT);
                        _pdesignerDB.SaveChanges();
                    }
                    if (t.Type == PD_TransitionTypes.TimeoutTransition)
                    {
                        var oT = (PD_TimeoutTransition)t;
                        PD_TimeoutTransition newT = new PD_TimeoutTransition()
                        {
                            Id = oT.Id, PD_Process_Id = newProcess.Id, PD_Subject_Id = newSubject.Id, Source = oT.Source, Target = oT.Target, Type = oT.Type, TimeSpan = oT.TimeSpan
                        };
                        _pdesignerDB.PD_TimeoutTransitions.Add(newT);
                    }
                }
            }

            _pdesignerDB.SaveChanges();

            return(newProcess.Id);
        }