コード例 #1
0
        protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
        {
            //...xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression"
            //....
            //<Configuration>
            //    <AllowMultiple>true<AllowMultiple>
            //    <AllowedTypes>
            //        <Type>Folder</Type>
            //        <Type>File</Type>
            //    </AllowedTypes>
            //    <SelectionRoot>
            //        <Path>/Root/.../1</Path>
            //        <Path>/Root/.../2</Path>
            //    <SelectionRoot>
            //    <Query>
            //        <q:And>
            //          <q:String op="StartsWith" property="Path">.</q:String>
            //          <q:String op="NotEqual" property="Name">Restricted</q:String>
            //        </q:And>
            //    </Query>
            //</Configuration>
            foreach (XPathNavigator element in configurationElement.SelectChildren(XPathNodeType.Element))
            {
                switch (element.LocalName)
                {
                case AllowMultipleName:
                    _allowMultiple = element.InnerXml == "true";
                    break;

                case AllowedTypesName:
                    _allowedTypes = new List <string>();
                    foreach (XPathNavigator typeElement in element.SelectChildren(TypeName, element.NamespaceURI))
                    {
                        string typeName = typeElement.InnerXml;
                        _allowedTypes.Add(typeName);
                    }
                    break;

                case SelectionRootName:
                    _selectionRoots = new List <string>();
                    foreach (XPathNavigator pathElement in element.SelectChildren(PathName, element.NamespaceURI))
                    {
                        string path = pathElement.InnerXml;
                        if (path != ".")
                        {
                            try
                            {
                                RepositoryPath.CheckValidPath(path);
                            }
                            catch (InvalidPathException e)                                     //rethrow
                            {
                                throw new InvalidPathException(String.Concat("Given path is invalid in SelectionRoot element. ContentType: ", contentType.Name,
                                                                             ", Field name: '", this.Name, "', path: '", path, "'. Reason: ", e.Message));
                            }
                        }
                        _selectionRoots.Add(path);
                    }
                    break;

                case QueryName:
                    var sb = new StringBuilder();
                    sb.Append("<SearchExpression xmlns=\"").Append(NodeQuery.XmlNamespace).Append("\">");
                    sb.Append(element.InnerXml);
                    sb.Append("</SearchExpression>");
                    _query = NodeQuery.Parse(sb.ToString());
                    break;

                case FieldNameName:
                    _fieldName = element.InnerXml;
                    break;
                }
            }
        }