当前位置: 首页>>代码示例>>C#>>正文


C# Group.AddPermission方法代码示例

本文整理汇总了C#中Group.AddPermission方法的典型用法代码示例。如果您正苦于以下问题:C# Group.AddPermission方法的具体用法?C# Group.AddPermission怎么用?C# Group.AddPermission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Group的用法示例。


在下文中一共展示了Group.AddPermission方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadPermisions

        public void LoadPermisions()
        {
            //Create a temporary list so if there is an error it doesn't override the currently loaded groups with broken groups.
            var tempgroups = new List<Group>();
            tempgroups.Add(new SuperAdminGroup());

            if (groups == null || groups.Count < 2)
                groups = tempgroups;

            try
            {
                var groupsparents = new List<Tuple<Group, string>>();
                using (var reader = database.QueryReader("SELECT * FROM GroupList"))
                {
                    while (reader.Read())
                    {
                        string groupname = reader.Get<String>("GroupName");
                        var group = new Group(groupname);

                        //Inherit Given commands
                        String[] commands = reader.Get<String>("Commands").Split(',');
                        foreach (var t in commands)
                        {
                            var str = t.Trim();
                            if (str.StartsWith("!"))
                            {
                                group.NegatePermission(str.Substring(1));
                            }
                            else
                            {
                                group.AddPermission(str);
                            }
                        }
                        String[] chatcolour = (reader.Get<String>("ChatColor") ?? "").Split(',');
                        if (chatcolour.Length == 3)
                        {
                            byte.TryParse(chatcolour[0], out group.R);
                            byte.TryParse(chatcolour[1], out group.G);
                            byte.TryParse(chatcolour[2], out group.B);
                        }

                        groupsparents.Add(Tuple.Create(group, reader.Get<string>("Parent")));
                    }
                }

                foreach (var t in groupsparents)
                {
                    var group = t.Item1;
                    var parentname = t.Item2;
                    if (!string.IsNullOrWhiteSpace(parentname))
                    {
                        var parent = groupsparents.FirstOrDefault(gp => gp.Item1.Name == parentname);
                        if (parent == null)
                        {
                            Log.ConsoleError("Invalid parent {0} for group {1}".SFormat(group.Name, parentname));
                            return;
                        }
                        group.Parent = parent.Item1;
                    }
                    tempgroups.Add(group);
                }

                groups = tempgroups;
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
开发者ID:char213,项目名称:TShock,代码行数:69,代码来源:GroupManager.cs

示例2: LoadPermisions

        public void LoadPermisions()
        {
            groups = new List<Group>();
            groups.Add(new SuperAdminGroup());

            try
            {
                using (var reader = database.QueryReader("SELECT * FROM GroupList"))
                {
                    while (reader.Read())
                    {
                        Group group = null;
                        string groupname = reader.Get<String>("GroupName");
                        group = new Group(groupname);

                        //Inherit Given commands
                        String[] commands = reader.Get<String>("Commands").Split(',');
                        for (int i = 0; i < commands.Length; i++)
                        {
                            group.AddPermission(commands[i].Trim());
                        }
                        String[] chatcolour = (reader.Get<String>("ChatColor") ?? "").Split(',');
                        if (chatcolour.Length == 3)
                        {
                            byte.TryParse(chatcolour[0], out group.R);
                            byte.TryParse(chatcolour[1], out group.G);
                            byte.TryParse(chatcolour[2], out group.B);
                        }
                        groups.Add(group);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
开发者ID:BlueJayofEvil,项目名称:TShock,代码行数:37,代码来源:GroupManager.cs


注:本文中的Group.AddPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。