예제 #1
0
		protected override XmlElement ToXmlNode(XmlDocument doc)
		{
			string str;
			XmlElement xmlElement = base.CreateRequestElement(doc, "searchRequest", true, this.dn);
			XmlAttribute xmlAttribute = doc.CreateAttribute("scope", null);
			SearchScope searchScope = this.directoryScope;
			switch (searchScope)
			{
				case SearchScope.Base:
				{
					xmlAttribute.InnerText = "baseObject";
					break;
				}
				case SearchScope.OneLevel:
				{
					xmlAttribute.InnerText = "singleLevel";
					break;
				}
				case SearchScope.Subtree:
				{
					xmlAttribute.InnerText = "wholeSubtree";
					break;
				}
			}
			xmlElement.Attributes.Append(xmlAttribute);
			XmlAttribute xmlAttribute1 = doc.CreateAttribute("derefAliases", null);
			DereferenceAlias dereferenceAlia = this.directoryRefAlias;
			switch (dereferenceAlia)
			{
				case DereferenceAlias.Never:
				{
					xmlAttribute1.InnerText = "neverDerefAliases";
					break;
				}
				case DereferenceAlias.InSearching:
				{
					xmlAttribute1.InnerText = "derefInSearching";
					break;
				}
				case DereferenceAlias.FindingBaseObject:
				{
					xmlAttribute1.InnerText = "derefFindingBaseObj";
					break;
				}
				case DereferenceAlias.Always:
				{
					xmlAttribute1.InnerText = "derefAlways";
					break;
				}
			}
			xmlElement.Attributes.Append(xmlAttribute1);
			XmlAttribute str1 = doc.CreateAttribute("sizeLimit", null);
			str1.InnerText = this.directorySizeLimit.ToString(CultureInfo.InvariantCulture);
			xmlElement.Attributes.Append(str1);
			XmlAttribute str2 = doc.CreateAttribute("timeLimit", null);
			long ticks = this.directoryTimeLimit.Ticks / (long)0x989680;
			str2.InnerText = ticks.ToString(CultureInfo.InvariantCulture);
			xmlElement.Attributes.Append(str2);
			XmlAttribute xmlAttribute2 = doc.CreateAttribute("typesOnly", null);
			XmlAttribute xmlAttribute3 = xmlAttribute2;
			if (this.directoryTypesOnly)
			{
				str = "true";
			}
			else
			{
				str = "false";
			}
			xmlAttribute3.InnerText = str;
			xmlElement.Attributes.Append(xmlAttribute2);
			XmlElement outerXml = doc.CreateElement("filter", "urn:oasis:names:tc:DSML:2:0:core");
			if (this.Filter == null)
			{
				outerXml.InnerXml = "<present name='objectClass' xmlns=\"urn:oasis:names:tc:DSML:2:0:core\"/>";
			}
			else
			{
				StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
				XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
				try
				{
					if (this.Filter as XmlDocument == null)
					{
						if (this.Filter as string != null)
						{
							string filter = (string)this.Filter;
							if (!filter.StartsWith("(", StringComparison.Ordinal) && !filter.EndsWith(")", StringComparison.Ordinal))
							{
								filter = filter.Insert(0, "(");
								filter = string.Concat(filter, ")");
							}
							ADFilter aDFilter = FilterParser.ParseFilterString(filter);
							if (aDFilter != null)
							{
								DSMLFilterWriter dSMLFilterWriter = new DSMLFilterWriter();
								dSMLFilterWriter.WriteFilter(aDFilter, false, xmlTextWriter, "urn:oasis:names:tc:DSML:2:0:core");
								outerXml.InnerXml = stringWriter.ToString();
							}
							else
							{
								throw new ArgumentException(Res.GetString("BadSearchLDAPFilter"));
							}
						}
					}
					else
					{
						if (((XmlDocument)this.Filter).NamespaceURI.Length != 0)
						{
							outerXml.InnerXml = ((XmlDocument)this.Filter).OuterXml;
						}
						else
						{
							this.CopyFilter((XmlDocument)this.Filter, xmlTextWriter);
							outerXml.InnerXml = stringWriter.ToString();
						}
					}
				}
				finally
				{
					xmlTextWriter.Close();
				}
			}
			xmlElement.AppendChild(outerXml);
			if (this.directoryAttributes != null && this.directoryAttributes.Count != 0)
			{
				XmlElement xmlElement1 = doc.CreateElement("attributes", "urn:oasis:names:tc:DSML:2:0:core");
				xmlElement.AppendChild(xmlElement1);
				foreach (string directoryAttribute in this.directoryAttributes)
				{
					DirectoryAttribute directoryAttribute1 = new DirectoryAttribute();
					directoryAttribute1.Name = directoryAttribute;
					XmlElement xmlNode = directoryAttribute1.ToXmlNode(doc, "attribute");
					xmlElement1.AppendChild(xmlNode);
				}
			}
			return xmlElement;
		}
