Exemple #1
0
        public ActionResult _ImportBPMN()
        {
            var m = new BPMNImportViewModel();
            List <WS_Folder> folderlist = _db.WS_Folders.Where(f => f.Parent_Id == null).ToList <WS_Folder>();


            m.folder = from c in folderlist
                       select new SelectListItem
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            };

            return(PartialView(m));
        }
Exemple #2
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"));
        }