Example #1
0
        /// <summary>
        /// Processes the response from the server.
        /// </summary>
        /// <param name="response">The raw response from the server.</param>
        private void ProcessResponse(string response)
        {
            try
            {
                XmlDocument XmlDoc = new XmlDocument();
                XmlDoc.LoadXml(response);
                XmlNodeList XmlResponseList = XmlDoc.GetElementsByTagName("D:response");
                if (XmlResponseList.Count == 0)
                {
                    XmlResponseList = XmlDoc.GetElementsByTagName("d:response");
                }
                WebDavHierarchyItem[] children = new WebDavHierarchyItem[XmlResponseList.Count];
                int counter = 0;
                foreach (XmlNode XmlCurrentResponse in XmlResponseList)
                {
                    WebDavHierarchyItem item = new WebDavHierarchyItem();
                    item.SetCredentials(this._credentials);

                    foreach (XmlNode XmlCurrentNode in XmlCurrentResponse.ChildNodes)
                    {
                        switch (XmlCurrentNode.LocalName)
                        {
                        case "href":
                            string href = XmlCurrentNode.InnerText;
                            if (!Regex.Match(href, "^https?:\\/\\/").Success)
                            {
                                href = this._path.Scheme + "://" + this._path.Host + href;
                            }
                            item.SetHref(href, this._path);
                            break;

                        case "propstat":
                            foreach (XmlNode XmlCurrentPropStatNode in XmlCurrentNode)
                            {
                                switch (XmlCurrentPropStatNode.LocalName)
                                {
                                case "prop":
                                    foreach (XmlNode XmlCurrentPropNode in XmlCurrentPropStatNode)
                                    {
                                        switch (XmlCurrentPropNode.LocalName)
                                        {
                                        case "creationdate":
                                            item.SetCreationDate(XmlCurrentPropNode.InnerText);
                                            break;

                                        case "getcontentlanguage":
                                            item.SetProperty(
                                                new Property(
                                                    new PropertyName("getcontentlanguage",
                                                                     XmlCurrentPropNode.NamespaceURI),
                                                    XmlCurrentPropNode.InnerText));
                                            break;

                                        case "getcontentlength":
                                            item.SetProperty(
                                                new Property(
                                                    new PropertyName("getcontentlength",
                                                                     XmlCurrentPropNode.NamespaceURI),
                                                    XmlCurrentPropNode.InnerText));
                                            break;

                                        case "getcontenttype":
                                            item.SetProperty(
                                                new Property(
                                                    new PropertyName("getcontenttype",
                                                                     XmlCurrentPropNode.NamespaceURI),
                                                    XmlCurrentPropNode.InnerText));
                                            break;

                                        case "getlastmodified":
                                            item.SetLastModified(XmlCurrentPropNode.InnerText);
                                            break;

                                        case "resourcetype":
                                            item.SetProperty(
                                                new Property(
                                                    new PropertyName("resourcetype",
                                                                     XmlCurrentPropNode.NamespaceURI),
                                                    XmlCurrentPropNode.InnerXml));
                                            break;
                                        }
                                    }
                                    break;

                                case "status":
                                    //Console.WriteLine("status: " + XmlCurrentPropStatNode.InnerText);
                                    break;
                                }
                            }
                            break;
                        }
                    }

                    if (item.DisplayName != String.Empty)
                    {
                        children[counter] = item;
                        counter++;
                    }
                    else
                    {
                        this.SetItemType(ItemType.Folder);
                        this.SetHref(item.Href.AbsoluteUri, item.Href);
                        this.SetCreationDate(item.CreationDate);
                        this.SetComment(item.Comment);
                        this.SetCreatorDisplayName(item.CreatorDisplayName);
                        this.SetLastModified(item.LastModified);
                        foreach (Property property in item.Properties)
                        {
                            this.SetProperty(property);
                        }
                    }
                    //Console.WriteLine();
                }

                int childrenCount = 0;
                foreach (IHierarchyItem item in children)
                {
                    if (item != null)
                    {
                        childrenCount++;
                    }
                }
                this._children = new IHierarchyItem[childrenCount];

                counter = 0;
                foreach (IHierarchyItem item in children)
                {
                    if (item != null)
                    {
                        this._children[counter] = item;
                        counter++;
                    }
                }
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(response);
            }
        }
