コード例 #1
0
        /// <summary>
        /// Loads the settings about cpu-miner quark.
        /// </summary>
        public void LoadQuark(string p_localDirectory, bool p_debugLog, int p_priority, string p_defUserName, string p_defPassword, string p_defMinerOpt, string p_defPool, string p_defHost, string p_defArgs, int p_defPort)
        {
            //load the moose options
            Dictionary <string, MinerOption> _options = new Dictionary <string, MinerOption>();
            {
                MinerOption _option = new MinerOption()
                {
                    ArgumentFormat = " -a quark -q --url {host}:{port} -u {username} -p {password} {args}",
                    Arguments      = p_defArgs,
                    Path           = @"packages\qrk\quark.exe"
                };
                _options.Add("quark", _option);
            }

            //load the miners
            Dictionary <string, MinerSetting> _miners = new Dictionary <string, MinerSetting>();
            {
                MinerSetting _miner = new MinerSetting()
                {
                    Pool      = p_defPool,
                    OptionKey = p_defMinerOpt,
                    Arguments = p_defArgs,
                    Host      = p_defHost,
                    Port      = (short)p_defPort,
                    UserName  = p_defUserName,
                    Password  = p_defPassword,
                    Enabled   = true,

                    CrashRecovery = new MinerCrashRecoverySetting()
                    {
                        AlternateMiner = "",
                        Interval       = 60,
                        Retries        = 3
                    },

                    Logging = new MinerLogSetting()
                    {
                        Enabled     = false,
                        MaxFileSize = 1048576
                    },

                    Process = new MinerProcessSetting()
                    {
                        Priority        = (short)p_priority,
                        CPUAffinity     = "",
                        LoadUserProfile = false,
                        WinDomain       = "",
                        WinUserName     = "",
                        WinPassword     = ""
                    },

                    StatusUpdates = false
                };

                _miners.Add("Default", _miner);
            }

            //load the pools
            List <MiningPool> _pools = new List <MiningPool>();

            {
                MiningPool _pool = new MiningPool()
                {
                    Name    = "coinmine",
                    Host    = "qrk.coinmine.pl",
                    Port    = 6010,
                    Website = "http://www2.coinmine.pl/qrk/"
                };
                _pools.Add(_pool);
            }

            //set values
            this.BitMoosePath       = p_localDirectory;
            this.DebugLogging       = p_debugLog;
            this.DefaultUserName    = (p_defUserName ?? DefaultUserNameValue).Trim();
            this.DefaultPassword    = (p_defPassword ?? DefaultPasswordValue).Trim();
            this.DefaultMinerOption = p_defMinerOpt;
            this.DefaultPool        = p_defPool;
            this.MinerOptions       = _options;
            this.Miners             = _miners;
            this.Pools = _pools.ToArray();
        }
