コード例 #1
0
        private void LoadDevice(IMiningDeviceObject d)
        {
            IDeviceLoader loader = d as IDeviceLoader;

            if (loader != null)
            {
                foreach (IMiningDevice device in loader.LoadDevices())
                {
                    LoadDevice(device);
                }
            }
            else
            {
                IHotplugLoader hotplugLoader = d as IHotplugLoader;

                if (hotplugLoader != null)
                {
                    hotplugLoader.DeviceFound += this.AddNewDevice;
                    hotplugLoader.StartListening();

                    lock (hotplugListLock)
                    {
                        hotplugLoaders.Add(hotplugLoader);
                    }
                }
                else
                {
                    IMiningDevice device = d as IMiningDevice;

                    if (device != null)
                    {
                        lock (deviceListLock)
                        {
                            device.Id = deviceId;
                            deviceId++;

                            loadedDevices.Add(device);
                        }

                        device.ValidNonce    += this.SubmitWork;
                        device.WorkRequested += this.RequestWork;
                        device.InvalidNonce  += this.InvalidNonce;

                        device.Connected    += OnDeviceConnected;
                        device.Disconnected += OnDeviceDisconnected;

                        device.Load();

                        this.SetUpDevice(device);
                    }
                }
            }
        }
コード例 #2
0
        Task LoadAsync(ILog log, IDeviceLoader deviceManager, string name)
        {
            log.Description = $"{name} Listing (in progress)";

            var capturedLog = log;

            return(deviceManager.LoadDevices(capturedLog, includeLocked: false, forceRefresh: true).ContinueWith((v) => {
                if (v.IsFaulted)
                {
                    capturedLog.WriteLine("Failed to load:");
                    capturedLog.WriteLine(v.Exception.ToString());
                    capturedLog.Description = $"{name} Listing {v.Exception.Message})";
                }
                else if (v.IsCompleted)
                {
                    capturedLog.Description = deviceManager switch
                    {
                        IHardwareDeviceLoader d => BuildDevicesDescription(d, name),
                        ISimulatorLoader s => BuildSimulatorsDescription(s, name),
                        _ => throw new NotImplementedException(),
                    };
                }
            }));
        }