public static CreateEditProfileModel Build(string mineOrProfileId) { var mineId = int.Parse(mineOrProfileId); var mp = MineProfile.TryFind(mineId); if (mp != null) { mineId = mp.MineId; } var mine = App.Web.Business.Data.Mine.Find(mineId); var model = new CreateEditProfileModel { Id = mp != null ? mp.Id : 0, Mine = mine.DisplayName, MineId = mine.Id, MineIcon = mine.Icon, MineIconText = mine.IconName, MineDescription = mine.Description, MineTaxRate = Format.AsPercent(mine.TaxRate, 100), CustomAccount = mp != null ? mp.CustomAccount : string.Empty, CustomPassword = mp != null ? mp.CustomPassword : string.Empty }; return(model); }
public ActionResult Profile(string id, CreateEditProfileModel model) { try { var account = Account.FindBy(WebSecurity.CurrentUserId); var mineId = model.MineId; //int.Parse(collection["Id"]); var customAccount = model.CustomAccount; // collection["CustomAccount"]; var customPassword = model.CustomPassword; //collection["CustomPassword"]; MineProfile mp = null; if (model.Id > 0) { mp = MineProfile.TryFind(model.Id); } if (mp == null) { mp = new MineProfile(); mp.AccountId = account.Id; mp.MineId = mineId; } mp.CustomAccount = customAccount; mp.CustomPassword = customPassword; mp.Save(); return(RedirectToAction("Index", "Work")); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(model)); } }
public void UpdateServerWithPreferredMineAndCredential() { if (isGateway) { return; } try { bot.Refresh(); //1. 优先查看 MineProfile 的配置 var cma = MineProfile.FindByBot(bot.Id); if (cma != null && cma.MineId > 0 && !string.IsNullOrWhiteSpace(cma.CustomAccount) && !string.IsNullOrWhiteSpace(cma.CustomPassword)) { var m = Mine.Find(cma.MineId); if (m != null) { server = BitServer.Create(m.Address, cma.CustomAccount, cma.CustomPassword); mine = m; return; } } //2. 其次查看 SystemPreferred var preferred = systemPreferred.Peek(); preferred.Refresh(); //2.5 如果有绑定信息的话 if (bot.Account != null) { var pma = MineProfile.FindByAccountMine(bot.Account.Id, preferred.Id); if (pma != null && !string.IsNullOrWhiteSpace(pma.CustomAccount) && !string.IsNullOrWhiteSpace(pma.CustomPassword)) { var m = Mine.Find(pma.MineId); if (m != null) { server = BitServer.Create(preferred.Address, pma.CustomAccount, pma.CustomPassword); mine = m; return; } } } //3. 最后使用系统自带的 server = BitServer.Create(preferred.Address, preferred.DefaultAccount, preferred.DefaultPassword); mine = preferred; } catch (Exception error) { logger.Error("UpdateServerWithPreferredMineAndCredential", error); } }
// // 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)); }
// // GET: /Work/DeleteProfile public ActionResult DeleteProfile(string id) { try { var profile = MineProfile.Find(int.Parse(id)); if (profile != null) { var account = Account.FindBy(WebSecurity.CurrentUserId); var mp = MineProfile.FindByAccountMine(account.Id, profile.MineId); mp.Delete(); } } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(RedirectToAction("Index", "Work")); }
public MineModel(Mine mine, MineProfile profile = null) { this.Id = profile == null ? mine.Id : profile.Id; this.Address = mine.Address; this.HomePage = mine.HomePage; //this.Certificated = mine.Certificated; this.DisplayName = mine.DisplayName; this.Name = mine.Name; this.Icon = mine.Icon; this.IconText = mine.IconName; this.Description = mine.Description ?? "暂时没啥好说的"; //this.Offshore = mine.Offshore; //this.Private = mine.Private; this.Speed = mine.Speed; this.Tax = Format.AsPercent(mine.TaxRate, 100); this.Status = mine.IsOnline ? "正常" : "离线"; //满载 this.UpdatedAt = mine.CheckTime; this.Ownership = mine.Account != null && mine.Account.UserId == WebSecurity.CurrentUserId; this.Action = "Profile";//profile == null ? "Profile" : "Edit"; this.ActionText = profile == null ? "自定义" : "修改"; }