diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog new file mode 100644 index 0000000..574c416 --- /dev/null +++ b/Claunia.IO/ChangeLog @@ -0,0 +1,17 @@ +2015-02-08 Natalia Portillo + + * DirectoryInfo.cs: + Created FileInfo class that cheats to inherint + System.IO.DirectoryInfo + + * FileInfo.cs: + Created FileInfo class that cheats to inherint + System.IO.FileInfo + + * Claunia.IO.csproj: + Removed skeleton class and added FileInfo and DirectoryInfo + classes. + + * MyClass.cs: + Removed skeleton empty class + diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index bceb3ae..e6a88d0 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -31,8 +31,9 @@ - + + diff --git a/Claunia.IO/DirectoryInfo.cs b/Claunia.IO/DirectoryInfo.cs new file mode 100644 index 0000000..f3e7e69 --- /dev/null +++ b/Claunia.IO/DirectoryInfo.cs @@ -0,0 +1,268 @@ +// +// DirectoryInfo.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2015 © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; + +#if !MOBILE +using System.Security.AccessControl; +#endif + + +namespace Claunia.IO +{ + [SerializableAttribute] + [ComVisibleAttribute(true)] + public sealed class DirectoryInfo : System.IO.FileSystemInfo + { + System.IO.DirectoryInfo _dirInfo; + + public DirectoryInfo(String path) + { + _dirInfo = new System.IO.DirectoryInfo(path); + } + + // For manual casting + public DirectoryInfo (System.IO.DirectoryInfo dirInfo) + { + _dirInfo = dirInfo; + } + + public override bool Exists { + get { + return _dirInfo.Exists; + } + } + + public override string Name { + get { return _dirInfo.Name; } + } + + public DirectoryInfo Parent { + get { + return new DirectoryInfo(_dirInfo.Parent); + } + } + + public DirectoryInfo Root { + get { + return new DirectoryInfo(_dirInfo.Root); + } + } + + public void Create () + { + _dirInfo.Create(); + } + + public DirectoryInfo CreateSubdirectory (string path) + { + return new DirectoryInfo(_dirInfo.CreateSubdirectory(path)); + } + + public FileInfo [] GetFiles () + { + System.IO.FileInfo[] _systemFileInfos = _dirInfo.GetFiles(); + FileInfo[] _fileInfos = new FileInfo[_systemFileInfos.Length]; + + for(int i = 0; i < _fileInfos.Length; i++) + _fileInfos[i] = new FileInfo(_systemFileInfos[i]); + + return _fileInfos; + } + + public FileInfo [] GetFiles (string searchPattern) + { + System.IO.FileInfo[] _systemFileInfos = _dirInfo.GetFiles(searchPattern); + FileInfo[] _fileInfos = new FileInfo[_systemFileInfos.Length]; + + for(int i = 0; i < _fileInfos.Length; i++) + _fileInfos[i] = new FileInfo(_systemFileInfos[i]); + + return _fileInfos; + } + + public FileInfo[] GetFiles (string searchPattern, System.IO.SearchOption searchOption) + { + System.IO.FileInfo[] _systemFileInfos = _dirInfo.GetFiles(searchPattern, searchOption); + FileInfo[] _fileInfos = new FileInfo[_systemFileInfos.Length]; + + for(int i = 0; i < _fileInfos.Length; i++) + _fileInfos[i] = new FileInfo(_systemFileInfos[i]); + + return _fileInfos; + } + + + public DirectoryInfo [] GetDirectories () + { + System.IO.DirectoryInfo[] _systemDirInfos = _dirInfo.GetDirectories(); + DirectoryInfo[] _dirInfos = new DirectoryInfo[_systemDirInfos.Length]; + + for(int i = 0; i < _dirInfos.Length; i++) + _dirInfos[i] = new DirectoryInfo(_systemDirInfos[i]); + + return _dirInfos; + } + + public DirectoryInfo [] GetDirectories (string searchPattern) + { + System.IO.DirectoryInfo[] _systemDirInfos = _dirInfo.GetDirectories(searchPattern); + DirectoryInfo[] _dirInfos = new DirectoryInfo[_systemDirInfos.Length]; + + for(int i = 0; i < _dirInfos.Length; i++) + _dirInfos[i] = new DirectoryInfo(_systemDirInfos[i]); + + return _dirInfos; + } + + public DirectoryInfo[] GetDirectories (string searchPattern, System.IO.SearchOption searchOption) + { + System.IO.DirectoryInfo[] _systemDirInfos = _dirInfo.GetDirectories(searchPattern, searchOption); + DirectoryInfo[] _dirInfos = new DirectoryInfo[_systemDirInfos.Length]; + + for(int i = 0; i < _dirInfos.Length; i++) + _dirInfos[i] = new DirectoryInfo(_systemDirInfos[i]); + + return _dirInfos; + } + + public System.IO.FileSystemInfo [] GetFileSystemInfos () + { + return _dirInfo.GetFileSystemInfos(); + } + + public System.IO.FileSystemInfo [] GetFileSystemInfos (string searchPattern) + { + return _dirInfo.GetFileSystemInfos(searchPattern); + } + + public + System.IO.FileSystemInfo [] GetFileSystemInfos (string searchPattern, System.IO.SearchOption searchOption) + { + return _dirInfo.GetFileSystemInfos(searchPattern, searchOption); + } + + public override void Delete () + { + _dirInfo.Delete(); + } + + public void Delete (bool recursive) + { + _dirInfo.Delete(recursive); + } + + public void MoveTo (string destDirName) + { + _dirInfo.MoveTo(destDirName); + } + + public override string ToString () + { + return _dirInfo.ToString(); + } + +#if !MOBILE + public void Create (DirectorySecurity directorySecurity) + { + _dirInfo.Create(directorySecurity); + } + + public DirectoryInfo CreateSubdirectory (string path, DirectorySecurity directorySecurity) + { + return new DirectoryInfo(_dirInfo.CreateSubdirectory(path, directorySecurity)); + } + + public DirectorySecurity GetAccessControl () + { + return _dirInfo.GetAccessControl(); + } + + public DirectorySecurity GetAccessControl (AccessControlSections includeSections) + { + return _dirInfo.GetAccessControl(includeSections); + } + + public void SetAccessControl (DirectorySecurity directorySecurity) + { + _dirInfo.SetAccessControl(directorySecurity); + } +#endif + + public IEnumerable EnumerateDirectories () + { + foreach(System.IO.DirectoryInfo _sysDirInfo in _dirInfo.EnumerateDirectories()) + yield return new DirectoryInfo(_sysDirInfo); + } + + public IEnumerable EnumerateDirectories (string searchPattern) + { + foreach(System.IO.DirectoryInfo _sysDirInfo in _dirInfo.EnumerateDirectories(searchPattern)) + yield return new DirectoryInfo(_sysDirInfo); + } + + public IEnumerable EnumerateDirectories (string searchPattern, System.IO.SearchOption searchOption) + { + foreach(System.IO.DirectoryInfo _sysDirInfo in _dirInfo.EnumerateDirectories(searchPattern, searchOption)) + yield return new DirectoryInfo(_sysDirInfo); + } + + public IEnumerable EnumerateFiles () + { + foreach(System.IO.FileInfo _sysFileInfo in _dirInfo.EnumerateFiles()) + yield return new FileInfo(_sysFileInfo); + } + + public IEnumerable EnumerateFiles (string searchPattern) + { + foreach(System.IO.FileInfo _sysFileInfo in _dirInfo.EnumerateFiles(searchPattern)) + yield return new FileInfo(_sysFileInfo); + } + + public IEnumerable EnumerateFiles (string searchPattern, System.IO.SearchOption searchOption) + { + foreach(System.IO.FileInfo _sysFileInfo in _dirInfo.EnumerateFiles(searchPattern, searchOption)) + yield return new FileInfo(_sysFileInfo); + } + + public IEnumerable EnumerateFileSystemInfos () + { + return _dirInfo.EnumerateFileSystemInfos(); + } + + public IEnumerable EnumerateFileSystemInfos (string searchPattern) + { + return _dirInfo.EnumerateFileSystemInfos(searchPattern); + } + + public IEnumerable EnumerateFileSystemInfos (string searchPattern, System.IO.SearchOption searchOption) + { + return _dirInfo.EnumerateFileSystemInfos(searchPattern, searchOption); + } + } +} + diff --git a/Claunia.IO/FileInfo.cs b/Claunia.IO/FileInfo.cs new file mode 100644 index 0000000..53fcadd --- /dev/null +++ b/Claunia.IO/FileInfo.cs @@ -0,0 +1,211 @@ +// +// FileInfo.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2015 © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System.Runtime.InteropServices; +using System.Runtime.Serialization; +using System.Security; +using System; +using System.IO; + +#if !MOBILE +using System.Security.AccessControl; +#endif + +namespace Claunia.IO +{ + [SerializableAttribute] + [ComVisibleAttribute(true)] + public sealed class FileInfo : System.IO.FileSystemInfo + { + // As FileInfo is sealed, let's gonna cheat a little :p + readonly System.IO.FileInfo _fileInfo; + + public FileInfo (string fileName) + { + _fileInfo = new System.IO.FileInfo(fileName); + } + + // For manual casting + public FileInfo (System.IO.FileInfo fileInfo) + { + _fileInfo = fileInfo; + } + + public override bool Exists { + get { + return _fileInfo.Exists; + } + } + + public override string Name { + get { + return _fileInfo.Name; + } + } + + public bool IsReadOnly { + get { + return _fileInfo.IsReadOnly; + } + + set { + _fileInfo.IsReadOnly = value; + } + } + + public void Encrypt () + { + _fileInfo.Encrypt(); + } + + public void Decrypt () + { + _fileInfo.Decrypt(); + } + + public long Length { + get { + return _fileInfo.Length; + } + } + + public string DirectoryName { + get { + return _fileInfo.DirectoryName; + } + } + + public DirectoryInfo Directory { + get { + return new DirectoryInfo(_fileInfo.Directory); + } + } + + public StreamReader OpenText () + { + return _fileInfo.OpenText(); + } + + public StreamWriter CreateText () + { + return _fileInfo.CreateText(); + } + + public StreamWriter AppendText () + { + return _fileInfo.AppendText(); + } + + public FileStream Create () + { + return _fileInfo.Create(); + } + + public FileStream OpenRead () + { + return _fileInfo.OpenRead(); + } + + public FileStream OpenWrite () + { + return _fileInfo.OpenWrite(); + } + + 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 override void Delete () + { + _fileInfo.Delete(); + } + + public void MoveTo (string destFileName) + { + _fileInfo.MoveTo(destFileName); + } + + public FileInfo CopyTo (string destFileName) + { + System.IO.FileInfo tmpFileInfo = _fileInfo.CopyTo(destFileName); + return new FileInfo(tmpFileInfo); + } + + public FileInfo CopyTo (string destFileName, bool overwrite) + { + System.IO.FileInfo tmpFileInfo = _fileInfo.CopyTo(destFileName, overwrite); + return new FileInfo(tmpFileInfo); + } + + public override string ToString () + { + return _fileInfo.ToString(); + } + + #if !MOBILE + public FileSecurity GetAccessControl () + { + return _fileInfo.GetAccessControl(); + } + + public FileSecurity GetAccessControl (AccessControlSections includeSections) + { + return _fileInfo.GetAccessControl(includeSections); + } + + public FileInfo Replace (string destinationFileName, + string destinationBackupFileName) + { + System.IO.FileInfo tmpFileInfo =_fileInfo.Replace(destinationFileName, destinationBackupFileName); + return new FileInfo(tmpFileInfo); + } + + public FileInfo Replace (string destinationFileName, + string destinationBackupFileName, + bool ignoreMetadataErrors) + { + System.IO.FileInfo tmpFileInfo = _fileInfo.Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors); + return new FileInfo(tmpFileInfo); + } + + public void SetAccessControl (FileSecurity fileSecurity) + { + _fileInfo.SetAccessControl(fileSecurity); + } + #endif + } +} \ No newline at end of file diff --git a/Claunia.IO/MyClass.cs b/Claunia.IO/MyClass.cs deleted file mode 100644 index dddb8ca..0000000 --- a/Claunia.IO/MyClass.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Claunia.IO -{ - public class MyClass - { - public MyClass() - { - } - } -} -