Exemplo n.º 1
0
        public void GenerateGraphReturnsByteArrayWithLengthGreaterOrEqualZero()
        {
            // Arrange
            _registerLayoutPluginCommandMock.Setup(m => m.Invoke("SomeLocation", Enums.RenderingEngine.Dot));
            _getProcessStartInfoQuery.Setup(m => m.Invoke(It.IsAny <IProcessStartInfoWrapper>())).Returns(
                new ProcessStartInfo
            {
                FileName = "cmd",
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            });

            var wrapper = new GraphGeneration(
                _getStartProcessQuery,
                _getProcessStartInfoQuery.Object,
                _registerLayoutPluginCommandMock.Object);

            // Act
            byte[] output = wrapper.GenerateGraph("digraph{a -> b; b -> c; c -> a;}", Enums.GraphReturnType.Png);

            // Assert
            Assert.That(output.Length, Is.GreaterThanOrEqualTo(0));
        }
Exemplo n.º 2
0
        public Image toDigraphImage()
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            StringBuilder sb = new StringBuilder("digraph{");

            for (int n1 = 0; n1 < NodesCount; n1++)
            {
                for (int n2 = 0; n2 < NodesCount; n2++)
                {
                    if (AdjMatrix[n1, n2] != Double.PositiveInfinity)
                    {
                        sb.AppendLine(String.Format("n{0}->n{1}", n1, n2));
                    }
                }
            }

            sb.AppendLine("}");

            byte[] output = wrapper.GenerateGraph(sb.ToString(), Enums.GraphReturnType.Png);

            using (MemoryStream ms = new MemoryStream(output))
            {
                return(Image.FromStream(ms));
            }
        }
Exemplo n.º 3
0
        public void GenerateCFG(TACode code)
        {
            try
            {
                var cfg = new ControlFlowGraph(code);

                string graph = BuildDotGraph(cfg);
                File.WriteAllText(@"cfg_graph.txt", graph);

                var processQuery          = new GetStartProcessQuery();
                var processStartInfoQuery = new GetProcessStartInfoQuery();
                var registerLayout        = new RegisterLayoutPluginCommand(processStartInfoQuery, processQuery);
                var wrapper = new GraphGeneration(processQuery, processStartInfoQuery, registerLayout)
                {
                    RenderingEngine = Enums.RenderingEngine.Dot
                };
                byte[] output = wrapper.GenerateGraph(graph, Enums.GraphReturnType.Png);

                using (var stream = new MemoryStream(output))
                {
                    var image = Image.FromStream(stream);
                    GenerationCompleted(null, image);
                }

                CfgGenerated(null, cfg);
            }
            catch (Exception ex)
            {
                GenerationErrored(null, ex);
            }
        }
Exemplo n.º 4
0
        public void GenerateGraphReturnsByteArrayWithLengthGreaterOrEqualZero()
        {
            // Arrange
            _registerLayoutPluginCommandMock.Setup(m => m.Invoke("SomeLocation", Enums.RenderingEngine.Dot));
            _getProcessStartInfoQuery.Setup(m => m.Invoke(It.IsAny<IProcessStartInfoWrapper>())).Returns(
                new ProcessStartInfo
                    {
                        FileName = "cmd",
                        RedirectStandardInput = true,
                        RedirectStandardOutput = true,
                        RedirectStandardError = true,
                        UseShellExecute = false,
                        CreateNoWindow = true
                    });

            var wrapper = new GraphGeneration(
                _getStartProcessQuery,
                _getProcessStartInfoQuery.Object,
                _registerLayoutPluginCommandMock.Object);

            // Act
            byte[] output = wrapper.GenerateGraph("digraph{a -> b; b -> c; c -> a;}", Enums.GraphReturnType.Png);

            // Assert
            Assert.That(output.Length, Is.GreaterThanOrEqualTo(0));
        }
