Example #1
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();
        }
Example #2
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();
        }