Exemplo n.º 1
0
        public bool InitPluginContainer()
        {
            if (IsInitialized)
            {
                return(true);
            }
            IsInitialized = true;
            try
            {
                // set identity
                PluginUUID = _plugin.PluginUUID;
                Version    = _plugin.Version;
                Name       = _plugin.Name;
                Author     = _plugin.Author;

                // get devices
                var baseDevices = AvailableDevices.Devices.Select(dev => dev.BaseDevice);
                // get devs
                // register and add
                var allDevUUIDs = baseDevices.Select(d => d.UUID);
                var hasDeviceWithSupportedAlgos = false;
                var supported = _plugin.GetSupportedAlgorithms(baseDevices);
                // who knows who wrote this don't blindly trust the content
                if (supported != null)
                {
                    foreach (var kvp in supported)
                    {
                        var baseDev   = kvp.Key;
                        var baseAlgos = kvp.Value;
                        if (baseDev == null || baseAlgos == null)
                        {
                            // TODO this is something we should consider harmfull ???
                            continue;
                        }
                        if (allDevUUIDs.Contains(baseDev.UUID) == false)
                        {
                            Logger.Error(LogTag, $"InitPluginContainer plugin GetSupportedAlgorithms returned an unknown device {baseDev.UUID}. Setting plugin as broken");
                            SetAsBroken(this);
                            return(false);
                        }
                        if (baseAlgos.Count == 0)
                        {
                            continue;
                        }
                        hasDeviceWithSupportedAlgos = true;
                        _cachedAlgorithms[baseDev]  = baseAlgos;
                    }
                }
                // dependencies and services are considered compatible or if we have algorithms on any device
                IsCompatible = (_plugin is IBackgroundService) || (_plugin is IPluginDependency) || hasDeviceWithSupportedAlgos;
                if (!IsCompatible)
                {
                    return(false);
                }

                // transform
                foreach (var deviceAlgosPair in _cachedAlgorithms)
                {
                    var deviceUUID = deviceAlgosPair.Key.UUID;
                    var algos      = deviceAlgosPair.Value
                                     .Select(a => new AlgorithmContainer(a, this, AvailableDevices.GetDeviceWithUuid(deviceUUID)))
                                     .ToList();
                    _cachedNiceHashMinerAlgorithms[deviceUUID] = algos;
                }

                // Ethlargement extra check
                if (_plugin == EthlargementIntegratedPlugin.Instance)
                {
                    IsCompatible = EthlargementIntegratedPlugin.Instance.SystemContainsSupportedDevices;
                }
            }
            catch (Exception e)
            {
                SetAsBroken(this);
                Logger.Error(LogTag, $"InitPluginContainer error: {e.Message}");
                return(false);
            }


            return(true);
        }