public void Activate(dynamic args) { if (JsApiService.RiotAccount != null && JsApiService.RiotAccount.IsBlocked) { throw new JsApiException("blocked"); } int num = (int)args.handle; RiotAccount riotAccount = JsApiService.AccountBag.Get(num); LittleClient client = JsApiService.Client; AccountReference accountReference = new AccountReference() { RealmId = riotAccount.RealmId, Username = riotAccount.Username }; client.Invoke("riot.accounts.activate", accountReference); JsApiService.AccountBag.SetActive(riotAccount); }
public async Task DownloadAccounts(JToken args) { bool flag = false; bool flag1; flag1 = (!args.Contains<JToken>("cleanse") ? false : args["cleanse"].ToObject<bool>()); bool flag2 = flag1; Func<string, string, bool> func = (string a, string b) => string.Equals(a, b, StringComparison.OrdinalIgnoreCase); Func<RiotAccount, AccountConfig, bool> username = (RiotAccount config, AccountConfig account) => { if (!func(config.Username, account.Username) || !func(config.RealmId, account.RealmId)) { return false; } return func(config.Password, account.Password); }; AccountSettings accountSettings = await this.GetAccountSettings(); AccountConfig[] accounts = accountSettings.Accounts; RiotAccount[] all = JsApiService.AccountBag.GetAll(); if (!flag2) { RiotAccount[] riotAccountArray = all; IEnumerable<RiotAccount> riotAccounts = ((IEnumerable<RiotAccount>)riotAccountArray).Where<RiotAccount>((RiotAccount x) => { if (!accounts.Any<AccountConfig>((AccountConfig config) => username(x, config))) { return true; } return x.State == ConnectionState.Error; }); foreach (RiotAccount riotAccount in riotAccounts) { JsApiService.AccountBag.Detach(riotAccount); } } else { RiotAccount[] riotAccountArray1 = all; for (int i = 0; i < (int)riotAccountArray1.Length; i++) { RiotAccount riotAccount1 = riotAccountArray1[i]; JsApiService.AccountBag.Detach(riotAccount1); } if (flag) { } } AccountConfig[] accountConfigArray = accounts; for (int j = 0; j < (int)accountConfigArray.Length; j++) { AccountConfig accountConfig = accountConfigArray[j]; JsApiService.AccountBag.Attach(accountConfig); } RiotAccount riotAccount2 = null; RiotAccount[] all1 = JsApiService.AccountBag.GetAll(); AccountReference active = accountSettings.Active; if (active != null) { RiotAccount[] riotAccountArray2 = all1; riotAccount2 = ((IEnumerable<RiotAccount>)riotAccountArray2).FirstOrDefault<RiotAccount>((RiotAccount x) => { if (!string.Equals(active.Username, x.Username, StringComparison.OrdinalIgnoreCase)) { return false; } return string.Equals(active.RealmId, x.RealmId, StringComparison.OrdinalIgnoreCase); }); } if (riotAccount2 == null) { riotAccount2 = all1.FirstOrDefault<RiotAccount>(); if (riotAccount2 != null) { LittleClient client = JsApiService.Client; AccountReference accountReference = new AccountReference() { Username = riotAccount2.Username, RealmId = riotAccount2.RealmId }; client.Invoke("riot.accounts.activate", accountReference); } } JsApiService.AccountBag.SetActive(riotAccount2); }
public ActionResult Confirm([Bind(Include = "Number,Password,SavedObject,ConfirmedAction")] ConfirmModel model) { if (ModelState.IsValid) { model.Number = model.Number - 1; User user = db.Users.FirstOrDefault(u => u.Login == User.Identity.Name && u.Password == model.Password); if (user != null) { User temp; AccountReference temp1; DistributionCentre temp3; int cur_lenght, pos; string[] lenghts; string l; switch (model.ConfirmedAction) { case "CreateUser": pos = Helper.GetPosOfSplit(model.SavedObject, 4) + 1; l = model.SavedObject.Substring(0, pos); lenghts = l.Split('/'); temp = new User(); cur_lenght = Convert.ToInt32(lenghts[1]); if (cur_lenght > 0) { temp.Login = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[2]); if (cur_lenght > 0) { temp.Password = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[3]); if (cur_lenght > 0) { temp.Admin = Boolean.Parse(model.SavedObject.Substring(pos, cur_lenght)); } return(RedirectToAction("CreateUserConfirmed", "AdminSettings", temp)); case "EditUser": pos = Helper.GetPosOfSplit(model.SavedObject, 5) + 1; l = model.SavedObject.Substring(0, pos); lenghts = l.Split('/'); temp = new User(); cur_lenght = Convert.ToInt32(lenghts[1]); if (cur_lenght > 0) { temp.Id = Convert.ToInt32(model.SavedObject.Substring(pos, cur_lenght)); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[2]); if (cur_lenght > 0) { temp.Login = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[3]); if (cur_lenght > 0) { temp.Password = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[4]); if (cur_lenght > 0) { temp.Admin = Boolean.Parse(model.SavedObject.Substring(pos, cur_lenght)); } return(RedirectToAction("EditUserConfirmed", "AdminSettings", temp)); case "DeleteUser": return(RedirectToAction("DeleteUserConfirmed", "AdminSettings", new { id = Convert.ToInt32(model.SavedObject) })); case "CreateReference": pos = Helper.GetPosOfSplit(model.SavedObject, 4) + 1; l = model.SavedObject.Substring(0, pos); lenghts = l.Split('/'); temp1 = new AccountReference(); cur_lenght = Convert.ToInt32(lenghts[1]); if (cur_lenght > 0) { temp1.UserId = Convert.ToInt32(model.SavedObject.Substring(pos, cur_lenght)); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[2]); if (cur_lenght > 0) { temp1.PersonId = Convert.ToInt32(model.SavedObject.Substring(pos, cur_lenght)); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[3]); if (cur_lenght > 0) { temp1.CentreId = Convert.ToInt32(model.SavedObject.Substring(pos, cur_lenght)); } return(RedirectToAction("CreateReferenceConfirmed", "AdminSettings", temp1)); case "DeleteReference": return(RedirectToAction("DeleteReferenceConfirmed", "AdminSettings", new { id = Convert.ToInt32(model.SavedObject) })); case "CreateCentre": pos = Helper.GetPosOfSplit(model.SavedObject, 5) + 1; l = model.SavedObject.Substring(0, pos); lenghts = l.Split('/'); temp3 = new DistributionCentre(); cur_lenght = Convert.ToInt32(lenghts[1]); if (cur_lenght > 0) { temp3.Index = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[2]); if (cur_lenght > 0) { temp3.CityId = Convert.ToInt32(model.SavedObject.Substring(pos, cur_lenght)); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[3]); if (cur_lenght > 0) { temp3.Address = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[4]); if (cur_lenght > 0) { temp3.Description = model.SavedObject.Substring(pos, cur_lenght); } return(RedirectToAction("CreateCentreConfirmed", "AdminSettings", temp3)); case "EditCentre": pos = Helper.GetPosOfSplit(model.SavedObject, 6) + 1; l = model.SavedObject.Substring(0, pos); lenghts = l.Split('/'); temp3 = new DistributionCentre(); cur_lenght = Convert.ToInt32(lenghts[1]); if (cur_lenght > 0) { temp3.Id = Convert.ToInt32(model.SavedObject.Substring(pos, cur_lenght)); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[2]); if (cur_lenght > 0) { temp3.Index = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[3]); if (cur_lenght > 0) { temp3.CityId = Convert.ToInt32(model.SavedObject.Substring(pos, cur_lenght)); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[4]); if (cur_lenght > 0) { temp3.Address = model.SavedObject.Substring(pos, cur_lenght); } pos += cur_lenght; cur_lenght = Convert.ToInt32(lenghts[5]); if (cur_lenght > 0) { temp3.Description = model.SavedObject.Substring(pos, cur_lenght); } return(RedirectToAction("EditCentreConfirmed", "AdminSettings", temp3)); case "DeleteCentre": return(RedirectToAction("DeleteCentreConfirmed", "AdminSettings", new { id = Convert.ToInt32(model.SavedObject) })); } //return RedirectToAction(model.Action, "AdminSettings", ); } else { ModelState.AddModelError("", "Пароль введен неверно"); if (model.Number <= 0) { return(RedirectToAction("Logoff", "Account")); } } } return(RedirectToAction("ConfirmRepeat", "AdminSettings", model)); }