private ResourceItem ConvertToResourceItem(WebDAVClient.Model.Item item)
 {
     return(new ResourceItem()
     {
         IsSelected = false,
         ItemName = item.DisplayName,
         ItemSize = item.ContentLength,
         ItemType = item.ContentType,
         ItemHref = item.Href,
         IsFolder = item.ContentType == null,
         ModifyTime = item.LastModified,
         CreateTime = item.CreationDate
     });
 }
Esempio n. 2
0
        /// <summary>
        /// Retrieve a file or folder from the remote repository
        /// Return either a RepositoryElement or a FileSystem Error Message
        /// </summary>
        public WebDAVClient.Model.Item GetRepositoryElement(String LocalFileName)
        {
            String RepositoryDocumentName = FileNode.ConvertLocalPathToRepositoryPath(LocalFileName);

            WebDAVClient.Model.Item RepositoryElement = null;

            if (RepositoryDocumentName.Contains("."))
            {
                //We assume the FileName refers to a file
                try
                {
                    RepositoryElement = this.GetFile(RepositoryDocumentName).GetAwaiter().GetResult();
                    return(RepositoryElement);
                }
                catch (WebDAVException ex) when(ex.GetHttpCode() == 404)
                {
                    return(null);
                }
                catch (WebDAVException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                //We assume it's a folder
                try
                {
                    RepositoryElement = this.GetFolder(RepositoryDocumentName).GetAwaiter().GetResult();
                    if (FileNode.IsRepositoryRootPath(RepositoryDocumentName))
                    {
                        RepositoryElement.DisplayName = "";
                    }
                    return(RepositoryElement);
                }
                catch (WebDAVException ex) when(ex.GetHttpCode() == 404)
                {
                    //Try as a file
                    try
                    {
                        RepositoryElement = this.GetFile(RepositoryDocumentName).GetAwaiter().GetResult();
                        return(RepositoryElement);
                    }
                    catch (WebDAVException ex1) when(ex1.GetHttpCode() == 404)
                    {
                        return(null);
                    }
                    catch (WebDAVException ex1)
                    {
                        throw ex1;
                    }
                    catch (Exception ex1)
                    {
                        throw ex1;
                    }
                }
                catch (WebDAVException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 3
0
        public FileNode(WebDAVClient.Model.Item WebDavObject)
        {
            if (!FileNode._IsInited)
            {
                throw new InvalidOperationException("Please Call Init First");
            }

            lock (_handlelock)
            {
                this.ObjectId = (++ObjetIdSequence).ToString();
            }

            this.LastRefresh = DateTime.Now;
            this.Name        = WebDavObject.DisplayName;

            if (Uri.TryCreate(WebDavObject.Href, UriKind.Absolute, out Uri ParsedUri))
            {
                this.RepositoryPath = new Uri(WebDavObject.Href).PathAndQuery;
            }
            else
            {
                this.RepositoryPath = WebDavObject.Href;
            }

            this.LocalPath = HttpUtility.UrlDecode(ConvertRepositoryPathToLocalPath(this.RepositoryPath));

            if (this.RepositoryPath[this.RepositoryPath.Length - 1] == '/' && this.RepositoryPath.Length > 1)
            {
                this.RepositoryPath = this.RepositoryPath.Remove(this.RepositoryPath.Length - 1);
            }

            if (FileNode._WebDAVMode == WebDAVMode.AOS) //AOS
            {
                if (WebDavObject.IsCollection)
                {
                    this.FileInfo.FileAttributes = (UInt32)System.IO.FileAttributes.Directory;
                }
                else
                {
                    this.FileInfo.FileAttributes = (UInt32)System.IO.FileAttributes.Normal;
                }
            }
            else //Webdav
            {
                //Note : Detecting a webDAV directory from properties can change from one implementation to another. The folowing test is subject to evolve when testing new webDAV servers
                if ((WebDavObject.Etag == null && WebDavObject.ContentLength == 0) || (WebDavObject.ContentLength == null))
                {
                    this.FileInfo.FileAttributes = (UInt32)System.IO.FileAttributes.Directory;
                }
                else
                {
                    this.FileInfo.FileAttributes = (UInt32)System.IO.FileAttributes.Normal;
                }
            }

            if (WebDavObject.CreationDate.HasValue)
            {
                this.FileInfo.CreationTime = (UInt64)WebDavObject.CreationDate.Value.ToFileTimeUtc();
            }
            this.FileInfo.LastAccessTime = (UInt64)DateTime.Now.ToFileTimeUtc();
            if (WebDavObject.LastModified.HasValue)
            {
                this.FileInfo.LastWriteTime = (UInt64)WebDavObject.LastModified.Value.ToFileTimeUtc();
            }
            if (WebDavObject.LastModified.HasValue)
            {
                this.FileInfo.ChangeTime = (UInt64)WebDavObject.LastModified.Value.ToFileTimeUtc();
            }
            this.FileInfo.AllocationSize = WebDavObject.ContentLength.HasValue ? (UInt64)WebDavObject.ContentLength.Value : 0;
            this.FileInfo.FileSize       = WebDavObject.ContentLength.HasValue ? (UInt64)WebDavObject.ContentLength.Value : 0;
            //CFN.FileInfo.IndexNumber = CFN.GetIndex(); //TEMP
            this.FileSecurity = GetDefaultSecurity();
        }