コード例 #1
0
        public bool Load()
        {
            try
            {
                //var slz = new XmlSerializer(typeof(XmlReflect));
                //using (var fs = File.OpenRead(_path))
                //{
                //    _store = (XmlReflect)slz.Deserialize(fs);
                //}

                _store = new XmlReflect();
                using (var reader = new System.Xml.XmlTextReader(_path))
                {
                    var doc = new System.Xml.XmlDocument();
                    doc.Load(reader);
                    var list = doc.SelectNodes("XmlPermissions");
                    if (list.Count > 0)
                    {
                        //Support for multiple documents
                        foreach (System.Xml.XmlNode item in list)
                        {
                            foreach (System.Xml.XmlNode node in item)
                            {
                                switch (node.NodeType)
                                {
                                    case System.Xml.XmlNodeType.Element:
                                        switch (node.Name)
                                        {
                                            case "Groups":
                                                foreach (System.Xml.XmlNode child in node)
                                                    ParseGroup(child);
                                                break;
                                            case "Players":
                                                foreach (System.Xml.XmlNode child in node)
                                                    ParsePlayer(child);
                                                break;
                                            default:
                                                PermissionsManager.RequestParse(this, new XmlNodeEventArgs()
                                                {
                                                    Node = node
                                                });
                                                break;
                                        }
                                        break;
                                    case System.Xml.XmlNodeType.None:
                                        break;
                                }
                            }
                        }
                    }
                }

                if (_store.Players != null)
                    foreach (var user in _store.Players)
                    {
                        if (_store.Groups != null && user.Groups != null)
                            user.MatchedGroups = _store.Groups
                                .Where(x =>
                                    user.Groups.Where(y => x.Name != null && y.ToLower() == x.Name.ToLower()).Count() > 0
                                    ||
                                    x.Attributes
                                        .Where(y => y.Key == "ApplyToGuests" && y.Value.ToLower() == "true")
                                        .Count() > 0
                                 )
                                .Distinct()
                                .ToArray();
                    }
                return true;
            }
            catch (Exception e)
            {
                ProgramLog.Log("Failed to load {0}", _path);
                ProgramLog.Log(e);
            }
            Console.Read();
            return false;
        }
コード例 #2
0
        public bool Load()
        {
            try
            {
                //var slz = new XmlSerializer(typeof(XmlReflect));
                //using (var fs = File.OpenRead(_path))
                //{
                //    _store = (XmlReflect)slz.Deserialize(fs);
                //}

                _store = new XmlReflect();
                using (var reader = new System.Xml.XmlTextReader(_path))
                {
                    var doc = new System.Xml.XmlDocument();
                    doc.Load(reader);
                    var list = doc.SelectNodes("XmlPermissions");
                    if (list.Count > 0)
                    {
                        //Support for multiple documents
                        foreach (System.Xml.XmlNode item in list)
                        {
                            foreach (System.Xml.XmlNode node in item)
                            {
                                switch (node.NodeType)
                                {
                                case System.Xml.XmlNodeType.Element:
                                    switch (node.Name)
                                    {
                                    case "Groups":
                                        foreach (System.Xml.XmlNode child in node)
                                        {
                                            ParseGroup(child);
                                        }
                                        break;

                                    case "Players":
                                        foreach (System.Xml.XmlNode child in node)
                                        {
                                            ParsePlayer(child);
                                        }
                                        break;

                                    default:
                                        PermissionsManager.RequestParse(this, new XmlNodeEventArgs()
                                        {
                                            Node = node
                                        });
                                        break;
                                    }
                                    break;

                                case System.Xml.XmlNodeType.None:
                                    break;
                                }
                            }
                        }
                    }
                }

                if (_store.Players != null)
                {
                    foreach (var user in _store.Players)
                    {
                        if (_store.Groups != null && user.Groups != null)
                        {
                            user.MatchedGroups = _store.Groups
                                                 .Where(x =>
                                                        user.Groups.Where(y => x.Name != null && y.ToLower() == x.Name.ToLower()).Count() > 0
                                                        ||
                                                        x.Attributes
                                                        .Where(y => y.Key == "ApplyToGuests" && y.Value.ToLower() == "true")
                                                        .Count() > 0
                                                        )
                                                 .Distinct()
                                                 .ToArray();
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Tools.WriteLine("Failed to load {0}", _path);
                Tools.WriteLine(e);
            }
            Console.Read();
            return(false);
        }