Example #1
0
        /// <summary>
        ///     Handle command line.
        /// </summary>
        /// <param name="command"></param>
        public static void CommandLine(string command)
        {
            switch (command.ToLower())
            {
            case "h":
                if (Program.ClassMinerConfigObject.mining_show_calculation_speed)
                {
                    WriteLine(
                        Program.TotalHashrate + " H/s | " + Program.TotalCalculation + " C/s > ACCEPTED[" +
                        Program.TotalBlockAccepted + "] REFUSED[" +
                        Program.TotalBlockRefused + "]", 4);
                }
                else
                {
                    WriteLine(
                        Program.TotalHashrate + " H/s | ACCEPTED[" +
                        Program.TotalBlockAccepted + "] REFUSED[" +
                        Program.TotalBlockRefused + "]", 4);
                }

                break;

            case "d":
                WriteLine("Current Block: " + Program.CurrentBlockId + " Difficulty: " +
                          Program.CurrentBlockDifficulty);
                break;

            case "c":
                if (Program.ClassMinerConfigObject.mining_enable_cache)
                {
                    var   allocationInMb = Process.GetCurrentProcess().PrivateMemorySize64 / 1e+6;
                    float availbleRam    = 0;

                    if (Environment.OSVersion.Platform == PlatformID.Unix)
                    {
                        availbleRam = long.Parse(ClassUtility.RunCommandLineMemoryAvailable());
                    }
                    else
                    {
                        if (_ramCounter == null)
                        {
                            _ramCounter = new PerformanceCounter("Memory", "Available MBytes", true);
                        }

                        availbleRam = _ramCounter.NextValue();
                    }

                    WriteLine("Current math combinaisons cached: " + Program.DictionaryCacheMining.Count.ToString("F0") + " | RAM Used: " + allocationInMb + " MB(s) | RAM Available: " + availbleRam + " MB(s).");
                }

                break;

            case "r":
                WriteLine("Current Range: " + Program.CurrentBlockJob.Replace(";", "|"));
                break;
            }
        }
        /// <summary>
        /// Insert new math combinaison
        /// </summary>
        /// <param name="combinaison"></param>
        /// <param name="idThread"></param>
        public bool InsertMathCombinaison(string combinaison, int idThread)
        {
            if (_lastDateRamCounted < DateTimeOffset.Now.ToUnixTimeSeconds())
            {
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    var availbleRam = long.Parse(ClassUtility.RunCommandLineMemoryAvailable());
                    _lastDateRamCounted = DateTimeOffset.Now.ToUnixTimeSeconds() + RamCounterInterval;
                    if (availbleRam <= _ramLimitInMb)
                    {
                        return(true);
                    }
                }
                else
                {
                    float availbleRam = _ramCounter.NextValue();
                    _lastDateRamCounted = DateTimeOffset.Now.ToUnixTimeSeconds() + RamCounterInterval;
                    if (availbleRam <= _ramLimitInMb)
                    {
                        return(true);
                    }
                }
            }

            try
            {
                if (MiningListCache.Count > 0)
                {
                    bool inserted = false;
                    for (int i = 0; i < MiningListCache.Count; i++)
                    {
                        if (!inserted)
                        {
                            if (i < MiningListCache.Count)
                            {
                                if (MiningListCache[i].Count < MaxMathCombinaisonPerCache)
                                {
                                    if (MiningListCache[i].ContainsKey(combinaison))
                                    {
                                        return(false);
                                    }

                                    MiningListCache[i].Add(combinaison, idThread);
                                    inserted = true;
                                }
                            }
                        }
                    }

                    if (!inserted)
                    {
                        MiningListCache.Add(new Dictionary <string, int>());
                        if (!MiningListCache[MiningListCache.Count - 1].ContainsKey(combinaison))
                        {
                            MiningListCache[MiningListCache.Count - 1].Add(combinaison, idThread);
                            return(true);
                        }
                    }
                }
                else
                {
                    MiningListCache.Add(new Dictionary <string, int>());
                    if (!MiningListCache[0].ContainsKey(combinaison))
                    {
                        MiningListCache[0].Add(combinaison, idThread);
                        return(true);
                    }

                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }