Пример #1
0
 internal void Update(DiscChanger discChanger, string name, string type, string connection, string commandMode, string portName, bool?HardwareFlowControl, string networkHost, int?networkPort)
 {
     lock (this.DiscChangers)
     {
         if (DiscChangers.Any(dc => dc != discChanger && dc.Name == name))
         {
             throw new Exception($"Name {name} already exists");
         }
         if (DiscChangers.Any(dc => dc != discChanger && dc.Connection == connection && dc.PortName == portName && dc.NetworkHost == networkHost && dc.NetworkPort == networkPort))
         {
             throw new Exception($"Connection {connection}:{portName} {networkHost} already in use");
         }
         discChanger.Name = name;
         discChanger.Type = type;
         if (discChanger.Connection != connection ||
             discChanger.PortName != portName ||
             discChanger.CommandMode != commandMode ||
             discChanger.HardwareFlowControl != HardwareFlowControl ||
             discChanger.NetworkHost != networkHost ||
             discChanger.NetworkPort != networkPort)
         {
             discChanger.Disconnect();
             //discChanger.Protocol   = protocol;
             discChanger.Connection          = connection;
             discChanger.CommandMode         = commandMode;
             discChanger.PortName            = portName;
             discChanger.HardwareFlowControl = HardwareFlowControl;
             discChanger.NetworkHost         = networkHost;
             discChanger.NetworkPort         = networkPort;
             discChanger.Connect(this, this._hubContext, _logger);
         }
     }
 }
Пример #2
0
        internal async Task <string> Test(string key, string type, string connection, string commandMode, string portName, bool?HardwareFlowControl, string networkHost, int?networkPort)
        {
            DiscChanger d = null;
            bool        b = key != null && key2DiscChanger.TryGetValue(key, out d) && connection == d.Connection && portName == d.PortName && networkHost == d.NetworkHost && networkPort == d.NetworkPort;

            if (b)
            {
                d.Disconnect();
            }
            DiscChanger dc = DiscChanger.Create(type);

            try
            {
                dc.Connection          = connection;
                dc.CommandMode         = commandMode;
                dc.PortName            = portName;
                dc.HardwareFlowControl = HardwareFlowControl;
                dc.NetworkHost         = networkHost;
                dc.NetworkPort         = networkPort;
                await dc.Connect(null, null, _logger);

                return(await dc.Test());
            }
            catch (Exception e)
            {
                return($"Disc changer testing of ({key},{type},{connection},{commandMode},{portName},{HardwareFlowControl},{networkHost}) returned error: {e.Message}");
            }
            finally
            {
                dc.Disconnect();
                if (b)
                {
                    await d.Connect();
                }
            }
        }