public BotModel(Bot bot) { this.Id = bot.Id; this.Name = bot.Name ?? bot.IPAddress; this.WorkHours = Format.AsAge(bot.CreationDate); this.Profit = Format.AsBitCoin(bot.Balance); this.Efficiency = Format.AsPercent(bot.Share, bot.TotalShare); this.EfficiencyText = string.Format("工作:{0} (总数:{1})", bot.Share, bot.TotalShare); this.Shares = Format.AsCurrentAndPercent(bot.Share, Server.Recent.TotalShare); this.Action = bot.Account == null ? "Authorize" : "Manage"; this.ActionText = bot.Account == null ? "认领" : "管理"; //try get mine information from bot var cm = ComputeManager.ByBot(bot); if (cm != null) { var mine = Mine.Find(cm.MineId); if (mine != null) { this.MineIcon = mine.Icon; this.MineText = mine.IconName; } } //try get bot speed var speed = Server.Recent.TestBotSpeed(bot.Id); this.StatusIcon = "/Content/status/" + Format.AsSpeedIcon(speed) + ".png"; this.StatusText = Format.AsSpeed(speed); }
// // GET: /Work/ public ActionResult Index() { var account = Account.FindBy(WebSecurity.CurrentUserId); var wm = new WorkModel(); //对矿池进行统计 var profiles = MineProfile.FindByAccount(account.Id); var profileIds = profiles.Select(p => p.MineId).Distinct().ToList(); var custom = from m in Mine.FindAll() join p in profiles on m.Id equals p.MineId select new MineModel(m, p); var available = from m in Mine.FindAll() where !profileIds.Contains(m.Id) select new MineModel(m); wm.CustomMines = custom.ToList(); wm.Mines = available.ToList(); List <BotModel> bots = new List <BotModel>(); if (account.Bots != null) { bots.AddRange(account.Bots.Select(b => new BotModel(b)).ToList()); } var freeBots = Bot.FindBy(WebSecurity.CurrentUserName); if (freeBots != null && freeBots.Length > 0) { bots.AddRange(freeBots.Where(b => b.Account == null).Select(b => new BotModel(b))); } wm.Bots = bots; wm.Account = User.Identity.Name; wm.Credit = account.Credit; wm.CreditAccount = account.CreditAccount; wm.BitCoin = account.BitCoin; wm.BitCoinAccount = account.BitCoinAccount; wm.MiningSpeed = Format.AsSpeed(wm.Bots.Sum(b => Business.Cache.Server.Recent.TestBotSpeed(b.Id))); wm.PoolSpeed = Format.AsSpeed(wm.Mines.Sum(m => m.Speed)); wm.Workers = string.Format("{0} ({1})", wm.Bots.Count(b => !b.StatusIcon.Contains("offline")), wm.Bots.Count); return(View(wm)); }