Beispiel #1
0
        private static void AddConnector(ModelBusReference processOverview, ProcessOverview.SubProcessElement fromSubProcess, ProcessOverview.SubProcessElement toSubProcess)
        {
            IModelBus modelbus = processOverview.ModelBus;
            ModelBusAdapter adapter = modelbus.CreateAdapter(processOverview);
            Diagram diagram = ((StandardVsModelingDiagramView)adapter.GetDefaultView()).Diagram;

            using (Transaction t = fromSubProcess.Store.TransactionManager.BeginTransaction("Add Connector"))
            {
                //Connector must be added when BTSubProcessActivity is added
                ProcessOverview.SubProcessElementReferencesTargets refTargets = new ProcessOverview.SubProcessElementReferencesTargets(fromSubProcess, toSubProcess);
                ProcessOverview.SubProcessConnector connector = new ProcessOverview.SubProcessConnector(diagram.Partition);

                connector.Associate(refTargets);
                diagram.NestedChildShapes.Add(connector);

                t.Commit();
            }
        }
Beispiel #2
0
        public static void AddConnectors(SubProcessBase element, ModelBusReference newValue)
        {
            string fileName = Utilities.GetFileNameForStore(element.Store);

            if (fileName == "")
                return;

            if (newValue == null)
                return;

            ProcessOverview.Process targetProc = null;

            IModelBus modelBus = element.Store.GetService(typeof(SModelBus)) as IModelBus;
            ModelBusAdapterManager manager = modelBus.FindAdapterManagers(fileName).First();
            ModelBusReference reference = manager.CreateReference(fileName);

            List<ProcessOverview.SubProcessElement> subProcList = new List<ProcessOverview.SubProcessElement>();

            Diagram targetDiagram;

            using (ModelBusAdapter targetAdapter = modelBus.CreateAdapter(newValue))
            {
                ModelBusView view = targetAdapter.GetDefaultView();
                targetDiagram = ((StandardVsModelingDiagramView)view).Diagram;
            }

            targetProc = (ProcessOverview.Process)targetDiagram.ModelElement;
            subProcList.AddRange(targetProc.BTSubProcess);

            foreach (var item in subProcList)
            {
                using (ModelBusAdapter adapter = modelBus.CreateAdapter(item.SubProcessRef))
                {
                    SubProcessBase subProcessBase = (SubProcessBase)adapter.ResolveElementReference(item.SubProcessRef);

                    List<Activity> toSubProcActs = new List<Activity>();

                    toSubProcActs.AddRange(subProcessBase.Activities.Where(a => a is ToProcessConnector));

                    foreach (var toProcAct in toSubProcActs)
                    {
                        try
                        {
                            using (Transaction t = item.Store.TransactionManager.BeginTransaction("Add Connector"))
                            {
                                List<ProcessOverview.SubProcessElement> toSub = new List<ProcessOverview.SubProcessElement>();

                                ModelBusReference mbr = ((ToProcessConnector)toProcAct).ExternalActivityRef;

                                if (mbr == null)
                                    continue;

                                using (ModelBusAdapter mba = modelBus.CreateAdapter(mbr))
                                {
                                    FromProcessConnector fpa = (FromProcessConnector)mba.ResolveElementReference(mbr);

                                    ModelBusReference subProcessRef = mba.GetElementReference(fpa.SubProcess);

                                    IEnumerable<ProcessOverview.SubProcessElement> toSubProcess = subProcList.Where(p => p.SubProcessRef == subProcessRef);

                                    foreach (var i in toSubProcess)
                                    {
                                        ProcessOverview.SubProcessElementReferencesTargets refTargets = new ProcessOverview.SubProcessElementReferencesTargets(item, i);
                                        ProcessOverview.SubProcessConnector connector = new ProcessOverview.SubProcessConnector(targetDiagram.Partition);

                                        connector.Associate(refTargets);

                                        if (targetDiagram.NestedChildShapes.Where(s => s == connector).Count() == 0)
                                            targetDiagram.NestedChildShapes.Add(connector);
                                    }
                                }

                                t.Commit();
                            }
                        }
                        catch (Exception)
                        {
                            return;
                        }
                    }
                }
            }
        }