Exemplo n.º 5
0
        public void GenerateGraph_Called_ReturnsByteArrayWithLengthGreaterThanZero()
        {
            var _getProcessStartInfoQueryMock    = Substitute.For <IGetProcessStartInfoQuery>();
            var _registerLayoutPluginCommandMock = Substitute.For <IRegisterLayoutPluginCommand>();

            _registerLayoutPluginCommandMock.Invoke(Arg.Any <string>(), Arg.Any <Enums.RenderingEngine>());
            _getProcessStartInfoQueryMock.Invoke(Arg.Any <IProcessStartInfoWrapper>()).Returns(
                new ProcessStartInfo
            {
                FileName = "cmd",
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            });

            var wrapper = new GraphGeneration(
                _getStartProcessQuery,
                _getProcessStartInfoQueryMock,
                _registerLayoutPluginCommandMock);

            _wrapper.RenderingEngine = Enums.RenderingEngine.Dot;
            // Act
            byte[] output = wrapper.GenerateGraph("digraph{a -> b; b -> c; c -> a;}", Enums.GraphReturnType.Png);
            // Assert
            output.Length.Should().BePositive($"because Rendering Engine is {Enums.RenderingEngine.Dot.ToString()}");
        }
Exemplo n.º 6
0
        /// <summary>
        /// generate an image from .gv strings
        /// </summary>
        /// <param name="diagraph"></param>
        /// <param name="imgFile"></param>
        private static void generateGraphImage(string diagraph, string imgFile)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuerty   = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuerty, getStartProcessQuery);

            var wrapper = new GraphGeneration(
                getStartProcessQuery,
                getProcessStartInfoQuerty,
                registerLayoutPluginCommand);

            // wrapper.RenderingEngine = Enums.RenderingEngine.Fdp;
            //wrapper.RenderingEngine = Enums.RenderingEngine.Sfdp;
            wrapper.RenderingEngine = Enums.RenderingEngine.Dot;

            byte[] output = wrapper.GenerateGraph(diagraph, Enums.GraphReturnType.Png);

            // byte[] to Image
            System.Drawing.Image img = byteArrayToImage(output);

            // save the image
            img.Save(imgFile, System.Drawing.Imaging.ImageFormat.Png);

            img.Dispose();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            var wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph("digraph G {a -> b; b -> c; c -> a;}", Enums.GraphReturnType.Png);

            /*
             * ArqTable ar = new ArqTable();
             * ar.lerArquivo("Table.txt");
             * string[,] table = new string[ar.contLine(), ar.contColum()];
             * ar.matriz(table);
             * PredictiveAnalysis analysis = new PredictiveAnalysis("(i)*(i)$");
             * analysis.inicioAnalise(table);
             * Console.WriteLine("\n");
             * Console.WriteLine("\\\\\\\\\\---------- TABELA --------\\\\\\\\\\");
             * for (int i=0; i < ar.contLine(); i++)
             * {
             *  for(int j=0; j < ar.contColum(); j++)
             *  {
             *      Console.Write(table[i, j] + " \t");
             *  }
             *  Console.WriteLine();
             * }*/
            Console.ReadLine();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Generiert einen gerenderten Netzplan zu dem im übergebenen Prozessablaufplan
        /// beschriebenen Prozess.
        /// </summary>
        /// <param name="processTitle">Titel des im Prozessplan beschriebenen Prozesses.</param>
        /// <param name="processPlan">
        /// Prozessablaufplan der den Prozess beschreibt, welcher gerendert wird.
        /// </param>
        /// <param name="format">Grafikformat der Netzplangrafik.</param>
        /// <returns>Gerenderter Netzplan.</returns>
        public byte[] GeneratePrecedenceDiagram(string processTitle, string[] processPlan, GraphicFormat format)
        {
            Process process    = new Process(processTitle, processPlan);
            string  diagramDot = process.GetDot();

            Enums.GraphReturnType gVFormat = ConvertToGraphVizEnum(format);
            return(wrapper.GenerateGraph(diagramDot, gVFormat));
        }
