aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Emulations/Emulators/MobileEmulator.cs
blob: 086d256f22a9ddd9b63909447d4214c986660877 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tango.PMR;
using Tango.PMR.Common;
using Tango.PMR.Stubs;
using Tango.Transport;

namespace Tango.Emulations.Emulators
{
    public class MobileEmulator : EmulatorBase
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MobileEmulator "/> class.
        /// </summary>
        public MobileEmulator() : base()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MobileEmulator "/> class.
        /// </summary>
        /// <param name="transporter">The transporter.</param>
        public MobileEmulator(ITransporter transporter) : base(transporter)
        {

        }

        #endregion

        #region Override Methods

        /// <summary>
        /// Called on new request message.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="container">The container.</param>
        protected override void OnTransporterRequestReceived(object sender, RequestReceivedEventArgs e)
        {
            var container = e.Container;

            switch (container.Type)
            {
                case MessageType.CalculateRequest:

                    Thread.Sleep(1000);
                    var request = MessageFactory.ExtractMessageFromContainer<CalculateRequest>(container);
                    Transporter.SendResponse<CalculateResponse>(new CalculateResponse()
                    {
                        Sum = request.A + request.B,
                    }, container.Token);
                    break;
            }
        }

        #endregion
    }
}