Example #1
0
        public CallResult GetFileInfo(string virtualPath)
        {
            logger.Info("Getting FileInfo for {0}", virtualPath);

            if (mountErrorOccurred)
            {
                logger.Error("Mount error found");
                return(new ErrorResult(RemoteErrorCode.MountError));
            }

            if (mountErrorOccurred)
            {
                logger.Error("Mount error found");
                return(new ErrorResult(RemoteErrorCode.MountError));
            }

            try
            {
                if (!checkPermission(virtualPath))
                {
                    logger.Error("Permission denied");
                    return(new ErrorResult(RemoteErrorCode.NotAuthorizedError));
                }

                var localPath = getLocalPath(virtualPath);

                if (localPath.IsNullOrEmpty())
                {
                    throw new FileNotFoundException();
                }


                var file = new FileObject();
                file.LocalPath = localPath;
                file.LoadFromDisk();

                return(new ResponseResult(file));
            }
            catch (Exception ex)
            {
                if (ex is FileNotFoundException || ex is DirectoryNotFoundException)
                {
                    logger.Error("Item not found");
                    return(new ErrorResult(RemoteErrorCode.ItemNotFoundError));
                }
                else
                {
                    throw ex;
                }
            }
        }
Example #2
0
        public void TestFileObjectSerialization()
        {
            FileObject file = new FileObject();

            file.LocalPath = Directory.GetFiles(".").First();
            file.LoadFromDisk();

            file.Path = "/" + file.Name;

            var xml = file.Serialize();

            var strResult = xml.ToString();

            var roundtrip = new FileObject();

            Assert.IsTrue(roundtrip.Validate(xml));
            roundtrip.Deserialize(xml);

            assertAreEqual(file, roundtrip);
        }