public static S3V4ListBucketItem FromXElement(XElement contentElement, string prefix) { string key = null; DateTime lastModified = DateTime.MinValue; string eTag = null; ulong size = 0; bool isFolder = false; string itemName = null; bool isNested = false; foreach (XElement e in contentElement.Elements()) { if (e.Name.LocalName == "Key") { key = e.Value.Substring(prefix.Length); isFolder = key.EndsWith("/"); isNested = isKeyNested(key); itemName = key.TrimEnd('/').Split('/').Last(); } else if (e.Name.LocalName == "ETag") { eTag = e.Value; } else if (e.Name.LocalName == "LastModified") { lastModified = DateTime.Parse(e.Value); } else if (e.Name.LocalName == "Size") { size = ulong.Parse(e.Value); } } S3V4ListBucketItem item = new S3V4ListBucketItem() { Key = key, ItemName = itemName, LastModified = lastModified, ETag = eTag, Size = size, IsFolder = isFolder, IsNested = isNested }; return(item); }
public void AddXML(string xml) { XDocument xdoc = XDocument.Parse(xml); XElement resultRoot = xdoc.Elements().First(e => e.Name.LocalName == "ListBucketResult"); string strIsTruncated = resultRoot.Elements().First(e => e.Name.LocalName == "IsTruncated").Value; m_IsTruncated = bool.Parse(strIsTruncated); string prefix = resultRoot.Elements().First(e => e.Name.LocalName == "Prefix").Value; List <S3V4ListBucketItem> items = xdoc.Descendants().Where(x => x.Name.LocalName == "Contents") .Select(c => S3V4ListBucketItem.FromXElement(c, prefix)) .Where(i => !string.IsNullOrWhiteSpace(i.Key) && i.Key != prefix) // skip containig folder .ToList(); m_Items.AddRange(items); }
public static S3V4ListBucketItem FromXElement(XElement contentElement, string prefix) { string key = null; DateTime lastModified = DateTime.MinValue; string eTag = null; ulong size = 0; bool isFolder = false; string itemName = null; bool isNested = false; foreach (XElement e in contentElement.Elements()) { if (e.Name.LocalName == "Key") { key = e.Value.Substring(prefix.Length); isFolder = key.EndsWith("/"); isNested = isKeyNested( key); itemName = key.TrimEnd('/').Split('/').Last(); } else if (e.Name.LocalName == "ETag") eTag = e.Value; else if (e.Name.LocalName == "LastModified") lastModified = DateTime.Parse(e.Value); else if (e.Name.LocalName == "Size") size = ulong.Parse(e.Value); } S3V4ListBucketItem item = new S3V4ListBucketItem() { Key = key, ItemName = itemName, LastModified = lastModified, ETag = eTag, Size = size, IsFolder = isFolder, IsNested = isNested }; return item; }