From bfcd1b520fd79b893e721ba916ae5e1656407d2f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Aug 2017 02:43:41 -0400 Subject: merge common implementations and server implementations --- .../IO/SharpCifs/Smb/SmbFileExtensions.cs | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs (limited to 'Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs') diff --git a/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs new file mode 100644 index 0000000000..2ebcfa20f4 --- /dev/null +++ b/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs @@ -0,0 +1,133 @@ +// SmbFileExtensions.cs implementation by J. Arturo +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +using System; +using System.Threading.Tasks; +using SharpCifs.Util.Sharpen; + +namespace SharpCifs.Smb +{ + public static class SmbFileExtensions + { + /// + /// Get file's creation date converted to local timezone + /// + /// + /// + public static DateTime GetLocalCreateTime(this SmbFile smbFile) + { + return TimeZoneInfo.ConvertTime(Extensions.CreateDateFromUTC(smbFile.CreateTime()), + TimeZoneInfo.Local); + } + + /// + /// Get file's last modified date converted to local timezone + /// + /// + /// + public static DateTime GetLocalLastModified(this SmbFile smbFile) + { + return TimeZoneInfo.ConvertTime(Extensions.CreateDateFromUTC(smbFile.LastModified()), + TimeZoneInfo.Local); + } + + + /// + /// List files async + /// + /// + /// + public static Task ListFilesAsync(this SmbFile smbFile) + { + return Task.Run(() => smbFile.ListFiles()); + } + + /// + /// List files async + /// + /// + /// + /// + public static Task ListFilesAsync(this SmbFile smbFile, string wildcard) + { + return Task.Run(() => smbFile.ListFiles(wildcard)); + } + + /// + /// List files async + /// + /// + /// + public static Task ListAsync(this SmbFile smbFile) + { + return Task.Run(() => smbFile.List()); + } + + /// + /// MkDir async method + /// + /// + /// + public static Task MkDirAsync(this SmbFile smbFile) + { + return Task.Run(() => smbFile.Mkdir()); + } + + + /// + /// Delete file async + /// + /// + /// + public static Task DeleteAsync(this SmbFile smbFile) + { + return Task.Run(() => smbFile.Delete()); + } + + /// + /// Rename file async + /// + /// + /// + /// + public static Task RenameToAsync(this SmbFile smbFile, SmbFile destination) + { + return Task.Run(() => smbFile.RenameTo(destination)); + } + + /// + /// Get input stream async + /// + /// + /// + public static Task GetInputStreamAsync(this SmbFile smbFile) + { + return Task.Run(() => smbFile.GetInputStream()); + } + + + /// + /// Get output stream async + /// + /// + /// + /// + public static Task GetOutputStreamAsync(this SmbFile smbFile, bool append = false) + { + return Task.Run(() => new SmbFileOutputStream(smbFile, append) as OutputStream); + } + } +} -- cgit v1.2.3