Ejemplo n.º 1
0
        private bool HandleReplInput(string request)
        {
            if (request.Equals("clear", StringComparison.OrdinalIgnoreCase))
            {
                outputTextBox.Clear();
            }
            else
            {
                Xgminer.Api.ApiContext apiContext = apiContexts[minerComboBox.SelectedIndex];
                if (apiContext != null)
                {
                    string response        = apiContext.GetResponse(request, Xgminer.Api.ApiContext.LongCommandTimeoutMs);
                    string requestResponse = String.Format("{0} => {1}{2}", request, Environment.NewLine, response);
                    outputTextBox.AppendText(Environment.NewLine + Environment.NewLine + requestResponse);
                }
                else
                {
                    minerComboBox.Focus();
                }
            }
            inputTextBox.Clear();
            if ((requests.Count == 0) || !requests.Last().Equals(request))
            {
                requests.Add(request);
            }
            requestIndex = requests.Count - 1;

            return(true);
        }
Ejemplo n.º 2
0
        private void SetNetworkDevicePool(int poolIndex)
        {
            DeviceViewModel networkDevice = (DeviceViewModel)deviceListView.FocusedItem.Tag;
            Uri uri = new Uri("http://" + networkDevice.Path);
            Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(uri.Port, uri.Host);

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            apiContext.SwitchPool(poolIndex);
        }
Ejemplo n.º 3
0
        private void RestartNetworkDevice()
        {
            DeviceViewModel networkDevice = (DeviceViewModel)deviceListView.FocusedItem.Tag;
            Uri uri = new Uri("http://" + networkDevice.Path);
            Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(uri.Port, uri.Host);

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            apiContext.RestartMining();
        }
Ejemplo n.º 4
0
        private VersionInformation GetVersionInfoFromAddress(string ipAddress, int port)
        {
            Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(port, ipAddress);

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            VersionInformation versionInformation = null;
            try
            {
                try
                {
                    versionInformation = apiContext.GetVersionInformation();
                }
                catch (IOException)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    versionInformation = null;
                }
            }
            catch (SocketException)
            {
                //won't be able to connect for the first 5s or so
                versionInformation = null;
            }

            return versionInformation;
        }
Ejemplo n.º 5
0
        private List<DeviceInformation> GetDeviceInfoFromAddress(string ipAddress, int port)
        {
            Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(port, ipAddress);

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            List<DeviceInformation> deviceInformationList = null;
            try
            {
                try
                {
                    //assume Network Devices, for now, run cgminer or older bfgminer with default --log of 5s
                    const int networkDeviceLogInterval = 5;
                    deviceInformationList = apiContext.GetDeviceInformation(networkDeviceLogInterval).Where(d => d.Enabled).ToList();
                }
                catch (IOException)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    deviceInformationList = null;
                }
            }
            catch (SocketException)
            {
                //won't be able to connect for the first 5s or so
                deviceInformationList = null;
            }

            return deviceInformationList;
        }