Exemplo n.º 9
0
        private async void GraphCode(UndertaleCode code)
        {
            if (code.DuplicateEntry)
            {
                GraphView.Source = null;
                CurrentGraphed   = code;
                return;
            }

            LoaderDialog dialog = new LoaderDialog("Generating graph", "Generating graph, please wait...");

            dialog.Owner = Window.GetWindow(this);
            Task t = Task.Run(() =>
            {
                ImageSource image = null;
                try
                {
                    code.UpdateAddresses();
                    var blocks = Decompiler.DecompileFlowGraph(code);
                    string dot = Decompiler.ExportFlowGraph(blocks);

                    try
                    {
                        var getStartProcessQuery        = new GetStartProcessQuery();
                        var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
                        var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
                        var wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);

                        byte[] output = wrapper.GenerateGraph(dot, Enums.GraphReturnType.Png); // TODO: Use SVG instead

                        image = new ImageSourceConverter().ConvertFrom(output) as ImageSource;
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                        if (MessageBox.Show("Unable to execute GraphViz: " + e.Message + "\nMake sure you have downloaded it and set the path in settings.\nDo you want to open the download page now?", "Graph generation failed", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
                        {
                            Process.Start("https://graphviz.gitlab.io/_pages/Download/Download_windows.html");
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                    MessageBox.Show(e.Message, "Graph generation failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                Dispatcher.Invoke(() =>
                {
                    GraphView.Source = image;
                    CurrentGraphed   = code;
                    dialog.Hide();
                });
            });

            dialog.ShowDialog();
            await t;
        }
Exemplo n.º 10
0
        public void CreateGraph(string graph, string filename)
        {
            byte[] output = wrapper.GenerateGraph(graph, Enums.GraphReturnType.Png);

            using (Image image = Image.FromStream(new MemoryStream(output)))
            {
                image.Save(filename, ImageFormat.Png);
            }
        }
Exemplo n.º 11
0
        public static void Save(string graphText, string outFile)
        {
            var outFileInfo = new FileInfo(outFile);

            // These three instances can be injected via the IGetStartProcessQuery,
            //                                               IGetProcessStartInfoQuery and
            //                                               IRegisterLayoutPluginCommand interfaces

            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            // GraphGeneration can be injected via the IGraphGeneration interface

            var wrapper = new GraphGeneration(
                getStartProcessQuery,
                getProcessStartInfoQuery,
                registerLayoutPluginCommand);

            Enums.GraphReturnType saveType;
            switch (outFileInfo.Extension)
            {
            case ".pdf":
                saveType = Enums.GraphReturnType.Pdf;
                break;

            case ".jpg":
                saveType = Enums.GraphReturnType.Jpg;
                break;

            case ".png":
                saveType = Enums.GraphReturnType.Png;
                break;

            default:
                throw new Exception($"Unknown extension: {outFileInfo.Extension}");
            }

            var currentDirectory = Directory.GetCurrentDirectory();

            byte[] output;

            try
            {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
                output = wrapper.GenerateGraph(graphText, saveType);
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }

            File.WriteAllBytes(outFile, output);

            Console.WriteLine();
            Console.WriteLine($"{output.Length} bytes written to {outFile}.");
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
            var wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph("", Enums.GraphReturnType.Svg);
            File.WriteAllBytes("Foo.svg", output.ToArray());
        }
Exemplo n.º 13
0
        public IActionResult PathToRoot(string id, long token, int nodeid, bool raw)
        {
            if (staticState.TryGetValue(token, out var state))
            {
                if (state.State is MultiThreadedSolverState multiResult)
                {
                    var node = nodeid == null
                        ? multiResult.Root
                        : nodeid > 0
                            ? multiResult.Root.FirstOrDefault(x => x.SolverNodeId == nodeid) ?? multiResult.RootReverse.FirstOrDefault(x => x.SolverNodeId == nodeid)
                            : multiResult.RootReverse;

                    var path = node.PathToRoot();

                    var expanded = new List <SolverNode>();
                    foreach (var p in path)
                    {
                        expanded.Add(p);
                        if (p.HasChildren)
                        {
                            foreach (var kid in p.Children)
                            {
                                if (!path.Contains(kid))
                                {
                                    expanded.Add(kid);
                                }
                            }
                        }
                    }

                    var render = new GraphVisRender();
                    var sb     = new StringBuilder();
                    using (var ss = new StringWriter(sb))
                    {
                        render.Render(expanded, ss);
                    }



                    var getStartProcessQuery        = new GetStartProcessQuery();
                    var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
                    var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
                    var wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);
                    var b       = wrapper.GenerateGraph(sb.ToString(), Enums.GraphReturnType.Svg);

                    if (raw)
                    {
                    }

                    return(new FileContentResult(b, "image/svg+xml"));
                }
            }

            return(RedirectToAction("Home", new { id, txt = "NotFound" }));
        }
Exemplo n.º 14
0
        static void BuildGraph(Node init, string filename)
        {
            var tab      = GetNodesTable(init);
            var graphStr = BuildGraphString(tab);

            byte[] output = wrapper.GenerateGraph(graphStr, Enums.GraphReturnType.Png);
            using (Image image = Image.FromStream(new MemoryStream(output)))
            {
                image.Save(filename, ImageFormat.Png);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Generate dot string that represents graph and write to file.
        /// </summary>
        /// <param name="codeGraph"></param>
        /// <param name="outputFileName"></param>
        public static void GenerateDotGraph(CodeGraph codeGraph, string outputFileName)
        {
            Console.WriteLine($"Writing code graph to {outputFileName}");

            GraphGeneration wrapper = GetGraphvizWrapper();

            string graphDotString = ConvertGraphToDotString(codeGraph);

            byte[] output = wrapper.GenerateGraph(graphDotString, Enums.GraphReturnType.Png);
            WriteGraphToImageFile(output, outputFileName);
        }
        /// <summary>
        /// Guarda el resultado de compilar con dot el string srcCode en name
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="srcCode"></param>
        public static Image SavePng(string filepath, string srcCode)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            // GraphGeneration can be injected via the IGraphGeneration interface

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);
            var indexOfDot = filepath.LastIndexOf('.');

            if (indexOfDot < 0 || indexOfDot + 1 >= filepath.Length)
            {
                return(null);
            }
            var stringFormat = filepath.Substring(indexOfDot + 1);

            Enums.GraphReturnType returnType;

            switch (stringFormat)
            {
            case "jpg":
                returnType = Enums.GraphReturnType.Jpg;
                break;

            case "jpeg":
                returnType = Enums.GraphReturnType.Jpg;
                break;

            case "png":
                returnType = Enums.GraphReturnType.Png;
                break;

            default:
                return(null);
            }

            var imgBytes = wrapper.GenerateGraph(srcCode, returnType);

            if (imgBytes.Length < 1)//Error al compilar el graphviz
            {
                return(null);
            }
            var ms  = new MemoryStream(imgBytes, 0, imgBytes.Length);
            var img = Image.FromStream(ms, true);

            img.Save(filepath);
            return(img);
        }
Exemplo n.º 17
0
        private void button1_Click(object sender, EventArgs e)
        {
            Ember apa  = new Ember("Apa");
            Ember anya = new Ember("Anya");
            Ember gy1  = new Ember("Gy1");
            Ember gy2  = new Ember("Gy2");
            Ember u1   = new Ember("U");
            Ember uu1  = new Ember("uu1");
            Ember uu2  = new Ember("uu2");
            Ember uu3  = new Ember("uu3");

            apa.parja  = anya;
            anya.parja = apa;

            apa.gyermeke.Add(gy1);
            apa.gyermeke.Add(gy2);
            anya.gyermeke.Add(gy1);
            anya.gyermeke.Add(gy2);

            gy1.gyermeke.Add(u1);

            u1.gyermeke.Add(uu1);
            u1.gyermeke.Add(uu2);
            u1.gyermeke.Add(uu3);



            string s = gyujto(apa);



            //

            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            // GraphGeneration can be injected via the IGraphGeneration interface

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph("digraph{" + s + "}", Enums.GraphReturnType.Png);

            using (MemoryStream ms = new MemoryStream(output))
            {
                Image i = Image.FromStream(ms);
                pictureBox1.Image = i;
            }
        }
        public byte[] VisualiseGraph <T>(Graph <T> graph)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            // GraphGeneration can be injected via the IGraphGeneration interface

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            return(wrapper.GenerateGraph(GenerateGraphVizString(graph), Enums.GraphReturnType.Png));
        }
Exemplo n.º 19
0
        public byte[] GetByteGraph()
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph(GraphStringBuilder(ProcessRepo.Processes), Enums.GraphReturnType.Png);

            return(output);
        }
Exemplo n.º 20
0
        static void GenerateGraphFile(string data, string filename)
        {
            GetStartProcessQuery        getStartProcessQuery        = new GetStartProcessQuery();
            GetProcessStartInfoQuery    getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            RegisterLayoutPluginCommand registerLayoutPluginCommand =
                new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            GraphGeneration wrapper = new GraphGeneration(getStartProcessQuery,
                                                          getProcessStartInfoQuery,
                                                          registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph(data, Enums.GraphReturnType.Jpg);
            System.IO.File.WriteAllBytes("Images/" + filename + ".jpg", output);
        }
Exemplo n.º 21
0
        public static Bitmap ToImage(string str)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph(str /*"digraph{a -> b; b -> c; c -> a;}"*/, Enums.GraphReturnType.Png);

            return(ByteToImage(output));
        }
Exemplo n.º 22
0
        private void VisualizeGraph(string dot)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph(dot, Enums.GraphReturnType.Png);

            graphView.Image = (Bitmap)((new ImageConverter()).ConvertFrom(output));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Swimlane style - vertical lane per label, ACU A/B values with label
        /// </summary>
        /// <param name="dfbState"></param>
        /// <returns></returns>
        public byte[] Generate(
            DFBState dfbState)
        {
            // Graph
            GraphViz.Graph graph = CreateGraph("dfb_call");

            const double labelColWidth = 2.25f;
            const double rowHeight     = 1.5f;
            double       currCol_x     = 0;
            double       currRow_y     = 0;

            // Subgraphs
            var labels = dfbState.StateFrames
                         .Where(x => x.CodeStateCycle.IsJumpInstruction == true)
                         .Select(x => x.CodeStateCycle.Label)
                         .Distinct()
                         .ToList();

            labels.ForEach(x => CreateSubgraph(graph, x));

            // Cycle through all of the jump instructions and build call sequence
            var jumpStateFrames = dfbState.StateFrames
                                  .Where(x => x.CodeStateCycle.IsJumpInstruction == true)
                                  .OrderBy(x => x.Cycle);

            foreach (var stateFrame in jumpStateFrames)
            {
                // Place all nodes for same label in one column
                var xPos = (currCol_x + (labelColWidth * stateFrame.CodeStateCycle.CodeState.State.StateNumber));

                // Place every node in an exclusive row
                var yPos = currRow_y;
                currRow_y -= rowHeight;

                AddSubgraphNode(
                    graph,
                    dfbState,
                    stateFrame,
                    xPos,
                    yPos);
            }

            var text = graph.ToString();

            wrapper.RenderingEngine = Enums.RenderingEngine.Neato;
            //wrapper.RenderingEngine = Enums.RenderingEngine.Dot;            // doesn't do absolute pos

            return(wrapper.GenerateGraph(text, Enums.GraphReturnType.Svg));
        }
Exemplo n.º 24
0
        static void GenerateGraphFile(string data, string filename)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand =
                new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            byte[] output = wrapper.GenerateGraph(data, Enums.GraphReturnType.Jpg);
            System.IO.File.WriteAllBytes(filename + ".jpg", output);
            System.Diagnostics.Process.Start($"{filename}.jpg");
        }