Example #2
0
			/// <summary>
			/// Processes the response from the server.
			/// </summary>
			/// <param name="response">The raw response from the server.</param>
			private void ProcessResponse(string response) {
				try {
					XmlDocument XmlDoc = new XmlDocument();
					XmlDoc.LoadXml(response);
					XmlNodeList XmlResponseList = XmlDoc.GetElementsByTagName("D:response");
					if (XmlResponseList.Count == 0) {
						XmlResponseList = XmlDoc.GetElementsByTagName("d:response");
					}
					WebDavHierarchyItem[] children = new WebDavHierarchyItem[XmlResponseList.Count];
					int counter = 0;
					foreach(XmlNode XmlCurrentResponse in XmlResponseList) {
						WebDavHierarchyItem item = new WebDavHierarchyItem();
						item.SetCredentials(this._credentials);

						foreach(XmlNode XmlCurrentNode in XmlCurrentResponse.ChildNodes) {
							switch(XmlCurrentNode.LocalName) {
								case "href":
									string href = XmlCurrentNode.InnerText;
									if (!Regex.Match(href, "^https?:\\/\\/").Success) {
										href = this._path.Scheme + "://" + this._path.Host + href;
									}
									item.SetHref(href, this._path);
									break;

								case "propstat":
									foreach(XmlNode XmlCurrentPropStatNode in XmlCurrentNode) {
										switch(XmlCurrentPropStatNode.LocalName) {
											case "prop":
												foreach(XmlNode XmlCurrentPropNode in XmlCurrentPropStatNode) {
													switch(XmlCurrentPropNode.LocalName) {
														case "creationdate":
															item.SetCreationDate(XmlCurrentPropNode.InnerText);
															break;

														case "getcontentlanguage":
															item.SetProperty(new Property(new PropertyName("getcontentlanguage", XmlCurrentPropNode.NamespaceURI), XmlCurrentPropNode.InnerText));
															break;

														case "getcontentlength":
															item.SetProperty(new Property(new PropertyName("getcontentlength", XmlCurrentPropNode.NamespaceURI), XmlCurrentPropNode.InnerText));
															break;
														case "getcontenttype":
															item.SetProperty(new Property(new PropertyName("getcontenttype", XmlCurrentPropNode.NamespaceURI), XmlCurrentPropNode.InnerText));
															break;

														case "getlastmodified":
															item.SetLastModified(XmlCurrentPropNode.InnerText);
															break;

														case "resourcetype":
															item.SetProperty(new Property(new PropertyName("resourcetype", XmlCurrentPropNode.NamespaceURI), XmlCurrentPropNode.InnerXml));
															break;
													}
												}
												break;

											case "status":
                                                //Console.WriteLine("status: " + XmlCurrentPropStatNode.InnerText);
												break;
										}
									}
									break;
							}
						}

						if (item.DisplayName != String.Empty) {
							children[counter] = item;
							counter++;
						} else {
							this.SetItemType(ItemType.Folder);
							this.SetHref(item.Href.AbsoluteUri, item.Href);
							this.SetCreationDate(item.CreationDate);
							this.SetComment(item.Comment);
							this.SetCreatorDisplayName(item.CreatorDisplayName);
							this.SetLastModified(item.LastModified);
							foreach(Property property in item.Properties) {
								this.SetProperty(property);
							}
						}
						//Console.WriteLine();
					}

					int childrenCount = 0;
					foreach(IHierarchyItem item in children) {
						if (item != null) {
							childrenCount++;
						}
					}
					this._children = new IHierarchyItem[childrenCount];

					counter = 0;
					foreach(IHierarchyItem item in children) {
						if (item != null) {
							this._children[counter] = item;
							counter++;
						}
					}
				} catch(XmlException e) {
					Console.WriteLine(e.Message);
					Console.WriteLine(response);
				}
			}