aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/Examples/SendContinuous/Program.cs
blob: 2f81156423bdec78223dc7bf574e39e40d108552 (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
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.SendContinuous
{
    #region Example
    public class Program
    {
        private IProcedureContext _context;

        public void OnExecute(IProcedureContext context)
        {
            //Sends a continuous request by providing the request name, a callback method and comma separated arguments.
            context.SendContinuous<ProgressResponse>("ProgressRequest", (response) =>
            {
                //Each response will be provided here...
                context.WriteLine(response);
            }, 100, 10);


            //Sends a continuous request by providing the request name, a callback method, a timeout, and comma separated arguments.
            context.SendContinuous<ProgressResponse>("progress", (response) =>
            {
                context.WriteLine(response);
            }, TimeSpan.FromSeconds(5), 100, 10);


            //Sends a continuous request by providing the request object, a callback method and a 5 seconds timeout.
            ProgressRequest request = new ProgressRequest();
            request.Amount = 100;
            request.Delay = 10;

            context.SendContinuous<ProgressResponse>(request, (response) =>
            {
                context.WriteLine(response);
            }, 5);


            //Sends a continuous request by providing the request object, a defined callback method and a 5 seconds timeout.
            //We need to store the context globally so the callback method will have access to it.
            _context = context;
            context.SendContinuous<ProgressResponse>(request, OnProgressResponse, 5);
        }

        private void OnProgressResponse(ProgressResponse response)
        {
            _context.WriteLine(response);
        }
    }
    #endregion
}