-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add smb file share. * update smb library * try * revert * test * revert * update --------- Co-authored-by: Dibianco, Jason <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,007 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Src/LibraryCore.FileShare.Smb/CustomExceptions/SmbStatusException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using SMBLibrary; | ||
|
||
namespace LibraryCore.FileShare.Smb.CustomExceptions; | ||
|
||
public class SmbStatusException(NTStatus statusFound, string? Expression = null) : Exception | ||
{ | ||
public NTStatus StatusFound { get; } = statusFound; | ||
public string? Expression { get; } = Expression; | ||
|
||
public override string ToString() | ||
{ | ||
return $"SMB Status Exception: StatusId = {StatusFound} - Expression = {Expression}"; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Src/LibraryCore.FileShare.Smb/ExtensionMethods/ThrowUtilities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using LibraryCore.FileShare.Smb.CustomExceptions; | ||
using SMBLibrary; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("LibraryCore.Tests.FileShare.Smb")] | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] | ||
|
||
namespace LibraryCore.FileShare.Smb.ExtensionMethods; | ||
|
||
internal static class ThrowUtilities | ||
{ | ||
internal static NTStatus[] OnlySuccess { get; } = [NTStatus.STATUS_SUCCESS]; | ||
|
||
internal static void ThrowIfNotSuccessful(this NTStatus value, [CallerArgumentExpression(nameof(value))] string? expression = null) | ||
{ | ||
value.ThrowIfNotStatus(OnlySuccess, expression); | ||
} | ||
|
||
internal static void ThrowIfNotStatus(this NTStatus value, NTStatus[] statusValuesToAllow, [CallerArgumentExpression(nameof(value))] string? expression = null) | ||
{ | ||
if (!statusValuesToAllow.Contains(value)) | ||
{ | ||
throw new SmbStatusException(value, expression); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Src/LibraryCore.FileShare.Smb/LibraryCore.FileShare.Smb.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks> | ||
<Authors>Jason DiBianco</Authors> | ||
<Description>Shared Package For Smb File Share Functionality</Description> | ||
<Version>1.0.0</Version> | ||
<RepositoryUrl>https://github.com/dibiancoj/LibraryCore</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<Title>LibraryCore - SmbFileShare</Title> | ||
<IsTrimmable>true</IsTrimmable> | ||
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" /> | ||
<PackageReference Include="SMBLibrary" Version="1.5.3.5" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
55 changes: 55 additions & 0 deletions
55
Src/LibraryCore.FileShare.Smb/Service/ISmbFileShareService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using SMBLibrary; | ||
|
||
namespace LibraryCore.FileShare.Smb.Service; | ||
|
||
/// <summary> | ||
/// Service class to interact with the SMB file share. This service will support Smb 2.0 on a linux or windows device / server. | ||
/// </summary> | ||
public interface ISmbFileShareService : IDisposable | ||
{ | ||
/// <summary> | ||
/// Get a list of file shares for a given server | ||
/// </summary> | ||
/// <returns>List of file share names</returns> | ||
public IEnumerable<string> ListShares(); | ||
|
||
/// <summary> | ||
/// Get a list of directories and files for a given share | ||
/// </summary> | ||
/// <param name="shareName">The share name to connect to</param> | ||
/// <param name="fileName">File name to search for or use the default of a star to search for everything</param> | ||
/// <param name="path">Search on a specific path. Format should be @"MySubFolder\MySubSubFolder. Or you can leave it blank to search from the root of the file share</param> | ||
/// <returns>List of files and directories which you can parse through</returns> | ||
public IEnumerable<QueryDirectoryFileInformation> ListFileAndDirectories(string shareName, string fileName = "*", string path = ""); | ||
|
||
/// <summary> | ||
/// Read a file from a share and path | ||
/// </summary> | ||
/// <param name="shareName">The share name to connect to</param> | ||
/// <param name="filePath">Full Path to the file to read</param> | ||
/// <returns>The file in a byte array</returns> | ||
public byte[] ReadFile(string shareName, string filePath); | ||
|
||
/// <summary> | ||
/// Create a file in a share and folder path | ||
/// </summary> | ||
/// <param name="shareName">The share name to connect to</param> | ||
/// <param name="filePath">Full Path to the file to create</param> | ||
/// <param name="fileStream">The stream of the file you want to create</param> | ||
public void CreateFile(string shareName, string filePath, Stream fileStream); | ||
|
||
/// <summary> | ||
/// Delete a file from a share and folder path | ||
/// </summary> | ||
/// <param name="shareName">The share name to connect to</param> | ||
/// <param name="filePath">Full Path to the file to delete</param> | ||
public void DeleteFile(string shareName, string filePath); | ||
|
||
/// <summary> | ||
/// Move a file from a folder to another folder in a share | ||
/// </summary> | ||
/// <param name="shareName">Share name</param> | ||
/// <param name="currentFilePath">The current path to the file. Ie: FolderA/File.pdf</param> | ||
/// <param name="destinationFilePath">The destination to move it to. Ie: FolderB/File.pdf</param> | ||
public void MoveFile(string shareName, string currentFilePath, string destinationFilePath); | ||
} |
Oops, something went wrong.