コード例 #1
0
        private void UpdateDeviceStatTimer_Tick(object sender, EventArgs e)
        {
            Speed = 0;
            double cpuSpeed = 0;
            double gpuSpeed = 0;

            Devices.ForEach(x => { x.Speed = 0; });

            if (!IsIdle)
            {
                foreach (var mp in _minerProcesses)
                {
                    foreach (var miner in mp.Miners)
                    {
                        Devices.Where(x => x.ADLAdapterIndex == miner.Device.ADLAdapterIndex).FirstOrDefault().Speed += miner.Speed;
                        gpuSpeed += miner.Speed;
                    }
                }

                try
                {
                    if (SelectedMinerSettings.IsCPUMiningEnabled && SelectedMinerSettings.ApplicationMode.Equals(ApplicationMode.Normal))
                    {
                        using (var client = new WebClient())
                        {
                            var json     = client.DownloadString("http://localhost:54321");
                            var response = JsonConvert.DeserializeObject <XmrigJson>(json);

                            if (response != null)
                            {
                                cpuSpeed += response.hashrate.total.First();

                                var cpuDevice = Devices.Where(x => x.ADLAdapterIndex == -2).FirstOrDefault();
                                if (cpuDevice != null)
                                {
                                    cpuDevice.Speed          = cpuSpeed;
                                    cpuDevice.SharesAccepted = response.results.shares_good;
                                    cpuDevice.SharesRejected = response.results.shares_total - response.results.shares_good;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    //ham megesszük
                };
            }

            Speed = cpuSpeed + gpuSpeed;

            if (SelectedMinerSettings.IsRemoteManagementEnabled)
            {
                List <SimpleDevice> devices = new List <SimpleDevice>();
                Devices.ForEach(x => devices.Add(new SimpleDevice()
                {
                    Activity  = x.Activity,
                    Algo      = string.Empty,
                    Fan       = x.FanSpeed,
                    ID        = x.ADLAdapterIndex,
                    Intensity = x.Intensity,
                    Name      = x.Name,
                    Speed     = x.Speed,
                    Temp      = x.Temperature,
                    Threads   = x.Threads,
                    Worksize  = x.WorkSize,
                    Shares    = x.Shares
                }));
                RemoteManagerHandler.SendMessageAsync(new SimpleMinerManager.Model.StatusMessage()
                {
                    CPUSpeed = cpuSpeed, GPUSpeed = gpuSpeed, Speed = Speed, IP = IPAddress, Worker = SelectedMinerSettings.RemoteManagerWorkerName, Devices = devices, State = IsIdle ? "Idle" : "Working"
                }, SelectedMinerSettings.RemoteManagerHost);
            }

            Hash = $"Current speed {Speed:N2} h/s (CPU: {cpuSpeed:N2} h/s, GPU: {gpuSpeed:N2} h/s)";
            RaisePropertyChanged(nameof(Hash));
            RefreshDevices?.Invoke();
            //Messenger.Default.Send<MinerOutputMessage>(new MinerOutputMessage() { OutputText = Hash });
        }
コード例 #2
0
        public MainViewModel()
        {
            setDefaultValues();

            registerMessageListeners();

            Log.SetLogger(log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
            Log.InsertInfo($"Starting Simple Miner v{VersionNumber} OS: Windows{OSType}");

            Utils.TryKillProcess(Consts.ProcessName);

            loadConfigFile();
            SetApplicationMode(SelectedMinerSettings.ApplicationMode);

            if (SelectedMinerSettings.IsAutoUpdateEnabled)
            {
                if (Process.GetProcessesByName("SimpleMinerUpdater2").Length == 0)
                {
                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        File.Copy(AutoUpdatePathOrig, AutoUpdatePath, true);
                        var psi = new ProcessStartInfo()
                        {
                            FileName        = AutoUpdatePath,
                            UseShellExecute = false,
                            CreateNoWindow  = true
                        };

#if X86
                        psi.Arguments = "is32bit";
#endif
                        Process.Start(psi);
                    });
                }
            }

            if (SelectedMinerSettings.IsRemoteManagementEnabled)
            {
                List <SimpleDevice> devices = new List <SimpleDevice>();
                Devices.ForEach(x => devices.Add(new SimpleDevice()
                {
                    Activity  = x.Activity,
                    Algo      = string.Empty,
                    Fan       = x.FanSpeed,
                    ID        = x.ADLAdapterIndex,
                    Intensity = x.Intensity,
                    Name      = x.Name,
                    Speed     = x.Speed,
                    Temp      = x.Temperature,
                    Threads   = x.Threads,
                    Worksize  = x.WorkSize,
                    Shares    = x.Shares
                }));

                RemoteManagerHandler.SendMessageAsync(new SimpleMinerManager.Model.RegisterMessage()
                {
                    IP      = IPAddress,
                    Worker  = SelectedMinerSettings.RemoteManagerWorkerName,
                    Devices = devices,
                    RemotePoolListEnabled = SelectedMinerSettings.IsRemotePoolListEnabled,
                    State   = "Idle",
                    Version = Consts.VersionNumber
                }, SelectedMinerSettings.RemoteManagerHost);
            }

            ThreadNumber       = SelectedMinerSettings.NumberOfThreads;
            isAutostartMining  = SelectedMinerSettings.IsAutostartMining;
            StartingDelayInSec = SelectedMinerSettings.StartingDelayInSec;

            SetCommands();

            tempDelayInSec = SelectedMinerSettings.StartingDelayInSec;
            if (SelectedMinerSettings.IsLaunchOnWindowsStartup && SelectedMinerSettings.IsLaunchOnWindowsStartup != Utils.IsStartupItem())
            {
                setStartup(0);
            }
            else
            {
                Utils.RemoveProgramFromStartup();
            }

            if (SelectedMinerSettings.IsAutostartMining)
            {
                autoStartMiningWithDelay();
            }

            if (IsGenerateDefaultPoolList)
            {
                SavePools(null);
            }

            if (CustomSettings != null)
            {
                AboutContact = CustomSettings.ContactEmailAddress ?? AboutContact;
            }

            if (SelectedMinerSettings.VersionNumber != VersionNumber)
            {
                DirectoryInfo di = new DirectoryInfo(ApplicationPath + "\\Miners\\Kernel\\Bins");

                if (di.Exists)
                {
                    foreach (var file in di.GetFiles())
                    {
                        file.Delete();
                    }
                }

                SelectedMinerSettings.VersionNumber = VersionNumber;
            }

            InitializeOpenCLDevices();
        }