aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService.Gateway/Web.Debug.config
blob: d7712aaf178326511b84c9be85967b18cc17241b (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
<?xml version="1.0"?>

<!-- For more information on using Web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=301874 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
    finds an attribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB"
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->
  <system.web>
    <!--
      In the example below, the "Replace" transform will replace the entire
      <customErrors> section of your Web.config file.
      Note that because there is only one customErrors section under the
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>
le.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.Core;
using Tango.Integration.Operation;
using Tango.PMR.Connection;
using Tango.Transport.Adapters;

namespace Tango.PPC.Common.Connection
{
    public class DefaultMachineProvider : ExtendedObject, IMachineProvider
    {
        private bool _isInitialized;

        public event EventHandler<MachineOperatorChangedEventArgs> MachineOperatorChanged;

        private Machine _machine;
        public Machine Machine
        {
            get
            {
                return _machine;
            }
            private set
            {
                _machine = value;
                RaisePropertyChangedAuto();
            }
        }

        private IMachineOperator _machineOperator;
        public IMachineOperator MachineOperator
        {
            get
            {
                return _machineOperator;
            }
            private set
            {
                var oldOperator = _machineOperator;
                _machineOperator = value;
                OnMachineOperatorChanged(oldOperator, _machineOperator);
                RaisePropertyChangedAuto();
            }
        }

        protected virtual void OnMachineOperatorChanged(IMachineOperator oldOperator, IMachineOperator newOperator)
        {
            MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(oldOperator, newOperator));
        }

        public DefaultMachineProvider()
        {
            MachineOperator = new MachineOperator();
        }

        public void Init()
        {
            if (!_isInitialized)
            {
                _isInitialized = true;

                Machine = ObservablesEntitiesAdapter.Instance.Machines.FirstOrDefault();
                ConnectToMachine();
            }
        }

        private async void ConnectToMachine()
        {
            try
            {
                Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse> scanner = new Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse>(UsbSerialBaudRates.BR_9600);
                var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, TimeSpan.FromSeconds(10));

                await MachineOperator.Disconnect();
                MachineOperator.Adapter = response.Adapter;
                await MachineOperator.Connect();
            }
            catch { }
        }
    }
}