Example #1
0
        public static Graph GenerateGraph(DrawItem drawItem, ref Palette palette, ref string message, string savePath = null)
        {
            try
            {
                var graph = new Graph(GetTitle(drawItem));

                switch (drawItem.ViewLevel)
                {
                    case ViewLevel.Activity:
                        DrawActivity(ref graph, drawItem, ref palette);
                        break;
                    case ViewLevel.SubProcess:
                        DrawTask(ref graph, drawItem, ref palette);
                        break;
                }


                //Saves the graph to file if a file name is specified
                if (!string.IsNullOrEmpty(savePath))
                {
                    try
                    {
                        var renderer = new Microsoft.Msagl.GraphViewerGdi.GraphRenderer(graph);

                        renderer.CalculateLayout();
                        
                        var img = new System.Drawing.Bitmap((int) graph.Width, (int) graph.Height, PixelFormat.Format32bppPArgb);
                        renderer.Render(img);

                        var encoderParameters = new EncoderParameters(1);
                        encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                        img.Save(savePath, ImageCodecInfo.GetImageDecoders().Where(e => e.FormatID == ImageFormat.Png.Guid).First(), encoderParameters);
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                        return null;
                    }
                }

                return graph;

            } catch (Exception ex)
            {
                message = ex.Message;
                return null;
            }
         
        }
Example #2
0
 public MsaglForm(DrawItem result)
 {
     InitializeComponent();
     _palette = new Palette(2, 20, 10);
     _result = result;
 }
Example #3
0
        private static bool DoCoreTask(Arguments args)
        {
            try
            {
                var db = new ProcessViewer.Data1.CloudCoreDB(args.Connection);

                 var drawItem = new DrawItem
                                   {
                                       ConnectionString = args.Connection,
                                       ViewLevel = args.ViewLevel,
                                       DiagramType = args.Visio ? DiagramType.Visio : DiagramType.Msagl,
                                       Version = DBVersion.Version2,
                                       ResetRevisions = false,

                                   };

                var processes = from p in db.Cloudcoremodel_ProcessModel
                                join r in db.Cloudcoremodel_ProcessRevision on p.ProcessModelId equals r.ProcessModelId
                                orderby r.ProcessRevision descending
                                where p.ProcessModelId == args.ProcessID
                                select new Process(drawItem)
                                           {
                                               Id = p.ProcessModelId,
                                               Title = p.ProcessName,
                                               RevisionId = r.ProcessRevisionId
                                           };

                if (args.Revision > 0)
                    processes = processes.Where(p => p.RevisionId == args.Revision);

                var options = Options.None;

                if (args.Colour)
                    options |= Options.Colour;
                if (args.Identity)
                    options |= Options.Id;
                if (args.Instance)
                    options |= Options.Instance;

                var palette = new Palette(2, 20, 10);

                drawItem.Options = options;
                drawItem.Process = new List<Process> {processes.FirstOrDefault()};

                if (args.Visio)
                    VisioGraph.GenerateGraph(drawItem, ref palette, args.Path);
                else
                    MsaglGraph.GenerateGraph(drawItem, ref palette, args.Path);
  
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }

            return true;
        }
Example #4
0
 public static Graph GenerateGraph(DrawItem drawItem, ref Palette palette, string savePath = null)
 {
     var msg = String.Empty;
     return GenerateGraph(drawItem, ref palette, ref msg, savePath);
 }
Example #5
0
        private static void AddNodeToGraph(ref Graph graph, DrawItem drawItem, ref Palette palette, Library.Node snope, ShapeType shapeType)
        {

            if (snope.ID == 0)
                snope.Title = "Finish";

            if (Options.Id == (drawItem.Options & Options.Id) && snope.ID != 0)
            {
                snope.Title = snope.ID + ": " + snope.Title;
            }

            if ((drawItem.Options & Options.Instance) == Options.Instance && snope.ID != 0)
                snope.Title = String.Format(@"{0} {2}(Instances: {1})", snope.Title, snope.Instances, '\n');

            var node = graph.AddNode(snope.ID.ToString());
            node.Attr.AddStyle(Style.Bold);

            node.Label.Text = "\n" + snope.Title + "\n\n";

            
            FormatShapes(node, shapeType);

            if ((Options.Colour != (drawItem.Options & Options.Colour)) || snope.GroupID == 0) return;
            var colour = palette.AddColor(snope.GroupID ?? 0, snope.GroupTitle);
            var groupColour = new Color(colour.Color.R, colour.Color.G, colour.Color.B);
            node.Attr.FillColor = groupColour;
        }
