示例#1
0
        public ShareObject TryGetSharedObject(FileType expectedFileType, String localParentDirectory, String localPathAndName)
        {
            switch (expectedFileType)
            {
            case FileType.Regular:
                if (!File.Exists(localPathAndName))
                {
                    return(null);
                }
                break;

            case FileType.Directory:
                if (!Directory.Exists(localPathAndName))
                {
                    return(null);
                }
                break;

            default:
                return(null);
            }

            ShareObject shareObject;

            if (shareObjectsByLocalPath.TryGetValue(localPathAndName, out shareObject))
            {
                if (shareObject.fileType == expectedFileType)
                {
                    return(shareObject);
                }
                DisposeShareObject(shareObject);
            }

            String shareName = PlatformPath.LocalPathDiff(localParentDirectory, localPathAndName);

            if (!PlatformPath.IsValidUnixFileName(shareName))
            {
                throw new InvalidOperationException(String.Format("The file you supplied '{0}' is not a valid unix file name", shareName));
            }

            return(CreateNewShareObject(expectedFileType, localPathAndName, shareName));
        }