Exemplo n.º 25
0
        public IActionResult Test()
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

// GraphGeneration can be injected via the IGraphGeneration interface

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            var b = wrapper.GenerateGraph("digraph{a -> b; b -> c; c -> a;}", Enums.GraphReturnType.Svg);

            return(new FileContentResult(b, "image/svg+xml"));
        }
Exemplo n.º 26
0
        public void AllowsPlainTextOutputType() {
            // Arrange
            var getProcessStartInfoQuery = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, _getStartProcessQuery);

            var wrapper = new GraphGeneration(
                _getStartProcessQuery,
                getProcessStartInfoQuery,
                registerLayoutPluginCommand);

            // Act
            byte[] output = wrapper.GenerateGraph("digraph{a -> b; b -> c; c -> a;}", Enums.GraphReturnType.Plain);

            var graphPortion = System.Text.Encoding.Default.GetString(output).Split(new string[] { "\r\n" }, System.StringSplitOptions.None);

            Assert.AreEqual("graph 1 1.125 2.5", graphPortion[0]);
        }
Exemplo n.º 27
0
        public static void BuildGraph(TreeNode root, string filename)
        {
            GetStartProcessQuery        getStartProcessQuery        = new GetStartProcessQuery();
            GetProcessStartInfoQuery    getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            RegisterLayoutPluginCommand registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
            GraphGeneration             wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);

            var graphStr = BuildGraphString(root);

            //Console.WriteLine(graphStr);
            byte[] output = wrapper.GenerateGraph(graphStr, Enums.GraphReturnType.Png);
            File.WriteAllText($"{filename}.txt", graphStr);
            using (Image image = Image.FromStream(new MemoryStream(output)))
            {
                image.Save($"{filename}.png", ImageFormat.Png);
            }
        }
