private int GetXPosByPreviousSibling(ProcessDetailTN CurrentNode) { int Result = -1; int X = -1; if (!CurrentNode.IsRoot) { ProcessDetailTN PrevSibling = (ProcessDetailTN)CurrentNode.PrevNode; if (PrevSibling != null) { if (PrevSibling.Nodes.Count > 0) { X = Convert.ToInt32(GetMaxXOfDescendants((ProcessDetailTN)PrevSibling.LastNode)); Result = X + _boxWidth + _horizontalSpace; } else { Result = PrevSibling.X + _boxWidth + _horizontalSpace; } } } return(Result); }
private void AppendProcessNode(ProcessDetailTN node, ProcessDetail pd, int depth) { depth--; if (depth < 0) { return; } var childNode = new ProcessDetailTN(); childNode.Text = pd.Name; childNode.Id = pd.Id; childNode.Category = pd.Category; childNode.Type = pd.Type; childNode.PrimaryEntityName = pd.PrimaryEntityName; node.Nodes.Add(childNode); childNode.IsVisited = IsComponentVisited(childNode, childNode.Id); if (!childNode.IsVisited) { foreach (var cpd in pd.ChildProcess) { AppendProcessNode(childNode, cpd, depth); } } }
public ProcessDiagram(EntityDetail eDetail, ProcessDetailTN rProcess, string url) { InitializeComponent(); entityDetail = eDetail; rootProcess = rProcess; webApplicationUrl = url; }
public MemoryStream PaintDiagram(ProcessDetailTN pdRoot, ref int width, ref int height, string startFromNodeID, ImageFormat imageType) { pdRoot = pdRoot.CloneMe(); TreeView tv = new TreeView(); tv.Nodes.Add(pdRoot); //reset image size imgHeight = 0; imgWidth = 0; MemoryStream Result = new MemoryStream(); BuildTree(pdRoot, 0); Bitmap bmp = new Bitmap(imgWidth, imgHeight); gr = Graphics.FromImage(bmp); gr.Clear(_bgColor); DrawChart(pdRoot); Bitmap ResizedBMP = new Bitmap(bmp, new Size(imgWidth, imgHeight)); ResizedBMP.Save(Result, imageType); ResizedBMP.Dispose(); bmp.Dispose(); gr.Dispose(); width = imgWidth; height = imgHeight; return(Result); }
private int GetXPosByParentPreviousSibling(ProcessDetailTN CurrentNode) { int Result = -1; int X = -1; var Parent = (ProcessDetailTN)CurrentNode.Parent; if (!CurrentNode.IsRoot && Parent != null && !Parent.IsRoot) { var ParentPrevSibling = (ProcessDetailTN)Parent.PrevNode; if (ParentPrevSibling != null) { if (ParentPrevSibling.Nodes.Count > 0) { X = GetMaxXOfDescendants((ProcessDetailTN)ParentPrevSibling.LastNode); Result = X + _boxWidth + _horizontalSpace; } else { X = ParentPrevSibling.X; Result = X + _boxWidth + _horizontalSpace; } } else { if (!CurrentNode.IsRoot && CurrentNode.Parent != null) { Result = GetXPosByParentPreviousSibling((ProcessDetailTN)CurrentNode.Parent); } } } return(Result); }
private int GetMaxXOfDescendants(ProcessDetailTN CurrentNode) { while (CurrentNode.Nodes.Count > 0) { CurrentNode = (ProcessDetailTN)CurrentNode.LastNode; } return(CurrentNode.X); }
public Rectangle GetTitleRectangle(ProcessDetailTN oNode) { int X = oNode.X; int Y = oNode.Y; Rectangle Result = new Rectangle(X, Y, (int)(_boxWidth), 20); return(Result); }
public Rectangle GetMainRectangle(ProcessDetailTN oNode) { int X = oNode.X; int Y = oNode.Y + 20; Rectangle Result = new Rectangle(X, Y, (int)(_boxWidth), (int)(_boxHeight) - 20); return(Result); }
private int GetXPosByOwnChildren(ProcessDetailTN CurrentNode) { int Result = -1; if (CurrentNode.Nodes.Count > 0) { int lastChildX = ((ProcessDetailTN)CurrentNode.LastNode).X; int firstChildX = ((ProcessDetailTN)CurrentNode.FirstNode).X; Result = (((lastChildX + _boxWidth) - firstChildX) / 2) - (_boxWidth / 2) + firstChildX; } return(Result); }
private void btnWFE_Click(object sender, EventArgs e) { if (cboEntities.SelectedItem == null || this.Service == null) { return; } entityDetail = ((EntityDetail)cboEntities.SelectedItem); WorkAsync(new WorkAsyncInfo { Message = "Getting Process Info...", AsyncArgument = null, Work = (worker, args) => { using (var cpm = new CRMProcessExplorerManager(this.Service)) { args.Result = cpm.GetWorkflowsByEntity(entityDetail); } }, ProgressChanged = (args) => { SetWorkingMessage(args.UserState.ToString()); }, PostWorkCallBack = (args) => { if (args.Error != null) { MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } var result = args.Result as List <ProcessDetail>; var rootComponent = new ProcessDetailTN(); rootComponent.Type = ProcessDetail.eTypes.Entity; rootComponent.PrimaryEntityName = entityDetail.LogicalName; rootComponent.Text = entityDetail.DisplayName; rootComponent.Id = entityDetail.Metadata.MetadataId.Value; result.ForEach(pd => { AppendProcessNode(rootComponent, pd, 6); }); _selectedNode = rootComponent; var pdf = new ProcessDiagram(entityDetail, _selectedNode, this.ConnectionDetail.WebApplicationUrl); pdf.StartPosition = FormStartPosition.CenterParent; pdf.Show(); } }); }
private Color GetBoxColor(ProcessDetailTN node) { Color color = Color.White; if (node.Type == ProcessDetail.eTypes.Entity) { color = _entityBoxFillColor; } else if (node.Type == ProcessDetail.eTypes.Workflow) { switch (node.Category) { case ProcessDetail.eCategories.Action: color = _actionBoxFillColor; break; case ProcessDetail.eCategories.Workflow: color = _workflowBoxFillColor; break; case ProcessDetail.eCategories.Dialog: color = _dialogBoxFillColor; break; case ProcessDetail.eCategories.BusinessRule: color = _brBoxFillColor; break; case ProcessDetail.eCategories.BusinessProcessFlow: color = _bpfBoxFillColor; break; } } else if (node.Type == ProcessDetail.eTypes.CustomCode) { if (node.Category == ProcessDetail.eCategories.Plugins) { color = _pluginBoxFillColor; } else { color = _pluginTypeBoxFillColor; } } return(color); }
private bool IsComponentVisited(ProcessDetailTN node, Guid id) { var parent = (ProcessDetailTN)node.Parent; if (parent != null) { if (parent.Id == id) { return(true); } else { return(IsComponentVisited(parent, id)); } } return(false); }
private void BuildTree(ProcessDetailTN oNode, int y) { if (!ShowAssemblies && oNode.Type == ProcessDetail.eTypes.CustomCode) { oNode.IsHidden = true; } foreach (ProcessDetailTN childNode in oNode.Nodes) { BuildTree(childNode, y + 1); } //build node data //after checking for nodes we can add the current node int StartX; int StartY; int[] ResultsArr = new int[] { GetXPosByOwnChildren(oNode), GetXPosByParentPreviousSibling(oNode), GetXPosByPreviousSibling(oNode), _margin }; Array.Sort(ResultsArr); StartX = ResultsArr[3]; StartY = (y * (_boxHeight + _verticalSpace)) + _margin; int width = _boxWidth; int height = _boxHeight; //update the coordinates of this box into the matrix, for later calculations oNode.X = StartX; oNode.Y = StartY; //update the image size if (imgWidth < (StartX + width + _margin)) { imgWidth = StartX + width + _margin; } if (imgHeight < (StartY + height + _margin)) { imgHeight = StartY + height + _margin; } }
public ProcessDetailTN CloneMe() { var newNode = new ProcessDetailTN() { Name = this.Name, Id = this.Id, IsHidden = this.IsHidden, Category = this.Category, Type = this.Type, Text = this.Text, PrimaryEntityName = this.PrimaryEntityName, IsVisited = this.IsVisited }; foreach (ProcessDetailTN childNode in this.Nodes) { var newChildNode = childNode.CloneMe(); newNode.Nodes.Add(newChildNode); } return(newNode); }
private void DrawChart(ProcessDetailTN oNode) { // Create font and brush. Font drawFont = new Font("Microsoft Sans Serif", _fontSize); SolidBrush drawBrush = new SolidBrush(_fontColor); Pen boxPen = new Pen(_lineColor, _lineWidth); var drawFormat = new StringFormat(); drawFormat.Alignment = StringAlignment.Center; //find children foreach (ProcessDetailTN childNode in oNode.Nodes) { if (!childNode.IsHidden) { DrawChart(childNode); } } Rectangle outerRectangle = new Rectangle(oNode.X, oNode.Y, (int)(_boxWidth), (int)(_boxHeight)); Rectangle titleRectangle = new Rectangle(oNode.X, oNode.Y, (int)(_boxWidth), 18); Rectangle detailRectangle = new Rectangle(oNode.X, oNode.Y + 20, (int)(_boxWidth), (int)(_boxHeight) - 20); gr.DrawRectangle(boxPen, titleRectangle); gr.DrawRectangle(boxPen, detailRectangle); Color detailFillColor = _titleBoxFillColor; Color titleFillColor = GetBoxColor(oNode); gr.FillRectangle(new SolidBrush(detailFillColor), detailRectangle); gr.FillRectangle(new SolidBrush(titleFillColor), titleRectangle); // Draw string to screen. var displayName = string.Empty; var rectangleDisplayInfo = string.Empty; rectangleDisplayInfo = oNode.Text.Replace($"({oNode.Tag}) ", string.Empty); if (oNode.Type == ProcessDetail.eTypes.Entity) { displayName = oNode.Text; rectangleDisplayInfo = $"{rectangleDisplayInfo} ({oNode.PrimaryEntityName})"; } else if (oNode.Type == ProcessDetail.eTypes.CustomCode && oNode.Category == ProcessDetail.eCategories.Workflow) { displayName = oNode.Type.ToString(); } else if (oNode.Type == ProcessDetail.eTypes.CustomCode && oNode.Category == ProcessDetail.eCategories.Plugins) { displayName = oNode.Category.ToString(); string[] separatingStrings = { "::" }; var vals = rectangleDisplayInfo.Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries); if (vals.Length > 2) { rectangleDisplayInfo = vals[0]; } } else { displayName = oNode.Category.ToString(); } drawFormat.LineAlignment = StringAlignment.Center; drawFormat.Alignment = StringAlignment.Center; gr.DrawString(displayName, drawFont, drawBrush, titleRectangle, drawFormat); gr.DrawString(rectangleDisplayInfo, drawFont, drawBrush, detailRectangle, drawFormat); //draw connecting lines if (!oNode.IsRoot) { //all but the top box should have lines growing out of their top gr.DrawLine(boxPen, outerRectangle.Left + (_boxWidth / 2), outerRectangle.Top, outerRectangle.Left + (_boxWidth / 2), outerRectangle.Top - (_verticalSpace / 2)); } if (oNode.Nodes.Count > 0) { //all nodes which have nodes should have lines coming from bottom down gr.DrawLine(boxPen, outerRectangle.Left + (_boxWidth / 2), outerRectangle.Top + _boxHeight, outerRectangle.Left + (_boxWidth / 2), outerRectangle.Top + _boxHeight + (_verticalSpace / 2)); } if (!oNode.IsRoot && oNode.PrevNode != null) { //the prev node has the same parent node - connect to 2 nodes ProcessDetailTN prevNode = (ProcessDetailTN)oNode.PrevNode; Rectangle prevOuterRectangle = new Rectangle(prevNode.X, prevNode.Y, (int)(_boxWidth), (int)(_boxHeight)); gr.DrawLine(boxPen, prevOuterRectangle.Left + (_boxWidth / 2) - (_lineWidth / 2), prevOuterRectangle.Top - (_verticalSpace / 2), outerRectangle.Left + (_boxWidth / 2) + (_lineWidth / 2), outerRectangle.Top - (_verticalSpace / 2)); } }