Example #6
0
        private static void DrawActivity(ref Graph graph, DrawItem drawItem, ref Palette palette)
        {
            foreach (var node in Nodes.GetStructureNodes(drawItem.Version, drawItem.ConnectionString, drawItem.ViewLevel, drawItem.Process, (drawItem.Options & Options.Instance) == Options.Instance))
            {
                ShapeType shape;
                if (node.Startable)
                    shape = ShapeType.StartPage;
                else if (node.ID == 0)
                    shape = ShapeType.Finish;
                else switch (node.ActivityType)
                    {
                        case "Business Rule":
                            shape = ShapeType.Rule;
                            break;
                        case "Trigger":
                            shape = ShapeType.Trigger;
                            break;
                        case "Page":
                            shape = ShapeType.Page;
                            break;
                        case "Event":
                            shape = ShapeType.Event;
                            break;
                        case "Parked":
                            shape = ShapeType.Page;
                            break;
                        default:
                            shape = ShapeType.Page;
                            break;
                    }

                AddNodeToGraph(ref graph, drawItem, ref palette, node, shape);
            }

            foreach (var connector in Connectors.GetStructureConnectors(drawItem.Version, drawItem.ConnectionString, drawItem.ViewLevel, drawItem.Process))
            {
                var edge = graph.AddEdge(connector.FromID.ToString(), connector.Title, connector.ToID.ToString());

                if (connector.FlowInd != 0)
                {
                    switch (connector.FlowInd)
                    {
                        case 1: //Optimal Flow
                            edge.Attr.Color = Color.Green;
                            break;
                        case 2: //Negative Flow
                            edge.Attr.Color = Color.Red;
                            break;
                    }
                }
            }
        }
Example #7
0
        private static void DrawTask(ref Graph graph, DrawItem drawItem, ref Palette palette)
        {
            foreach (var node in Nodes.GetStructureNodes(drawItem.Version, drawItem.ConnectionString, drawItem.ViewLevel, drawItem.Process, (drawItem.Options & Options.Instance) == Options.Instance))
            {

                

                ShapeType shape;
                if (node.ID == 0)
                {
                    shape = ShapeType.Finish;
                    node.Title = "Finish";
                }
                else if (node.Startable)
                {
                    shape = ShapeType.StartableTask;
                }
                else if (node.Decision)
                {
                    shape = ShapeType.DecisionTask;
                }
                else
                {
                    shape = ShapeType.NormalTask;
                }

                AddNodeToGraph(ref graph, drawItem, ref palette, node, shape);
            }

            foreach (var connector in Connectors.GetStructureConnectors(drawItem.Version, drawItem.ConnectionString, drawItem.ViewLevel, drawItem.Process))
            {
                graph.AddEdge(connector.FromID.ToString(), connector.Title, connector.ToID.ToString());
            }
        }
Example #8
0
        public static void GenerateGraph(DrawItem drawItem, ref Palette palette, ref string message, string savePath = null)
        {
            try
            {
                if (savePath == null)
                    return;

                var vapp = new Visio.InvisibleApp();

                var vdoc = vapp.Documents.Add("");

  
                try
                {

                    var snopes = new List<Snope>();



                    SetPageLayoutAndRouting(vapp.ActivePage);

                    vapp.ActiveDocument.SaveAs(savePath);
                    vdoc.Saved = true;


                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                vapp.Quit();
                Utilities.NullAndRelease(vdoc);
                Utilities.NullAndRelease(vapp);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }