From c01d056aff905339d5d2626671a3f5d1380fbdf2 Mon Sep 17 00:00:00 2001 From: Andrew Chung Date: Wed, 11 May 2016 14:49:03 -0700 Subject: [PATCH 1/2] [REEF-1389] Add wrapper interface for DirectoryInfo and FileInfo to facilitate testing for REEF-1357 JIRA: [REEF-1389](https://issues.apache.org/jira/browse/REEF-1389) --- .../Files/DefaultDirectoryInfo.cs | 310 ++++++++++++++++++ .../Files/DefaultFileInfo.cs | 224 +++++++++++++ .../Files/FileSystemInfoFactory.cs | 45 +++ .../Files/IDirectoryInfo.cs | 89 +++++ .../Files/IFIleSystemInfo.cs | 56 ++++ lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs | 68 ++++ .../Org.Apache.REEF.IO.csproj | 6 + 7 files changed, 798 insertions(+) create mode 100644 lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs create mode 100644 lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs create mode 100644 lang/cs/Org.Apache.REEF.IO/Files/FileSystemInfoFactory.cs create mode 100644 lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs create mode 100644 lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs create mode 100644 lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs diff --git a/lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs new file mode 100644 index 0000000000..943395507b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs @@ -0,0 +1,310 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.AccessControl; + +namespace Org.Apache.REEF.IO.Files +{ + /// + /// A proxy class for . + /// To create a object from a object, + /// please use the static factory method . + /// + public sealed class DefaultDirectoryInfo : IDirectoryInfo + { + private readonly DirectoryInfo _directoryInfo; + + private DefaultDirectoryInfo(DirectoryInfo info) + { + _directoryInfo = info; + } + + public static IDirectoryInfo FromDirectoryInfo(DirectoryInfo info) + { + return new DefaultDirectoryInfo(info); + } + + public FileAttributes Attributes + { + get { return _directoryInfo.Attributes; } + } + + public DateTime CreationTime + { + get { return _directoryInfo.CreationTime; } + } + + public DateTime CreationTimeUtc + { + get { return _directoryInfo.CreationTimeUtc; } + } + + public bool Exists + { + get { return _directoryInfo.Exists; } + } + + public string Extension + { + get { return _directoryInfo.Extension; } + } + + public string FullName + { + get { return _directoryInfo.FullName; } + } + + public DateTime LastAccessTime + { + get { return _directoryInfo.LastAccessTime; } + } + + public DateTime LastAccessTimeUtc + { + get { return _directoryInfo.LastAccessTime; } + } + + public DateTime LastWriteTime + { + get { return _directoryInfo.LastWriteTime; } + } + + public DateTime LastWriteTimeUtc + { + get { return _directoryInfo.LastWriteTimeUtc; } + } + + public string Name + { + get { return _directoryInfo.Name; } + } + + public IDirectoryInfo Parent + { + get { return FromDirectoryInfo(_directoryInfo.Parent); } + } + + public IDirectoryInfo Root + { + get { return FromDirectoryInfo(_directoryInfo.Root); } + } + + public void Delete() + { + _directoryInfo.Delete(); + } + + public void Refresh() + { + _directoryInfo.Refresh(); + } + + public void Create() + { + _directoryInfo.Create(); + } + + public void Create(DirectorySecurity directorySecurity) + { + _directoryInfo.Create(directorySecurity); + } + + public IDirectoryInfo CreateSubdirectory(string path) + { + return FromDirectoryInfo(_directoryInfo.CreateSubdirectory(path)); + } + + public IDirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity) + { + return FromDirectoryInfo(_directoryInfo.CreateSubdirectory(path, directorySecurity)); + } + + public void Delete(bool recursive) + { + _directoryInfo.Delete(recursive); + } + + public IEnumerable EnumerateDirectories() + { + return _directoryInfo.EnumerateDirectories().Select(FromDirectoryInfo); + } + + public IEnumerable EnumerateDirectories(string searchPattern) + { + return _directoryInfo.EnumerateDirectories(searchPattern).Select(FromDirectoryInfo); + } + + public IEnumerable EnumerateDirectories(string searchPattern, SearchOption searchOption) + { + return _directoryInfo.EnumerateDirectories(searchPattern, searchOption).Select(FromDirectoryInfo); + } + + public IEnumerable EnumerateFiles() + { + return _directoryInfo.EnumerateFiles().Select(DefaultFileInfo.FromFileInfo); + } + + public IEnumerable EnumerateFiles(string searchPattern) + { + return _directoryInfo.EnumerateFiles(searchPattern).Select(DefaultFileInfo.FromFileInfo); + } + + public IEnumerable EnumerateFiles(string searchPattern, SearchOption searchOption) + { + return _directoryInfo.EnumerateFiles(searchPattern, searchOption).Select(DefaultFileInfo.FromFileInfo); + } + + public IEnumerable EnumerateFileSystemInfos() + { + return ConvertFileSystemInfoEnumerable(_directoryInfo.EnumerateFileSystemInfos()); + } + + public IEnumerable EnumerateFileSystemInfos(string searchPattern) + { + return ConvertFileSystemInfoEnumerable(_directoryInfo.EnumerateFileSystemInfos(searchPattern)); + } + + public IEnumerable EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption) + { + return ConvertFileSystemInfoEnumerable(_directoryInfo.EnumerateFileSystemInfos(searchPattern, searchOption)); + } + + private static IEnumerable ConvertFileSystemInfoEnumerable(IEnumerable fileSystemInfos) + { + return fileSystemInfos.Select(FileSystemInfoFactory.FromFileSystemInfo).Where(fsInfo => fsInfo != null); + } + + public DirectorySecurity GetAccessControl() + { + return _directoryInfo.GetAccessControl(); + } + + public DirectorySecurity GetAccessControl(AccessControlSections includeSections) + { + return _directoryInfo.GetAccessControl(includeSections); + } + + public IDirectoryInfo[] GetDirectories() + { + return ConvertDirectoryArray(_directoryInfo.GetDirectories()); + } + + public IDirectoryInfo[] GetDirectories(string searchPattern) + { + return ConvertDirectoryArray(_directoryInfo.GetDirectories(searchPattern)); + } + + public IDirectoryInfo[] GetDirectories(string searchPattern, SearchOption searchOption) + { + return ConvertDirectoryArray(_directoryInfo.GetDirectories(searchPattern, searchOption)); + } + + private static IDirectoryInfo[] ConvertDirectoryArray(DirectoryInfo[] directoryInfos) + { + var arr = new IDirectoryInfo[directoryInfos.Length]; + + for (var i = 0; i < directoryInfos.Length; i++) + { + arr[i] = FromDirectoryInfo(directoryInfos[i]); + } + + return arr; + } + + public IFileInfo[] GetFiles() + { + return ConvertFileArray(_directoryInfo.GetFiles()); + } + + public IFileInfo[] GetFiles(string searchPattern) + { + return ConvertFileArray(_directoryInfo.GetFiles(searchPattern)); + } + + public IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption) + { + return ConvertFileArray(_directoryInfo.GetFiles(searchPattern, searchOption)); + } + + private static IFileInfo[] ConvertFileArray(FileInfo[] fileInfos) + { + var arr = new IFileInfo[fileInfos.Length]; + + for (var i = 0; i < fileInfos.Length; i++) + { + arr[i] = DefaultFileInfo.FromFileInfo(fileInfos[i]); + } + + return arr; + } + + public IFileSystemInfo[] GetFileSystemInfos() + { + return ConvertFileSystemInfoArray(_directoryInfo.GetFileSystemInfos()); + } + + public IFileSystemInfo[] GetFileSystemInfos(string searchPattern) + { + return ConvertFileSystemInfoArray(_directoryInfo.GetFileSystemInfos(searchPattern)); + } + + public IFileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption) + { + return ConvertFileSystemInfoArray(_directoryInfo.GetFileSystemInfos(searchPattern, searchOption)); + } + + private static IFileSystemInfo[] ConvertFileSystemInfoArray(IEnumerable fsInfos) + { + return ConvertFileSystemInfoEnumerable(fsInfos).ToArray(); + } + + public void MoveTo(string destDirName) + { + _directoryInfo.MoveTo(destDirName); + } + + public void SetAccessControl(DirectorySecurity directorySecurity) + { + _directoryInfo.SetAccessControl(directorySecurity); + } + + public override bool Equals(object obj) + { + var other = obj as DefaultDirectoryInfo; + return other != null && Equals(other); + } + + private bool Equals(DefaultDirectoryInfo other) + { + return Equals(_directoryInfo, other._directoryInfo); + } + + public override int GetHashCode() + { + return _directoryInfo != null ? _directoryInfo.GetHashCode() : 0; + } + + public override string ToString() + { + return _directoryInfo.ToString(); + } + } +} \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs new file mode 100644 index 0000000000..9820da1f67 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs @@ -0,0 +1,224 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System; +using System.IO; +using System.Security.AccessControl; + +namespace Org.Apache.REEF.IO.Files +{ + /// + /// A proxy class for . + /// To create a object from a object, + /// please use the static method . + /// + public sealed class DefaultFileInfo : IFileInfo + { + private readonly FileInfo _fileInfo; + + private DefaultFileInfo(FileInfo info) + { + _fileInfo = info; + } + + public static IFileInfo FromFileInfo(FileInfo fileInfo) + { + return new DefaultFileInfo(fileInfo); + } + + public FileAttributes Attributes + { + get { return _fileInfo.Attributes; } + } + + public DateTime CreationTime + { + get { return _fileInfo.CreationTime; } + } + + public DateTime CreationTimeUtc + { + get { return _fileInfo.CreationTimeUtc; } + } + + public IDirectoryInfo Directory + { + get { return DefaultDirectoryInfo.FromDirectoryInfo(_fileInfo.Directory); } + } + + public string DirectoryName + { + get { return _fileInfo.DirectoryName; } + } + + public bool Exists + { + get { return _fileInfo.Exists; } + } + + public string Extension + { + get { return _fileInfo.Extension; } + } + + public string FullName + { + get { return _fileInfo.FullName; } + } + + public bool IsReadOnly + { + get { return _fileInfo.IsReadOnly; } + } + + public DateTime LastAccessTime + { + get { return _fileInfo.LastAccessTime; } + } + + public DateTime LastAccessTimeUtc + { + get { return _fileInfo.LastAccessTimeUtc; } + } + + public DateTime LastWriteTime + { + get { return _fileInfo.LastWriteTime; } + } + + public DateTime LastWriteTimeUtc + { + get { return _fileInfo.LastWriteTimeUtc; } + } + + public long Length + { + get { return _fileInfo.Length; } + } + + public string Name + { + get { return _fileInfo.Name; } + } + + public StreamWriter AppendText() + { + return _fileInfo.AppendText(); + } + + public IFileInfo CopyTo(string destFileName) + { + return FromFileInfo(_fileInfo.CopyTo(destFileName)); + } + + public IFileInfo CopyTo(string destFileName, bool overwrite) + { + return FromFileInfo(_fileInfo.CopyTo(destFileName, overwrite)); + } + + public FileStream Create() + { + return _fileInfo.Create(); + } + + public StreamWriter CreateText() + { + return _fileInfo.CreateText(); + } + + public void Delete() + { + _fileInfo.Delete(); + } + + public void MoveTo(string destFileName) + { + _fileInfo.MoveTo(destFileName); + } + + public FileStream Open(FileMode mode) + { + return _fileInfo.Open(mode); + } + + public FileStream Open(FileMode mode, FileAccess access) + { + return _fileInfo.Open(mode, access); + } + + public FileStream Open(FileMode mode, FileAccess access, FileShare share) + { + return _fileInfo.Open(mode, access, share); + } + + public FileStream OpenRead() + { + return _fileInfo.OpenRead(); + } + + public StreamReader OpenText() + { + return _fileInfo.OpenText(); + } + + public FileStream OpenWrite() + { + return _fileInfo.OpenWrite(); + } + + public void Refresh() + { + _fileInfo.Refresh(); + } + + public IFileInfo Replace(string destinationFileName, string destinationBackupFileName) + { + return FromFileInfo(_fileInfo.Replace(destinationFileName, destinationBackupFileName)); + } + + public IFileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors) + { + return FromFileInfo(_fileInfo.Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors)); + } + + public void SetAccessControl(FileSecurity fileSecurity) + { + _fileInfo.SetAccessControl(fileSecurity); + } + + public override bool Equals(object obj) + { + var other = obj as DefaultFileInfo; + return other != null && Equals(other); + } + + private bool Equals(DefaultFileInfo other) + { + return Equals(_fileInfo, other._fileInfo); + } + + public override int GetHashCode() + { + return _fileInfo != null ? _fileInfo.GetHashCode() : 0; + } + + public override string ToString() + { + return _fileInfo.ToString(); + } + } +} \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/FileSystemInfoFactory.cs b/lang/cs/Org.Apache.REEF.IO/Files/FileSystemInfoFactory.cs new file mode 100644 index 0000000000..81a628d70f --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IO/Files/FileSystemInfoFactory.cs @@ -0,0 +1,45 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System.IO; + +namespace Org.Apache.REEF.IO.Files +{ + /// + /// A static factory class that creates an object from + /// a object. + /// + public static class FileSystemInfoFactory + { + public static IFileSystemInfo FromFileSystemInfo(FileSystemInfo fsInfo) + { + var dirInfo = fsInfo as DirectoryInfo; + if (dirInfo != null) + { + return DefaultDirectoryInfo.FromDirectoryInfo(dirInfo); + } + + var fileInfo = fsInfo as FileInfo; + if (fileInfo != null) + { + return DefaultFileInfo.FromFileInfo(fileInfo); + } + + return null; + } + } +} \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs new file mode 100644 index 0000000000..05e804ff53 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs @@ -0,0 +1,89 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System.Collections.Generic; +using System.IO; +using System.Security.AccessControl; + +namespace Org.Apache.REEF.IO.Files +{ + /// + /// A proxy interface for . + /// To create an object from a object, + /// please use the static method . + /// + public interface IDirectoryInfo : IFileSystemInfo + { + IDirectoryInfo Parent { get; } + + IDirectoryInfo Root { get; } + + void Create(); + + void Create(DirectorySecurity directorySecurity); + + IDirectoryInfo CreateSubdirectory(string path); + + IDirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity); + + void Delete(bool recursive); + + IEnumerable EnumerateDirectories(); + + IEnumerable EnumerateDirectories(string searchPattern); + + IEnumerable EnumerateDirectories(string searchPattern, SearchOption searchOption); + + IEnumerable EnumerateFiles(); + + IEnumerable EnumerateFiles(string searchPattern); + + IEnumerable EnumerateFiles(string searchPattern, SearchOption searchOption); + + IEnumerable EnumerateFileSystemInfos(); + + IEnumerable EnumerateFileSystemInfos(string searchPattern); + + IEnumerable EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption); + + DirectorySecurity GetAccessControl(); + + DirectorySecurity GetAccessControl(AccessControlSections includeSections); + + IDirectoryInfo[] GetDirectories(); + + IDirectoryInfo[] GetDirectories(string searchPattern); + + IDirectoryInfo[] GetDirectories(string searchPattern, SearchOption searchOption); + + IFileInfo[] GetFiles(); + + IFileInfo[] GetFiles(string searchPattern); + + IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption); + + IFileSystemInfo[] GetFileSystemInfos(); + + IFileSystemInfo[] GetFileSystemInfos(string searchPattern); + + IFileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption); + + void MoveTo(string destDirName); + + void SetAccessControl(DirectorySecurity directorySecurity); + } +} \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs new file mode 100644 index 0000000000..f49c33d103 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System; +using System.IO; + +namespace Org.Apache.REEF.IO.Files +{ + /// + /// A Proxy interface for . + /// To create an object from a + /// object, please use the static factory method . + /// + public interface IFileSystemInfo + { + FileAttributes Attributes { get; } + + DateTime CreationTime { get; } + + DateTime CreationTimeUtc { get; } + + bool Exists { get; } + + string Extension { get; } + + string FullName { get; } + + DateTime LastAccessTime { get; } + + DateTime LastAccessTimeUtc { get; } + + DateTime LastWriteTime { get; } + + DateTime LastWriteTimeUtc { get; } + + string Name { get; } + + void Delete(); + + void Refresh(); + } +} \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs new file mode 100644 index 0000000000..4e3e918716 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System.IO; +using System.Security.AccessControl; + +namespace Org.Apache.REEF.IO.Files +{ + /// + /// A proxy interface for . + /// To create an object from a object, + /// please use the static factory method . + /// + public interface IFileInfo : IFileSystemInfo + { + IDirectoryInfo Directory { get; } + + string DirectoryName { get; } + + bool IsReadOnly { get; } + + long Length { get; } + + StreamWriter AppendText(); + + IFileInfo CopyTo(string destFileName); + + IFileInfo CopyTo(string destFileName, bool overwrite); + + FileStream Create(); + + StreamWriter CreateText(); + + void MoveTo(string destFileName); + + FileStream Open(FileMode mode); + + FileStream Open(FileMode mode, FileAccess access); + + FileStream Open(FileMode mode, FileAccess access, FileShare share); + + FileStream OpenRead(); + + StreamReader OpenText(); + + FileStream OpenWrite(); + + IFileInfo Replace(string destinationFileName, string destinationBackupFileName); + + IFileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors); + + void SetAccessControl(FileSecurity fileSecurity); + } +} \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj b/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj index 2fda1205e0..cd5045be5b 100644 --- a/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj +++ b/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj @@ -98,6 +98,12 @@ under the License. + + + + + + From cbbd4e04a7f08bfb3406a926f3a8de75d9ecc319 Mon Sep 17 00:00:00 2001 From: Andrew Chung Date: Fri, 13 May 2016 11:56:08 -0700 Subject: [PATCH 2/2] Added docs for all files. Address comments. --- .../Files/DefaultDirectoryInfo.cs | 222 ++++++++++++++---- .../Files/DefaultFileInfo.cs | 122 +++++++++- .../Files/IDirectoryInfo.cs | 90 ++++++- .../Files/IFIleSystemInfo.cs | 42 +++- lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs | 60 ++++- .../Org.Apache.REEF.IO.csproj | 2 +- 6 files changed, 487 insertions(+), 51 deletions(-) diff --git a/lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs index 943395507b..47a86fea1f 100644 --- a/lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs +++ b/lang/cs/Org.Apache.REEF.IO/Files/DefaultDirectoryInfo.cs @@ -24,7 +24,8 @@ namespace Org.Apache.REEF.IO.Files { /// - /// A proxy class for . + /// This is meant only as a proxy class for and has no + /// relation to classes in . /// To create a object from a object, /// please use the static factory method . /// @@ -37,274 +38,413 @@ private DefaultDirectoryInfo(DirectoryInfo info) _directoryInfo = info; } + /// + /// Factory method to create an object + /// from a object. + /// public static IDirectoryInfo FromDirectoryInfo(DirectoryInfo info) { return new DefaultDirectoryInfo(info); } + /// + /// See . + /// public FileAttributes Attributes { get { return _directoryInfo.Attributes; } } + /// + /// See . + /// public DateTime CreationTime { get { return _directoryInfo.CreationTime; } } + /// + /// See . + /// public DateTime CreationTimeUtc { get { return _directoryInfo.CreationTimeUtc; } } + /// + /// See . + /// public bool Exists { get { return _directoryInfo.Exists; } } + /// + /// See . + /// public string Extension { get { return _directoryInfo.Extension; } } + /// + /// See . + /// public string FullName { get { return _directoryInfo.FullName; } } + /// + /// See . + /// public DateTime LastAccessTime { get { return _directoryInfo.LastAccessTime; } } + /// + /// See . + /// public DateTime LastAccessTimeUtc { - get { return _directoryInfo.LastAccessTime; } + get { return _directoryInfo.LastAccessTimeUtc; } } + /// + /// See . + /// public DateTime LastWriteTime { get { return _directoryInfo.LastWriteTime; } } + /// + /// See . + /// public DateTime LastWriteTimeUtc { get { return _directoryInfo.LastWriteTimeUtc; } } + /// + /// See . + /// public string Name { get { return _directoryInfo.Name; } } + /// + /// See . + /// public IDirectoryInfo Parent { get { return FromDirectoryInfo(_directoryInfo.Parent); } } + /// + /// See . + /// public IDirectoryInfo Root { get { return FromDirectoryInfo(_directoryInfo.Root); } } + /// + /// See . + /// public void Delete() { _directoryInfo.Delete(); } + /// + /// See . + /// public void Refresh() { _directoryInfo.Refresh(); } + /// + /// See . + /// public void Create() { _directoryInfo.Create(); } + /// + /// See . + /// public void Create(DirectorySecurity directorySecurity) { _directoryInfo.Create(directorySecurity); } + /// + /// See . + /// public IDirectoryInfo CreateSubdirectory(string path) { return FromDirectoryInfo(_directoryInfo.CreateSubdirectory(path)); } + /// + /// See . + /// public IDirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity) { return FromDirectoryInfo(_directoryInfo.CreateSubdirectory(path, directorySecurity)); } + /// + /// See . + /// public void Delete(bool recursive) { _directoryInfo.Delete(recursive); } + /// + /// See . + /// public IEnumerable EnumerateDirectories() { return _directoryInfo.EnumerateDirectories().Select(FromDirectoryInfo); } + /// + /// See . + /// public IEnumerable EnumerateDirectories(string searchPattern) { return _directoryInfo.EnumerateDirectories(searchPattern).Select(FromDirectoryInfo); } + /// + /// See . + /// public IEnumerable EnumerateDirectories(string searchPattern, SearchOption searchOption) { return _directoryInfo.EnumerateDirectories(searchPattern, searchOption).Select(FromDirectoryInfo); } + /// + /// See . + /// public IEnumerable EnumerateFiles() { return _directoryInfo.EnumerateFiles().Select(DefaultFileInfo.FromFileInfo); } + /// + /// See . + /// public IEnumerable EnumerateFiles(string searchPattern) { return _directoryInfo.EnumerateFiles(searchPattern).Select(DefaultFileInfo.FromFileInfo); } + /// + /// See . + /// public IEnumerable EnumerateFiles(string searchPattern, SearchOption searchOption) { return _directoryInfo.EnumerateFiles(searchPattern, searchOption).Select(DefaultFileInfo.FromFileInfo); } + /// + /// See . + /// public IEnumerable EnumerateFileSystemInfos() { return ConvertFileSystemInfoEnumerable(_directoryInfo.EnumerateFileSystemInfos()); } + /// + /// See . + /// public IEnumerable EnumerateFileSystemInfos(string searchPattern) { return ConvertFileSystemInfoEnumerable(_directoryInfo.EnumerateFileSystemInfos(searchPattern)); } + /// + /// See . + /// public IEnumerable EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption) { return ConvertFileSystemInfoEnumerable(_directoryInfo.EnumerateFileSystemInfos(searchPattern, searchOption)); } - private static IEnumerable ConvertFileSystemInfoEnumerable(IEnumerable fileSystemInfos) - { - return fileSystemInfos.Select(FileSystemInfoFactory.FromFileSystemInfo).Where(fsInfo => fsInfo != null); - } - + /// + /// See . + /// public DirectorySecurity GetAccessControl() { return _directoryInfo.GetAccessControl(); } + /// + /// See . + /// public DirectorySecurity GetAccessControl(AccessControlSections includeSections) { return _directoryInfo.GetAccessControl(includeSections); } + /// + /// See . + /// public IDirectoryInfo[] GetDirectories() { return ConvertDirectoryArray(_directoryInfo.GetDirectories()); } + /// + /// See . + /// public IDirectoryInfo[] GetDirectories(string searchPattern) { return ConvertDirectoryArray(_directoryInfo.GetDirectories(searchPattern)); } + /// + /// See . + /// public IDirectoryInfo[] GetDirectories(string searchPattern, SearchOption searchOption) { return ConvertDirectoryArray(_directoryInfo.GetDirectories(searchPattern, searchOption)); } - private static IDirectoryInfo[] ConvertDirectoryArray(DirectoryInfo[] directoryInfos) - { - var arr = new IDirectoryInfo[directoryInfos.Length]; - - for (var i = 0; i < directoryInfos.Length; i++) - { - arr[i] = FromDirectoryInfo(directoryInfos[i]); - } - - return arr; - } - + /// + /// See . + /// public IFileInfo[] GetFiles() { return ConvertFileArray(_directoryInfo.GetFiles()); } + /// + /// See . + /// public IFileInfo[] GetFiles(string searchPattern) { return ConvertFileArray(_directoryInfo.GetFiles(searchPattern)); } + /// + /// See . + /// public IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption) { return ConvertFileArray(_directoryInfo.GetFiles(searchPattern, searchOption)); } - private static IFileInfo[] ConvertFileArray(FileInfo[] fileInfos) - { - var arr = new IFileInfo[fileInfos.Length]; - - for (var i = 0; i < fileInfos.Length; i++) - { - arr[i] = DefaultFileInfo.FromFileInfo(fileInfos[i]); - } - - return arr; - } - + /// + /// See . + /// public IFileSystemInfo[] GetFileSystemInfos() { return ConvertFileSystemInfoArray(_directoryInfo.GetFileSystemInfos()); } + /// + /// See . + /// public IFileSystemInfo[] GetFileSystemInfos(string searchPattern) { return ConvertFileSystemInfoArray(_directoryInfo.GetFileSystemInfos(searchPattern)); } + /// + /// See . + /// public IFileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption) { return ConvertFileSystemInfoArray(_directoryInfo.GetFileSystemInfos(searchPattern, searchOption)); } - private static IFileSystemInfo[] ConvertFileSystemInfoArray(IEnumerable fsInfos) - { - return ConvertFileSystemInfoEnumerable(fsInfos).ToArray(); - } - + /// + /// See . + /// public void MoveTo(string destDirName) { _directoryInfo.MoveTo(destDirName); } + /// + /// See . + /// public void SetAccessControl(DirectorySecurity directorySecurity) { _directoryInfo.SetAccessControl(directorySecurity); } + /// + /// See . + /// public override bool Equals(object obj) { var other = obj as DefaultDirectoryInfo; return other != null && Equals(other); } - private bool Equals(DefaultDirectoryInfo other) - { - return Equals(_directoryInfo, other._directoryInfo); - } - + /// + /// See . + /// public override int GetHashCode() { return _directoryInfo != null ? _directoryInfo.GetHashCode() : 0; } + /// + /// See . + /// public override string ToString() { return _directoryInfo.ToString(); } + + private static IFileSystemInfo[] ConvertFileSystemInfoArray(IEnumerable fsInfos) + { + return ConvertFileSystemInfoEnumerable(fsInfos).ToArray(); + } + + private static IEnumerable ConvertFileSystemInfoEnumerable(IEnumerable fileSystemInfos) + { + return fileSystemInfos.Select(FileSystemInfoFactory.FromFileSystemInfo).Where(fsInfo => fsInfo != null); + } + + private static IDirectoryInfo[] ConvertDirectoryArray(DirectoryInfo[] directoryInfos) + { + var arr = new IDirectoryInfo[directoryInfos.Length]; + + for (var i = 0; i < directoryInfos.Length; i++) + { + arr[i] = FromDirectoryInfo(directoryInfos[i]); + } + + return arr; + } + + private static IFileInfo[] ConvertFileArray(FileInfo[] fileInfos) + { + var arr = new IFileInfo[fileInfos.Length]; + + for (var i = 0; i < fileInfos.Length; i++) + { + arr[i] = DefaultFileInfo.FromFileInfo(fileInfos[i]); + } + + return arr; + } + + private bool Equals(DefaultDirectoryInfo other) + { + return Equals(_directoryInfo, other._directoryInfo); + } } } \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs index 9820da1f67..be4bfee5ac 100644 --- a/lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs +++ b/lang/cs/Org.Apache.REEF.IO/Files/DefaultFileInfo.cs @@ -22,7 +22,8 @@ namespace Org.Apache.REEF.IO.Files { /// - /// A proxy class for . + /// This is meant only as a proxy class for and has no + /// relation to classes in . /// To create a object from a object, /// please use the static method . /// @@ -35,190 +36,299 @@ private DefaultFileInfo(FileInfo info) _fileInfo = info; } + /// + /// Factory method to create an object + /// from a object. + /// public static IFileInfo FromFileInfo(FileInfo fileInfo) { return new DefaultFileInfo(fileInfo); } + /// + /// See . + /// public FileAttributes Attributes { get { return _fileInfo.Attributes; } } + /// + /// See . + /// public DateTime CreationTime { get { return _fileInfo.CreationTime; } } + /// + /// See . + /// public DateTime CreationTimeUtc { get { return _fileInfo.CreationTimeUtc; } } + /// + /// See . + /// public IDirectoryInfo Directory { get { return DefaultDirectoryInfo.FromDirectoryInfo(_fileInfo.Directory); } } + /// + /// See . + /// public string DirectoryName { get { return _fileInfo.DirectoryName; } } + /// + /// See . + /// public bool Exists { get { return _fileInfo.Exists; } } + /// + /// See . + /// public string Extension { get { return _fileInfo.Extension; } } + /// + /// See . + /// public string FullName { get { return _fileInfo.FullName; } } + /// + /// See . + /// public bool IsReadOnly { get { return _fileInfo.IsReadOnly; } } + /// + /// See . + /// public DateTime LastAccessTime { get { return _fileInfo.LastAccessTime; } } + /// + /// See . + /// public DateTime LastAccessTimeUtc { get { return _fileInfo.LastAccessTimeUtc; } } + /// + /// See . + /// public DateTime LastWriteTime { get { return _fileInfo.LastWriteTime; } } + /// + /// See . + /// public DateTime LastWriteTimeUtc { get { return _fileInfo.LastWriteTimeUtc; } } + /// + /// See . + /// public long Length { get { return _fileInfo.Length; } } + /// + /// See . + /// public string Name { get { return _fileInfo.Name; } } + /// + /// See . + /// public StreamWriter AppendText() { return _fileInfo.AppendText(); } + /// + /// See . + /// public IFileInfo CopyTo(string destFileName) { return FromFileInfo(_fileInfo.CopyTo(destFileName)); } + /// + /// See . + /// public IFileInfo CopyTo(string destFileName, bool overwrite) { return FromFileInfo(_fileInfo.CopyTo(destFileName, overwrite)); } + /// + /// See . + /// public FileStream Create() { return _fileInfo.Create(); } + /// + /// See . + /// public StreamWriter CreateText() { return _fileInfo.CreateText(); } + /// + /// See . + /// public void Delete() { _fileInfo.Delete(); } + /// + /// See . + /// public void MoveTo(string destFileName) { _fileInfo.MoveTo(destFileName); } + /// + /// See . + /// public FileStream Open(FileMode mode) { return _fileInfo.Open(mode); } + /// + /// See . + /// public FileStream Open(FileMode mode, FileAccess access) { return _fileInfo.Open(mode, access); } + /// + /// See . + /// public FileStream Open(FileMode mode, FileAccess access, FileShare share) { return _fileInfo.Open(mode, access, share); } + /// + /// See . + /// public FileStream OpenRead() { return _fileInfo.OpenRead(); } + /// + /// See . + /// public StreamReader OpenText() { return _fileInfo.OpenText(); } + /// + /// See . + /// public FileStream OpenWrite() { return _fileInfo.OpenWrite(); } + /// + /// See . + /// public void Refresh() { _fileInfo.Refresh(); } + /// + /// See . + /// public IFileInfo Replace(string destinationFileName, string destinationBackupFileName) { return FromFileInfo(_fileInfo.Replace(destinationFileName, destinationBackupFileName)); } + /// + /// See . + /// public IFileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors) { return FromFileInfo(_fileInfo.Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors)); } + /// + /// See . + /// public void SetAccessControl(FileSecurity fileSecurity) { _fileInfo.SetAccessControl(fileSecurity); } + /// + /// See . + /// public override bool Equals(object obj) { var other = obj as DefaultFileInfo; return other != null && Equals(other); } - private bool Equals(DefaultFileInfo other) - { - return Equals(_fileInfo, other._fileInfo); - } - + /// + /// See . + /// public override int GetHashCode() { return _fileInfo != null ? _fileInfo.GetHashCode() : 0; } + /// + /// See . + /// public override string ToString() { return _fileInfo.ToString(); } + + private bool Equals(DefaultFileInfo other) + { + return Equals(_fileInfo, other._fileInfo); + } } } \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs index 05e804ff53..9d8af33bcb 100644 --- a/lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs +++ b/lang/cs/Org.Apache.REEF.IO/Files/IDirectoryInfo.cs @@ -22,68 +22,156 @@ namespace Org.Apache.REEF.IO.Files { /// - /// A proxy interface for . + /// This is meant only as a proxy interface for and has no + /// relation to classes in . /// To create an object from a object, /// please use the static method . /// public interface IDirectoryInfo : IFileSystemInfo { + /// + /// See . + /// IDirectoryInfo Parent { get; } + /// + /// See . + /// IDirectoryInfo Root { get; } + /// + /// See . + /// void Create(); + /// + /// See . + /// void Create(DirectorySecurity directorySecurity); + /// + /// See . + /// IDirectoryInfo CreateSubdirectory(string path); + /// + /// See . + /// IDirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity); + /// + /// See . + /// void Delete(bool recursive); + /// + /// See . + /// IEnumerable EnumerateDirectories(); + /// + /// See . + /// IEnumerable EnumerateDirectories(string searchPattern); + /// + /// See . + /// IEnumerable EnumerateDirectories(string searchPattern, SearchOption searchOption); + /// + /// See . + /// IEnumerable EnumerateFiles(); + /// + /// See . + /// IEnumerable EnumerateFiles(string searchPattern); + /// + /// See . + /// IEnumerable EnumerateFiles(string searchPattern, SearchOption searchOption); + /// + /// See . + /// IEnumerable EnumerateFileSystemInfos(); + /// + /// See . + /// IEnumerable EnumerateFileSystemInfos(string searchPattern); + /// + /// See . + /// IEnumerable EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption); + /// + /// See . + /// DirectorySecurity GetAccessControl(); + /// + /// See . + /// DirectorySecurity GetAccessControl(AccessControlSections includeSections); + /// + /// See . + /// IDirectoryInfo[] GetDirectories(); + /// + /// See . + /// IDirectoryInfo[] GetDirectories(string searchPattern); + /// + /// See . + /// IDirectoryInfo[] GetDirectories(string searchPattern, SearchOption searchOption); + /// + /// See . + /// IFileInfo[] GetFiles(); + /// + /// See . + /// IFileInfo[] GetFiles(string searchPattern); + /// + /// See . + /// IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption); + /// + /// See . + /// IFileSystemInfo[] GetFileSystemInfos(); + /// + /// See . + /// IFileSystemInfo[] GetFileSystemInfos(string searchPattern); + /// + /// See . + /// IFileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption); + /// + /// See . + /// void MoveTo(string destDirName); + /// + /// See . + /// void SetAccessControl(DirectorySecurity directorySecurity); } } \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs index f49c33d103..ea258dcb34 100644 --- a/lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs +++ b/lang/cs/Org.Apache.REEF.IO/Files/IFIleSystemInfo.cs @@ -21,36 +21,76 @@ namespace Org.Apache.REEF.IO.Files { /// - /// A Proxy interface for . + /// This is meant only as a proxy interface for and has no + /// relation to classes in . /// To create an object from a /// object, please use the static factory method . /// public interface IFileSystemInfo { + /// + /// See . + /// FileAttributes Attributes { get; } + /// + /// See . + /// DateTime CreationTime { get; } + /// + /// See . + /// DateTime CreationTimeUtc { get; } + /// + /// See . + /// bool Exists { get; } + /// + /// See . + /// string Extension { get; } + /// + /// See . + /// string FullName { get; } + /// + /// See . + /// DateTime LastAccessTime { get; } + /// + /// See . + /// DateTime LastAccessTimeUtc { get; } + /// + /// See . + /// DateTime LastWriteTime { get; } + /// + /// See . + /// DateTime LastWriteTimeUtc { get; } + /// + /// See . + /// string Name { get; } + /// + /// See . + /// void Delete(); + /// + /// See . + /// void Refresh(); } } \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs b/lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs index 4e3e918716..bcb43c0a96 100644 --- a/lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs +++ b/lang/cs/Org.Apache.REEF.IO/Files/IFileInfo.cs @@ -21,48 +21,106 @@ namespace Org.Apache.REEF.IO.Files { /// - /// A proxy interface for . + /// This is meant only as a proxy interface for and has no + /// relation to classes in . /// To create an object from a object, /// please use the static factory method . /// public interface IFileInfo : IFileSystemInfo { + /// + /// See . + /// IDirectoryInfo Directory { get; } + /// + /// See . + /// string DirectoryName { get; } + /// + /// See . + /// bool IsReadOnly { get; } + /// + /// See . + /// long Length { get; } + /// + /// See . + /// StreamWriter AppendText(); + /// + /// See . + /// IFileInfo CopyTo(string destFileName); + /// + /// See . + /// IFileInfo CopyTo(string destFileName, bool overwrite); + /// + /// See . + /// FileStream Create(); + /// + /// See . + /// StreamWriter CreateText(); + /// + /// See . + /// void MoveTo(string destFileName); + /// + /// See . + /// FileStream Open(FileMode mode); + /// + /// See . + /// FileStream Open(FileMode mode, FileAccess access); + /// + /// See . + /// FileStream Open(FileMode mode, FileAccess access, FileShare share); + /// + /// See . + /// FileStream OpenRead(); + /// + /// See . + /// StreamReader OpenText(); + /// + /// See . + /// FileStream OpenWrite(); + /// + /// See . + /// IFileInfo Replace(string destinationFileName, string destinationBackupFileName); + /// + /// See . + /// IFileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors); + /// + /// See . + /// void SetAccessControl(FileSecurity fileSecurity); } } \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj b/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj index cd5045be5b..eedc6a907f 100644 --- a/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj +++ b/lang/cs/Org.Apache.REEF.IO/Org.Apache.REEF.IO.csproj @@ -103,7 +103,7 @@ under the License. - +