예제 #2
0
        protected override XmlElement ToXmlNode(XmlDocument doc)
        {
            string       str;
            XmlElement   xmlElement   = base.CreateRequestElement(doc, "searchRequest", true, this.dn);
            XmlAttribute xmlAttribute = doc.CreateAttribute("scope", null);
            SearchScope  searchScope  = this.directoryScope;

            switch (searchScope)
            {
            case SearchScope.Base:
            {
                xmlAttribute.InnerText = "baseObject";
                break;
            }

            case SearchScope.OneLevel:
            {
                xmlAttribute.InnerText = "singleLevel";
                break;
            }

            case SearchScope.Subtree:
            {
                xmlAttribute.InnerText = "wholeSubtree";
                break;
            }
            }
            xmlElement.Attributes.Append(xmlAttribute);
            XmlAttribute     xmlAttribute1   = doc.CreateAttribute("derefAliases", null);
            DereferenceAlias dereferenceAlia = this.directoryRefAlias;

            switch (dereferenceAlia)
            {
            case DereferenceAlias.Never:
            {
                xmlAttribute1.InnerText = "neverDerefAliases";
                break;
            }

            case DereferenceAlias.InSearching:
            {
                xmlAttribute1.InnerText = "derefInSearching";
                break;
            }

            case DereferenceAlias.FindingBaseObject:
            {
                xmlAttribute1.InnerText = "derefFindingBaseObj";
                break;
            }

            case DereferenceAlias.Always:
            {
                xmlAttribute1.InnerText = "derefAlways";
                break;
            }
            }
            xmlElement.Attributes.Append(xmlAttribute1);
            XmlAttribute str1 = doc.CreateAttribute("sizeLimit", null);

            str1.InnerText = this.directorySizeLimit.ToString(CultureInfo.InvariantCulture);
            xmlElement.Attributes.Append(str1);
            XmlAttribute str2  = doc.CreateAttribute("timeLimit", null);
            long         ticks = this.directoryTimeLimit.Ticks / (long)0x989680;

            str2.InnerText = ticks.ToString(CultureInfo.InvariantCulture);
            xmlElement.Attributes.Append(str2);
            XmlAttribute xmlAttribute2 = doc.CreateAttribute("typesOnly", null);
            XmlAttribute xmlAttribute3 = xmlAttribute2;

            if (this.directoryTypesOnly)
            {
                str = "true";
            }
            else
            {
                str = "false";
            }
            xmlAttribute3.InnerText = str;
            xmlElement.Attributes.Append(xmlAttribute2);
            XmlElement outerXml = doc.CreateElement("filter", "urn:oasis:names:tc:DSML:2:0:core");

            if (this.Filter == null)
            {
                outerXml.InnerXml = "<present name='objectClass' xmlns=\"urn:oasis:names:tc:DSML:2:0:core\"/>";
            }
            else
            {
                StringWriter  stringWriter  = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
                try
                {
                    if (this.Filter as XmlDocument == null)
                    {
                        if (this.Filter as string != null)
                        {
                            string filter = (string)this.Filter;
                            if (!filter.StartsWith("(", StringComparison.Ordinal) && !filter.EndsWith(")", StringComparison.Ordinal))
                            {
                                filter = filter.Insert(0, "(");
                                filter = string.Concat(filter, ")");
                            }
                            ADFilter aDFilter = FilterParser.ParseFilterString(filter);
                            if (aDFilter != null)
                            {
                                DSMLFilterWriter dSMLFilterWriter = new DSMLFilterWriter();
                                dSMLFilterWriter.WriteFilter(aDFilter, false, xmlTextWriter, "urn:oasis:names:tc:DSML:2:0:core");
                                outerXml.InnerXml = stringWriter.ToString();
                            }
                            else
                            {
                                throw new ArgumentException(Res.GetString("BadSearchLDAPFilter"));
                            }
                        }
                    }
                    else
                    {
                        if (((XmlDocument)this.Filter).NamespaceURI.Length != 0)
                        {
                            outerXml.InnerXml = ((XmlDocument)this.Filter).OuterXml;
                        }
                        else
                        {
                            this.CopyFilter((XmlDocument)this.Filter, xmlTextWriter);
                            outerXml.InnerXml = stringWriter.ToString();
                        }
                    }
                }
                finally
                {
                    xmlTextWriter.Close();
                }
            }
            xmlElement.AppendChild(outerXml);
            if (this.directoryAttributes != null && this.directoryAttributes.Count != 0)
            {
                XmlElement xmlElement1 = doc.CreateElement("attributes", "urn:oasis:names:tc:DSML:2:0:core");
                xmlElement.AppendChild(xmlElement1);
                foreach (string directoryAttribute in this.directoryAttributes)
                {
                    DirectoryAttribute directoryAttribute1 = new DirectoryAttribute();
                    directoryAttribute1.Name = directoryAttribute;
                    XmlElement xmlNode = directoryAttribute1.ToXmlNode(doc, "attribute");
                    xmlElement1.AppendChild(xmlNode);
                }
            }
            return(xmlElement);
        }
