Ejemplo n.º 1
0
 public void SetDirectoryPath(string directoryPath)
 {
     if (directoryPath != null)
     {
         this.FilePath = LongPath.Combine(directoryPath, this.RelativePath);
     }
 }
Ejemplo n.º 2
0
        private FileLocation(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new System.ArgumentNullException("info");
            }

            if (context.Context is StreamJournal &&
                "RelativePath".Equals(info.GetString(FilePathType)))
            {
                this.RelativePath = info.GetString(FilePathName);
                this.FilePath     = LongPath.Combine(((StreamJournal)context.Context).DirectoryPath, this.RelativePath);
            }
            else
            {
                this.RelativePath = null;
                this.FilePath     = info.GetString(FilePathName);
            }
        }
 protected TransferEntry CreateDirectoryTransferEntry(string relativePath)
 {
     if (this.Source.Type == TransferLocationType.AzureFileDirectory)
     {
         return(new AzureFileDirectoryEntry(
                    relativePath,
                    (this.Source as AzureFileDirectoryLocation).FileDirectory.GetDirectoryReference(relativePath),
                    null));
     }
     else if (this.Source.Type == TransferLocationType.LocalDirectory)
     {
         return(new DirectoryEntry
                    (relativePath,
                    LongPath.Combine(this.Source.Instance as string, relativePath), null));
     }
     else
     {
         // For now, HierarchyDirectoryTransfer should only be used when source is Azure File Directory.
         throw new ArgumentException("TransferLocationType");
     }
 }
        protected TransferLocation GetDestinationSubDirTransferLocation(TransferLocation dirLocation, TransferEntry entry)
        {
            string destRelativePath = this.NameResolver.ResolveName(entry);

            switch (dirLocation.Type)
            {
            case TransferLocationType.AzureBlobDirectory:
            {
                AzureBlobDirectoryLocation blobDirLocation = dirLocation as AzureBlobDirectoryLocation;
                BlobType destBlobType = this.BlobType;

                // TODO: should handle blob type here.
                AzureBlobDirectoryLocation retLocation = new AzureBlobDirectoryLocation(blobDirLocation.BlobDirectory.GetDirectoryReference(destRelativePath));
                retLocation.BlobRequestOptions = blobDirLocation.BlobRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.AzureFileDirectory:
            {
                AzureFileDirectoryLocation fileDirLocation = dirLocation as AzureFileDirectoryLocation;
                CloudFileDirectory         azureDirectory  = fileDirLocation.FileDirectory.GetDirectoryReference(destRelativePath);

                AzureFileDirectoryLocation retLocation = new AzureFileDirectoryLocation(azureDirectory);
                retLocation.FileRequestOptions = fileDirLocation.FileRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.LocalDirectory:
            {
                DirectoryLocation localDirLocation = dirLocation as DirectoryLocation;
                string            path             = LongPath.Combine(localDirLocation.DirectoryPath, destRelativePath);

                return(new DirectoryLocation(path));
            }

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }
        public static IEnumerable <string> EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption, FilesOrDirectory filter)
        {
#if DOTNET5_4
            return(Directory.EnumerateFileSystemEntries(path, searchPattern, searchOption));
#else
            NativeMethods.WIN32_FIND_DATA findData;
            NativeMethods.SafeFindHandle  findHandle;
            string currentPath = null;
            int    errorCode   = 0;

            Queue <string> folders    = new Queue <string>();
            String         searchPath = LongPath.Combine(path, searchPattern);
            path          = LongPath.GetDirectoryName(searchPath);
            searchPattern = LongPath.GetFileName(searchPath);
            folders.Enqueue(path);
            while (folders.Count > 0)
            {
                currentPath = folders.Dequeue();
                if (searchOption == SearchOption.AllDirectories)
                {
                    findHandle = NativeMethods.FindFirstFileW(LongPath.Combine(LongPath.ToUncPath(currentPath), "*"), out findData);
                    if (!findHandle.IsInvalid)
                    {
                        do
                        {
                            if (findData.FileName != "." &&
                                findData.FileName != "..")
                            {
                                if (findData.FileAttributes == FileAttributes.Directory)
                                {
                                    folders.Enqueue(LongPath.Combine(currentPath, findData.FileName));
                                }
                            }
                        }while (NativeMethods.FindNextFileW(findHandle, out findData));

                        // Get last Win32 error right after native calls.
                        // Dispose SafeFindHandle will call native methods, it is possible to set last Win32 error.
                        errorCode = Marshal.GetLastWin32Error();
                        if (findHandle != null &&
                            !findHandle.IsInvalid)
                        {
                            findHandle.Dispose();
                        }
                        NativeMethods.ThrowExceptionForLastWin32ErrorIfExists(errorCode,
                                                                              new int[] {
                            NativeMethods.ERROR_SUCCESS,
                            NativeMethods.ERROR_NO_MORE_FILES,
                            NativeMethods.ERROR_FILE_NOT_FOUND
                        });
                    }
                    else
                    {
                        NativeMethods.ThrowExceptionForLastWin32ErrorIfExists(new int[] {
                            NativeMethods.ERROR_SUCCESS,
                            NativeMethods.ERROR_NO_MORE_FILES,
                            NativeMethods.ERROR_FILE_NOT_FOUND
                        });
                    }
                }

                findHandle = NativeMethods.FindFirstFileW(LongPath.Combine(LongPath.ToUncPath(currentPath), searchPattern), out findData);
                if (!findHandle.IsInvalid)
                {
                    do
                    {
                        if (findData.FileName != "." &&
                            findData.FileName != "..")
                        {
                            if ((filter == FilesOrDirectory.All) ||
                                (filter == FilesOrDirectory.Directory && findData.FileAttributes == FileAttributes.Directory) ||
                                (filter == FilesOrDirectory.File && findData.FileAttributes != FileAttributes.Directory))
                            {
                                yield return(LongPath.Combine(currentPath, findData.FileName));
                            }
                        }
                    }while (NativeMethods.FindNextFileW(findHandle, out findData));

                    // Get last Win32 error right after native calls.
                    // Dispose SafeFindHandle will call native methods, it is possible to set last Win32 error.
                    errorCode = Marshal.GetLastWin32Error();
                    if (findHandle != null &&
                        !findHandle.IsInvalid)
                    {
                        findHandle.Dispose();
                    }
                    NativeMethods.ThrowExceptionForLastWin32ErrorIfExists(errorCode,
                                                                          new int[] {
                        NativeMethods.ERROR_SUCCESS,
                        NativeMethods.ERROR_NO_MORE_FILES,
                        NativeMethods.ERROR_FILE_NOT_FOUND
                    });
                }
                else
                {
                    NativeMethods.ThrowExceptionForLastWin32ErrorIfExists(new int[] {
                        NativeMethods.ERROR_SUCCESS,
                        NativeMethods.ERROR_NO_MORE_FILES,
                        NativeMethods.ERROR_FILE_NOT_FOUND
                    });
                }
            }
#endif
        }