示例#1
0
        public void LoadConfiguration()
        {
            if (!agent.HasKey(configFile))
            {
                CreateEmptyConfiguration();
            }

            XDocument doc  = XDocument.Parse(agent.Read(configFile));
            XElement  root = doc.Element("config");

            FromXml(root);
        }
示例#2
0
        public void Open()
        {
            if (null == this._agent)
            {
                throw new InvalidOperationException("Agent not set");
            }

            // this._data = (HttpContext.Current.Cache[User.CurrentUser.Name] as Dictionary<string, object>);

            XDocument doc = null;

            if (_agent.HasKey(STORAGE_KEY))
            {
                doc = XDocument.Parse(_agent.Read(STORAGE_KEY));
            }

            if (null == this._data)
            {
                this._data = new Dictionary <string, object>();
                if (null != doc)
                {
                    foreach (string normalizedkey in this._agent.List())
                    {
                        XElement keyelement = doc.Element("keys")
                                              .Elements()
                                              .SingleOrDefault(x => x.Attribute("normalized").Value == normalizedkey);
                        if (null != keyelement)
                        {
                            string key           = keyelement.Attribute("full").Value;
                            string persisteddata = _agent.Read(normalizedkey);
                            if (!String.IsNullOrEmpty(persisteddata))
                            {
                                this._data.Add(key, SerializationServices.BinaryDeserialize(persisteddata));
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public bool HasAccess(string app, string screen, string user)
        {
            string editRepo = ConfigurationManager.AppSettings["EDIT_REPO"];

            if (String.IsNullOrEmpty(editRepo))
            {
                throw new InvalidOperationException("EDIT_REPO key not set in config file");
            }
            string accessRepo = ConfigurationManager.AppSettings["EDIT_REPO_ROLES"];

            if (String.IsNullOrEmpty(accessRepo))
            {
                throw new InvalidOperationException("EDIT_REPO_ROLES key not set in config file");
            }
            string accessFile = ConfigurationManager.AppSettings["EDIT_ACCESS"];

            if (String.IsNullOrEmpty(accessFile))
            {
                throw new InvalidOperationException("EDIT_ACCESS key not set in config file");
            }
            string rolesFile = ConfigurationManager.AppSettings["EDIT_ROLES"];

            if (String.IsNullOrEmpty(accessFile))
            {
                throw new InvalidOperationException("EDIT_ROLES key not set in config file");
            }

            string fileA = System.IO.Path.Combine(editRepo, app);

            fileA = System.IO.Path.Combine(fileA, accessRepo);
            fileA = System.IO.Path.Combine(fileA, accessFile);

            XmlDocument docAccess = new XmlDocument();

            if (_agent.HasKey(fileA))
            {
                docAccess.LoadXml(this._agent.Read(fileA));
            }
            else
            {
                return(true);
            }

            string fileR = System.IO.Path.Combine(editRepo, app);

            fileR = System.IO.Path.Combine(fileR, accessRepo);
            fileR = System.IO.Path.Combine(fileR, rolesFile);

            XmlDocument docRoles = new XmlDocument();

            if (_agent.HasKey(fileR))
            {
                docRoles.Load(this._agent.OpenStream(fileR));
            }
            else
            {
                return(true);
            }

            XmlNode rootAccess       = docAccess.SelectSingleNode("access");
            XmlNode rootRoles        = docRoles.SelectSingleNode("roles");
            XmlNode screenAccessNode = rootAccess.SelectSingleNode("descendant::screen[attribute::key='" + screen + "']");

            if (null != screenAccessNode)
            {
                foreach (XmlNode roleAccessNode in screenAccessNode.ChildNodes)
                {
                    XmlNode roleUsersNode = rootRoles.SelectSingleNode("descendant::role[attribute::name='" + roleAccessNode.Attributes["name"].Value + "']");
                    if (null != roleUsersNode)
                    {
                        if (null != roleUsersNode.SelectSingleNode("descendant::user[attribute::name='" + user + "']"))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }