Пример #1
0
 private void _mySignalRMiningDataReceivedHandler(object sender, MiningData miningData)
 {
     Application.Current.Dispatcher.BeginInvoke(new Action(() =>
     {
         // Got message from SignalR ==> discard here in client
         Debug.WriteLine($"Got MiningData from {miningData.Sender}");
     }));
 }
Пример #2
0
 public MiningData HandleNewMiningData(MiningData miningData)
 {
     //var miningData = new MiningDataRepository().GetMiningDataFromRepository(miningData.Sender);
     //if (miningData != null)
     //{
     //    SignalRManager.TriggerSendData(miningData);
     //}
     return(miningData);
 }
Пример #3
0
        public MiningData GetMiningDataFromRepository(string sender)
        {
            try
            {
                HttpContext.Current.Application.Lock(); // BAD for performance, do never use in real world!
                int eventACounter = (int)HttpContext.Current.Application["EventA"];
                int eventBCounter = (int)HttpContext.Current.Application["EventB"];
                int eventCCounter = (int)HttpContext.Current.Application["EventC"];
                int eventDCounter = (int)HttpContext.Current.Application["EventD"];
                //switch (id)
                //{
                //    case 1:
                //        eventACounter++;
                //        break;
                //    case 2:
                //        eventBCounter++;
                //        break;
                //    case 3:
                //        eventCCounter++;
                //        break;
                //    case 4:
                //        eventDCounter++;
                //        break;
                //}
                HttpContext.Current.Application["EventA"] = eventACounter;
                HttpContext.Current.Application["EventB"] = eventBCounter;
                HttpContext.Current.Application["EventC"] = eventCCounter;
                HttpContext.Current.Application["EventD"] = eventDCounter;

                var miningData = new MiningData()
                {
                    //Sender = id.ToString(),
                    //Timestamp = DateTime.UtcNow.ToString("HH:mm:ss"),
                    //EventACount = eventACounter,
                    //EventBCount = eventBCounter,
                    //EventCCount = eventCCounter,
                    //EventDCount = eventDCounter,
                };
                return(miningData);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                HttpContext.Current.Application.UnLock();
            }
            return(null);
        }
Пример #4
0
 public async Task SendDataToMiningCenter(MiningData miningData)
 {
     try
     {
         if (hubConnection.State == ConnectionState.Connected)
         {
             await hubProxy.Invoke("SendDataToMiningCenter", miningData);
         }
         else
         {
             await HubReconnect();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("SendDataToMiningCenter() failed wit ex:" + ex.Message);
     }
 }
Пример #5
0
        public void SendDataToMiningCenter(MiningData miningData)
        {
            Clients.All.SendDataToMiningCenter(miningData); // defined in Interface => define camelCased in Javascript on the client

            //    Debug.WriteLine($"SendDataToBank({miningData.Sender}, {miningData.CrunchesPerSecond}");
            //    //            var motionRepos = new MotionDataRepository();
            //    //            var motionData = motionRepos.HandleMotion(id);
            //    //            SignalRManager.TriggerSendData(motionData);
            //    //try
            //    //{
            //    //    Debug.WriteLine($"TriggerSendData({miningData}");
            //    //    var hubContext = GlobalHost.ConnectionManager.GetHubContext<MiningHub>();
            //    //    if (hubContext != null)
            //    //    {
            //    //        hubContext.Clients.All.SendDataToMiningCenter(miningData);
            //    //    }
            //    //}
            //    //catch (Exception ex)
            //    //{
            //    //    LogiT
            //    //}
        }
Пример #6
0
        public void NumbersShouldFactorCorrectly()
        {
            const double rate  = 4.0365457518060869E-05;
            const double speed = 57644160;

            var stats = new MiningStats.DeviceMiningStats
            {
                Rates = new List <(AlgorithmType type, double rate)>
                {
                    (AlgorithmType.Lyra2REv3, rate)
                },
                Speeds = new List <(AlgorithmType type, double speed)>
                {
                    (AlgorithmType.Lyra2REv3, speed)
                },
                PowerUsageAPI           = 300,
                PowerUsageDeviceReading = 280.435
            };

            var data = new MiningData(new ComputeDevice(null, 0, ""));

            data.Stats = stats;

            Assert.AreEqual(speed, data.Hashrate);
            Assert.AreEqual(rate, data.Payrate);
            Assert.AreEqual(300, data.PowerUsage);

            ExchangeRateApi.UsdBtcRate           = 10000;
            ConfigManager.GeneralConfig.KwhPrice = 0.1;

            Assert.AreEqual(rate * 10000, data.FiatPayrate);

            // 300W uses 0.3 * 24 = 7.2 kWh per day
            // At 10 cents per kWh that is 72 cents
            Assert.AreEqual(0.72, data.PowerCost, 0.00005);
            Assert.AreEqual(rate * 10000 - 0.72, data.Profit, 0.00005);
        }
    }
Пример #7
0
        private void UpdateUI(int requestPerSecond, long copyOfTotalRequestCount, int secondsSinceThreadStart, string msg)
        {
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                if (lstStatus.Items.Count > 100)
                {
                    lstStatus.Items.RemoveAt(99);
                }
                var time = DateTime.Now.ToString("HH:mm:ss");

                if (String.IsNullOrEmpty(msg))
                {
                    msg = $"{time}: {txtCount.Text} threads: / {requestPerSecond} req/sec Total Req: {copyOfTotalRequestCount} / Seconds elapsed: {secondsSinceThreadStart}";
                }
                lstStatus.Items.Insert(0, new ListBoxItem().Content = msg);

                MiningData miningData = new MiningData()
                {
                    Sender = MinerName, CrunchesPerSecond = requestPerSecond, Timestamp = time
                };
                _mySignalRComMgr.SendDataToMiningCenter(miningData);
            }));
        }