示例#1
0
        public IEnumerable <PD_StateDTO> GetAllStates(int id, int sid)
        {
            List <PD_StateDTO> tmp = new List <PD_StateDTO>();
            PD_Subject         i   = _db.PD_Subjects.Find(id, sid);

            foreach (PD_State s in i.States)
            {
                PD_StateDTO dto = new PD_StateDTO {
                    Id = s.Id, Name = s.Name, EndState = s.EndState, StartState = s.StartState, Type = s.Type, PositionLeft = s.PositionLeft, PositionTop = s.PositionTop
                };
                if (s.Type == PD_StateTypes.FunctionState)
                {
                    dto.ReadableParameters = ((PD_FunctionState)s).ReadableParameters;
                    dto.EditableParameters = ((PD_FunctionState)s).EditableParameters;
                }
                if (s.Type == PD_StateTypes.SendState)
                {
                    dto.ReadableParameters = ((PD_SendState)s).ReadableParameters;
                    dto.EditableParameters = ((PD_SendState)s).EditableParameters;
                    dto.Message            = ((PD_SendState)s).Message;
                }
                tmp.Add(dto);
            }
            return(tmp);
        }
示例#2
0
        public HttpResponseMessage PostSubject(PD_SubjectDTO item, int id)
        {
            var _p = _db.PD_Processes.Find(id);

            if (User.Identity.Name.Equals(_p.LockedBy))
            {
                PD_Subject newSubject = new PD_Subject()
                {
                    Name = "newSubject", PositionTop = item.PositionTop, PositionLeft = item.PositionLeft
                };
                newSubject.Id = IdHelper.getSubjectId(_db, id);
                _p.Subjects.Add(newSubject);
                _db.SaveChanges();

                var response = Request.CreateResponse <PD_SubjectDTO>(HttpStatusCode.Created, new PD_SubjectDTO {
                    Id = newSubject.Id, Name = newSubject.Name, PositionLeft = newSubject.PositionLeft, PositionTop = newSubject.PositionTop, CanBeStarted = newSubject.CanBeStarted, ExternalSubject = newSubject.CanBeStarted, MultiSubject = newSubject.MultiSubject
                });

                string uri = Url.Content("Designer" + id + "/Subjects/" + newSubject.Id);
                response.Headers.Location = new Uri(uri);
                return(response);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        public void DeleteSubject(int id, int sid)
        {
            var _p = _db.PD_Processes.Find(id);

            if (User.Identity.Name.Equals(_p.LockedBy))
            {
                //var _p = _db.PD_Processes.Find(id);
                PD_Subject i = _db.PD_Subjects.Find(id, sid);

                if (i != null)
                {
                    var toDelete = _db.PD_Messages.Where(result => result.From == i.Id && result.PD_Process_Id == id || result.To == i.Id && result.PD_Process_Id == id);
                    _db.PD_Messages.RemoveRange(toDelete);

                    var toDelete2 = _db.PD_Transitions.Where(result => result.PD_Process_Id == id && result.PD_Subject_Id == sid);
                    _db.PD_Transitions.RemoveRange(toDelete2);

                    var toDelete3 = _db.PD_States.Where(result => result.PD_Process_Id == id && result.PD_Subject_Id == sid);
                    _db.PD_States.RemoveRange(toDelete3);

                    _db.PD_Subjects.Remove(i);

                    /*var subjUpdate = _db.PD_Subjects.Where(result => result.PD_Process_Id == id && result.Id > sid);
                     * foreach (PD_Subject j in subjUpdate)
                     * {
                     *  j.Id = j.Id - 1;
                     * }*/
                    _db.SaveChanges();
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
        }
示例#4
0
        public IHttpActionResult GetSubject(int id, int sid)
        {
            PD_Subject i = _db.PD_Subjects.Find(id, sid);

            return(Ok(new PD_SubjectDTO()
            {
                Id = i.Id, Name = i.Name, CanBeStarted = i.CanBeStarted, MultiSubject = i.MultiSubject, ExternalSubject = i.ExternalSubject
            }));
        }
示例#5
0
        public IHttpActionResult getCanvas(int id, int sid)
        {
            PD_Canvas  c = new PD_Canvas();
            PD_Subject s = _db.PD_Subjects.Find(id, sid);

            c.CanvasWidth  = s.CanvasWidth;
            c.CanvasHeight = s.CanvasHeight;
            return(Ok(c));
        }
示例#6
0
        public IEnumerable <PD_TransitionDTO> GetAllTransitions(int id, int sid)
        {
            PD_Subject i = _db.PD_Subjects.Find(id, sid);
            List <PD_TransitionDTO> t = new List <PD_TransitionDTO>();

            foreach (var tr in i.Transitions)
            {
                var temp = new PD_TransitionDTO()
                {
                    Id = tr.Id, Source = tr.Source, Target = tr.Target, Type = tr.Type, LabelPosition = tr.LabelPosition
                };

                if (tr.Type == PD_TransitionTypes.RegularTransition)
                {
                    temp.Label = ((PD_RegularTransition)tr).Name;
                }
                if (tr.Type == PD_TransitionTypes.ReceiveTransition)
                {
                    try
                    {
                        PD_Message     m  = _db.PD_Messages.Find(id, ((PD_ReceiveTransition)tr).Message);
                        PD_MessageType mt = m.PD_MessageType;
                        PD_Subject     s  = _db.PD_Subjects.Find(id, m.From);
                        temp.Label = s.Name + "|" + mt.Name;
                    }
                    catch (Exception e)
                    {
                        temp.Label = "Receive";
                    }
                }
                if (tr.Type == PD_TransitionTypes.TimeoutTransition)
                {
                    temp.Label = ((PD_TimeoutTransition)tr).TimeSpan;
                }
                if (temp.Label == null)
                {
                    temp.Label = "EMPTY";
                }
                t.Add(temp);
            }
            return(t.ToArray());
        }
示例#7
0
        public void DeleteState(int id, int sid, int stid)
        {
            var _p = _db.PD_Processes.Find(id);

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

                if (state != null)
                {
                    var todelete = _db.PD_Transitions.Where(result => result.Source == state.Id && result.PD_Process_Id == id && result.PD_Subject_Id == sid || result.Target == state.Id && result.PD_Process_Id == id && result.PD_Subject_Id == sid);
                    _db.PD_Transitions.RemoveRange(todelete);
                    i.States.Remove(state);
                    _db.SaveChanges();
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
        }
示例#8
0
        public void PutSubject(PD_SubjectDTO item, int id, int sid)
        {
            var _p = _db.PD_Processes.Find(id);

            if (User.Identity.Name.Equals(_p.LockedBy))
            {
                PD_Subject i = _db.PD_Subjects.Find(id, sid);

                if (i != null)
                {
                    if (item.Name != null)
                    {
                        i.Name = item.Name;
                    }
                    i.PositionTop  = item.PositionTop;
                    i.PositionLeft = item.PositionLeft;
                    _db.SaveChanges();
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
        }
示例#9
0
        public ActionResult ImportBPMN(BPMNImportViewModel model)
        {
            model.description = "Imported from BPMN";
            ZipArchive         a       = new ZipArchive(model.zipfile.InputStream);
            List <definitions> imports = new List <definitions>();

            foreach (ZipArchiveEntry entry in a.Entries)
            {
                if (entry.FullName.EndsWith(".bpmn", StringComparison.OrdinalIgnoreCase))
                {
                    StreamReader reader = new StreamReader(entry.Open());


                    XmlRootAttribute xRoot = new XmlRootAttribute();
                    xRoot.ElementName = "definitions";
                    xRoot.Namespace   = "http://www.omg.org/spec/BPMN/20100524/MODEL";
                    xRoot.IsNullable  = true;
                    XmlSerializer serializer = new XmlSerializer(typeof(definitions), xRoot);
                    XmlReader     xRdr       = XmlReader.Create(reader);
                    definitions   import     = (definitions)serializer.Deserialize(xRdr);
                    //   BPMNImport import = (BPMNImport)serializer.Deserialize(new XmlTextReader(reader));


                    imports.Add(import);
                }
            }



            foreach (definitions i in imports)
            {
                WS_Project p = new WS_Project();

                p.Name        = i.BPMNDiagram.name;
                p.Description = model.description;
                p.Folder_Id   = model.folderId;

                this.CreateProject(p);

                int pd_id = p.ModelVersions.FirstOrDefault().PD_ProcessId;


                PD_Process pdp = _pDesignerDB.PD_Processes.Find(pd_id);
                int        n   = 50;
                int        c   = 0;
                int        t   = 50;
                foreach (var x in i.collaboration.participant)
                {
                    PD_Subject s = new PD_Subject();

                    s.Name = x.name;
                    if (c == 10)
                    {
                        t += 400;
                        c  = 0;
                        n  = 50;
                    }
                    s.PositionLeft = n;

                    s.PositionTop = t;
                    c++;
                    n += 200;
                    s.CanvasHeight = 1000;
                    s.CanvasWidth  = 1000;
                    s.Id           = IdHelper.getSubjectId(_pDesignerDB, pdp.Id);

                    pdp.Subjects.Add(s);
                    pdp.CanvasHeight = 200 + t;
                    if (s.PositionLeft > pdp.CanvasWidth)
                    {
                        pdp.CanvasWidth = s.PositionLeft;
                    }
                }
                if (i.collaboration.messageFlow != null)
                {
                    foreach (var x in i.collaboration.messageFlow)
                    {
                        PD_MessageType pdm = new PD_MessageType();
                        pdm.PD_Process_Id = pdp.Id;
                        pdm.Id            = IdHelper.getMessageTypeId(_pDesignerDB, pdp.Id);
                        pdm.Name          = x.name;
                        pdp.MessageTypes.Add(pdm);

                        /* try {
                         * PD_Message m = new PD_Message();
                         * m.Id = IdHelper.getMessageId(_pDesignerDB, pdp.Id);
                         *
                         *
                         * string fname = i.collaboration.participant.Where(s => s.id.Equals(x.sourceRef)).FirstOrDefault().name;
                         * m.From = pdp.Subjects.Where(y => y.Name.Equals(fname)).FirstOrDefault().Id;
                         * m.To = pdp.Subjects.Where(y => y.Name.Equals(i.collaboration.participant.Where(s => s.id.Equals(x.targetRef)).FirstOrDefault().name)).FirstOrDefault().Id;
                         * m.PD_MessageType_Id = pdm.Id;
                         * pdp.Messages.Add(m);
                         *  }
                         * catch (Exception e)
                         * {
                         *
                         * }*/
                    }
                }
                foreach (var x in i.process)
                {
                    PD_Subject pds = pdp.Subjects.Where(z => z.Name.Equals(x.name)).FirstOrDefault();
                    foreach (var y in x.Items)
                    {
                        PD_FunctionState pdf = new PD_FunctionState();
                        const string     pre = "strICT.InFlow.Web.Models.";
                        Type             w   = y.GetType();
                        switch (w.FullName)
                        {
                        case pre + "definitionsProcessAssociation":

                            definitionsProcessAssociation var1 = (definitionsProcessAssociation)y;

                            break;

                        case pre + "definitionsProcessDataStoreReference":

                            definitionsProcessDataStoreReference var2 = (definitionsProcessDataStoreReference)y;

                            break;

                        case pre + "definitionsProcessIntermediateCatchEvent":

                            definitionsProcessIntermediateCatchEvent var3 = (definitionsProcessIntermediateCatchEvent)y;
                            pdf               = new PD_FunctionState();
                            pdf.Name          = var3.name;
                            pdf.PD_Process_Id = pdp.Id;
                            pdf.PD_Subject_Id = pds.Id;
                            pdf.Type          = PD_StateTypes.FunctionState;
                            pdf.Id            = IdHelper.getStateId(_pDesignerDB, pdp.Id, pds.Id);
                            if (var3.incoming == null)
                            {
                                pdf.StartState = true;
                            }
                            if (var3.outgoing == null)
                            {
                                pdf.EndState = true;
                            }

                            pds.States.Add(pdf);


                            break;

                        case pre + "definitionsProcessIntermediateThrowEvent":

                            definitionsProcessIntermediateThrowEvent var4 = (definitionsProcessIntermediateThrowEvent)y;
                            pdf               = new PD_FunctionState();
                            pdf.Name          = var4.name;
                            pdf.PD_Process_Id = pdp.Id;
                            pdf.PD_Subject_Id = pds.Id;
                            pdf.Type          = PD_StateTypes.FunctionState;
                            pdf.Id            = IdHelper.getStateId(_pDesignerDB, pdp.Id, pds.Id);
                            if (var4.incoming == null)
                            {
                                pdf.StartState = true;
                            }
                            if (var4.outgoing == null)
                            {
                                pdf.EndState = true;
                            }

                            pds.States.Add(pdf);
                            break;

                        case pre + "definitionsProcessSequenceFlow":

                            definitionsProcessSequenceFlow var5 = (definitionsProcessSequenceFlow)y;

                            break;

                        case pre + "definitionsProcessServiceTask":

                            definitionsProcessServiceTask var6 = (definitionsProcessServiceTask)y;
                            pdf               = new PD_FunctionState();
                            pdf.Name          = var6.name;
                            pdf.PD_Process_Id = pdp.Id;
                            pdf.PD_Subject_Id = pds.Id;
                            pdf.Type          = PD_StateTypes.FunctionState;
                            pdf.Id            = IdHelper.getStateId(_pDesignerDB, pdp.Id, pds.Id);
                            if (var6.incoming == null)
                            {
                                pdf.StartState = true;
                            }
                            if (var6.outgoing == null)
                            {
                                pdf.EndState = true;
                            }
                            pds.States.Add(pdf);
                            break;

                        case pre + "definitionsProcessTextAnnotation":

                            definitionsProcessTextAnnotation var7 = (definitionsProcessTextAnnotation)y;

                            break;

                        case pre + "definitionsProcessUserTask":

                            definitionsProcessUserTask var8 = (definitionsProcessUserTask)y;
                            pdf               = new PD_FunctionState();
                            pdf.Name          = var8.name;
                            pdf.PD_Process_Id = pdp.Id;
                            pdf.PD_Subject_Id = pds.Id;
                            pdf.Type          = PD_StateTypes.FunctionState;
                            pdf.Id            = IdHelper.getStateId(_pDesignerDB, pdp.Id, pds.Id);
                            if (var8.incoming == null)
                            {
                                pdf.StartState = true;
                            }
                            if (var8.outgoing == null)
                            {
                                pdf.EndState = true;
                            }
                            pds.States.Add(pdf);
                            break;
                        }
                    }
                }

                pdp.CanvasWidth  += 100;
                pdp.CanvasHeight += 100;
            }

            _pDesignerDB.SaveChanges();
            return(View("Index"));
        }
示例#10
0
        private string buildXaml(PD_Process process, PD_Subject subject)
        {
            Flowchart flow = new Flowchart();
            Variable  flowGlobalTransition = new Variable <String> {
                Name = "GlobalTransition"
            };
            Variable flowGlobalVariables = new Variable <DynamicValue> {
                Name = "GlobalVariables"
            };



            string globVariablesInit = "";

            if (subject.GlobalParameters.Count > 0)
            {
                globVariablesInit = "{";
                foreach (string p in subject.GlobalParameters)
                {
                    var par = _pdesignerDB.PD_Parameters.Find(subject.PD_Process_Id, p);
                    globVariablesInit = globVariablesInit + "\"" + p + "\":" + par.Config + ",";
                }
                globVariablesInit = globVariablesInit.Remove(globVariablesInit.Length - 1, 1);
                globVariablesInit = globVariablesInit + "}";
            }

            Variable flowGlobalVariablesSchema = new Variable <string> {
                Name = "GlobalVariablesSchema", Default = globVariablesInit
            };

            Dictionary <int, FlowStep> nodeList = new Dictionary <int, System.Activities.Statements.FlowStep>();

            flow.Variables.Add(flowGlobalTransition);
            flow.Variables.Add(flowGlobalVariables);
            flow.Variables.Add(flowGlobalVariablesSchema);



            foreach (var state in subject.States)
            {
                FlowStep f;
                if (state.Type == PD_StateTypes.FunctionState)
                {
                    var    s       = (PD_FunctionState)state;
                    string timeout = "";
                    try
                    {
                        var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition);

                        timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan;
                    }
                    catch (Exception e)
                    {
                    }
                    var           transitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.RegularTransition);
                    List <string> titems      = new List <string>();
                    transitions.ToList().ForEach(i => titems.Add(((PD_RegularTransition)i).Name));
                    f = new FlowStep()
                    {
                        Action = new FunctionStateT()
                        {
                            DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), TimeOut = timeout, transitions = collectionToString(titems)
                        }
                    };
                }
                else if (state.Type == PD_StateTypes.SendState)
                {
                    var    s       = (PD_SendState)state;
                    string timeout = "";
                    try
                    {
                        var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition);

                        timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan;
                    }
                    catch (Exception e)
                    {
                    }
                    var    message = process.Messages.First(result => result.Id == s.Message);
                    string to      = process.Subjects.First(result => result.Id == message.To).Name;
                    f = new FlowStep()
                    {
                        Action = new SendStateT()
                        {
                            DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), messageType = message.PD_MessageType.Name, parameters = collectionToString(message.PD_MessageType.Parameters), toSubject = to, TimeOut = timeout
                        }
                    };
                }
                else //(state.Type == PD_StateTypes.ReceiveState)
                {
                    var           s                  = (PD_ReceiveState)state;
                    string        messages           = "";
                    List <string> messagelist        = new List <string>();
                    var           receivetransitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.ReceiveTransition);

                    foreach (var i in receivetransitions)
                    {
                        messagelist.Add(receiveTranstionToString(process, (PD_ReceiveTransition)i));
                    }
                    messages = collectionToString(messagelist);

                    string timeout = "";
                    try
                    {
                        var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition);
                        timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan;
                    }
                    catch (Exception e)
                    {
                    }

                    f = new FlowStep()
                    {
                        Action = new ReceiveStateT()
                        {
                            DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, TimeOut = timeout, messages = messages
                        }
                    };
                }
                flow.Nodes.Add(f);
                nodeList.Add(state.Id, f);
            }


            var initGP = new FlowStep()
            {
                Action = new InitializeGlobalParameters()
                {
                    DisplayName = "init GP", DynamicVal = new InOutArgument <DynamicValue>(flowGlobalVariables), GlobalParameterSchema = new InArgument <string>(flowGlobalVariablesSchema)
                }
            };

            initGP.Next    = nodeList[subject.States.First(result => result.StartState == true).Id];
            flow.StartNode = initGP;

            // flow.StartNode = nodeList[subject.States.First(result => result.StartState == true).Id];


            foreach (var state in subject.States)
            {
                List <PD_Transition> transitions = new List <PD_Transition>();
                try
                {
                    subject.Transitions.Where(result => result.Source == state.Id).ToList().ForEach(item => transitions.Add(item));
                }
                catch (Exception e) { }

                if (transitions.Count > 0)
                {
                    if (transitions.Count == 1)
                    {
                        var t = transitions[0];
                        nodeList[t.Source].Next = nodeList[t.Target];
                    }
                    else
                    {
                        FlowSwitch <String> newSwitch = new FlowSwitch <String> {
                            Expression = flowGlobalTransition
                        };
                        flow.Nodes.Add(newSwitch);
                        nodeList[state.Id].Next = newSwitch;

                        try
                        {
                            var timeouttransition = transitions.First(result => result.Type == PD_TransitionTypes.TimeoutTransition);

                            newSwitch.Cases.Add("TimeOut!", nodeList[timeouttransition.Target]);
                            transitions.Remove(timeouttransition);
                        }
                        catch (Exception e) { }

                        if (state.Type == PD_StateTypes.SendState)
                        {
                            newSwitch.Default = nodeList[transitions[0].Target];
                        }
                        else if (state.Type == PD_StateTypes.ReceiveState)
                        {
                            foreach (var t in transitions)
                            {
                                newSwitch.Cases.Add(receiveTranstionToString(process, (PD_ReceiveTransition)t), nodeList[t.Target]);
                            }
                        }
                        else
                        {
                            foreach (var t in transitions)
                            {
                                newSwitch.Cases.Add(((PD_RegularTransition)t).Name, nodeList[t.Target]);
                            }
                        }
                    }
                }
            }

            ActivityBuilder builder = new ActivityBuilder();

            builder.Name = "strICT.InFlowTest.WFProcesses." + process.Name + "." + subject.Name;


            builder.Implementation = flow;

            VisualBasic.SetSettings(builder, new VisualBasicSettings());

            //StringBuilder sb = new StringBuilder();
            StringWriterUtf8 stream = new StringWriterUtf8();
            XamlWriter       writer = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(stream, new XamlSchemaContext()));

            XamlServices.Save(writer, builder);


            string res = stream.GetStringBuilder().ToString();

            res = res.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
            return(res);
        }
示例#11
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);
        }