예제 #3
0
        protected override XmlElement ToXmlNode(XmlDocument doc)
        {
            XmlElement elem = CreateRequestElement(doc, "searchRequest", true, _dn);

            // attach the "scope" attribute (required)
            XmlAttribute attrScope = doc.CreateAttribute("scope", null);

            switch (_directoryScope)
            {
            case SearchScope.Subtree:
                attrScope.InnerText = "wholeSubtree";
                break;

            case SearchScope.OneLevel:
                attrScope.InnerText = "singleLevel";
                break;

            case SearchScope.Base:
                attrScope.InnerText = "baseObject";
                break;

            default:
                Debug.Assert(false, "Unknown DsmlSearchScope type");
                break;
            }

            elem.Attributes.Append(attrScope);

            // attach the "derefAliases" attribute (required)
            XmlAttribute attrDerefAliases = doc.CreateAttribute("derefAliases", null);

            switch (_directoryRefAlias)
            {
            case DereferenceAlias.Never:
                attrDerefAliases.InnerText = "neverDerefAliases";
                break;

            case DereferenceAlias.InSearching:
                attrDerefAliases.InnerText = "derefInSearching";
                break;

            case DereferenceAlias.FindingBaseObject:
                attrDerefAliases.InnerText = "derefFindingBaseObj";
                break;

            case DereferenceAlias.Always:
                attrDerefAliases.InnerText = "derefAlways";
                break;

            default:
                Debug.Assert(false, "Unknown DsmlDereferenceAlias type");
                break;
            }

            elem.Attributes.Append(attrDerefAliases);

            // attach the "sizeLimit" attribute (optional)
            XmlAttribute attrSizeLimit = doc.CreateAttribute("sizeLimit", null);

            attrSizeLimit.InnerText = _directorySizeLimit.ToString(CultureInfo.InvariantCulture);
            elem.Attributes.Append(attrSizeLimit);

            // attach the "timeLimit" attribute (optional)
            XmlAttribute attrTimeLimit = doc.CreateAttribute("timeLimit", null);

            attrTimeLimit.InnerText = (_directoryTimeLimit.Ticks / TimeSpan.TicksPerSecond).ToString(CultureInfo.InvariantCulture);
            elem.Attributes.Append(attrTimeLimit);

            // attach the "typesOnly" attribute (optional, defaults to false)
            XmlAttribute attrTypesOnly = doc.CreateAttribute("typesOnly", null);

            attrTypesOnly.InnerText = _directoryTypesOnly ? "true" : "false";
            elem.Attributes.Append(attrTypesOnly);

            // add in the <filter> element (required)
            XmlElement elemFilter = doc.CreateElement("filter", DsmlConstants.DsmlUri);

            if (Filter != null)
            {
                StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

                try
                {
                    if (Filter is XmlDocument)
                    {
                        if (((XmlDocument)Filter).NamespaceURI.Length == 0)
                        {
                            // namespaceURI is not explicitly specified
                            CopyFilter((XmlDocument)Filter, xmlWriter);
                            elemFilter.InnerXml = stringWriter.ToString();
                        }
                        else
                        {
                            elemFilter.InnerXml = ((XmlDocument)Filter).OuterXml;
                        }
                    }
                    else if (Filter is string)
                    {
                        //
                        // Search Filter
                        // We make use of the code from DSDE, which requires an intermediary
                        // trip through the ADFilter representation.  Although ADFilter is unnecessary
                        // for our purposes, this enables us to use the same exact code as
                        // DSDE, without having to maintain a second copy of it.
                        //

                        // AD filter currently does not support filter without paranthesis, so adding it explicitly
                        string tempFilter = (string)Filter;
                        if (!tempFilter.StartsWith("(", StringComparison.Ordinal) && !tempFilter.EndsWith(")", StringComparison.Ordinal))
                        {
                            tempFilter = tempFilter.Insert(0, "(");
                            tempFilter = String.Concat(tempFilter, ")");
                        }

                        // Convert LDAP filter string to ADFilter representation
                        ADFilter adfilter = FilterParser.ParseFilterString(tempFilter);

                        if (adfilter == null)
                        {
                            // The LDAP filter string didn't parse correctly
                            throw new ArgumentException(Res.GetString(Res.BadSearchLDAPFilter));
                        }

                        // Convert ADFilter representation to a DSML filter string
                        //   Ideally, we'd skip the intemediary string, but the DSDE conversion
                        //   routines expect a XmlWriter, and the only XmlWriter available
                        //   is the XmlTextWriter, which produces text.
                        DSMLFilterWriter filterwriter = new DSMLFilterWriter();

                        filterwriter.WriteFilter(adfilter, false, xmlWriter, DsmlConstants.DsmlUri);

                        elemFilter.InnerXml = stringWriter.ToString();
                    }
                    else
                    {
                        Debug.Assert(false, "Unknown filter type");
                    }
                }
                finally
                {
                    // close this stream and the underlying stream.
                    xmlWriter.Close();
                }
            }
            else
            {
                // default filter: (objectclass=*)
                elemFilter.InnerXml = DsmlConstants.DefaultSearchFilter;
            }

            elem.AppendChild(elemFilter);

            // add in the <attributes> element (optional)
            if (_directoryAttributes != null && _directoryAttributes.Count != 0)
            {
                // create and attach the <attributes> element
                XmlElement elemAttributes = doc.CreateElement("attributes", DsmlConstants.DsmlUri);
                elem.AppendChild(elemAttributes);

                // create and attach the <attribute> elements under the <attributes> element
                foreach (string attrName in _directoryAttributes)
                {
                    // DsmlAttribute objects know how to persist themself in the right
                    // XML format, so we'll make use of that here rather than
                    // duplicating the code
                    DirectoryAttribute attr = new DirectoryAttribute();
                    attr.Name = attrName;
                    XmlElement elemAttr = attr.ToXmlNode(doc, "attribute");
                    elemAttributes.AppendChild(elemAttr);
                }
            }

            return(elem);
        }