Ejemplo n.º 6
0
 private void CheckAndSetNetworkDifficulty(string ipAddress, int port, string coinSymbol)
 {
     double difficulty = GetMinerNetworkDifficulty(coinSymbol);
     if (difficulty == 0.0)
     {
         MultiMiner.Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(port, ipAddress);
         difficulty = GetNetworkDifficultyFromMiner(apiContext);
         SetMinerNetworkDifficulty(coinSymbol, difficulty);
     }
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll

            //download and install the latest version of bfgminer
            const string executablePath = @"D:\bfgminer\";
            const string executableName = "bfgminer.exe";
            MinerBackend minerBackend = MinerBackend.Bfgminer;

            Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}",
                executableName, Xgminer.Installer.GetMinerDownloadRoot(minerBackend), executablePath);

            //download and install bfgminer from the official website
            Xgminer.Installer.InstallMiner(minerBackend, executablePath);
            try
            {
                //create an instance of Miner with the downloaded executable
                MinerConfiguration minerConfiguration = new MinerConfiguration()
                {
                    MinerBackend = minerBackend,
                    ExecutablePath = Path.Combine(executablePath, executableName)
                };
                Miner miner = new Miner(minerConfiguration);

                //use it to iterate through devices
                List<Device> deviceList = miner.DeviceList();

                Console.WriteLine("Using {0} to list available mining devices", executableName);

                //output devices
                foreach (Device device in deviceList)
                    Console.WriteLine("Device detected: {0}\t{1}\t{2}", device.Kind, device.Driver, device.Identifier);

                //start mining if there are devices
                if (deviceList.Count > 0)
                {
                    Console.WriteLine("{0} device(s) detected, mining Bitcoin on Bitminter using all devices", deviceList.Count);

                    //setup a pool
                    MiningPool pool = new MiningPool()
                    {
                        Host = "mint.bitminter.com",
                        Port = 3333,
                        Username = "******",
                        Password = "******"
                    };
                    minerConfiguration.Pools.Add(pool);

                    //specify algorithm
                    minerConfiguration.Algorithm = CoinAlgorithm.SHA256;

                    //disable GPU mining
                    minerConfiguration.DisableGpu = true;

                    //specify device indexes to use
                    for (int i = 0; i < deviceList.Count; i++)
                        minerConfiguration.DeviceIndexes.Add(i);

                    //enable RPC API
                    minerConfiguration.ApiListen = true;
                    minerConfiguration.ApiPort = 4028;

                    Console.WriteLine("Launching {0}", executableName);

                    //start mining
                    miner = new Miner(minerConfiguration);
                    System.Diagnostics.Process minerProcess = miner.Launch();
                    try
                    {
                        //get an API context
                        Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(minerConfiguration.ApiPort);
                        try
                        {
                            //mine for one minute, monitoring hashrate via the API
                            for (int i = 0; i < 6; i++)
                            {
                                Thread.Sleep(1000 * 10); //sleep 10s

                                //query the miner process via its RPC API for device information
                                List<Xgminer.Api.DeviceInformation> deviceInformation = apiContext.GetDeviceInformation();

                                //output device information
                                foreach (Xgminer.Api.DeviceInformation item in deviceInformation)
                                    Console.WriteLine("Hasrate for device {0}: {1} current, {2} average", item.Index,
                                            item.CurrentHashrate, item.AverageHashrate);
                            }
                        }
                        finally
                        {
                            Console.WriteLine("Quitting mining via the RPC API");

                            //stop mining, try the API first
                            apiContext.QuitMining();
                        }
                    }
                    finally
                    {
                        Console.WriteLine("Killing any remaining process");

                        //then kill the process
                        try
                        {
                            minerProcess.Kill();
                            minerProcess.WaitForExit();
                            minerProcess.Close();
                        }
                        catch (InvalidOperationException ex)
                        {
                            //already closed
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No devices capable of mining detected");
                }
            }
            finally
            {
                Console.WriteLine("Cleaning up, deleting directory {0}", executablePath);
                Directory.Delete(executablePath, true);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll

            //download and install the latest version of Gateless Gate
            const string executablePath = @"D:\gatelessgate\";
            const string executableName = "gatlessgate.exe";
            const string userAgent      = "MultiMiner/V3-Example";

            //download and install bfgminer from MultiMinerApp.com
            List <AvailableMiner> availableMiners = AvailableMiners.GetAvailableMiners(userAgent);
            AvailableMiner        gatelessgate    = availableMiners.Single(am => am.Name.Equals(MinerNames.GatelessGate, StringComparison.OrdinalIgnoreCase));

            Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}",
                              executableName, new Uri(gatelessgate.Url).Authority, executablePath);

            MinerInstaller.InstallMiner(userAgent, gatelessgate, executablePath);
            try
            {
                //create an instance of Miner with the downloaded executable
                Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
                {
                    ExecutablePath = Path.Combine(executablePath, executableName)
                };
                Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration, false);

                //use it to iterate through devices
                List <Device> deviceList = miner.ListDevices();

                Console.WriteLine("Using {0} to list available mining devices", executableName);

                //output devices
                foreach (Device device in deviceList)
                {
                    Console.WriteLine("Device detected: {0}\t{1}\t{2}", device.Kind, device.Driver, device.Name);
                }

                //start mining if there are devices
                if (deviceList.Count > 0)
                {
                    Console.WriteLine("{0} device(s) detected, mining Bitcoin on Bitminter using all devices", deviceList.Count);

                    //setup a pool
                    MiningPool pool = new MiningPool()
                    {
                        Host     = "mint.bitminter.com",
                        Port     = 3333,
                        Username = "******",
                        Password = "******"
                    };
                    minerConfiguration.Pools.Add(pool);

                    //specify algorithm
                    minerConfiguration.Algorithm = MinerFactory.Instance.GetAlgorithm(AlgorithmNames.SHA256);

                    //disable GPU mining
                    minerConfiguration.DisableGpu = true;

                    //specify device indexes to use
                    for (int i = 0; i < deviceList.Count; i++)
                    {
                        minerConfiguration.DeviceDescriptors.Add(deviceList[i]);
                    }

                    //enable RPC API
                    minerConfiguration.ApiListen = true;
                    minerConfiguration.ApiPort   = 4028;

                    Console.WriteLine("Launching {0}", executableName);

                    //start mining
                    miner = new Xgminer.Miner(minerConfiguration, false);
                    System.Diagnostics.Process minerProcess = miner.Launch();
                    try
                    {
                        //get an API context
                        Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(minerConfiguration.ApiPort);
                        try
                        {
                            //mine for one minute, monitoring hashrate via the API
                            for (int i = 0; i < 6; i++)
                            {
                                Thread.Sleep(1000 * 10); //sleep 10s

                                //query the miner process via its RPC API for device information
                                List <Xgminer.Api.Data.DeviceInformation> deviceInformation = apiContext.GetDeviceInformation();

                                //output device information
                                foreach (Xgminer.Api.Data.DeviceInformation item in deviceInformation)
                                {
                                    Console.WriteLine("Hasrate for device {0}: {1} current, {2} average", item.Index,
                                                      item.CurrentHashrate, item.AverageHashrate);
                                }
                            }
                        }
                        finally
                        {
                            Console.WriteLine("Quitting mining via the RPC API");

                            //stop mining, try the API first
                            apiContext.QuitMining();
                        }
                    }
                    finally
                    {
                        Console.WriteLine("Killing any remaining process");

                        //then kill the process
                        try
                        {
                            minerProcess.Kill();
                            minerProcess.WaitForExit();
                            minerProcess.Close();
                        }
                        catch (InvalidOperationException)
                        {
                            //already closed
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No devices capable of mining detected");
                }
            }
            finally
            {
                Console.WriteLine("Cleaning up, deleting directory {0}", executablePath);
                Directory.Delete(executablePath, true);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 9
0
        private void ProcessRemoteCommands(List<MobileMiner.Data.RemoteCommand> commands)
        {
            if (commands.Count > 0)
            {
                MobileMiner.Data.RemoteCommand command = commands.First();

                //check this before actually executing the command
                //point being, say for some reason it takes 2 minutes to restart mining
                //if we check for commands again in that time, we don't want to process it again
                if (processedCommandIds.Contains(command.Id))
                    return;

                processedCommandIds.Add(command.Id);

                if (deleteRemoteCommandDelegate == null)
                    deleteRemoteCommandDelegate = DeleteRemoteCommand;

                if (command.Machine.Name.Equals(Environment.MachineName, StringComparison.OrdinalIgnoreCase))
                {
                    if (command.CommandText.Equals("START", StringComparison.OrdinalIgnoreCase))
                    {
                        SaveChangesLocally(); //necessary to ensure device configurations exist for devices
                        StartMiningLocally();
                    }
                    else if (command.CommandText.Equals("STOP", StringComparison.OrdinalIgnoreCase))
                        StopMiningLocally();
                    else if (command.CommandText.Equals("RESTART", StringComparison.OrdinalIgnoreCase))
                    {
                        StopMiningLocally();
                        SaveChangesLocally(); //necessary to ensure device configurations exist for devices
                        StartMiningLocally();
                    }
                    else if (command.CommandText.StartsWith("SWITCH", StringComparison.OrdinalIgnoreCase))
                    {
                        string[] parts = command.CommandText.Split('|');
                        string coinName = parts[1];
                        Engine.Data.Configuration.Coin coinConfiguration = engineConfiguration.CoinConfigurations.SingleOrDefault(cc => cc.CryptoCoin.Name.Equals(coinName));
                        if (coinConfiguration != null)
                            SetAllDevicesToCoinLocally(coinConfiguration.CryptoCoin.Symbol, true);
                    }

                    deleteRemoteCommandDelegate.BeginInvoke(command, deleteRemoteCommandDelegate.EndInvoke, null);
                }
                else
                {
                    string remoteMachineName = command.Machine.Name;
                    DeviceViewModel networkDevice = GetNetworkDeviceByFriendlyName(remoteMachineName);
                    if (networkDevice != null)
                    {
                        Uri uri = new Uri("http://" + networkDevice.Path);
                        Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(uri.Port, uri.Host);

                        //setup logging
                        apiContext.LogEvent -= LogApiEvent;
                        apiContext.LogEvent += LogApiEvent;

                        if (command.CommandText.StartsWith("SWITCH", StringComparison.OrdinalIgnoreCase))
                        {
                            string[] parts = command.CommandText.Split('|');
                            string poolName = parts[1];

                            List<PoolInformation> pools = networkDevicePools[networkDevice.Path];
                            int poolIndex = pools.FindIndex(pi => pi.Url.DomainFromHost().Equals(poolName, StringComparison.OrdinalIgnoreCase));

                            apiContext.SwitchPool(poolIndex);
                        }
                        else if (command.CommandText.Equals("RESTART", StringComparison.OrdinalIgnoreCase))
                        {
                            apiContext.RestartMining();
                        }

                        deleteRemoteCommandDelegate.BeginInvoke(command, deleteRemoteCommandDelegate.EndInvoke, null);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll

            //download and install the latest version of bfgminer
            const string executablePath = @"D:\bfgminer\";
            const string executableName = "bfgminer.exe";
            MinerBackend minerBackend   = MinerBackend.Bfgminer;

            Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}",
                              executableName, Xgminer.Installer.GetMinerDownloadRoot(minerBackend), executablePath);

            //download and install bfgminer from the official website
            Xgminer.Installer.InstallMiner(minerBackend, executablePath);
            try
            {
                //create an instance of Miner with the downloaded executable
                MinerConfiguration minerConfiguration = new MinerConfiguration()
                {
                    MinerBackend   = minerBackend,
                    ExecutablePath = Path.Combine(executablePath, executableName)
                };
                Miner miner = new Miner(minerConfiguration);

                //use it to iterate through devices
                List <Device> deviceList = miner.DeviceList();

                Console.WriteLine("Using {0} to list available mining devices", executableName);

                //output devices
                foreach (Device device in deviceList)
                {
                    Console.WriteLine("Device detected: {0}\t{1}\t{2}", device.Kind, device.Driver, device.Identifier);
                }

                //start mining if there are devices
                if (deviceList.Count > 0)
                {
                    Console.WriteLine("{0} device(s) detected, mining Bitcoin on Bitminter using all devices", deviceList.Count);

                    //setup a pool
                    MiningPool pool = new MiningPool()
                    {
                        Host     = "mint.bitminter.com",
                        Port     = 3333,
                        Username = "******",
                        Password = "******"
                    };
                    minerConfiguration.Pools.Add(pool);

                    //specify algorithm
                    minerConfiguration.Algorithm = CoinAlgorithm.SHA256;

                    //disable GPU mining
                    minerConfiguration.DisableGpu = true;

                    //specify device indexes to use
                    for (int i = 0; i < deviceList.Count; i++)
                    {
                        minerConfiguration.DeviceIndexes.Add(i);
                    }

                    //enable RPC API
                    minerConfiguration.ApiListen = true;
                    minerConfiguration.ApiPort   = 4028;

                    Console.WriteLine("Launching {0}", executableName);

                    //start mining
                    miner = new Miner(minerConfiguration);
                    System.Diagnostics.Process minerProcess = miner.Launch();
                    try
                    {
                        //get an API context
                        Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(minerConfiguration.ApiPort);
                        try
                        {
                            //mine for one minute, monitoring hashrate via the API
                            for (int i = 0; i < 6; i++)
                            {
                                Thread.Sleep(1000 * 10); //sleep 10s

                                //query the miner process via its RPC API for device information
                                List <Xgminer.Api.DeviceInformation> deviceInformation = apiContext.GetDeviceInformation();

                                //output device information
                                foreach (Xgminer.Api.DeviceInformation item in deviceInformation)
                                {
                                    Console.WriteLine("Hasrate for device {0}: {1} current, {2} average", item.Index,
                                                      item.CurrentHashrate, item.AverageHashrate);
                                }
                            }
                        }
                        finally
                        {
                            Console.WriteLine("Quitting mining via the RPC API");

                            //stop mining, try the API first
                            apiContext.QuitMining();
                        }
                    }
                    finally
                    {
                        Console.WriteLine("Killing any remaining process");

                        //then kill the process
                        try
                        {
                            minerProcess.Kill();
                            minerProcess.WaitForExit();
                            minerProcess.Close();
                        }
                        catch (InvalidOperationException ex)
                        {
                            //already closed
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No devices capable of mining detected");
                }
            }
            finally
            {
                Console.WriteLine("Cleaning up, deleting directory {0}", executablePath);
                Directory.Delete(executablePath, true);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 11
0
        private List<PoolInformationResponse> GetPoolInfoFromAddress(string ipAddress, int port)
        {
            Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(port, ipAddress);

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            List<PoolInformationResponse> poolInformation = null;
            try
            {
                try
                {
                    poolInformation = apiContext.GetPoolInformation();
                }
                catch (IOException ex)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    poolInformation = null;
                }
            }
            catch (SocketException ex)
            {
                //won't be able to connect for the first 5s or so
                poolInformation = null;
            }

            return poolInformation;
        }
Ejemplo n.º 12
0
        private List<DeviceInformationResponse> GetDeviceInfoFromAddress(string ipAddress, int port)
        {
            Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(port, ipAddress);

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            List<DeviceInformationResponse> deviceInformationList = null;
            try
            {
                try
                {
                    deviceInformationList = apiContext.GetDeviceInformation().Where(d => d.Enabled).ToList();
                }
                catch (IOException ex)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    deviceInformationList = null;
                }
            }
            catch (SocketException ex)
            {
                //won't be able to connect for the first 5s or so
                deviceInformationList = null;
            }

            return deviceInformationList;
        }
Ejemplo n.º 13
0
        private void SubmitMobileMinerNetworkDeviceStatistics(NetworkDevices.NetworkDevice networkDevice)
        {
            //are remote monitoring enabled?
            if (!applicationConfiguration.MobileMinerMonitoring)
                return;

            //is MobileMiner configured?
            if (string.IsNullOrEmpty(applicationConfiguration.MobileMinerApplicationKey) ||
                string.IsNullOrEmpty(applicationConfiguration.MobileMinerEmailAddress))
                return;

            List<MultiMiner.MobileMiner.Data.MiningStatistics> statisticsList = new List<MobileMiner.Data.MiningStatistics>();

            List<DeviceInformation> deviceInformationList = GetDeviceInfoFromAddress(networkDevice.IPAddress, networkDevice.Port);

            if (deviceInformationList == null) //handled failure getting API info
                return;

            List<PoolInformation> poolInformationList = GetCachedPoolInfoFromAddress(networkDevice.IPAddress, networkDevice.Port);

            Xgminer.Api.Data.VersionInformation versionInformation = new Xgminer.Api.ApiContext(networkDevice.Port, networkDevice.IPAddress).GetVersionInformation();

            foreach (DeviceInformation deviceInformation in deviceInformationList)
            {
                MobileMiner.Data.MiningStatistics miningStatistics = new MobileMiner.Data.MiningStatistics()
                {
                    MinerName = versionInformation.Name,
                    CoinName = NetworkDeviceCoinName,
                    CoinSymbol = NetworkDeviceCoinSymbol,
                    Algorithm = "SHA-256"
                };

                miningStatistics.PopulateFrom(deviceInformation);

                //ensure poolIndex is valid for poolInformationList
                //user(s) reported index errors so we can't out on the RPC API here
                //https://github.com/nwoolls/MultiMiner/issues/64
                if ((deviceInformation.PoolIndex >= 0) && (deviceInformation.PoolIndex < poolInformationList.Count))
                    miningStatistics.PoolName = poolInformationList[deviceInformation.PoolIndex].Url.DomainFromHost();

                statisticsList.Add(miningStatistics);
            }

            if (statisticsList.Count > 0)
            {
                if (submitMiningStatisticsDelegate == null)
                    submitMiningStatisticsDelegate = SubmitMiningStatistics;

                submitMiningStatisticsDelegate.BeginInvoke(statisticsList, networkDevice.IPAddress, submitMiningStatisticsDelegate.EndInvoke, null);
            }
        }
Ejemplo n.º 14
0
        private void AddNetworkMinerStatistics(List<MultiMiner.MobileMiner.Data.MiningStatistics> statisticsList)
        {
            //is Network Device detection enabled?
            if (!applicationConfiguration.NetworkDeviceDetection)
                return;

            foreach (Data.Configuration.NetworkDevices.NetworkDevice networkDevice in networkDevicesConfiguration.Devices)
            {
                List<DeviceInformation> deviceInformationList = GetDeviceInfoFromAddress(networkDevice.IPAddress, networkDevice.Port);

                if (deviceInformationList == null) //handled failure getting API info
                    continue;

                List<PoolInformation> poolInformationList = GetCachedPoolInfoFromAddress(networkDevice.IPAddress, networkDevice.Port);

                Xgminer.Api.Data.VersionInformation versionInformation = new Xgminer.Api.ApiContext(networkDevice.Port, networkDevice.IPAddress).GetVersionInformation();

                foreach (DeviceInformation deviceInformation in deviceInformationList)
                {
                    MobileMiner.Data.MiningStatistics miningStatistics = new MobileMiner.Data.MiningStatistics()
                    {
                        MachineName = String.Format("{0}:{1}", networkDevice.IPAddress, networkDevice.Port),
                        MinerName = versionInformation.Name,
                        CoinName = NetworkDeviceCoinName,
                        CoinSymbol = NetworkDeviceCoinSymbol,
                        Algorithm = "SHA-256"
                    };

                    miningStatistics.PopulateFrom(deviceInformation);

                    //ensure poolIndex is valid for poolInformationList
                    //user(s) reported index errors so we can't out on the RPC API here
                    //https://github.com/nwoolls/MultiMiner/issues/64
                    if ((deviceInformation.PoolIndex >= 0) && (deviceInformation.PoolIndex < poolInformationList.Count))
                        miningStatistics.PoolName = poolInformationList[deviceInformation.PoolIndex].Url.DomainFromHost();

                    statisticsList.Add(miningStatistics);
                }
            }
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll

            //download and install the latest version of BFGMiner
            const string executablePath = @"D:\bfgminer\";
            const string executableName = "bfgminer.exe";
            const string userAgent = "MultiMiner/V3-Example";

            //download and install bfgminer from MultiMinerApp.com
            List<AvailableMiner> availableMiners = AvailableMiners.GetAvailableMiners(userAgent);
            AvailableMiner bfgminer = availableMiners.Single(am => am.Name.Equals(MinerNames.BFGMiner, StringComparison.OrdinalIgnoreCase));

            Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}",
                executableName, new Uri(bfgminer.Url).Authority, executablePath);

            MinerInstaller.InstallMiner(userAgent, bfgminer, executablePath);
            try
            {
                //create an instance of Miner with the downloaded executable
                Xgminer.Data.Configuration.Miner minerConfiguration = new Xgminer.Data.Configuration.Miner()
                {
                    ExecutablePath = Path.Combine(executablePath, executableName)
                };
                Xgminer.Miner miner = new Xgminer.Miner(minerConfiguration, false);

                //use it to iterate through devices
                List<Device> deviceList = miner.ListDevices();

                Console.WriteLine("Using {0} to list available mining devices", executableName);

                //output devices
                foreach (Device device in deviceList)
                    Console.WriteLine("Device detected: {0}\t{1}\t{2}", device.Kind, device.Driver, device.Name);

                //start mining if there are devices
                if (deviceList.Count > 0)
                {
                    Console.WriteLine("{0} device(s) detected, mining Bitcoin on Bitminter using all devices", deviceList.Count);

                    //setup a pool
                    MiningPool pool = new MiningPool()
                    {
                        Host = "mint.bitminter.com",
                        Port = 3333,
                        Username = "******",
                        Password = "******"
                    };
                    minerConfiguration.Pools.Add(pool);

                    //specify algorithm
                    minerConfiguration.Algorithm = MinerFactory.Instance.GetAlgorithm(AlgorithmNames.SHA256);

                    //disable GPU mining
                    minerConfiguration.DisableGpu = true;

                    //specify device indexes to use
                    for (int i = 0; i < deviceList.Count; i++)
                        minerConfiguration.DeviceDescriptors.Add(deviceList[i]);

                    //enable RPC API
                    minerConfiguration.ApiListen = true;
                    minerConfiguration.ApiPort = 4028;

                    Console.WriteLine("Launching {0}", executableName);

                    //start mining
                    miner = new Xgminer.Miner(minerConfiguration, false);
                    System.Diagnostics.Process minerProcess = miner.Launch();
                    try
                    {
                        //get an API context
                        Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(minerConfiguration.ApiPort);
                        try
                        {
                            //mine for one minute, monitoring hashrate via the API
                            for (int i = 0; i < 6; i++)
                            {
                                Thread.Sleep(1000 * 10); //sleep 10s

                                //query the miner process via its RPC API for device information
                                List<Xgminer.Api.Data.DeviceInformation> deviceInformation = apiContext.GetDeviceInformation(minerConfiguration.LogInterval);

                                //output device information
                                foreach (Xgminer.Api.Data.DeviceInformation item in deviceInformation)
                                    Console.WriteLine("Hasrate for device {0}: {1} current, {2} average", item.Index,
                                            item.CurrentHashrate, item.AverageHashrate);
                            }
                        }
                        finally
                        {
                            Console.WriteLine("Quitting mining via the RPC API");

                            //stop mining, try the API first
                            apiContext.QuitMining();
                        }
                    }
                    finally
                    {
                        Console.WriteLine("Killing any remaining process");

                        //then kill the process
                        try
                        {
                            minerProcess.Kill();
                            minerProcess.WaitForExit();
                            minerProcess.Close();
                        }
                        catch (InvalidOperationException)
                        {
                            //already closed
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No devices capable of mining detected");
                }
            }
            finally
            {
                Console.WriteLine("Cleaning up, deleting directory {0}", executablePath);
                Directory.Delete(executablePath, true);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }