private void ExportFile(GraphNode startNode, IDictionary <string, double> results)
        {
            var fileName = MakeFileName(startNode.Name);

            using (var sw = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                var sourcePerson = ((PersonNode)startNode.Tag).Person;

                sw.WriteLine(PersonFormatter.GetName(sourcePerson));
                sw.WriteLine();

                var relevantResults = results.Where(kvp => kvp.Value != double.PositiveInfinity).OrderByDescending(kvp => kvp.Value);

                foreach (var kvp in relevantResults)
                {
                    var targetNode = _graph.GetNode(kvp.Key);

                    if (targetNode.Tag is PersonNode targetPersonNode)
                    {
                        var targetPerson = targetPersonNode.Person;

                        sw.WriteLine($"{PersonFormatter.GetName(targetPerson)}: {kvp.Value / 2}");
                    }
                }
            }
        }
        private static ListViewItem CreateRow(Step firstStep, Step secondStep)
        {
            var profile = (ProfileNode)firstStep.Left.Tag;

            var title = profile.Profile.Title;

            var leftPerson = (PersonNode)firstStep.Right.Tag;

            var leftName = PersonFormatter.GetName(leftPerson.Person);

            var leftJob = leftPerson.GetJobs(profile).First();

            var leftJobDescription = PersonFormatter.GetJob(leftJob);

            var rightPerson = (PersonNode)secondStep.Left.Tag;

            var rightName = PersonFormatter.GetName(rightPerson.Person);

            var rightJob = rightPerson.GetJobs(profile).First();

            var rightJobDescription = PersonFormatter.GetJob(rightJob);

            var subItems = new[] { title, leftName, leftJobDescription, rightName, rightJobDescription };

            var row = new ListViewItem(subItems);

            return(row);
        }
        private static void CheckNewWinner(ref int maxUndefined, ref int minUndefined, ref double maxMaxDistance, ref double minMaxDistance, GraphNode startNode, int?numUndefined, double?numMaxDistance)
        {
            if ((numUndefined.HasValue && numUndefined > maxUndefined) ||
                (numUndefined.HasValue && numUndefined < minUndefined) ||
                (numMaxDistance.HasValue && numMaxDistance.Value > maxMaxDistance) ||
                (numMaxDistance.HasValue && numMaxDistance.Value < minMaxDistance))
            {
                var person = ((PersonNode)startNode.Tag).Person;

                var name = PersonFormatter.GetName(person);

                if (numUndefined.HasValue && numUndefined > maxUndefined)
                {
                    maxUndefined = numUndefined.Value;

                    Trace.WriteLine($"new max undefined: {name}: {maxUndefined}");
                }

                if (numUndefined.HasValue && numUndefined < minUndefined)
                {
                    minUndefined = numUndefined.Value;

                    Trace.WriteLine($"new min undefined: {name}: {minUndefined}");
                }

                if (numMaxDistance.HasValue && numMaxDistance.Value > maxMaxDistance)
                {
                    maxMaxDistance = numMaxDistance.Value;

                    Trace.WriteLine($"new max max distance: {name}: {maxMaxDistance}");
                }

                if (numMaxDistance.HasValue && numMaxDistance < minMaxDistance)
                {
                    minMaxDistance = numMaxDistance.Value;

                    Trace.WriteLine($"new min max distance: {name}: {minMaxDistance}");
                }
            }
        }
 public static string BuildNodeName(IPerson person) => "Person: " + PersonFormatter.GetName(person).ToLower(Thread.CurrentThread.CurrentUICulture);
        private void SaveImage(FileInfo fileInfo)
        {
            foreach (var node in _resultGraph.Nodes)
            {
                if (node.Tag is PersonNode personNode)
                {
                    node.Description = PersonFormatter.GetName(personNode.Person).Replace("\"", "'");
                }
                else if (node.Tag is ProfileNode profileNode)
                {
                    node.Description = profileNode.Profile.Title.Replace("\"", "'");
                }
            }

            foreach (var edge in _resultGraph.Edges)
            {
                if (_withJobs)
                {
                    PersonNode  personNode;
                    ProfileNode profileNode;

                    if (edge.SourceNode.Tag is PersonNode temp)
                    {
                        personNode  = temp;
                        profileNode = (ProfileNode)edge.TargetNode.Tag;
                    }
                    else
                    {
                        personNode  = (PersonNode)edge.TargetNode.Tag;
                        profileNode = (ProfileNode)edge.SourceNode.Tag;
                    }

                    var jobs = personNode.GetJobs(profileNode);

                    edge.Description = PersonFormatter.GetJob(jobs.First()).Replace("\"", "'");
                }
                else
                {
                    edge.Description = string.Empty;
                }
            }

            var dotText = _resultGraph.ToDotText();

            switch (fileInfo.Extension.ToLower())
            {
            case ".png":
            {
                _renderer.RenderImage(dotText, fileInfo.FullName, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                break;
            }

            case ".svg":
            {
                _renderer.RenderImage(dotText, fileInfo.FullName, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.svg);

                break;
            }

            case ".bmp":
            {
                var image = _renderer.RenderImage(dotText, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                image.Save(fileInfo.FullName, System.Drawing.Imaging.ImageFormat.Bmp);

                break;
            }

            case ".tif":
            case ".tiff":
            {
                var image = _renderer.RenderImage(dotText, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                image.Save(fileInfo.FullName, System.Drawing.Imaging.ImageFormat.Tiff);

                break;
            }

            case ".jpg":
            case ".jpeg":
            {
                _renderer.RenderImage(dotText, fileInfo.FullName, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.jpg);

                break;
            }

            case ".gif":
            {
                var image = _renderer.RenderImage(dotText, mitoSoft.Graphs.GraphVizInterop.Enums.LayoutEngine.dot, mitoSoft.Graphs.GraphVizInterop.Enums.ImageFormat.png);

                image.Save(fileInfo.FullName, System.Drawing.Imaging.ImageFormat.Gif);

                break;
            }

            default:
            {
                MessageBox.Show($"Unknown file format: {fileInfo.Extension}", "GraphWiz", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }
            }

            Process.Start(fileInfo.FullName);
        }