Exemplo n.º 28
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Melakukan pembangkitan gambar untuk hasil solusi sequence dari topological sort
            //Menggunakan library graphviz
            //Gambar akan ditampilkan pada picturebox1
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            // GraphGeneration can be injected via the IGraphGeneration interface

            //Deklarasi wrapper
            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            // Membuat query ke graphviz
            string request = "digraph G{{rank = same;";

            for (int i = 0; i < resultGraph.getSize(); i++)
            {
                request = request + pemetaanIndex[solution[i]] + ";";
            }

            for (int i = 0; i < resultGraph.getSize(); i++)
            {
                for (int j = 0; j < resultGraph.getSize(); j++)
                {
                    if (resultGraph.isAdjacent(i, j))
                    {
                        request = request + pemetaanIndex[i] + "->" + pemetaanIndex[j] + ";";
                    }
                }
            }
            request = request + "}}";

            // Membangkitkan gambar lau disimpan dalam byte
            byte[] output = wrapper.GenerateGraph(request, Enums.GraphReturnType.Jpg);

            //Drawing ke object Image
            Image gambar = System.Drawing.Image.FromStream(new MemoryStream(output));

            //Tampilkan gambar;
            pictureBox1.Image = gambar;
        }
Exemplo n.º 29
0
        public void DoesNotCrashWithLargeInput()
        {
            // Arrange
            var getProcessStartInfoQuerty = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuerty, _getStartProcessQuery);

            var wrapper = new GraphGeneration(
                _getStartProcessQuery,
                getProcessStartInfoQuerty,
                registerLayoutPluginCommand);

            // Act

            var diagraph =
                "digraph G {subgraph cluster_T1 { label = \"WORK ORDER\"; S1 [label = \"ACCEPTED\"]; S2 [label = \"DENIED\"]; S5 [label = \"SCHEDULED\"]; S44 [label = \"COMPLETE\"]; S47 [label = \"DELIVERED\"]; S48 [label = \"CANCELLED\"]; } subgraph cluster_T2 { label = \"MILL/DIG CHECK OUT\"; S3 [label = \"PROGRAMMING\"]; S4 [label = \"CUTTER PATH\"]; } subgraph cluster_T24 { label = \"OFFLOAD INTERNAL\"; S83 [label = \"IN PROCESS\"]; S84 [label = \"FINISHED\"]; } subgraph cluster_T23 { label = \"OFFLOAD EXTERNAL\"; S45 [label = \"IN PROCESS\"]; S46 [label = \"FINISHED\"]; S82 [label = \"QUOTE PENDING\"]; } subgraph cluster_T1 { label = \"WORK ORDER\"; S49 [label = \"WAITING 5-AXIS\"]; S50 [label = \"WAITING DATA CHANGE\"]; } subgraph cluster_T8 { label = \"MILL 1\"; S15 [label = \"IN PROCESS\"]; S16 [label = \"FINISHED\"]; } subgraph cluster_T9 { label = \"MILL 2\"; S17 [label = \"IN PROCESS\"]; S18 [label = \"FINISHED\"]; } subgraph cluster_T10 { label = \"MILL 3\"; S20 [label = \"IN PROCESS\"]; S21 [label = \"FINISHED\"]; } subgraph cluster_T11 { label = \"MILL 4\"; S22 [label = \"IN PROCESS\"]; S23 [label = \"FINISHED\"]; } subgraph cluster_T12 { label = \"MILL 5\"; S24 [label = \"IN PROCESS\"]; S25 [label = \"FINISHED\"]; } subgraph cluster_T13 { label = \"MILL 6\"; S26 [label = \"IN PROCESS\"]; S27 [label = \"FINISHED\"]; } subgraph cluster_T14 { label = \"MILL 7\"; S28 [label = \"IN PROCESS\"]; S29 [label = \"FINISHED\"]; } subgraph cluster_T15 { label = \"MILL 8\"; S30 [label = \"IN PROCESS\"]; S31 [label = \"FINISHED\"]; } subgraph cluster_T16 { label = \"HAAS\"; S32 [label = \"IN PROCESS\"]; S33 [label = \"FINISHED\"]; } subgraph cluster_T17 { label = \"FADAL 1\"; S34 [label = \"IN PROCESS\"]; S35 [label = \"FINISHED\"]; } subgraph cluster_T18 { label = \"FADAL 2\"; S36 [label = \"IN PROCESS\"]; S37 [label = \"FINISHED\"]; } subgraph cluster_T19 { label = \"DUPLICATOR\"; S38 [label = \"IN PROCESS\"]; S39 [label = \"FINISHED\"]; } subgraph cluster_T20 { label = \"TWIN RED\"; S40 [label = \"IN PROCESS\"]; S41 [label = \"FINISHED\"]; } subgraph cluster_T21 { label = \"TWIN BLUE\"; S42 [label = \"IN PROCESS\"]; S43 [label = \"FINISHED\"]; } S1->S3;S47->S44;S3->S4;S4->S5;S83->S84;S84->S47;S45->S46;S46->S47;S82->S45;S15->S16;S16->S47;S17->S18;S18->S47;S20->S21;S21->S47;S22->S23;S23->S47;S24->S25;S25->S47;S26->S27;S27->S47;S28->S29;S29->S47;S30->S31;S31->S47;S32->S33;S33->S47;S34->S35;S35->S47;S36->S37;S37->S47;S38->S39;S39->S47;S40->S41;S41->S47;S42->S43;S43->S47;}";

            byte[] output = wrapper.GenerateGraph(diagraph, Enums.GraphReturnType.Png);
        }
