void Start() { var e = ContentItem.GetComponentsInChildren <Text>(); foreach (var item in e) { if (item.gameObject.name.Contains("Name")) { item.text = myItem.NameItem; } if (item.gameObject.name.Contains("tion")) { item.text = myItem.Description; } } GameObject[] g = SceneManager.GetSceneByName("PlayCampaing").GetRootGameObjects(); foreach (var item in g) { if (item.tag.Contains("Player")) { main = item.GetComponent <mainController>(); break; } } RightItem.GetComponentInChildren <Text>().text = myItem.UpCoin.ToString(); RightItem.GetComponentInChildren <Button>().onClick.AddListener(BuyItem); LeftItem.GetComponentInChildren <Image>().sprite = (Sprite)Resources.Load <Sprite>("UI/Shop/" + myItem.TypeItem.ToString()); OnLoad(); }
/// <summary> /// 获取权限树 /// </summary> /// <returns></returns> protected string GetRightTree() { List <Right> rights = new URBasicInfoService().GetRights(SelectedSysID); List <RightItem> selectedRights = UserID > 0 ? new URRightsService().GetUserRights(SelectedSysID, UserID) : new URRightsService().GetRoleRights(RoleID); StringBuilder jsonBuilder = new StringBuilder("["); for (int i = 0; i < rights.Count(); i++) { Right right = rights.ElementAt(i); jsonBuilder.AppendFormat("{{\"id\":\"{0}\",\"pId\":\"{1}\",\"name\":\"{2}\",\"open\":{3}", right.ID, right.ParentID, right.Name, "true"); RightItem rr = selectedRights.FirstOrDefault(r => r.RightID == right.ID); if (rr != null) { jsonBuilder.Append(",\"checked\":true"); if (rr.FromRole) { jsonBuilder.Append(",\"disabled\":true"); } } jsonBuilder.Append("},"); } return(jsonBuilder.ToString().TrimEnd(',') + "]"); }
public ActionResult <RightItem> createRight(RightItem right_in) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (right_in == null || right_in.Path == "") { return(BadRequest("Right not found")); } foreach (RightItem right in rightsDB.getAllRights()) { if (right_in.Path == right.Path) { return(BadRequest("Path is already existing.")); } } if (right_in.RightID.ToString() == "") { return(BadRequest("Failure. No RightID entered.")); } RightItem right_out = rightsDB.createRight(right_in); return(Created("", right_out)); }
/// <summary> /// Validate all Rights /// Throws RightIDNotFoundException and RightItemNotFoundException /// </summary> /// <param name="rights"></param> private void validateRights(RightItem[] rights) { if (rights.Length == 0) { throw new RightsNotFoundException(); } foreach (RightItem right in rights) { if (String.IsNullOrWhiteSpace(right.RightID.ToString())) { throw new RightIDNotFoundException(right.Path); } else { RightItem databaseRight = rightsDB.getRight(right.RightID); if (databaseRight == null) { throw new RightItemNotFoundException(right.RightID); } } if (String.IsNullOrWhiteSpace(right.Path)) { throw new RightPathInvalidException(right.Path); } bool duplicateRightsID = rights.Where(x => x.RightID == right.RightID).ToArray().Length > 1; if (duplicateRightsID) { throw new DuplicateRightsItemFoundException(right.RightID); } } }
public RightItem getRightbyPath(string path) { RightItem[] allRights = getAllRights(); RightItem right = allRights.Where(item => item.Path.ToLower() == path.ToLower()).Single(); return(right); }
void OnLoad() { GameObject.Find("textGold").GetComponent <Text>().text = main.MyPlayer.Player.Coin.ToString(); if (RightItem.GetComponentInChildren <Button>().interactable) { RightItem.GetComponentInChildren <Button>().interactable = main.MyPlayer.Player.Coin >= myItem.UpCoin ? true : false; } }
private void CopiedFromItem(ISynchronizedItem sourceSynchronizedItem, IItem newItem) { if (sourceSynchronizedItem == LeftItem) { RightItem.UpdateItem(newItem); } else { LeftItem.UpdateItem(newItem); } }
internal static void UpdateDBRight(string databaseName, string userName, RightItem right) { lock (_LockObj) { if (_UserRightDict == null) { return; } string key = userName.ToLower().Trim(); UserRight userRight; if (!_UserRightDict.TryGetValue(key, out userRight)) { throw new UserRightException(string.Format("user name:{0} does not exist!", userName)); } if (databaseName == "") { if (_UserRightDict.Count == 1) { if ((right & RightItem.ManageUser) == 0) { throw new UserRightException("Last user must has ManageUser right"); } } if (userRight.ServerRangeRight == null) { userRight.ServerRangeRight = new DatabaseRight("", right); } else { userRight.ServerRangeRight.Right = right; } } else { foreach (DatabaseRight dbRight in userRight.DatabaseRights) { if (dbRight.DatabaseName.Equals(databaseName, StringComparison.CurrentCultureIgnoreCase)) { dbRight.Right = right; return; } } userRight.DatabaseRights.Add(new DatabaseRight(databaseName, right)); } Save(); } }
internal static void CanDo(string databaseName, RightItem right) { Service.ConnectionInformation connInfo = Service.CurrentConnection.ConnectionInfo; if (connInfo == null) { return; } string userName = connInfo.UserName; CanDo(databaseName, userName, right); }
internal static void CreateUser(string userName, string password, RightItem systemRight) { lock (_LockObj) { string key = userName.ToLower().Trim(); if (_UserRightList == null) { _UserRightList = new List <UserRight>(); _UserRightDict = new Dictionary <string, UserRight>(); } if (_UserRightDict.ContainsKey(key)) { throw new UserRightException(string.Format("user name:{0} exist!", userName)); } if (_UserRightList.Count == 0) { if ((systemRight & RightItem.ManageUser) == 0) { throw new UserRightException("First user must has ManageUser right"); } } UserRight systemUserRight = new UserRight(); systemUserRight.UserName = userName.Trim(); System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] b = new byte[password.Length * 2]; for (int i = 0; i < password.Length; i++) { char c = password[i]; b[2 * i] = (byte)(c % 256); b[2 * i + 1] = (byte)(c / 256); } systemUserRight.PasswordHash = md5.ComputeHash(b); systemUserRight.ServerRangeRight = new DatabaseRight("", systemRight); systemUserRight.DatabaseRights = new List <DatabaseRight>(); _UserRightList.Add(systemUserRight); _UserRightDict.Add(key, systemUserRight); Save(); } }
public ActionResult <RightItem> getRight(int id) { RightItem right = rightsDB.getRight(id); if (right == null) { return(NotFound($"No right found for id: {id}")); } else { return(Ok(right)); } }
/// <summary> /// 加载产品权限 /// </summary> private void BindSofts() { URBasicInfoService biService = new URBasicInfoService(); URRightsService rightService = new URRightsService(); List <Soft> softs = biService.GetSofts(); List <ProjectSource> projectSources = biService.GetProjectSources(); List <RightItem> selectedSofts = UserID > 0 ? rightService.GetUserSoftRights(UserID) : rightService.GetRoleSoftRights(RoleID); List <RightItem> selectedProjectSources = UserID > 0 ? rightService.GetUserProjectSourceRights(UserID) : rightService.GetRoleProjectSourceRights(RoleID); List <RightItem> resIds = new List <RightItem>(); //产品管理员不能设置资源查看权限 if (loginService.LoginUser.AccountType != UserTypeOptions.ProductAdmin && UserID > 0) { resIds = rightService.GetUserResRights(UserID); } softs.ForEach(soft => { var item = new ListItem("[" + soft.OutID.ToString().PadLeft(6, '0') + "]" + soft.Name, soft.ID.ToString()); RightItem ri = selectedSofts.FirstOrDefault(f => f.RightID == soft.ID); item.Selected = ri != null; item.Enabled = ri == null || !ri.FromRole; item.Attributes.Add("stype", soft.SoftType.ToString()); item.Attributes.Add("intype", "checkbox"); if (soft.SoftType == SoftTypeOptions.InternalSoft || soft.SoftType == SoftTypeOptions.MultiSofts) { cbkListSoft.Items.Add(item); } else { cbkListSoftout.Items.Add(item); } }); if (resIds.Count > 0) { txtResIdList.Text = string.Join(", ", resIds.Select(a => a.RightID.ToString()).ToArray()); } projectSources.ForEach(projectSource => { var item = new ListItem("[" + projectSource.ProjectSourceID + "]" + projectSource.Name, projectSource.ProjectSourceID.ToString()); RightItem ri = selectedProjectSources.FirstOrDefault(f => f.RightID == projectSource.ProjectSourceID); item.Selected = ri != null; item.Enabled = ri == null || !ri.FromRole; item.Attributes.Add("intype", "checkbox"); cbkProjectSource.Items.Add(item); }); }
internal static void CanDo(string databaseName, string userName, RightItem right) { lock (_LockObj) { if (_UserRightDict == null) { return; } if (_UserRightDict.Count == 0) { return; } string key = userName.ToLower().Trim(); UserRight userRight; if (!_UserRightDict.TryGetValue(key, out userRight)) { throw new UserRightException(string.Format("user name:{0} does not exist!", userName)); } if (userRight.ServerRangeRight != null) { if ((right & userRight.ServerRangeRight.Right) != 0) { return; } } foreach (DatabaseRight dbRight in userRight.DatabaseRights) { if (dbRight.DatabaseName.Equals(databaseName, StringComparison.CurrentCultureIgnoreCase)) { if ((right & dbRight.Right) == 0) { throw new UserRightException(string.Format("Current user hasn't {0} right for this operation", right)); } else { return; } } } throw new UserRightException(string.Format("Current user hasn't {0} right for this operation", right)); } }
public ActionResult <RightItem> editRight(int id, [FromBody] RightItem right_in) { //Check if id is valid if (rightsDB.getRight(id) == null) { return(NotFound(($"No Right found for ID: {id}"))); } //Check if rights are not null if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //update existing right RightItem right_out = rightsDB.editRight(id, right_in); //return new item return(Ok(right_out)); }
/// <summary> /// returns array of Rights /// </summary> /// <returns>Right[]</returns> public RightItem[] getAllRights() { List <RightItem> list = new List <RightItem>(); using (StreamReader reader = new StreamReader(csvFile)) { string line; while ((line = reader.ReadLine()) != null) { string[] args = line.Split(";"); RightItem right = new RightItem() { RightID = Convert.ToInt32(args[0]), Path = args[1], }; list.Add(right); } } return(list.ToArray()); }
/// <summary> /// creates a Right based on the given Right /// </summary> /// <param name="right"></param> /// <returns>Right</returns> public RightItem createRight(RightItem right) { //1. Generate ID RightItem[] rights = getAllRights(); int id = 0; foreach (RightItem right_ in rights) { if (right_.RightID >= id) { id = right_.RightID; } } id++; right.RightID = id; //2. Save Right File.AppendAllLines(csvFile, new string[] { right.RightID + ";" + right.Path }); //3. Return Right return(getRight(id)); }
/// <summary> /// 设置登录信息、权限及上下文 /// </summary> protected override void SetLoginContext() { try { Dictionary <string, RightItem> rights = new Dictionary <string, RightItem>(); //1. 调用权限接口获取权限 string userCode = base._loginContext[KeyConst.LoginUserKey].ToString(); List <RightModel> rightList = _UserRepository.GetUserRights(userCode); if (rightList != null && rightList.Count > 0) { foreach (RightModel rightDto in rightList) { RightItem item = new RightItem() { RightCode = rightDto.RightCode, RightName = rightDto.RightName }; rights.Add(item.RightCode, item); } } base._loginContext.Add(KeyConst.RightKey, rights); InitSetting(); InitMenuList(); //2.todo 调用数据权限 base.SetLoginContext(); } catch (System.Exception ex) { ThrowException("SetLoginContext", ex); } }
/// <summary> /// edits the Right based on the given Right except for the ID /// </summary> /// <param name="id"></param> /// <param name="Right"></param> /// <returns>Right</returns> public RightItem editRight(int id, RightItem right) { string tempFile = Path.GetTempFileName(); using (StreamWriter writer = new StreamWriter(tempFile)) using (StreamReader reader = new StreamReader(csvFile)) { string line; while ((line = reader.ReadLine()) != null) { if (Convert.ToInt32(line.Split(";")[0]) == id) { writer.WriteLine(id + ";" + right.Path); } else { writer.WriteLine(line); } } } File.Delete(csvFile); File.Move(tempFile, csvFile); return(getRight(id)); }
void BuyItem() { main.GetComponent <mainItemControll>().GetItem(myItem); RightItem.GetComponentInChildren <Button>().interactable = false; }
private static void addAllRight(string keyRight, string rightName) { RightItem item = new RightItem(rightName); m_all.Add(keyRight, item); }
public DatabaseRight(string databaseName, RightItem right) { DatabaseName = databaseName; Right = right; }
public void addRight(string rightKey, RightItem item) { m_all.Add(rightKey, item); }