aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/Examples/AddResult/Program.cs
blob: 750dd436da08aca9933597b64d7cfaadc9c8af0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
using Google.Protobuf;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.PMR.Stubs;
using Tango.PMR.Diagnostics;
using Tango.FSE.Common.Connection;
using Tango.FSE.Common.Diagnostics;
using Tango.FSE.Procedures;

namespace Tango.FSE.Procedures.Examples.AddResult
{
    #region Example
    public class Program
    {
        public class Person
        {
            public int Age;

            //Here we use the Description attribute in order to set a custom name
            //for this field at the results grid and csv file.
            [Description("First Name")]
            public String Name;
        }

        public void OnExecute(IProcedureContext context)
        {
            //Add scalar result with the value 10.
            context.AddResult(ResultType.Passed, "My Scalar Result", 10);

            //Initialize a list of persons.
            List<Person> persons = new List<Person>();

            for (int i = 0; i < 100; i++)
            {
                Person p = new Person();
                p.Age = i;
                p.Name = "Name " + i;
                persons.Add(p);
            }

            //Add the persons list as a result.
            //This will allow the user to display a grid with all the persons in the list.
            //The list can also be exported to CSV.
            context.AddResult(ResultType.Passed, "Persons", persons);

            //Here is how we can get only the ages from the persons list and cast them as double values.
            List<double> ages = persons.Select(x => x.Age).Cast<double>().ToList();

            //Adding the ages list as a result..
            context.AddResult(ResultType.Passed, "Ages", ages);

            //Plotting the ages list as a graph result..
            context.AddGraphResult(ResultType.Passed, "Ages Graph", ages);



            //And here is how we can draw a completely customized result by drawing a bitmap.
            Bitmap bitmap = context.CreateBitmap(400, 200);
            Graphics g = context.GetDrawingContext(bitmap);

            //Draw a simple rectangle border.
            g.DrawRectangle(Pens.Gray, 0, 0, 399, 199);

            //Draw a diagonal red line across the rectangle.
            g.DrawLine(Pens.Red, 0, 0, 400, 200);

            //Draw a string at the center of the rect.
            Font font = new Font("Tahoma", 24, FontStyle.Bold, GraphicsUnit.Pixel);
            RectangleF layout = new RectangleF(0, 0, 400, 200);
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            g.DrawString("Bitmap Result", font, Brushes.YellowGreen, layout, format);

            //Dispose the drawing context after you done drawing.
            g.Dispose();

            context.AddBitmapResult(ResultType.Passed, "Bitmap Result", bitmap);
        }
    }
    #endregion
}