コード例 #2
0
        /// <summary>
        /// Loads the settings from the XML file.
        /// </summary>
        public void Load(string p_config_file_name)
        {
            string _localDirectory = Path.GetDirectoryName(p_config_file_name);

            if (Directory.Exists(_localDirectory))
            {
                if (File.Exists(p_config_file_name))
                {
                    Dictionary <string, MinerOption>  _options = new Dictionary <string, MinerOption>();
                    Dictionary <string, MinerSetting> _miners  = new Dictionary <string, MinerSetting>();

                    XDocument _xdoc = null;
                    try
                    {
                        _xdoc = XDocument.Load(p_config_file_name);
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException("Failed to load settings from XML file. " + ex.Message, ex);
                    }

                    //load the defaults
                    bool debugLog = false;
                    if (_xdoc.Root.Element("DebugLogging") != null)
                    {
                        debugLog = Convert.ToBoolean(_xdoc.Root.Element("DebugLogging").Value);
                    }

                    string defUserName = (from n in _xdoc.Root.Descendants("DefaultUserName")
                                          select n.Value).FirstOrDefault();
                    string defPassword = (from n in _xdoc.Root.Descendants("DefaultPassword")
                                          select n.Value).FirstOrDefault();
                    string defMinerOpt = (from n in _xdoc.Root.Descendants("DefaultMinerOption")
                                          select n.Value).FirstOrDefault();
                    string defPool = (from n in _xdoc.Root.Descendants("DefaultPool")
                                      select n.Value).FirstOrDefault();

                    //load the moose options
                    foreach (var element in _xdoc.Root.Element("MinerOptions").Descendants("MinerOption"))
                    {
                        string      name = null;
                        MinerOption opt  = LoadMinerOption(element, out name);
                        if (_options.ContainsKey(name))
                        {
                            throw new ApplicationException(String.Format("Duplicate moose option name '{0}' detected. moose names must be unique.", name));
                        }
                        _options.Add(name, opt);
                    }

                    //load the miners
                    int minerIndex = 1;
                    foreach (var element in _xdoc.Root.Element("Miners").Descendants("Miner"))
                    {
                        string       name = null;
                        MinerSetting m    = LoadMiner(element, out name);
                        name       = name ?? String.Format("Miner #{0}", minerIndex);
                        m.UserName = m.UserName ?? defUserName;
                        m.Password = m.Password ?? defPassword;
                        if (_miners.ContainsKey(name))
                        {
                            throw new ApplicationException(String.Format("Duplicate moose name '{0}' detected. moose names must be unique.", name));
                        }
                        _miners.Add(name, m);
                        minerIndex++;
                    }

                    //load the pools
                    List <MiningPool> pools = new List <MiningPool>();
                    foreach (var element in _xdoc.Root.Element("Pools").Descendants("Pool"))
                    {
                        MiningPool pool = new MiningPool()
                        {
                            Name = element.Attribute("name").Value,
                            Host = element.Attribute("host").Value,
                            Port = Convert.ToInt16(element.Attribute("port").Value)
                        };
                        if (element.Attribute("website") != null)
                        {
                            pool.Website = element.Attribute("website").Value;
                        }
                        pools.Add(pool);
                    }

                    //validate
                    if (String.IsNullOrEmpty(defMinerOpt))
                    {
                        throw new ApplicationException("The default moose option is not specified in the settings file. It must be named as the value for the 'DefaultMinerOption' element.");
                    }

                    foreach (var option in _options)
                    {
                        if (File.Exists(option.Value.Path) == false)
                        {
                            if (File.Exists(Path.Combine(_localDirectory, option.Value.Path)) == false)
                            {
                                throw new ApplicationException(String.Format("Invalid path for moose option '{0}'. The file was not found or is inaccessible.", option.Key));
                            }
                            else
                            {
                                option.Value.Path = Path.Combine(_localDirectory, option.Value.Path); //update path to use combined.
                            }
                        }
                        if (String.IsNullOrEmpty(option.Key))
                        {
                            throw new ApplicationException("Invalid name on moose option. All moose options must have a name attribute specified with a unique value.");
                        }
                    }

                    foreach (var _miner in _miners)
                    {
                        if (_options.ContainsKey(_miner.Value.OptionKey) == false)
                        {
                            throw new ApplicationException(String.Format("Invalid option value '{1}' on moose '{0}'. The option value must be a name from the available moose options.", _miner.Key, _miner.Value.OptionKey));
                        }
                        if (String.IsNullOrEmpty(_miner.Key))
                        {
                            throw new ApplicationException("Invalid name on moose. All miners must have a name attribute specified with a unique value.");
                        }
                    }

                    if (String.IsNullOrEmpty(defPool) == false && pools.Any(a => a.Name == defPool) == false)
                    {
                        throw new ApplicationException("The specified default pool does not exist.");
                    }

                    //set values
                    this.BitMoosePath       = _localDirectory;
                    this.DebugLogging       = debugLog;
                    this.DefaultUserName    = (defUserName ?? DefaultUserNameValue).Trim();
                    this.DefaultPassword    = (defPassword ?? DefaultPasswordValue).Trim();
                    this.DefaultMinerOption = defMinerOpt;
                    this.DefaultPool        = defPool;
                    this.MinerOptions       = _options;
                    this.Miners             = _miners;
                    this.Pools = pools.ToArray();
                }
                else
                {
                    throw new FileNotFoundException(String.Format("The settings file '{0}' was not found or is inaccessible.", p_config_file_name), p_config_file_name);
                }
            }
            else
            {
                throw new DirectoryNotFoundException(String.Format("The directory path '{0}' was not found or is inaccessible.", _localDirectory));
            }
        }
