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;
            
        }
Esempio 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);
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
 void InitialiseDotWrapper()
 {
     var getStartProcessQuery = new GetStartProcessQuery();
     var getProcessStartInfoQuery = new GetProcessStartInfoQuery();
     var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
     wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);
 }
Esempio n. 5
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;
        }