Exemplo n.º 30
0
        public void DoesNotCrashWithLargeInput()
        {
            // Arrange
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, _getStartProcessQuery);

            var wrapper = new GraphGeneration(
                _getStartProcessQuery,
                getProcessStartInfoQuery,
                registerLayoutPluginCommand);

            // Act

            var diagraph =
                "digraph G {subgraph cluster_T1 { label = \"WORK ORDER\"; S1 [label = \"ACCEPTED\"]; S2 [label = \"DENIED\"]; S5 [label = \"SCHEDULED\"]; S44 [label = \"COMPLETE\"]; S47 [label = \"DELIVERED\"]; S48 [label = \"CANCELLED\"]; } subgraph cluster_T2 { label = \"MILL/DIG CHECK OUT\"; S3 [label = \"PROGRAMMING\"]; S4 [label = \"CUTTER PATH\"]; } subgraph cluster_T24 { label = \"OFFLOAD INTERNAL\"; S83 [label = \"IN PROCESS\"]; S84 [label = \"FINISHED\"]; } subgraph cluster_T23 { label = \"OFFLOAD EXTERNAL\"; S45 [label = \"IN PROCESS\"]; S46 [label = \"FINISHED\"]; S82 [label = \"QUOTE PENDING\"]; } subgraph cluster_T1 { label = \"WORK ORDER\"; S49 [label = \"WAITING 5-AXIS\"]; S50 [label = \"WAITING DATA CHANGE\"]; } subgraph cluster_T8 { label = \"MILL 1\"; S15 [label = \"IN PROCESS\"]; S16 [label = \"FINISHED\"]; } subgraph cluster_T9 { label = \"MILL 2\"; S17 [label = \"IN PROCESS\"]; S18 [label = \"FINISHED\"]; } subgraph cluster_T10 { label = \"MILL 3\"; S20 [label = \"IN PROCESS\"]; S21 [label = \"FINISHED\"]; } subgraph cluster_T11 { label = \"MILL 4\"; S22 [label = \"IN PROCESS\"]; S23 [label = \"FINISHED\"]; } subgraph cluster_T12 { label = \"MILL 5\"; S24 [label = \"IN PROCESS\"]; S25 [label = \"FINISHED\"]; } subgraph cluster_T13 { label = \"MILL 6\"; S26 [label = \"IN PROCESS\"]; S27 [label = \"FINISHED\"]; } subgraph cluster_T14 { label = \"MILL 7\"; S28 [label = \"IN PROCESS\"]; S29 [label = \"FINISHED\"]; } subgraph cluster_T15 { label = \"MILL 8\"; S30 [label = \"IN PROCESS\"]; S31 [label = \"FINISHED\"]; } subgraph cluster_T16 { label = \"HAAS\"; S32 [label = \"IN PROCESS\"]; S33 [label = \"FINISHED\"]; } subgraph cluster_T17 { label = \"FADAL 1\"; S34 [label = \"IN PROCESS\"]; S35 [label = \"FINISHED\"]; } subgraph cluster_T18 { label = \"FADAL 2\"; S36 [label = \"IN PROCESS\"]; S37 [label = \"FINISHED\"]; } subgraph cluster_T19 { label = \"DUPLICATOR\"; S38 [label = \"IN PROCESS\"]; S39 [label = \"FINISHED\"]; } subgraph cluster_T20 { label = \"TWIN RED\"; S40 [label = \"IN PROCESS\"]; S41 [label = \"FINISHED\"]; } subgraph cluster_T21 { label = \"TWIN BLUE\"; S42 [label = \"IN PROCESS\"]; S43 [label = \"FINISHED\"]; } S1->S3;S47->S44;S3->S4;S4->S5;S83->S84;S84->S47;S45->S46;S46->S47;S82->S45;S15->S16;S16->S47;S17->S18;S18->S47;S20->S21;S21->S47;S22->S23;S23->S47;S24->S25;S25->S47;S26->S27;S27->S47;S28->S29;S29->S47;S30->S31;S31->S47;S32->S33;S33->S47;S34->S35;S35->S47;S36->S37;S37->S47;S38->S39;S39->S47;S40->S41;S41->S47;S42->S43;S43->S47;}";

            byte[] output = wrapper.GenerateGraph(diagraph, Enums.GraphReturnType.Png);
        }
