Exemple #1
0
 public bool CheckDataAndCodeIfExist(SubProcess entity)
 {
     if (CheckDataIfExists(entity) || CheckDataIfExists(entity.Code))
     {
         return true;
     }
     return false;
 }
Exemple #2
0
 public bool CheckDataIfExists(SubProcess entity)
 {
     Dictionary<string, object> parameter = new Dictionary<string, object>();
     parameter.Add("Code", entity.Code);
     parameter.Add("Name", entity.Name);
     parameter.Add("Active", entity.Active);
     parameter.Add("Process", entity.Process);
     List<SubProcess> process = this.subProcessRepository.CheckIfDataExists(parameter);
     if (process.Count() > 0)
     {
         return true;
     }
     return false;
 }
Exemple #3
0
 public static string GenerateWorkflowName(Workflow workflow, Process process, SubProcess subProcess, Classification classification)
 {
     if (classification != null)
     {
     return  string.Format("{0} {1}", string.Empty, classification.Name);
     }
     else if(subProcess !=null)
     {
         return string.Format("{0} {1}", string.Empty, subProcess.Name);
     }
      else if(process !=null)
     {
         return string.Format("{0} {1}", string.Empty, process.Name);
     }
     else
     {
         return string.Format("{0} {1} (Default workflow)", string.Empty, workflow.Name);
     }
 }
        public virtual IDataObject Execute(ICommandContext commandContext)
        {
            if (executionId is null)
            {
                throw new ActivitiIllegalArgumentException("executionId is null");
            }
            if (dataObjectName is null)
            {
                throw new ActivitiIllegalArgumentException("dataObjectName is null");
            }

            IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId);

            if (execution == null)
            {
                throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", typeof(IExecution));
            }

            IDataObject dataObject = null;

            IVariableInstance variableEntity;

            if (isLocal)
            {
                variableEntity = execution.GetVariableInstanceLocal(dataObjectName, false);
            }
            else
            {
                variableEntity = execution.GetVariableInstance(dataObjectName, false);
            }

            string localizedName        = null;
            string localizedDescription = null;

            if (variableEntity != null)
            {
                IExecutionEntity executionEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(variableEntity.ExecutionId);
                while (!executionEntity.IsScope)
                {
                    executionEntity = executionEntity.Parent;
                }

                BpmnModel        bpmnModel       = ProcessDefinitionUtil.GetBpmnModel(executionEntity.ProcessDefinitionId);
                ValuedDataObject foundDataObject = null;
                if (executionEntity.ParentId is null)
                {
                    foreach (ValuedDataObject dataObjectDefinition in bpmnModel.MainProcess.DataObjects)
                    {
                        if (dataObjectDefinition.Name.Equals(variableEntity.Name))
                        {
                            foundDataObject = dataObjectDefinition;
                            break;
                        }
                    }
                }
                else
                {
                    SubProcess subProcess = (SubProcess)bpmnModel.GetFlowElement(execution.ActivityId);
                    foreach (ValuedDataObject dataObjectDefinition in subProcess.DataObjects)
                    {
                        if (dataObjectDefinition.Name.Equals(variableEntity.Name))
                        {
                            foundDataObject = dataObjectDefinition;
                            break;
                        }
                    }
                }

                if (!(locale is null) && foundDataObject != null)
                {
                    JToken languageNode = Context.GetLocalizationElementProperties(locale, foundDataObject.Id, execution.ProcessDefinitionId, withLocalizationFallback);

                    if (variableEntity != null && languageNode != null)
                    {
                        JToken nameNode = languageNode[DynamicBpmnConstants.LOCALIZATION_NAME];
                        if (nameNode != null)
                        {
                            localizedName = nameNode.ToString();
                        }
                        JToken descriptionNode = languageNode[DynamicBpmnConstants.LOCALIZATION_DESCRIPTION];
                        if (descriptionNode != null)
                        {
                            localizedDescription = descriptionNode.ToString();
                        }
                    }
                }

                if (foundDataObject != null)
                {
                    dataObject = new DataObjectImpl(variableEntity.Name, variableEntity.Value, foundDataObject.Documentation, foundDataObject.Type, localizedName, localizedDescription, foundDataObject.Id);
                }
            }

            return(dataObject);
        }
 public JsonResult Manage(ClassificationModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             model.SubProcess = this.subProcessService.GetDataById(model.SubProcessId);
             bool ifExists = this.classificationService.CheckDataIfExists(model);
             if (!ifExists)
             {
                 Classification classification = new Classification();
                 SubProcess subProcess = new SubProcess();
                 subProcess = this.subProcessService.GetDataById(model.SubProcessId);
                 classification = this.classificationService.GetDataById(model.Id);
                 classification.SubProcess = subProcess;
                 classification.Code = model.Code;
                 classification.Name = model.Name;
                 classification.Description = model.Description;
                 classification.Active = model.Active;
                 classification.DateModified = DateTime.Now;
                 classification.ModifiedBy = User.Identity.Name.ToString();
                 this.classificationService.SaveChanges(classification);
                 return Json(new { result = Base.Encrypt(classification.Id.ToString()), message = MessageCode.modified, code = StatusCode.modified, content= model.Name });
             }
             return Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed });
         }
         return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
     }
     catch (Exception ex)
     {
         return Json(new { result = StatusCode.failed, message = ex.Message.ToString(), code = StatusCode.failed, content = model.Name });
     }
 }
