コード例 #1
0
        public bool CopyFileSystemEntry(string filePath, string newParentPath)
        {
            if ((filePath == null) || (newParentPath == null))
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters);

            var ph = new PathHelper(filePath);
            var dir = ph.GetDirectoryName();
            var file = ph.GetFileName();

            if (dir.Length == 0)
                dir = "/";

            var container = GetFolder(dir);

            var fsEntry = GetFileSystemObject(file, container);

            var newParent = GetFolder(newParentPath);

            return CopyFileSystemEntry(fsEntry, newParent);
        }
コード例 #2
0
        public static WebDavRequestResult CreateObjectsFromNetworkStream(Stream data, String targetUrl, IStorageProviderService service, IStorageProviderSession session, NameBaseFilterCallback callback)
        {
            var config = session.ServiceConfiguration as WebDavConfiguration;
            var results = new WebDavRequestResult();

            var queryLessUri = HttpUtilityEx.GetPathAndQueryLessUri(config.ServiceLocator).ToString().TrimEnd('/');
            var decodedTargetUrl = HttpUtility.UrlDecode(targetUrl);
                
            var s = new StreamReader(data).ReadToEnd();
            //todo:
            var xDoc = XDocument.Load(new StringReader(s.Replace("d:d:", "d:")));
            var responses = xDoc.Descendants(XName.Get("response", DavNamespace));

            foreach (var response in responses)
            {
                bool isHidden = false;
                bool isDirectory = false;
                DateTime lastModified = DateTime.Now;
                long contentLength = 0;

                var href = response.Element(XName.Get("href", DavNamespace)).ValueOrEmpty();
                var propstats = response.Descendants(XName.Get("propstat", DavNamespace));
                foreach (var propstat in propstats)
                {
                    var prop = propstat.Element(XName.Get("prop", DavNamespace));
                    var status = propstat.Element(XName.Get("status", DavNamespace)).ValueOrEmpty();

                    if (!status.Equals(HttpOk) || prop == null) continue;

                    var strLastModified = prop.Element(XName.Get("getlastmodified", DavNamespace)).ValueOrEmpty();
                    var strContentLength = prop.Element(XName.Get("getcontentlength", DavNamespace)).ValueOrEmpty();
                    var resourceType = prop.Element(XName.Get("resourcetype", DavNamespace));
                    var strIsHidden = prop.Element(XName.Get("ishidden", DavNamespace)).ValueOrEmpty();

                    if (!String.IsNullOrEmpty(strIsHidden))
                    {
                        int code;
                        if (!int.TryParse(strIsHidden, out code))
                            code = 0;
                        isHidden = Convert.ToBoolean(code);
                    }
                    if (resourceType.Element(XName.Get("collection", DavNamespace)) != null)
                        isDirectory = true;
                    if (!String.IsNullOrEmpty(strContentLength))
                        contentLength = Convert.ToInt64(strContentLength);
                    if (!String.IsNullOrEmpty(strLastModified))
                        DateTime.TryParse(strLastModified, out lastModified);
                }

                //entry not to be encluded
                if (isHidden) continue;

                var nameBase = href;

                if (callback != null)
                    nameBase = callback(targetUrl, service, session, nameBase);

                String nameBaseForSelfCheck;

                if (nameBase.StartsWith(config.ServiceLocator.ToString()))
                {
                    nameBaseForSelfCheck = HttpUtility.UrlDecode(nameBase);
                    nameBase = nameBase.Remove(0, config.ServiceLocator.ToString().Length);
                }
                else
                {
                    nameBaseForSelfCheck = queryLessUri + HttpUtilityEx.PathDecodeUTF8(nameBase);
                }

                nameBase = nameBase.TrimEnd('/');
                nameBaseForSelfCheck = nameBaseForSelfCheck.TrimEnd('/');
                if (targetUrl.EndsWith("/"))
                    nameBaseForSelfCheck += "/";

                bool isSelf = nameBaseForSelfCheck.Equals(decodedTargetUrl);

                var ph = new PathHelper(nameBase);
                var resourceName = HttpUtility.UrlDecode(ph.GetFileName());

                BaseFileEntry entry = !isDirectory
                                          ? new BaseFileEntry(resourceName, contentLength, lastModified, service, session)
                                          : new BaseDirectoryEntry(resourceName, contentLength, lastModified, service, session);

                if (isSelf)
                {
                    results.Self = entry;
                }
                else
                {
                    results.Childs.Add(entry);
                }
            }

            return results;
        }
コード例 #3
0
        /// <summary>
        /// This mehtod allows to perform a server side renam operation which is basicly the same
        /// then a move operation in the same directory
        /// </summary>
        /// <param name="filePath">File or directory which has to be renamed</param>
        /// <param name="newName">The new name of the targeted filesystem object</param>
        /// <returns></returns>        
        public bool RenameFileSystemEntry(String filePath, String newName)
        {
            // check parameter
            if ((filePath == null) || (newName == null))
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters);

            // get path and filename
            var ph = new PathHelper(filePath);
            String dir = ph.GetDirectoryName();
            String file = ph.GetFileName();

            // check if we are in root
            if (dir.Length == 0)
                dir = "/";

            // get parent container
            ICloudDirectoryEntry container = GetFolder(dir);

            // get filesystem entry
            ICloudFileSystemEntry fsEntry = GetFileSystemObject(file, container);

            // rename file
            return RenameFileSystemEntry(fsEntry, newName);
        }
コード例 #4
0
        /// <summary>
        /// This method creates a new file object in the cloud storage. Use the GetContentStream method to 
        /// get a .net stream which usable in the same way then local stream are usable
        /// </summary>
		/// <param name="filePath">The name of the targeted file</param>
        /// <returns></returns>        
        public ICloudFileSystemEntry CreateFile(String filePath)
        {
            // check parameter
            if (filePath == null)
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters);

            // get path and filename
            var ph = new PathHelper(filePath);
            String dir = ph.GetDirectoryName();
            String file = ph.GetFileName();

            // check if we are in root
            if (dir.Length == 0)
                dir = "/";

            // get parent container
            ICloudDirectoryEntry container = GetFolder(dir);

            // rename file
            return CreateFile(container, file);
        }
コード例 #5
0
        /// <summary>
        /// This function allows to download a specific file
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="targetPath"></param>
        /// <param name="delProgress"></param>
        /// <returns></returns>        
        public void DownloadFile(String filePath, String targetPath, FileOperationProgressChanged delProgress)
        {
            // check parameter
            if (filePath == null || targetPath == null)
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters);

            // get path and filename
            var ph = new PathHelper(filePath);
            String dir = ph.GetDirectoryName();
            String file = ph.GetFileName();

            // check if we are in root
            if (dir.Length == 0)
                dir = "/";

            // get parent container
            ICloudDirectoryEntry container = GetFolder(dir);

            // download file
            DownloadFile(container, file, targetPath, delProgress);
        }