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 persons = new List(); 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 ages = persons.Select(x => x.Age).Cast().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 }