コード例 #3
0
        /// <summary>
        /// Loads the moose from the settings XML into an represenative object
        /// </summary>
        private MinerSetting LoadMiner(XElement p_xminer, out string p_oname)
        {
            MinerSetting _ms = new MinerSetting();

            p_oname = p_xminer.Attribute("name").Value;

            _ms.OptionKey = p_xminer.Attribute("option").Value;
            if (p_xminer.Attribute("arguments") != null)
            {
                _ms.Arguments = p_xminer.Attribute("arguments").Value;
            }
            if (p_xminer.Attribute("pool") != null)
            {
                _ms.Pool = p_xminer.Attribute("pool").Value;
            }
            if (p_xminer.Attribute("host") != null)
            {
                _ms.Host = p_xminer.Attribute("host").Value;
            }
            if (p_xminer.Attribute("port") != null)
            {
                short port = 8332;
                if (short.TryParse(p_xminer.Attribute("port").Value, out port))
                {
                    _ms.Port = port;
                }
            }
            if (p_xminer.Attribute("username") != null)
            {
                _ms.UserName = p_xminer.Attribute("username").Value;
            }
            if (p_xminer.Attribute("password") != null)
            {
                _ms.Password = p_xminer.Attribute("password").Value;
            }
            if (p_xminer.Attribute("enabled") != null)
            {
                _ms.Enabled = Convert.ToBoolean(p_xminer.Attribute("enabled").Value);
            }
            if (p_xminer.Attribute("netupdate") != null)
            {
                _ms.StatusUpdates = Convert.ToBoolean(p_xminer.Attribute("netupdate").Value);
            }

            //load logging
            _ms.Logging = new MinerLogSetting();
            XElement logElement = p_xminer.Element("Log");

            if (logElement != null)
            {
                if (logElement.Attribute("enabled") != null)
                {
                    _ms.Logging.Enabled = Convert.ToBoolean(logElement.Attribute("enabled").Value);
                }
                if (logElement.Attribute("maxfilesize") != null)
                {
                    _ms.Logging.MaxFileSize = Convert.ToInt32(logElement.Attribute("maxfilesize").Value);
                }
            }

            //load crash recovery
            _ms.CrashRecovery = new MinerCrashRecoverySetting();
            XElement recoveryElement = p_xminer.Element("CrashRecovery");

            if (recoveryElement != null)
            {
                if (recoveryElement.Attribute("retries") != null)
                {
                    _ms.CrashRecovery.Retries = Convert.ToInt32(recoveryElement.Attribute("retries").Value);
                }
                if (recoveryElement.Attribute("interval") != null)
                {
                    _ms.CrashRecovery.Interval = Convert.ToInt32(recoveryElement.Attribute("interval").Value);
                }
                if (recoveryElement.Attribute("altminer") != null)
                {
                    _ms.CrashRecovery.AlternateMiner = recoveryElement.Attribute("altminer").Value;
                }
            }

            //load process
            _ms.Process = new MinerProcessSetting();
            XElement procElement = p_xminer.Element("Process");

            if (procElement != null)
            {
                if (procElement.Attribute("priority") != null)
                {
                    _ms.Process.Priority = Convert.ToInt16(procElement.Attribute("priority").Value);
                }
                if (procElement.Attribute("loadprofile") != null)
                {
                    _ms.Process.LoadUserProfile = Convert.ToBoolean(procElement.Attribute("loadprofile").Value);
                }
                if (procElement.Attribute("windomain") != null)
                {
                    _ms.Process.WinDomain = procElement.Attribute("windomain").Value;
                }
                if (procElement.Attribute("winusername") != null)
                {
                    _ms.Process.WinUserName = procElement.Attribute("winusername").Value;
                }
                if (procElement.Attribute("winpassword") != null)
                {
                    _ms.Process.WinPassword = procElement.Attribute("winpassword").Value;
                }
                if (procElement.Attribute("cpuaffinity") != null)
                {
                    _ms.Process.CPUAffinity = (procElement.Attribute("cpuaffinity").Value ?? String.Empty).Trim();
                }
            }
            return(_ms);
        }