Exemple #6
0
        /// <summary>
        /// Have the utility do what it does.
        /// </summary>
        public void Export(string outFullName)
        {
            #region Set up progress reporting

#if (TIME_IT)
            DateTime dt1 = DateTime.Now;    // time this thing
#endif
            var myCursor  = Common.UseWaitCursor();
            var curdir    = Environment.CurrentDirectory;
            var inProcess = Common.SetupProgressReporting(5, "Export Process");

            #endregion Set up progress reporting

            #region Process start

            inProcess.SetStatus("Export Process Started");
            inProcess.PerformStep();

            Common.SetupLocalization();
            Debug.Assert(DataType == "Scripture" || DataType == "Dictionary", "DataType must be Scripture or Dictionary");
            Debug.Assert(outFullName.IndexOf(Path.DirectorySeparatorChar) >= 0, "full path for output must be given");
            string caption = LocalizationManager.GetString("PsExport.ExportClick.Caption", "Pathway Export", "");

            #endregion

            try
            {
                #region Simplify Export Files

                inProcess.SetStatus("Simplify Export Files");
                inProcess.PerformStep();

                //get xsltFile from ExportThroughPathway.cs
                string revFileName = string.Empty;
                var    outDir      = Path.GetDirectoryName(outFullName);

                SimplifyExportFiles(outFullName, inProcess);

                #endregion

                #region Setting up Css and Xhtml

                inProcess.SetStatus("Setting up Css and Xhtml");
                inProcess.PerformStep();

                string supportPath = GetSupportPath();
                Backend.Load(Common.AssemblyPath);
                LoadProgramSettings(supportPath);
                LoadDataTypeSettings();

                DefaultProjectFileSetup(outDir);
                SubProcess.BeforeProcess(outFullName);

                var mainXhtml    = Path.GetFileNameWithoutExtension(outFullName) + ".xhtml";
                var mainFullName = Common.PathCombine(outDir, mainXhtml);
                Debug.Assert(mainFullName.IndexOf(Path.DirectorySeparatorChar) >= 0, "Path for input file missing");
                if (string.IsNullOrEmpty(mainFullName) || !File.Exists(mainFullName))
                {
                    return;
                }
                string cssFullName;
                if (GetCSSFileName(outFullName, outDir, mainFullName, out cssFullName))
                {
                    return;
                }

                _selectedCssFromTemplate = Path.GetFileNameWithoutExtension(cssFullName);
                string fluffedCssFullName;

                if (Path.GetFileNameWithoutExtension(outFullName) == "FlexRev")
                {
                    fluffedCssFullName = GetFluffedCssFullName(GetRevFullName(outFullName), outDir, cssFullName);
                }
                else
                {
                    fluffedCssFullName = GetFluffedCssFullName(outFullName, outDir, cssFullName);
                    revFileName        = GetRevFullName(outDir);
                }
                string fluffedRevCssFullName = string.Empty;
                if (revFileName.Length > 0)
                {
                    fluffedRevCssFullName = GetFluffedCssFullName(revFileName, outDir, cssFullName);
                }
                DestinationSetup();
                SetDefaultLanguageFontandBaseFontSize(fluffedCssFullName, mainFullName, revFileName, fluffedRevCssFullName);
                //Common.StreamReplaceInFile(fluffedCssFullName, "\\2B27", "\\25C6");
                WritePublishingInformationFontStyleinCSS(fluffedCssFullName);

                #endregion

                #region Close Reporting

                inProcess.Close();

                Environment.CurrentDirectory = curdir;
                Cursor.Current = myCursor;

                #endregion Close Reporting

                if (DataType == "Scripture")
                {
                    Common.GetFontFeatures();

                    SeExport(mainXhtml, Path.GetFileName(fluffedCssFullName), outDir);
                }
                else if (DataType == "Dictionary")
                {
                    string revFullName = GetRevFullName(outDir);
                    DeExport(outFullName, fluffedCssFullName, revFullName, fluffedRevCssFullName);
                }
            }
            catch (InvalidStyleSettingsException err)
            {
                if (_fromNUnit)
                {
                    Console.WriteLine(string.Format(err.ToString(), err.FullFilePath), "Pathway Export");
                }
                else
                {
                    Utils.MsgBox(string.Format(err.ToString(), err.FullFilePath), caption,
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            catch (UnauthorizedAccessException err)
            {
                if (_fromNUnit)
                {
                    Console.WriteLine(string.Format(err.ToString(), "Sorry! You might not have permission to use this resource."));
                }
                else
                {
                    var msg = LocalizationManager.GetString("PsExport.ExportClick.Message",
                                                            "Sorry! You might not have permission to use this resource.", "");
                    Utils.MsgBox(string.Format(err.ToString(), msg), caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            catch (Exception ex)
            {
                if (_fromNUnit)
                {
                    Console.WriteLine(ex.ToString());
                }
                else
                {
                    if (ex.ToString().IndexOf("Module1.xml") == -1)
                    {
                        Utils.MsgBox(ex.ToString(), caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                return;
            }
            finally
            {
            }
        }
Exemple #7
0
 public void SaveChanges(SubProcess entity)
 {
     this.subProcessRepository.SaveChanges(entity);
 }
Exemple #8
0
        private static void CreateAndSaveSubProcessFile(Partition partition, SerializationResult result, string subProcessFile, CloudCoreArchitectSubProcessSerializationHelper subProcessDSLSerializationHelper, SubProcess subProcess)
        {
            var bDiagram = subProcessDSLSerializationHelper.CreateDiagramHelper(partition, subProcess);

            subProcessDSLSerializationHelper.SaveModelAndDiagram(result, subProcess, subProcessFile, bDiagram, subProcessFile + ".diagram", Encoding.UTF8, false);
        }
        public JsonResult Manage(SubProcessModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {

                    bool ifExists = this.subProcessService.CheckDataIfExists(model);
                    if (!ifExists)
                    {
                        SubProcess subProcess = new SubProcess();
                        Process process = new Process();
                        process = this.processService.GetDataById(model.ProcessId);
                        subProcess = this.subProcessService.GetDataById(model.Id);
                        subProcess.Id = model.Id;
                        subProcess.Process = process;
                        subProcess.Code = model.Code;
                        subProcess.Name = model.Name;
                        subProcess.Description = model.Description;
                        subProcess.Active = model.Active;
                        subProcess.DateModified = DateTime.Now;
                        subProcess.ModifiedBy = User.Identity.Name.ToString();
                        this.subProcessService.SaveChanges(subProcess);
                        return Json(new { result = Base.Encrypt(subProcess.Id.ToString()), message = MessageCode.modified, code = StatusCode.modified, content = subProcess.Name });
                    }
                    return Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed, content = model.Name });
                }
                return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
            }
            catch (Exception ex)
            {
                return Json(new { result = StatusCode.failed, message = ex.Message.ToString(), code = StatusCode.failed, content = model.Name });
            }
        }
        // Subprocess

        public virtual SubProcessActivityBehavior CreateSubprocessActivityBehavior(SubProcess subProcess)
        {
            return(new SubProcessActivityBehavior());
        }
        public virtual BpmnModel ConvertToBpmnModel(XMLStreamReader xtr)
        {
            BpmnModel model = new BpmnModel
            {
                StartEventFormTypes = startEventFormTypes,
                UserTaskFormTypes   = userTaskFormTypes
            };

            try
            {
                Process            activeProcess        = null;
                IList <SubProcess> activeSubProcessList = new List <SubProcess>();
                while (xtr.HasNext())
                {
                    // xtr.next();
                    if (xtr.EndElement && (BpmnXMLConstants.ELEMENT_SUBPROCESS.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_TRANSACTION.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_ADHOC_SUBPROCESS.Equals(xtr.LocalName)))
                    {
                        activeSubProcessList.RemoveAt(activeSubProcessList.Count - 1);
                    }

                    if (!xtr.IsStartElement())
                    {
                        if (BpmnXMLConstants.ELEMENT_DI_DIAGRAM == xtr.LocalName)
                        {
                            xtr.Skip();
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (xtr.IsStartElement() && BpmnXMLConstants.ELEMENT_DEFINITIONS.Equals(xtr.LocalName))
                    {
                        definitionsParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_RESOURCE.Equals(xtr.LocalName))
                    {
                        resourceParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_SIGNAL.Equals(xtr.LocalName))
                    {
                        signalParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_MESSAGE.Equals(xtr.LocalName))
                    {
                        messageParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_ERROR.Equals(xtr.LocalName))
                    {
                        if (!string.IsNullOrWhiteSpace(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID)))
                        {
                            model.AddError(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID), xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ERROR_CODE));
                        }
                    }
                    else if (BpmnXMLConstants.ELEMENT_IMPORT.Equals(xtr.LocalName))
                    {
                        importParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_ITEM_DEFINITION.Equals(xtr.LocalName))
                    {
                        itemDefinitionParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_DATA_STORE.Equals(xtr.LocalName))
                    {
                        dataStoreParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_INTERFACE.Equals(xtr.LocalName))
                    {
                        interfaceParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_IOSPECIFICATION.Equals(xtr.LocalName))
                    {
                        ioSpecificationParser.ParseChildElement(xtr, activeProcess, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_PARTICIPANT.Equals(xtr.LocalName))
                    {
                        participantParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_MESSAGE_FLOW.Equals(xtr.LocalName))
                    {
                        messageFlowParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_PROCESS.Equals(xtr.LocalName))
                    {
                        Process process = processParser.Parse(xtr, model);
                        if (process != null)
                        {
                            activeProcess = process;
                        }
                    }
                    else if (BpmnXMLConstants.ELEMENT_POTENTIAL_STARTER.Equals(xtr.LocalName))
                    {
                        potentialStarterParser.Parse(xtr, activeProcess);
                    }
                    else if (BpmnXMLConstants.ELEMENT_LANE.Equals(xtr.LocalName))
                    {
                        laneParser.Parse(xtr, activeProcess, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_DOCUMENTATION.Equals(xtr.LocalName))
                    {
                        BaseElement parentElement = null;
                        if (activeSubProcessList.Count > 0)
                        {
                            parentElement = activeSubProcessList[activeSubProcessList.Count - 1];
                        }
                        else if (activeProcess != null)
                        {
                            parentElement = activeProcess;
                        }
                        documentationParser.ParseChildElement(xtr, parentElement, model);
                    }
                    else if (activeProcess == null && BpmnXMLConstants.ELEMENT_TEXT_ANNOTATION.Equals(xtr.LocalName))
                    {
                        string         elementId      = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID);
                        TextAnnotation textAnnotation = (TextAnnotation)(new TextAnnotationXMLConverter()).ConvertXMLToElement(xtr, model);
                        textAnnotation.Id = elementId;
                        model.GlobalArtifacts.Add(textAnnotation);
                    }
                    else if (activeProcess == null && BpmnXMLConstants.ELEMENT_ASSOCIATION.Equals(xtr.LocalName))
                    {
                        string      elementId   = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID);
                        Association association = (Association)(new AssociationXMLConverter()).ConvertXMLToElement(xtr, model);
                        association.Id = elementId;
                        model.GlobalArtifacts.Add(association);
                    }
                    else if (BpmnXMLConstants.ELEMENT_EXTENSIONS.Equals(xtr.LocalName))
                    {
                        extensionElementsParser.Parse(xtr, activeSubProcessList, activeProcess, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_SUBPROCESS.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_TRANSACTION.Equals(xtr.LocalName) || BpmnXMLConstants.ELEMENT_ADHOC_SUBPROCESS.Equals(xtr.LocalName))
                    {
                        subProcessParser.Parse(xtr, activeSubProcessList, activeProcess);
                    }
                    else if (BpmnXMLConstants.ELEMENT_COMPLETION_CONDITION.Equals(xtr.LocalName))
                    {
                        if (activeSubProcessList.Count > 0)
                        {
                            SubProcess subProcess = activeSubProcessList[activeSubProcessList.Count - 1];
                            if (subProcess is AdhocSubProcess adhocSubProcess)
                            {
                                adhocSubProcess.CompletionCondition = xtr.ElementText;
                            }
                        }
                    }
                    else if (BpmnXMLConstants.ELEMENT_DI_SHAPE.Equals(xtr.LocalName))
                    {
                        bpmnShapeParser.Parse(xtr, model);
                    }
                    else if (BpmnXMLConstants.ELEMENT_DI_EDGE.Equals(xtr.LocalName))
                    {
                        bpmnEdgeParser.Parse(xtr, model);
                    }
                    else
                    {
                        if (activeSubProcessList.Count > 0 && BpmnXMLConstants.ELEMENT_MULTIINSTANCE.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            multiInstanceParser.ParseChildElement(xtr, activeSubProcessList[activeSubProcessList.Count - 1], model);
                        }
                        else if (convertersToBpmnMap.ContainsKey(xtr.LocalName))
                        {
                            if (activeProcess != null)
                            {
                                BaseBpmnXMLConverter converter = convertersToBpmnMap[xtr.LocalName];
                                converter.ConvertToBpmnModel(xtr, model, activeProcess, activeSubProcessList);
                            }
                        }
                    }
                    //try
                    //{
                    //    xtr.next();
                    //}
                    //catch (Exception e)
                    //{
                    //    //LOGGER.debug("Error reading XML document", e);
                    //    throw new XMLException("Error reading XML", e);
                    //}
                }

                foreach (Process process in model.Processes)
                {
                    foreach (Pool pool in model.Pools)
                    {
                        if (process.Id.Equals(pool.ProcessRef))
                        {
                            pool.Executable = process.Executable;
                        }
                    }
                    ProcessFlowElements(process.FlowElements, process);
                }
            }
            catch (Exception e)
            {
                log.LogError(e, "Error processing BPMN document");
                throw new XMLException("Error processing BPMN document", e);
            }
            return(model);
        }
Exemple #12
0
        private void CreateCodeFiles(SubProcess btProcess)
        {
            Project project = _dte.Solution.FindProjectItem(_filePath).ContainingProject;

            foreach (var activity in btProcess.Activities)
            {
                foreach (var target in activity.TargetActs)
                {
                    //dynamic flow;

                    //if (activity is Rule)
                    //{
                    //    flow = Flow.GetLink(activity, target);
                    //}
                    //else
                    //{
                    //    flow = FlowMinimal.GetLink(activity, target);
                    //}
                }

                ////Create code pages
                //if (activity is StartEvent)
                //{
                //    SubProcessFiles.AddSql(project, activity.VisioId, btProcess.VisioId, "SQLEvent");
                //}
                //else if (activity is StartPage)
                //{
                //    SubProcessFiles.AddPage(project, activity.VisioId, btProcess.VisioId, true);

                //    var assemblyPath = string.Format(@"{0}\Properties\AssemblyInfo.cs", _projectFolderPath);
                //    ProjectItem assemblyProjectItem = _dte.Solution.FindProjectItem(assemblyPath);

                //    ImportHelper.AddAssembly(_dte, assemblyProjectItem.ContainingProject, btProcess, startPagesList);
                //}
                //else 
                //    if (activity is Page)
                //{
                //    SubProcessFiles.AddPage(project, activity.VisioId, btProcess.VisioId, false);
                //}
                //else if (activity is Rule)
                //{
                //    SubProcessFiles.AddSql(project, activity.VisioId, btProcess.VisioId, "SQLRule");
                //}
                //else if (activity is Event)
                //{
                //    SubProcessFiles.AddSql(project, activity.VisioId, btProcess.VisioId, "SQLEvent");
                //}
            }
        }
Exemple #13
0
        private void CreateNewProcessFile(SubProcess btProcess)
        {
            var store = new Store(typeof(CloudCoreArchitectSubProcessDomainModel));
            var result = new SerializationResult();

            #region Delete Existing start page elements from assemblyinfo

            var assemblyPath = string.Format(@"{0}\Properties\AssemblyInfo.cs", _projectFolderPath);
            ProjectItem assemblyProjectItem = _dte.Solution.FindProjectItem(assemblyPath);
            var elements = assemblyProjectItem.FileCodeModel.CodeElements;
            var processIdStr = string.Format(", \"{0}\"", btProcess.VisioId);

            for (var index = 1; index <= elements.Count; index++)
            {
                var elemnt = elements.Item(index);

                if (elemnt.Kind != vsCMElement.vsCMElementAttribute) continue;
                if (elemnt.Name != "BTEmbeddedProcessUrl") continue;

                var u = (CodeAttribute)elemnt;

                if (u.Value.IndexOf(processIdStr) != -1)
                {
                    u.Delete();
                }
            }

            #endregion

            #region Add start page elements to assembly info

            //ImportHelper.AddAssembly(_dte, assemblyProjectItem.ContainingProject, btProcess, startPagesList);

            #endregion

            using (Transaction trans = store.TransactionManager.BeginTransaction("save"))
            {
                CloudCoreArchitectSubProcessSerializationHelper.Instance.SaveModelAndDiagram(result, btProcess, _filePath, _bDiagram, _filePath + ".diagram", Encoding.UTF8, false);
                ProjectItem file = _l.FirstOrDefault(p => p.ProjectPath == lstProjects.SelectedValue.ToString()).ProjectObject.ProjectItems.AddFromFile(_filePath);
                file.Open().Activate();
                file.Save();
                //file.Properties.Item("CustomTool").Value = "SubProcessFileCodeGenerator";

                trans.Commit();
            }

            CreateCodeFiles(btProcess);
        }
Exemple #14
0
        private void BuildProcessFileVisioToSubProcess(string visioFilePath)
        {
            var store = new Store(typeof(CloudCoreArchitectSubProcessDomainModel));
            var partition = new Partition(store);
            btnNext.Enabled = false;
            IList<SubProcess> subProcessList = new List<SubProcess>();

            var vReader = new ProcessVisioReader(visioFilePath);

            foreach (VisioPage btVisioPage in vReader.Pages)
            {
                using (Transaction transaction = store.TransactionManager.BeginTransaction("create new model"))
                {
                    SubProcess btProcess = new SubProcess(store);

                    try
                    {
                        _projectFolderPath = lstProjects.SelectedValue.ToString().Substring(0, lstProjects.SelectedValue.ToString().LastIndexOf(@"\"));

                        _folderPath = string.Format(@"{0}\processes\", _projectFolderPath);

                        btProcess = ImportHelper.ProcessExists(btVisioPage.VisioId, _folderPath);

                        _filePath = string.Format("{0}{1}.subprocess", _folderPath, btVisioPage.ProcessName.Replace(" ", "_"));

                        //Read From Visio File                   
                        List<ProcessVisioShape> shapes = btVisioPage.ReadDocument();
                        shapes.ForEach(p => p.Initialise(shapes));

                        if (btProcess == null)
                        {
                            #region Create new .subprocess process file from visio import

                            btProcess = CloudCoreArchitectSubProcessSerializationHelper.Instance.CreateModelHelper(partition);
                            _btProcessList.Add(btProcess);

                            _bDiagram = CloudCoreArchitectSubProcessSerializationHelper.Instance.CreateDiagramHelper(partition, btProcess);
                            _bDiagram.ModelElement = btProcess;

                            btProcess.SubProcessName = btVisioPage.ProcessName;
                            btProcess.VisioId = btVisioPage.VisioId;

                            _bDiagram.ModelElement = btProcess;

                            var modelElementActivityList = new List<Activity>();

                            foreach (ProcessVisioShape activity in shapes.FindAll(p => p.ShapeCategory == ShapeTypeCategory.Activity))
                            {
                                List<ProcessVisioShape> attachments = shapes.FindAll(p => p.ShapeCategory == ShapeTypeCategory.Attachment && p.AttachedTo == activity);
                                var isStart = (attachments.FirstOrDefault(p => p.Type == ShapeTypes.Start) != null);

                                //TODO: Check if Activity already exists in returned Diagram, Update returned diagram, or create new Activity if it doesn't exist

                                if (activity.Type == ShapeTypes.PageActivity)
                                {
                                    if (isStart)
                                    {
                                        var PageShape = new PageShape(store);

                                        var btPage = new CloudcoreUser(store)
                                        {
                                            IsMenuItem = activity.IsMenuItem,
                                            VisioId = activity.VisioId,
                                            Name = activity.DescriptiveText,
                                            Height = PageShape.DefaultSize.Height,
                                            Width = PageShape.DefaultSize.Width,
                                            Left = activity.TopLeft.X,
                                            Top = activity.TopLeft.Y,
                                            IsStartable = true
                                        };

                                        btProcess.Activities.Add(btPage);
                                        modelElementActivityList.Add(btPage);
                                    }
                                    else
                                    {
                                        var pageShape = new PageShape(store);

                                        var btPage = new CloudcoreUser(store)
                                        {
                                            IsMenuItem = activity.IsMenuItem,
                                            VisioId = activity.VisioId,
                                            Name = activity.DescriptiveText,
                                            Height = pageShape.DefaultSize.Height,
                                            Width = pageShape.DefaultSize.Width,
                                            Left = activity.TopLeft.X,
                                            Top = activity.TopLeft.Y,
                                            IsStartable = false
                                        };
                                        btProcess.Activities.Add(btPage);
                                        modelElementActivityList.Add(btPage);
                                    }

                                }
                                else if (activity.Type == ShapeTypes.BusinessRule)
                                {
                                    var ruleShape = new WorkflowRuleShape(store);

                                    var btRule = new WorkflowRule(store)
                                    {
                                        VisioId = activity.VisioId,
                                        Name = activity.DescriptiveText,
                                        Height = ruleShape.DefaultSize.Height,
                                        Width = ruleShape.DefaultSize.Width,
                                        Left = activity.TopLeft.X,
                                        Top = activity.TopLeft.Y
                                    };

                                    btProcess.Activities.Add(btRule);
                                    modelElementActivityList.Add(btRule);
                                }
                                else if (activity.Type == ShapeTypes.SubProcess)
                                {
                                    var subProcessShape = new ToProcessConnectorShape(store);

                                    Visio.Hyperlinks hl = activity.VisShape.Hyperlinks;
                                    Visio.Shape sp = hl.Shape;
                                    var visioShape = new ProcessVisioShape(sp);

                                    var btSubProcess = new ToProcessConnector(store)
                                    {
                                        VisioId = activity.VisioId,
                                        Name = activity.DescriptiveText,
                                        Height = subProcessShape.DefaultSize.Height,
                                        Width = subProcessShape.DefaultSize.Width,
                                        Left = activity.TopLeft.X,
                                        Top = activity.TopLeft.Y,
                                        ExternalActivityRef = null,
                                        ToProcessConnectorRef = null,
                                        ToActivityId = visioShape.VisioId.ToString(),
                                        ToProcessId = btProcess.VisioId.ToString()
                                    };

                                    btProcess.Activities.Add(btSubProcess);
                                    modelElementActivityList.Add(btSubProcess);
                                }
                                else if (activity.Type == ShapeTypes.DatabaseActivity)
                                {
                                    if (isStart)
                                    {
                                        //var startEventShape = new StartEventShape(store);

                                        //var btEvent = new StartEvent(store)
                                        //{
                                        //    VisioId = activity.VisioId,
                                        //    Name = activity.DescriptiveText,
                                        //    Height = startEventShape.DefaultSize.Height,
                                        //    Width = startEventShape.DefaultSize.Width,
                                        //    Left = activity.TopLeft.X,
                                        //    Top = activity.TopLeft.Y
                                        //};

                                        //btProcess.Activities.Add(btEvent);
                                        //modelElementActivityList.Add(btEvent);
                                    }
                                    else
                                    {
                                        //var eventShape = new EventShape(store);

                                        //var btEvent = new Event(store)
                                        //{
                                        //    VisioId = activity.VisioId,
                                        //    Name = activity.DescriptiveText,
                                        //    Height = eventShape.DefaultSize.Height,
                                        //    Width = eventShape.DefaultSize.Width,
                                        //    Left = activity.TopLeft.X,
                                        //    Top = activity.TopLeft.Y
                                        //};
                                        //btProcess.Activities.Add(btEvent);
                                        //modelElementActivityList.Add(btEvent);
                                    }
                                }
                                else if (activity.Type == ShapeTypes.Completed)
                                {
                                    var stopShape = new StopShape(store);

                                    var btStop = new Stop(store)
                                    {
                                        VisioId = activity.VisioId,
                                        Name = activity.DescriptiveText,
                                        Height = stopShape.DefaultSize.Height,
                                        Width = stopShape.DefaultSize.Width,
                                        Left = activity.TopLeft.X,
                                        Top = activity.TopLeft.Y
                                    };

                                    btProcess.Activities.Add(btStop);
                                    modelElementActivityList.Add(btStop);
                                }
                                else if (activity.Type == ShapeTypes.Parked)
                                {
                                    //var parkShape = new DBParkShape(store);

                                    //var btParked = new DBPark(store)
                                    //{
                                    //    VisioId = activity.VisioId,
                                    //    Name = activity.DescriptiveText,
                                    //    Height = parkShape.DefaultSize.Height,
                                    //    Width = parkShape.DefaultSize.Width,
                                    //    Left = activity.TopLeft.X,
                                    //    Top = activity.TopLeft.Y
                                    //};

                                    //btProcess.Activities.Add(btParked);
                                    //modelElementActivityList.Add(btParked);
                                }
                            }

                            #region Create Activity Flows

                            foreach (ProcessVisioShape activity in shapes.FindAll(p => p.ShapeCategory == ShapeTypeCategory.Activity))
                            {
                                if (activity.Targets == null) break;

                                Activity sourceElement = modelElementActivityList.FirstOrDefault(p => p.VisioId == activity.VisioId);

                                foreach (ProcessVisioShape target in activity.Targets)
                                {
                                    Activity targetElement = modelElementActivityList.FirstOrDefault(p => p.VisioId == target.VisioId);

                                    if (sourceElement != null && targetElement != null)
                                    {
                                        foreach (var b in target.GetConnectors(activity).Where(b => b != null))
                                        {
                                            CreateNewFlow(sourceElement, targetElement, b.Outcome, b.StoryLine, b.VisioId, DetermineFlowType(b.FlowType));
                                        }
                                    }
                                }
                            }

                            #endregion

                            //vReader.CloseVisio();
                            subProcessList.Add(btProcess);
                            CreateNewProcessFile(btProcess);

                            #endregion

                        }
                        else
                        {
                            #region Update found .subprocess process file from visio import

                            #region Code Folder Variables

                            var processFolderPath = string.Format(@"{0}BTProcess_{1}\", _folderPath, btProcess.VisioId.ToString().Replace("-", "_"));
                            var pagesFolderPath = string.Format(@"{0}Pages\", processFolderPath);
                            var eventsFolderPath = string.Format(@"{0}Events\", processFolderPath);
                            var rulesFolderPath = string.Format(@"{0}Rules\", processFolderPath);

                            #endregion

                            _btProcessList.Add(btProcess);
                            _bDiagram = ImportHelper.GetSubProcessDiagram(btProcess);
                            //Update Process Details
                            btProcess.SubProcessName = btVisioPage.ProcessName;

                            #region Delete Elements that don't exist anymore

                            #region Build Activities List and delete from process diagram that don't exist in the Visio file

                            activityList.AddRange(from activity in btProcess.Activities
                                                  where shapes.FirstOrDefault(a => (a.VisioId == activity.VisioId) && (a.ShapeCategory == ShapeTypeCategory.Activity)) == null
                                                  select activity);

                            #region Complete Activity Deletion Process

                            foreach (var act in activityList)
                            {
                                using (Transaction trans = btProcess.Store.TransactionManager.BeginTransaction("delete activity"))
                                {
                                    #region  Check if link between activity and source activities

                                    //Check if link between activity and source activities
                                    foreach (Activity sAct in act.SourceActs)
                                    {
                                        if (sAct != null)
                                        {
                                            var fMCollection = new List<dynamic>();

                                            //if (sAct is Rule)
                                            //{
                                            //    fMCollection.AddRange(Flow.GetLinks(sAct, act));
                                            //}
                                            //else
                                            //{
                                            //    fMCollection.AddRange(FlowMinimal.GetLinks(sAct, act));
                                            //}
                                        }
                                    }

                                    #endregion

                                    var actName = string.Format("{0} ({1})", act.Name, act.GetType()).Replace("Architect.BT", string.Empty);

                                    #region Build ActivityDelete

                                    //if (act is Rule)
                                    //{
                                    //    string ruleFileName = string.Format(@"{0}BTRule_{1}.sql", rulesFolderPath, act.VisioId.Replace("-", "_"));

                                    //    if (File.Exists(ruleFileName))
                                    //    {
                                    //        deletedCode.Add(new DeletedInfo { Name = actName, Path = ruleFileName, Id = act.VisioId });
                                    //    }
                                    //}

                                    #endregion

                                    act.Delete();

                                    trans.Commit();
                                }
                            }

                            #endregion

                            #endregion

                            #region delete flows that don't exists anymore

                            List<string> connectorList = new List<string>();

                            foreach (var shapeSource in shapes.FindAll(x => (x.ShapeCategory == ShapeTypeCategory.Activity) && (x.Targets != null)))
                            {
                                foreach (var shapeTarget in shapeSource.Targets)
                                {
                                    foreach (var connector in shapeSource.GetConnectors(shapeTarget))
                                    {
                                        if (connector != null)
                                            connectorList.Add(connector.VisioId);
                                    }
                                }
                            }

                            foreach (var vtAct in btProcess.Activities)
                            {
                                var fL = FlowBase.GetLinksToTargetActs(vtAct);

                                foreach (var s in fL)
                                {
                                    if (connectorList.FindAll(f => f == s.VisioId).Count == 0)
                                    {
                                        using (Transaction trans = s.Store.TransactionManager.BeginTransaction("delete non-existing Flow Minimal"))
                                        {
                                            s.Delete();
                                            trans.Commit();
                                        }
                                    }
                                }

                            }

                            #endregion

                            #endregion

                            #region Create/Update Current Task's Activities

                            #region Loop through all activities in the process

                            foreach (ProcessVisioShape activity in shapes.FindAll(p => p.ShapeCategory == ShapeTypeCategory.Activity))
                            {
                                List<ProcessVisioShape> attachments = shapes.FindAll(p => p.ShapeCategory == ShapeTypeCategory.Attachment && p.AttachedTo == activity);
                                var isStart = (attachments.FirstOrDefault(p => p.Type == ShapeTypes.Start) != null);
                                Activity btActivity = btProcess.Activities.FirstOrDefault(a => a.VisioId == activity.VisioId);

                                //TODO: Check if Activity already exists in returned Diagram, Update returned diagram, or create new Activity if it doesn't exist

                                if (btActivity == null)
                                {
                                    #region Create New Activity

                                    using (Transaction trans = btProcess.Store.TransactionManager.BeginTransaction("Create activity"))
                                    {

                                        if (activity.Type == ShapeTypes.PageActivity)
                                        {
                                            if (isStart)
                                            {
                                                //var btPage = new StartPage(store)
                                                //{
                                                //    IsMenuItem = activity.IsMenuItem,
                                                //    VisioId = activity.VisioId,
                                                //    Name = activity.DescriptiveText,
                                                //    Height = activity.Height,
                                                //    Width = activity.Width,
                                                //    Left = activity.TopLeft.X,
                                                //    Top = activity.TopLeft.Y
                                                //};

                                                //startPagesList.Add(btPage);

                                                //btProcess.Activities.Add(btPage);
                                            }
                                            else
                                            {
                                                var btPage = new CloudcoreUser(store)
                                                {
                                                    IsMenuItem = activity.IsMenuItem,
                                                    VisioId = activity.VisioId,
                                                    Name = activity.DescriptiveText,
                                                    Height = activity.Height,
                                                    Width = activity.Width,
                                                    Left = activity.TopLeft.X,
                                                    Top = activity.TopLeft.Y
                                                };
                                                btProcess.Activities.Add(btPage);
                                            }

                                        }
                                        else if (activity.Type == ShapeTypes.BusinessRule)
                                        {
                                            //var btRule = new Rule(store)
                                            //{
                                            //    VisioId = activity.VisioId,
                                            //    Name = activity.DescriptiveText,
                                            //    Height = activity.Height,
                                            //    Width = activity.Width,
                                            //    Left = activity.TopLeft.X,
                                            //    Top = activity.TopLeft.Y
                                            //};

                                            //btProcess.Activities.Add(btRule);
                                        }
                                        else if (activity.Type == ShapeTypes.DatabaseActivity)
                                        {
                                            if (isStart)
                                            {
                                                //var btEvent = new StartEvent(store)
                                                //{
                                                //    VisioId = activity.VisioId,
                                                //    Name = activity.DescriptiveText,
                                                //    Height = activity.Height,
                                                //    Width = activity.Width,
                                                //    Left = activity.TopLeft.X,
                                                //    Top = activity.TopLeft.Y
                                                //};
                                                //btProcess.Activities.Add(btEvent);
                                            }
                                            else
                                            {
                                                //var btEvent = new Event(store)
                                                //{
                                                //    VisioId = activity.VisioId,
                                                //    Name = activity.DescriptiveText,
                                                //    Height = activity.Height,
                                                //    Width = activity.Width,
                                                //    Left = activity.TopLeft.X,
                                                //    Top = activity.TopLeft.Y
                                                //};
                                                //btProcess.Activities.Add(btEvent);
                                            }
                                        }
                                        else if (activity.Type == ShapeTypes.Completed)
                                        {
                                            var btStop = new Stop(store)
                                            {
                                                VisioId = activity.VisioId,
                                                Name = activity.DescriptiveText,
                                                Height = activity.Height,
                                                Width = activity.Width,
                                                Left = activity.TopLeft.X,
                                                Top = activity.TopLeft.Y
                                            };

                                            btProcess.Activities.Add(btStop);
                                        }

                                        trans.Commit();
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region Update Existing Activity

                                    //if (activity.Type == ShapeTypes.PageActivity && isStart)
                                    //    startPagesList.Add((StartPage)btActivity);

                                    using (Transaction trans = btActivity.Store.TransactionManager.BeginTransaction("update task"))
                                    {
                                        btActivity.Name = activity.DescriptiveText;
                                        btActivity.Height = activity.Height;
                                        btActivity.Width = activity.Width;
                                        btActivity.Left = activity.TopLeft.X;
                                        btActivity.Top = activity.TopLeft.Y;

                                        trans.Commit();
                                    }

                                    #endregion
                                }
                            }

                            #endregion

                            #endregion

                            #region Create/Update Activity Flows

                            #region Create ActivityList in current diagram

                            var modelElementActivityList = new List<Activity>();

                            modelElementActivityList.AddRange(from Activity a in ((SubProcess)_bDiagram.ModelElement).Activities
                                                              select a);

                            #endregion

                            //#region Create Flow List in current diagram

                            //List<dynamic> modelElementActivityFlowList = (from activitySource in modelElementActivityList
                            //                                              from activityTarget in modelElementActivityList.Where(a => a != activitySource)
                            //                                              select GetFlowDetermined(activitySource, activityTarget)
                            //                                                  into fFlow
                            //                                                  where fFlow != null
                            //                                                  select fFlow).ToList();

                            //#endregion

                            foreach (var shapeSource in shapes.FindAll(x => (x.ShapeCategory == ShapeTypeCategory.Activity) && (x.Targets != null)))
                            {
                                foreach (var shapeTarget in shapeSource.Targets)
                                {
                                    foreach (var connector in shapeSource.GetConnectors(shapeTarget))
                                    {
                                        if (connector != null)
                                        {
                                            //dynamic fMinimal = modelElementActivityFlowList.FirstOrDefault(f => f.VisioId == connector.VisioId);

                                            //if (fMinimal != null)
                                            //{
                                            //    #region Update existing flow

                                            //    var source = modelElementActivityList.FirstOrDefault(p => p.VisioId == shapeSource.VisioId);
                                            //    var target = modelElementActivityList.FirstOrDefault(p => p.VisioId == shapeTarget.VisioId);

                                            //    if (fMinimal.SourceBTActivity != source && fMinimal.TargetBTActivity != target)
                                            //    {
                                            //        using (Transaction trans = fMinimal.Store.TransactionManager.BeginTransaction("update Flow"))
                                            //        {
                                            //            fMinimal.Delete();
                                            //            trans.Commit();
                                            //        }
                                            //    }

                                            //    //Check if the source and the target are the same
                                            //    if ((source.VisioId != shapeSource.VisioId) || (target.VisioId != shapeTarget.VisioId))
                                            //    {
                                            //        #region The activity(source) connecting to current activity or activity(target) connected to this activity is different

                                            //        using (Transaction trans = fMinimal.Store.TransactionManager.BeginTransaction("update Flow"))
                                            //        {
                                            //            fMinimal.Delete();
                                            //            trans.Commit();
                                            //        }

                                            //        Activity start, end;

                                            //        //Source is an activity
                                            //        //Get existing in and outports for task to task flow
                                            //        start = fMinimal.TargetBTActivity;
                                            //        end = start.TargetActs[0];

                                            //        #region create new flow

                                            //        using (Transaction trans = fMinimal.Store.TransactionManager.BeginTransaction("Create New Flow"))
                                            //        {
                                            //            CreateNewFlow(source, target, connector.Outcome, connector.StoryLine, fMinimal.VisioId, fMinimal.Type);

                                            //            trans.Commit();
                                            //        }

                                            //        #endregion
                                            //        #endregion
                                            //    }
                                            //    else
                                            //    {
                                            //        #region The activity(source) connecting to current activity or or activity(target) connected to this activity is the same

                                            //        //if (source is Rule)
                                            //        //{
                                            //        //    Flow f = Flow.GetLink(source, target);

                                            //        //    if (f != null)
                                            //        //    {
                                            //        //        using (Transaction trans = fMinimal.Store.TransactionManager.BeginTransaction("update Flow Minimal"))
                                            //        //        {
                                            //        //            f.Storyline = connector.StoryLine;
                                            //        //            f.Outcome = connector.Outcome;

                                            //        //            trans.Commit();
                                            //        //        }
                                            //        //    }
                                            //        //    else
                                            //        //    {
                                            //        //        using (Transaction trans = source.Store.TransactionManager.BeginTransaction("Create Link"))
                                            //        //        {
                                            //        //            CreateNewFlow(source, target, connector.Outcome, connector.StoryLine, connector.VisioId, DetermineFlowType(connector.FlowType));

                                            //        //            trans.Commit();
                                            //        //        }
                                            //        //    }
                                            //        //}
                                            //        //else
                                            //        //{
                                            //        //    FlowMinimal f = FlowMinimal.GetLink(source, target);

                                            //        //    using (Transaction trans = fMinimal.Store.TransactionManager.BeginTransaction("update Flow Minimal"))
                                            //        //    {
                                            //        //        f.Storyline = connector.StoryLine;

                                            //        //        trans.Commit();
                                            //        //    }
                                            //        //}

                                            //        #endregion
                                            //    }

                                            //    #endregion

                                            //}
                                            //else
                                            //{
                                            //    #region Create new flow

                                            //    if (shapeSource.Targets != null && shapeTarget.Sources != null)
                                            //    {
                                            //        Activity source = modelElementActivityList.FirstOrDefault(p => p.VisioId == shapeSource.VisioId);
                                            //        Activity target = modelElementActivityList.FirstOrDefault(p => p.VisioId == shapeTarget.VisioId);

                                            //        #region Source Activity's Parent Task equal to Target Activity's Parent Task

                                            //        using (Transaction trans = source.Store.TransactionManager.BeginTransaction("update Flow Minimal"))
                                            //        {
                                            //            CreateNewFlow(source, target, connector.Outcome, connector.StoryLine, connector.VisioId, DetermineFlowType(connector.FlowType));

                                            //            trans.Commit();
                                            //        }

                                            //        #endregion
                                            //    }

                                            //    #endregion
                                            //}
                                        }
                                    }
                                }
                            }

                            #endregion

                            //vReader.CloseVisio();

                            if (deletedCode.Count > 0)
                            {
                                pnlBackup.Enabled = true;
                            }
                            else
                            {
                                deletedCode.Add(new DeletedInfo
                                                        {
                                                            Name = "No items will be deleted."
                                                        });

                                pnlBackup.Enabled = false;
                            }

                            lstDeleted.DataSource = deletedCode;
                            lstDeleted.DisplayMember = "Name";

                            pnlDeleted.Visible = true;

                            #endregion
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }


            IModelBus modelBus = store.GetService(typeof(SModelBus)) as IModelBus;

            if (modelBus != null)
            {
                foreach (SubProcess process in subProcessList)
                {
                    using (Transaction transaction = process.Store.TransactionManager.BeginTransaction("update modelbus"))
                    {
                        //List<Activity> subProcessActivities = process.Activities.Where(a => a is SubProcessActivity).ToList();
                        //foreach (Activity act in subProcessActivities)
                        //{
                        //    var _act = (SubProcessActivity)act;

                        //    string toProc = ((SubProcessActivity)act).ToProcessId;
                        //    string toAct = ((SubProcessActivity)act).ToActivityId;

                        //    var toProcess = (SubProcess)subProcessList.Where(p => p.VisioId.ToString() == toProc).SingleOrDefault();

                        //    var toActivity = (SubProcessActivity)toProcess.Activities.Where(a => a.VisioId.ToString() == toAct).SingleOrDefault();

                        //    string projectPath = lstProjects.SelectedValue.ToString().Substring(0, lstProjects.SelectedValue.ToString().LastIndexOf(@"\"));
                        //    string folderPath = string.Format(@"{0}\processes\", _projectFolderPath);
                        //    string filePath = string.Format("{0}{1}.subprocess", _folderPath, toActivity.SubProcess.SubProcessName.Replace(" ", "_"));


                        //    ModelBusAdapterManager manager = modelBus.FindAdapterManagers(filePath).First();
                        //    ModelBusReference reference = manager.CreateReference(filePath);

                        //    using (ModelBusAdapter adapter = modelBus.CreateAdapter(reference))
                        //    {
                        //        _act.ExternalActivityRef = adapter.GetElementReference(toActivity);
                        //        _act.SubProcessActivityRef = adapter.GetElementReference(toActivity);
                        //    }
                        //}

                        transaction.Commit();
                    }
                }
            }
           
            vReader.CloseVisio();
            Close();
        }
        public virtual IDictionary <string, IDataObject> Execute(ICommandContext commandContext)
        {
            // Verify existance of execution
            if (executionId is null)
            {
                throw new ActivitiIllegalArgumentException("executionId is null");
            }

            IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId);

            if (execution == null)
            {
                throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", typeof(IExecution));
            }

            IDictionary <string, IVariableInstance> variables;

            if ((dataObjectNames?.Count()).GetValueOrDefault(0) == 0)
            {
                // Fetch all
                if (isLocal)
                {
                    variables = execution.VariableInstancesLocal;
                }
                else
                {
                    variables = execution.VariableInstances;
                }
            }
            else
            {
                // Fetch specific collection of variables
                if (isLocal)
                {
                    variables = execution.GetVariableInstancesLocal(dataObjectNames, false);
                }
                else
                {
                    variables = execution.GetVariableInstances(dataObjectNames, false);
                }
            }

            IDictionary <string, IDataObject> dataObjects = null;

            if (variables != null)
            {
                dataObjects = new Dictionary <string, IDataObject>(variables.Count);

                foreach (KeyValuePair <string, IVariableInstance> entry in variables.SetOfKeyValuePairs())
                {
                    string            name           = entry.Key;
                    IVariableInstance variableEntity = entry.Value;

                    IExecutionEntity executionEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(variableEntity.ExecutionId);
                    while (!executionEntity.IsScope)
                    {
                        executionEntity = executionEntity.Parent;
                    }

                    BpmnModel        bpmnModel       = ProcessDefinitionUtil.GetBpmnModel(execution.ProcessDefinitionId);
                    ValuedDataObject foundDataObject = null;
                    if (executionEntity.ParentId is null)
                    {
                        foreach (ValuedDataObject dataObject in bpmnModel.MainProcess.DataObjects)
                        {
                            if (dataObject.Name.Equals(variableEntity.Name))
                            {
                                foundDataObject = dataObject;
                                break;
                            }
                        }
                    }
                    else
                    {
                        SubProcess subProcess = (SubProcess)bpmnModel.GetFlowElement(execution.ActivityId);
                        foreach (ValuedDataObject dataObject in subProcess.DataObjects)
                        {
                            if (dataObject.Name.Equals(variableEntity.Name))
                            {
                                foundDataObject = dataObject;
                                break;
                            }
                        }
                    }

                    string localizedName        = null;
                    string localizedDescription = null;

                    if (!(locale is null) && foundDataObject != null)
                    {
                        JToken languageNode = Context.GetLocalizationElementProperties(locale, foundDataObject.Id, execution.ProcessDefinitionId, withLocalizationFallback);

                        if (languageNode != null)
                        {
                            JToken nameNode = languageNode[DynamicBpmnConstants.LOCALIZATION_NAME];
                            if (nameNode != null)
                            {
                                localizedName = nameNode.ToString();
                            }
                            JToken descriptionNode = languageNode[DynamicBpmnConstants.LOCALIZATION_DESCRIPTION];
                            if (descriptionNode != null)
                            {
                                localizedDescription = descriptionNode.ToString();
                            }
                        }
                    }

                    if (foundDataObject != null)
                    {
                        dataObjects[name] = new DataObjectImpl(variableEntity.Name, variableEntity.Value, foundDataObject.Documentation, foundDataObject.Type, localizedName, localizedDescription, foundDataObject.Id);
                    }
                }
            }

            return(dataObjects);
        }
Exemple #16
0
 protected internal AbstractSubProcessBuilder(BpmnModelInstance modelInstance, SubProcess element, Type selfType) : base(modelInstance, element, selfType)
 {
 }
Exemple #17
0
 internal void StartSubProcess(SubProcess SubProcess, string incoming)
 {
     _WriteLogLine(SubProcess.id, LogLevels.Debug, "Starting SubProcess in Process Path");
     _addPathEntry(SubProcess.id, incoming, StepStatuses.Waiting, DateTime.Now);
 }
 public virtual AdhocSubProcessActivityBehavior CreateAdhocSubprocessActivityBehavior(SubProcess subProcess)
 {
     return(new AdhocSubProcessActivityBehavior());
 }
        public JsonResult New(SubProcessModel model)
        {
            try
            {
                SubProcess subProcess = new SubProcess();
                model.Process = this.processService.GetDataById(model.ProcessId);
                if (ModelState.IsValid)
                {
                    bool ifExists = this.subProcessService.CheckDataAndCodeIfExist(model);
                    if (!ifExists)
                    {
                        subProcess.Process = model.Process;
                        subProcess.Code = model.Code.ToUpper();
                        subProcess.Name = model.Name;
                        subProcess.Description = model.Description;
                        subProcess.Active = true;
                        subProcess.DateCreated = DateTime.Now;
                        subProcess.CreatedBy = User.Identity.Name.ToString();
                        subProcess.Id = this.subProcessService.Create(subProcess);
                        model.Id = subProcess.Id;
                        return Json(new { result = Base.Encrypt(subProcess.Id.ToString()), message = MessageCode.saved, code = StatusCode.saved, content= subProcess.Name });
                    }
                    return Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed });
                }
                return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });

            }
            catch (Exception ex)
            {
                return Json(new { result = StatusCode.failed, message = ex.Message.ToString(), code = StatusCode.failed, content = model.Name });
            }
        }
Exemple #20
0
        public JsonResult Manage(WorkflowModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.Process = this.processService.GetDataById(model.ProcessId);
                    model.SubProcess = this.subProcessService.GetDataById(model.SubProcessId ?? 0);
                    model.Classification = this.classificationService.GetDataById(model.ClassificationId ?? 0);

                    bool ifExists = this.workflowService.CheckDataIfExists(model);
                    if (!ifExists)
                    {
                        Workflow workflow = new Workflow();
                        Process process = new Process();
                        SubProcess subProcess = new SubProcess();
                        Classification classification = new Classification();
                        process = this.processService.GetDataById(model.ProcessId);
                        subProcess = this.subProcessService.GetDataById(model.SubProcessId ?? 0);
                        classification = this.classificationService.GetDataById(model.ClassificationId ?? 0);
                        workflow = this.workflowService.GetDataById(model.Id);
                        workflow.Process = process;
                        workflow.SubProcess = subProcess;
                        workflow.Classification = classification;
                        workflow.Code = model.Code;
                        workflow.Name = model.Name;
                        workflow.Description = model.Description;
                        workflow.Active = model.Active;
                        workflow.Requestor = model.RequestorCode != null ? string.Join(",", model.RequestorCode) : string.Empty;
                        workflow.DateModified = DateTime.Now;
                        workflow.ModifiedBy = User.Identity.Name.ToString();
                        this.workflowService.SaveChanges(workflow);
                        return Json(new { result = Base.Encrypt(workflow.Id.ToString()), message = MessageCode.saved, code = StatusCode.saved, content= MessageCode.saved });

                    }
                    return Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed });
                }
                return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
            }
            catch (Exception ex)
            {
                return Json(new { result = StatusCode.failed, message = ex.Message.ToString(), code = StatusCode.failed });
            }
        }
Exemple #21
0
 private static void SetSubProcessSettings(string subProcessName, SubProcess subProcess, ModelBusReference processReference)
 {
     subProcess.ProcessRef = processReference;
     subProcess.SubProcessName = subProcessName;
     subProcess.VisioId = subProcess.Id.ToString().ToLower();
 }
Exemple #22
0
        public static SubProcessElement CreateSubProcessElement(string subProcessName, Partition partition, ProcessOverview.Process process, SubProcess subProcess, ModelBusReference subProcessReference)
        {
            var childReferenceProperty = new PropertyAssignment(SubProcessElement.SubProcessRefDomainPropertyId, null);
            var nameProperty = new PropertyAssignment(SubProcessElement.NameDomainPropertyId, subProcessName);
            var subProcessElement = new ProcessOverview.SubProcessElement(partition, nameProperty, childReferenceProperty);

            subProcessElement.VisioId = subProcess.VisioId.ToString().ToLower();
            subProcessElement.SubProcessRef = subProcessReference;
            process.BTSubProcess.Add(subProcessElement);

            return subProcessElement;
        }
Exemple #23
0
 public static SubProcessDiagram GetSubProcessDiagram(SubProcess btProcess)
 {
     return btProcess.Store.ElementDirectory.AllElements.OfType<SubProcessDiagram>().FirstOrDefault();
 }        
Exemple #24
0
        public override void Execute(IExecutionEntity execution)
        {
            IExecutionEntity        executionEntity        = execution;
            ICommandContext         commandContext         = Context.CommandContext;
            IExecutionEntityManager executionEntityManager = commandContext.ExecutionEntityManager;

            // find cancel boundary event:
            IExecutionEntity parentScopeExecution       = null;
            IExecutionEntity currentlyExaminedExecution = executionEntityManager.FindById <IExecutionEntity>(executionEntity.ParentId);

            while (currentlyExaminedExecution != null && parentScopeExecution == null)
            {
                if (currentlyExaminedExecution.CurrentFlowElement is SubProcess)
                {
                    parentScopeExecution = currentlyExaminedExecution;
                    SubProcess subProcess = (SubProcess)currentlyExaminedExecution.CurrentFlowElement;
                    if (subProcess.LoopCharacteristics != null)
                    {
                        IExecutionEntity miExecution = parentScopeExecution.Parent;
                        FlowElement      miElement   = miExecution.CurrentFlowElement;
                        if (miElement != null && miElement.Id.Equals(subProcess.Id))
                        {
                            parentScopeExecution = miExecution;
                        }
                    }
                }
                else
                {
                    currentlyExaminedExecution = executionEntityManager.FindById <IExecutionEntity>(currentlyExaminedExecution.ParentId);
                }
            }

            if (parentScopeExecution == null)
            {
                throw new ActivitiException("No sub process execution found for cancel end event " + executionEntity.CurrentActivityId);
            }

            {
                SubProcess    subProcess          = (SubProcess)parentScopeExecution.CurrentFlowElement;
                BoundaryEvent cancelBoundaryEvent = null;
                if (CollectionUtil.IsNotEmpty(subProcess.BoundaryEvents))
                {
                    foreach (BoundaryEvent boundaryEvent in subProcess.BoundaryEvents)
                    {
                        if (CollectionUtil.IsNotEmpty(boundaryEvent.EventDefinitions) && boundaryEvent.EventDefinitions[0] is CancelEventDefinition)
                        {
                            cancelBoundaryEvent = boundaryEvent;
                            break;
                        }
                    }
                }

                if (cancelBoundaryEvent == null)
                {
                    throw new ActivitiException("Could not find cancel boundary event for cancel end event " + executionEntity.CurrentActivityId);
                }

                IExecutionEntity newParentScopeExecution = null;
                currentlyExaminedExecution = executionEntityManager.FindById <IExecutionEntity>(parentScopeExecution.ParentId);
                while (currentlyExaminedExecution != null && newParentScopeExecution == null)
                {
                    if (currentlyExaminedExecution.IsScope)
                    {
                        newParentScopeExecution = currentlyExaminedExecution;
                    }
                    else
                    {
                        currentlyExaminedExecution = executionEntityManager.FindById <IExecutionEntity>(currentlyExaminedExecution.ParentId);
                    }
                }

                ScopeUtil.CreateCopyOfSubProcessExecutionForCompensation(parentScopeExecution);

                if (subProcess.LoopCharacteristics != null)
                {
                    IList <IExecutionEntity> multiInstanceExecutions = parentScopeExecution.Executions;
                    IList <IExecutionEntity> executionsToDelete      = new List <IExecutionEntity>();
                    foreach (IExecutionEntity multiInstanceExecution in multiInstanceExecutions)
                    {
                        if (!multiInstanceExecution.Id.Equals(parentScopeExecution.Id))
                        {
                            ScopeUtil.CreateCopyOfSubProcessExecutionForCompensation(multiInstanceExecution);

                            // end all executions in the scope of the transaction
                            executionsToDelete.Add(multiInstanceExecution);
                            DeleteChildExecutions(multiInstanceExecution, executionEntity, commandContext, History.DeleteReasonFields.TRANSACTION_CANCELED);
                        }
                    }

                    foreach (IExecutionEntity executionEntityToDelete in executionsToDelete)
                    {
                        DeleteChildExecutions(executionEntityToDelete, executionEntity, commandContext, History.DeleteReasonFields.TRANSACTION_CANCELED);
                    }
                }

                // The current activity is finished (and will not be ended in the deleteChildExecutions)
                commandContext.HistoryManager.RecordActivityEnd(executionEntity, null);

                // set new parent for boundary event execution
                executionEntity.Parent             = newParentScopeExecution ?? throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event " + cancelBoundaryEvent.Id);
                executionEntity.CurrentFlowElement = cancelBoundaryEvent;

                // end all executions in the scope of the transaction
                DeleteChildExecutions(parentScopeExecution, executionEntity, commandContext, History.DeleteReasonFields.TRANSACTION_CANCELED);
                commandContext.HistoryManager.RecordActivityEnd(parentScopeExecution, History.DeleteReasonFields.TRANSACTION_CANCELED);

                Context.Agenda.PlanTriggerExecutionOperation(executionEntity);
            }
        }
Exemple #25
0
 public int Create(SubProcess entity)
 {
     return this.subProcessRepository.Create(entity);
 }
Exemple #26
0
 internal void StartSubProcess(SubProcess SubProcess, string incoming)
 {
     Log.Debug("Starting SubProcess {0} in Process Path", new object[] { SubProcess.id });
     _addPathEntry(SubProcess.id, incoming, StepStatuses.Waiting, DateTime.Now);
 }