Exemplo n.º 31
0
        public void AllowsPlainExtTextOutputType()
        {
            // Arrange
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, _getStartProcessQuery);

            var wrapper = new GraphGeneration(
                _getStartProcessQuery,
                getProcessStartInfoQuery,
                registerLayoutPluginCommand);

            // Act
            byte[] output = wrapper.GenerateGraph("digraph{a -> b; b -> c; c -> a;}", Enums.GraphReturnType.PlainExt);

            var graphPortion = System.Text.Encoding.Default.GetString(output).Split(new string[] { "\r\n" }, System.StringSplitOptions.None);

            Assert.AreEqual("graph 1 1.125 2.5", graphPortion[0]);
        }
Exemplo n.º 32
0
        public Image StringToImage(String s)
        {
            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);

            wrapper.RenderingEngine = Enums.RenderingEngine.Fdp;

            byte[] output = wrapper.GenerateGraph(s, Enums.GraphReturnType.Png);

            using (MemoryStream ms = new MemoryStream(output))
            {
                return(Image.FromStream(ms));
            }
        }
Exemplo n.º 33
0
        public void PrintToGraph(ResultGraphAfterUsingAlgorithms graphToPrint)
        {
            // These three instances can be injected via the IGetStartProcessQuery,
            //                                               IGetProcessStartInfoQuery and
            //                                               IRegisterLayoutPluginCommand interfaces

            var getStartProcessQuery        = new GetStartProcessQuery();
            var getProcessStartInfoQuery    = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            // GraphGeneration can be injected via the IGraphGeneration interface

            var wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);
            string description = "digraph{";

            if (graphToPrint == ResultGraphAfterUsingAlgorithms.InitialGraph)
            {
                for (int t = 0; t < m; t++)
                {
                    description += edges[t].I + " -> " + edges[t].J +
                                   " [label=" + edges[t].C + ",weight=" + edges[t].C + "] ;";
                }
            }
            else if (graphToPrint == ResultGraphAfterUsingAlgorithms.GraphAfterAlgKraskala)
            {
                for (int t = 0; t < w; t++)
                {
                    description += edges[K[t]].I + " -> " + edges[K[t]].J +
                                   " [label=" + edges[K[t]].C + ",weight=" + edges[K[t]].C + "] ;";
                }
            }

            description += "}";

            byte[] output = wrapper.GenerateGraph(description, Enums.GraphReturnType.Png);
            using (Stream ms = new MemoryStream(output))
            {
                System.Drawing.Image i = System.Drawing.Image.FromStream(ms);
                i.Save(pathPrint, ImageFormat.Png);
            }
        }