public async Task<List<byte[]>> DrawGraph(List<int>[][] orginalAutomaton, List<int>[][] foundAutomaton)
        {
            List<byte[]> graphs = new List<byte[]>();
            await Task.Run(() => 
                {
                    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[] orginal = wrapper.GenerateGraph(GenerateDotString(orginalAutomaton), Enums.GraphReturnType.Png);
            byte[] found = wrapper.GenerateGraph(GenerateDotString(foundAutomaton), Enums.GraphReturnType.Png);

            graphs.Add(orginal);
            graphs.Add(found);
                }
            );
            return graphs;
            
        }
Ejemplo n.º 2
0
        public GraphGenerator()
        {
            var getStartProcessQuery = new GetStartProcessQuery();
            var getProcessStartInfoQuery = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);

            _wrapper = new GraphGeneration(getStartProcessQuery,
                                              getProcessStartInfoQuery,
                                              registerLayoutPluginCommand);
        }
Ejemplo n.º 3
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]);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private void btnCreateGVFile_Click(object sender, EventArgs e)
        {
            disableControls();
            this.Cursor = Cursors.WaitCursor;
            Application.DoEvents();

            try
            {
                string gvContent = null;
                string chosenTypeName = null;
                //Opening the storage
                using (FileStream file = new FileStream(filePath, FileMode.Open))
                using (var storage = new IndexedFileStorage(file, clusterSize, safeWrite, header))
                {
                    TypesVisualisationService typesVisualisationService = new TypesVisualisationService(storage);
                    string rootTypeName = typesVisualisationService.getRootTypeName();
                    if (rbRootType.Checked)
                    {
                        chosenTypeName = rootTypeName;
                        gvContent = typesVisualisationService.GetGraphVizContentFromStorage(storage);

                    }
                    else
                    {
                        //Opening the dialog for choosing a type.
                        ChooseTypeForm chooseTypeForm = new ChooseTypeForm(typesVisualisationService.GetTypeVisualUnits(typesVisualisationService.GetRootTypeId()), rootTypeName);
                        if (chooseTypeForm.ShowDialog() == DialogResult.OK)
                        {
                            chosenTypeName = chooseTypeForm.CurrentType.Name;
                            gvContent = typesVisualisationService.GetGraphVizContentFromStorage(chosenTypeName, storage);
                        }
                    }
                }
                if (gvContent != null)
                {
                    this.Cursor = Cursors.WaitCursor;
                    Application.DoEvents();

                    //creating the filename for the image.
                    string fileLocation = filePath.Substring(0, filePath.LastIndexOf("\\") + 1);
                    string fileName = Path.GetFileNameWithoutExtension(filePath) + "_" + chosenTypeName;
                    string pngExtension = ".png";
                    string newFilePathPng = fileLocation + fileName + pngExtension;
                    int occurance = 0;
                    while (File.Exists(newFilePathPng))
                    {
                        occurance++;
                        newFilePathPng = fileLocation + fileName + occurance + pngExtension;
                    }

                    //Calling dot.exe to generate the image.
                    var getStartProcessQuery = new GetStartProcessQuery();
                    var getProcessStartInfoQuery = new GetProcessStartInfoQuery();
                    var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery,getStartProcessQuery);
                    var wrapper = new GraphVizWrapper.GraphVizWrapper(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);

                    byte[] output = wrapper.GenerateGraph(gvContent, Enums.GraphReturnType.Png);
                    File.WriteAllBytes(newFilePathPng, output);

                    panStatus.Visible = true;
                    tbStatus.Text = newFilePathPng;

                }

            }
            catch (FileNotFoundException ex)
            {
                String message = "File Path is invalid! The file has probably been moved or removed since opening it.\n Please check the file location.";
                ExceptionDialog exDialog = new ExceptionDialog(message, ex);
                exDialog.ShowDialog();
            }
            catch (Exception ex)
            {
                String message = "An exception has occured. Please consult the exception log below.";
                ExceptionDialog exDialog = new ExceptionDialog(message, ex);
                exDialog.ShowDialog();
            }
            enableControls();
            this.Cursor = Cursors.Default;
            Application.DoEvents();
        }
Ejemplo n.º 6
0
 void InitialiseDotWrapper()
 {
     var getStartProcessQuery = new GetStartProcessQuery();
     var getProcessStartInfoQuery = new GetProcessStartInfoQuery();
     var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
     wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);
 }
Ejemplo n.º 7
0
        //private string generateNextStepDot()
        //{
        //    StringBuilder sbFsm = new StringBuilder();
        //    sbFsm.Append("digraph finite_state_machine { rankdir=LR; size=\"7,5\" ");
        //    StringBuilder sbFinalStates = new StringBuilder();
        //    foreach (State state in _dfa.FinalStates)
        //    {
        //        sbFinalStates.Append("\"");
        //        sbFinalStates.Append(state.QLabel);
        //        sbFinalStates.Append("\" ");
        //    }
        //    sbFinalStates.Append("; ");
        //    sbFsm.Append("node [shape = doublecircle]; ");
        //    sbFsm.Append(sbFinalStates.ToString());
        //    sbFsm.Append("node [shape = circle]; ");
        //    for (int i = 0; i < _dfaBuilder.Steps.Count; i++)
        //    {
        //        State from = _dfa.States.LastOrDefault(s => s.RegexLabel == _steps[i].From.RegexLabel);
        //        State to = _dfa.States.LastOrDefault(s => s.RegexLabel == _steps[i].To.RegexLabel);
        //        sbFsm.Append(from.QLabel);
        //        sbFsm.Append(" -> ");
        //        sbFsm.Append(to.QLabel);
        //        sbFsm.Append(" [ label = \"");
        //        sbFsm.Append(_steps[i].Over);
        //    }
        //    sbFsm.Append("}");
        //    return sbFsm.ToString();
        //}
        private BitmapImage dot2bmp(string dot)
        {
            // Starting wrapper
            var getStartProcessQuery = new GetStartProcessQuery();
            var getProcessStartInfoQuery = new GetProcessStartInfoQuery();
            var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
            var wrapper = new GraphVizWrapper.GraphVizWrapper(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);

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

            //Conversion to BitmapImage
            var image = new BitmapImage();
            using (var mem = new MemoryStream(output))
            {
                mem.Position = 0;
                image.BeginInit();
                image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.UriSource = null;
                image.StreamSource = mem;
                image.EndInit();
            }

            return image;
        }