├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── dotnet-format-action.yml │ ├── dotnet-linux.yml │ ├── dotnet-macos.yml │ ├── dotnet-windows.yml │ ├── golang.yml │ ├── nuget-push-public.yml │ └── rust.yml ├── .gitignore ├── LICENSE ├── README.md └── src ├── CSharp ├── EasyMicroservices.FileManager.AmazonS3 │ ├── EasyMicroservices.FileManager.AmazonS3.csproj │ └── Providers │ │ ├── AmazonS3BucketProvider.cs │ │ ├── AmazonS3ObjectProvider.cs │ │ └── AmazonS3PathProvider.cs ├── EasyMicroservices.FileManager.Android │ ├── EasyMicroservices.FileManager.Android.csproj │ └── Providers │ │ ├── AndroidDiskDirectoryProvider.cs │ │ ├── AndroidDiskFileProvider.cs │ │ └── AndroidPermissionManager.cs ├── EasyMicroservices.FileManager.AndroidTestApp │ ├── AndroidManifest.xml │ ├── EasyMicroservices.FileManager.AndroidTestApp.csproj │ ├── MainActivity.cs │ └── Resources │ │ ├── AboutResources.txt │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── appicon.xml │ │ └── appicon_round.xml │ │ ├── mipmap-hdpi │ │ ├── appicon.png │ │ ├── appicon_background.png │ │ └── appicon_foreground.png │ │ ├── mipmap-mdpi │ │ ├── appicon.png │ │ ├── appicon_background.png │ │ └── appicon_foreground.png │ │ ├── mipmap-xhdpi │ │ ├── appicon.png │ │ ├── appicon_background.png │ │ └── appicon_foreground.png │ │ ├── mipmap-xxhdpi │ │ ├── appicon.png │ │ ├── appicon_background.png │ │ └── appicon_foreground.png │ │ ├── mipmap-xxxhdpi │ │ ├── appicon.png │ │ ├── appicon_background.png │ │ └── appicon_foreground.png │ │ └── values │ │ ├── ic_launcher_background.xml │ │ └── strings.xml ├── EasyMicroservices.FileManager.AzureStorageBlobs.Tests │ ├── EasyMicroservices.FileManager.AzureStorageBlobs.Tests.csproj │ ├── Providers │ │ └── AzureStorageBlobsTest.cs │ └── Usings.cs ├── EasyMicroservices.FileManager.AzureStorageBlobs │ ├── EasyMicroservices.FileManager.AzureStorageBlobs.csproj │ └── Providers │ │ └── AzureStorageBlobsProvider.cs ├── EasyMicroservices.FileManager.Tests │ ├── EasyMicroservices.FileManager.Tests.csproj │ └── Providers │ │ ├── DirectoryProviders │ │ ├── BaseDirectoryProviderTest.cs │ │ ├── DirectoryDiskProviderTest.cs │ │ └── MemoryDiskProviderTest.cs │ │ └── FileProviders │ │ ├── AmazonS3FileProviderTest.cs │ │ ├── BaseFileProviderTest.cs │ │ ├── DiskFileProviderTest.cs │ │ └── MemoryFileProviderTest.cs ├── EasyMicroservices.FileManager.sln └── EasyMicroservices.FileManager │ ├── EasyMicroservices.FileManager.csproj │ ├── Extensions │ ├── DirectoryExtensions.cs │ └── FileExtensions.cs │ ├── Interfaces │ ├── IDirectoryManagerProvider.cs │ ├── IFileManagerProvider.cs │ └── IPathProvider.cs │ ├── Models │ ├── DirectoryDetail.cs │ └── FileDetail.cs │ └── Providers │ ├── BasePathProvider.cs │ ├── DirectoryProviders │ ├── BaseDirectoryProvider.cs │ ├── DiskDirectoryProvider.cs │ └── MemoryDirectoryProvider.cs │ ├── FileProviders │ ├── BaseFileProvider.cs │ ├── DiskFileProvider.cs │ └── MemoryFileProvider.cs │ └── PathProviders │ ├── BasePathProvider.cs │ └── SystemPathProvider.cs ├── Golang ├── CHANGELOG.md ├── disk │ ├── lib.go │ └── lib_test.go ├── go.mod ├── go.sum ├── lib.go ├── models.go └── providers.go └── Rust ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml └── src ├── disk ├── lib.rs ├── lib_test.rs └── mod.rs ├── lib.rs ├── models.rs └── providers.rs /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Title 2 | 3 | 4 | 5 | ## Description 6 | 7 | 8 | 9 | ### Checklist: 10 | 11 | - [ ] It's a bug report. 12 | - [ ] It's a feature request. 13 | - [ ] Related language label is selected. 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | 4 | 5 | ### Related issue(s) 6 | 7 | 8 | 9 | ### Checklist: 10 | 11 | - [ ] It refers to an [Issue](https://github.com/EasyMicroservices/FileManager/issues). 12 | - [ ] It fixes a bug. 13 | - [ ] It's a new feature (non-breaking change which adds functionality) 14 | - [ ] It's a breaking (fix or feature that would cause existing functionality to change) 15 | - [ ] My code follows the code style of this project. 16 | - [ ] I have added tests to cover my changes. 17 | - [ ] All new and existing tests passed. 18 | - [ ] CHANGELOG is updated. 19 | - [ ] Related language label is selected. 20 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-format-action.yml: -------------------------------------------------------------------------------- 1 | name: dotnet format 2 | on: 3 | push: 4 | branches: [develop] 5 | 6 | jobs: 7 | format: 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Setup .NET 13 | uses: actions/setup-dotnet@v3 14 | with: 15 | dotnet-version: | 16 | 3.1.x 17 | 5.0.x 18 | 6.0.x 19 | 7.0.x 20 | - name: Install Android 21 | run: dotnet workload install android 22 | - name: Run dotnet format 23 | id: format 24 | uses: jfversluis/dotnet-format@v1.0.5 25 | with: 26 | repo-token: ${{ secrets.GITHUB_TOKEN }} 27 | action: "fix" 28 | workspace: "./src/CSharp/EasyMicroservices.FileManager.sln" 29 | - name: Test 30 | run: | 31 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln -f netcoreapp3.1 32 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln -f net6.0 33 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln -f net5.0 34 | - name: Commit files 35 | if: steps.format.outputs.has-changes == 'true' 36 | uses: EndBug/add-and-commit@v4.1.0 37 | with: 38 | author_name: Github Actions 39 | author_email: actions@github.com 40 | message: "chore: Automated dotnet-format update" 41 | ref: ${{ github.head_ref }} 42 | env: 43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 44 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-linux.yml: -------------------------------------------------------------------------------- 1 | name: Linux (dotnet build and test) 2 | 3 | on: 4 | push: 5 | branches: [develop] 6 | pull_request: 7 | branches: [develop] 8 | 9 | jobs: 10 | os-tests: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: | 18 | 3.1.x 19 | 5.0.x 20 | 6.0.x 21 | 7.0.x 22 | - name: Install Android 23 | run: dotnet workload install android 24 | - name: Restore dependencies 25 | run: dotnet restore ./src/CSharp/EasyMicroservices.FileManager.sln 26 | - name: Build 27 | run: dotnet build ./src/CSharp/EasyMicroservices.FileManager.sln --no-restore 28 | - name: Test 29 | run: | 30 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal -f netcoreapp3.1 31 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal -f net6.0 32 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal -f net5.0 33 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-macos.yml: -------------------------------------------------------------------------------- 1 | name: MacOS (dotnet build and test) 2 | 3 | on: 4 | push: 5 | branches: [develop] 6 | pull_request: 7 | branches: [develop] 8 | 9 | jobs: 10 | os-tests: 11 | runs-on: macos-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: | 18 | 3.1.x 19 | 5.0.x 20 | 6.0.x 21 | 7.0.x 22 | - name: Install Android 23 | run: dotnet workload install android 24 | - name: Restore dependencies 25 | run: dotnet restore ./src/CSharp/EasyMicroservices.FileManager.sln 26 | - name: Build 27 | run: dotnet build ./src/CSharp/EasyMicroservices.FileManager.sln --no-restore 28 | - name: Test 29 | run: | 30 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal -f netcoreapp3.1 31 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal -f net6.0 32 | dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal -f net5.0 33 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-windows.yml: -------------------------------------------------------------------------------- 1 | name: Windows (dotnet build and test) 2 | 3 | on: 4 | push: 5 | branches: [develop] 6 | pull_request: 7 | branches: [develop] 8 | 9 | jobs: 10 | os-tests: 11 | runs-on: windows-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: | 18 | 3.1.x 19 | 5.0.x 20 | 6.0.x 21 | 7.0.x 22 | - name: Install Android 23 | run: dotnet workload install android 24 | - name: Restore dependencies 25 | run: dotnet restore ./src/CSharp/EasyMicroservices.FileManager.sln 26 | - name: Build 27 | run: dotnet build ./src/CSharp/EasyMicroservices.FileManager.sln --no-restore 28 | - name: Test 29 | run: dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal 30 | -------------------------------------------------------------------------------- /.github/workflows/golang.yml: -------------------------------------------------------------------------------- 1 | name: Golang (build and test) 2 | on: 3 | push: 4 | branches: 5 | - develop 6 | - main 7 | pull_request: 8 | branches: 9 | - develop 10 | - main 11 | 12 | jobs: 13 | testing: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | with: 18 | fetch-depth: 2 19 | - uses: actions/setup-go@v3 20 | with: 21 | go-version: '1.19' 22 | check-latest: true 23 | cache: true 24 | cache-dependency-path: src/Golang/go.sum 25 | - name: Run coverage 26 | run: cd src/Golang/ ; go test -race -coverprofile=coverage.out -covermode=atomic $(find . -name go.mod | sed "s/go.mod/.../g") 27 | - name: Upload coverage to Codecov 28 | uses: codecov/codecov-action@v3 29 | with: 30 | token: 31 | files: src/Golang/coverage.out 32 | fail_ci_if_error: true 33 | -------------------------------------------------------------------------------- /.github/workflows/nuget-push-public.yml: -------------------------------------------------------------------------------- 1 | name: NuGet Push Public 2 | 3 | on: [workflow_dispatch] 4 | 5 | jobs: 6 | build-test-prep-push: 7 | runs-on: windows-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: actions/setup-dotnet@v3 11 | with: 12 | dotnet-version: | 13 | 3.1.x 14 | 5.0.x 15 | 6.0.x 16 | 7.0.x 17 | env: 18 | DOTNET_INSTALL_DIR: /usr/share/dotnet 19 | - name: Restore dependencies 20 | run: dotnet restore ./src/CSharp/EasyMicroservices.FileManager.sln 21 | - name: Build 22 | run: dotnet build ./src/CSharp/EasyMicroservices.FileManager.sln --no-restore 23 | - name: Test 24 | run: dotnet test ./src/CSharp/EasyMicroservices.FileManager.sln --no-build --verbosity normal 25 | - name: Create the package 26 | run: dotnet pack ./src/CSharp/EasyMicroservices.FileManager.sln --output nupkgs 27 | - name: Publish the package to NuGet.org 28 | run: dotnet nuget push nupkgs\*.nupkg -k ${{secrets.NUGET_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust (build and test) 2 | on: 3 | push: 4 | branches: 5 | - develop 6 | - main 7 | pull_request: 8 | branches: 9 | - develop 10 | - main 11 | 12 | jobs: 13 | testing: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout sources 17 | uses: actions/checkout@v3 18 | 19 | - name: Install nightly toolchain 20 | uses: actions-rs/toolchain@v1 21 | with: 22 | profile: minimal 23 | toolchain: nightly 24 | override: true 25 | 26 | - name: Installing dependencies 27 | run: | 28 | cargo version 29 | rustup component add rustfmt 30 | 31 | - name: Install Rust nightly 32 | run: rustup toolchain install nightly --component llvm-tools-preview 33 | 34 | - name: Install cargo-llvm-cov 35 | uses: taiki-e/install-action@cargo-llvm-cov 36 | 37 | - name: Generate code coverage 38 | run: cd src/Rust ; cargo llvm-cov --lib --all-features --workspace --lcov --output-path lcov.info 39 | 40 | - name: Upload coverage to Codecov 41 | uses: codecov/codecov-action@v3 42 | with: 43 | token: 44 | files: src/Rust/lcov.info 45 | fail_ci_if_error: true 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | ## Git ignore for rust 353 | # Generated by Cargo 354 | # will have compiled files and executables 355 | debug/ 356 | target/ 357 | 358 | # These are backup files generated by rustfmt 359 | **/*.rs.bk 360 | 361 | # MSVC Windows builds of rustc generate these, which store debugging information 362 | *.pdb 363 | 364 | # IDE 365 | **/.idea/ 366 | **/.vscode/ 367 | .idea/ 368 | .vscode/ 369 | 370 | ## For golang 371 | # If you prefer the allow list template instead of the deny list, see community template: 372 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 373 | # 374 | # Binaries for programs and plugins 375 | *.exe 376 | *.exe~ 377 | *.dll 378 | *.so 379 | *.dylib 380 | 381 | # Test binary, built with `go test -c` 382 | *.test 383 | 384 | # Output of the go coverage tool, specifically when used with LiteIDE 385 | *.out 386 | 387 | # Dependency directories (remove the comment below to include it) 388 | # vendor/ 389 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Easy-Microservise 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FileManager 2 | Manage your files with a wrapper in everywhere. 3 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AmazonS3/EasyMicroservices.FileManager.AmazonS3.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0;netstandard2.1;net6.0 5 | EasyMicroservices 6 | true 7 | 0.0.0.2 8 | Manage your files with a wrapper in everywhere. 9 | EasyMicroservice@gmail.com 10 | s3,storage 11 | https://github.com/Easy-Microservise/FileManager 12 | latest 13 | true 14 | .\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.FileManager.AmazonS3.xml 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AmazonS3/Providers/AmazonS3BucketProvider.cs: -------------------------------------------------------------------------------- 1 | using Amazon.S3; 2 | using Amazon.S3.Model; 3 | using Amazon.S3.Util; 4 | using EasyMicroservices.FileManager.Models; 5 | using EasyMicroservices.FileManager.Providers.DirectoryProviders; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace EasyMicroservices.FileManager.AmazonS3.Providers 10 | { 11 | /// 12 | /// Working with AWS S3 storage 13 | /// 14 | public class AmazonS3BucketProvider : BaseDirectoryProvider 15 | { 16 | internal readonly IAmazonS3 _client; 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | public AmazonS3BucketProvider(IAmazonS3 client, string bucket) : base(bucket, new AmazonS3PathProvider()) 23 | { 24 | _client = client; 25 | } 26 | 27 | /// 28 | /// 29 | /// 30 | /// Storage AccessKey 31 | /// Storage SecretKey 32 | /// Endpoint Url 33 | /// 34 | public AmazonS3BucketProvider(string accessKey, string secretKey, string endpointUrl, string bucket) : base(bucket, new AmazonS3PathProvider()) 35 | { 36 | var awsCredentials = new Amazon.Runtime.BasicAWSCredentials(accessKey, secretKey); 37 | var config = new AmazonS3Config { ServiceURL = endpointUrl, UseAccelerateEndpoint = false, UseHttp = true, ForcePathStyle = true }; 38 | _client = new AmazonS3Client(awsCredentials, config); 39 | } 40 | 41 | 42 | /// 43 | /// create a new Amazon S3 bucket. 44 | /// 45 | /// The name of the bucket to create. 46 | /// 47 | /// return result message. 48 | public override async Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default) 49 | { 50 | var putBucketRequest = new PutBucketRequest 51 | { 52 | BucketName = path, 53 | UseClientRegion = true 54 | }; 55 | 56 | await _client.PutBucketAsync(putBucketRequest); 57 | 58 | return new DirectoryDetail(this) 59 | { 60 | Name = path, 61 | }; 62 | } 63 | /// 64 | /// Get a list of the buckets owned by the default user. 65 | /// 66 | /// The response from the ListingBuckets call that contains a 67 | /// list of the buckets owned by the default user. 68 | public override Task GetDirectoryAsync(string path, CancellationToken cancellationToken = default) 69 | { 70 | throw new System.NotImplementedException(); 71 | } 72 | /// 73 | /// check the S3 bucket bucketName exists. 74 | /// 75 | /// The name of the bucket to check. 76 | /// 77 | /// return true if bucket exists. 78 | public override async Task IsExistDirectoryAsync(string path, CancellationToken cancellationToken = default) 79 | { 80 | return await AmazonS3Util.DoesS3BucketExistV2Async(_client, path); 81 | } 82 | /// 83 | /// delete the S3 bucket. 84 | /// 85 | /// The name of the bucket to be deleted. 86 | /// 87 | /// return result message. 88 | public override async Task DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default) 89 | { 90 | var response = await _client.DeleteBucketAsync(path); 91 | if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) 92 | { 93 | return true; 94 | } 95 | else 96 | { 97 | return false; 98 | } 99 | } 100 | /// 101 | /// 102 | /// 103 | /// 104 | /// 105 | /// 106 | /// 107 | /// 108 | public override Task DeleteDirectoryAsync(string path, bool recursive, CancellationToken cancellationToken = default) 109 | { 110 | throw new System.NotImplementedException(); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AmazonS3/Providers/AmazonS3ObjectProvider.cs: -------------------------------------------------------------------------------- 1 | using Amazon.S3; 2 | using Amazon.S3.Model; 3 | using Amazon.S3.Util; 4 | using EasyMicroservices.FileManager.Interfaces; 5 | using EasyMicroservices.FileManager.Models; 6 | using EasyMicroservices.FileManager.Providers.FileProviders; 7 | using System.IO; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace EasyMicroservices.FileManager.AmazonS3.Providers 12 | { 13 | /// 14 | /// Working with AWS S3 storage 15 | /// 16 | public class AmazonS3ObjectProvider : BaseFileProvider 17 | { 18 | private readonly IAmazonS3 _client; 19 | 20 | /// 21 | /// 22 | /// 23 | /// 24 | /// 25 | public AmazonS3ObjectProvider(IDirectoryManagerProvider directoryManagerProvider, IAmazonS3 client) : base(directoryManagerProvider) 26 | { 27 | DirectoryManagerProvider = directoryManagerProvider; 28 | PathProvider = directoryManagerProvider.PathProvider; 29 | _client = client; 30 | } 31 | 32 | /// 33 | /// 34 | /// 35 | /// 36 | public AmazonS3ObjectProvider(IDirectoryManagerProvider directoryManagerProvider) : base(directoryManagerProvider) 37 | { 38 | DirectoryManagerProvider = directoryManagerProvider; 39 | PathProvider = directoryManagerProvider.PathProvider; 40 | _client = (directoryManagerProvider as AmazonS3BucketProvider)._client; 41 | } 42 | 43 | /// 44 | /// Create a file 45 | /// 46 | /// 47 | /// 48 | /// 49 | /// 50 | public override async Task CreateFileAsync(string path, CancellationToken cancellationToken = default) 51 | { 52 | var file = await GetFileAsync(path); 53 | var putRequest = new PutObjectRequest 54 | { 55 | BucketName = DirectoryManagerProvider.Root, 56 | Key = file.Name, 57 | ContentType = "text/plain", 58 | UseChunkEncoding = false 59 | }; 60 | 61 | putRequest.Metadata.Add("x-amz-meta-title", "someTitle"); 62 | PutObjectResponse response = await _client.PutObjectAsync(putRequest, new System.Threading.CancellationToken()); 63 | 64 | var objects3 = new FileDetail(this); 65 | objects3.Name = putRequest.Key; 66 | objects3.DirectoryPath = putRequest.BucketName; 67 | return objects3; 68 | } 69 | /// 70 | /// delete file 71 | /// 72 | /// 73 | /// 74 | /// 75 | /// 76 | public override async Task DeleteFileAsync(string path, CancellationToken cancellationToken = default) 77 | { 78 | var file = await GetFileAsync(path); 79 | DeleteObjectRequest request = new() 80 | { 81 | BucketName = path, 82 | Key = file.Name 83 | }; 84 | 85 | DeleteObjectResponse response = await _client.DeleteObjectAsync(request); 86 | if (response.HttpStatusCode == System.Net.HttpStatusCode.NoContent) 87 | return true; 88 | else 89 | return false; 90 | 91 | } 92 | 93 | /// 94 | /// check if file is exists 95 | /// 96 | /// 97 | /// 98 | /// 99 | /// 100 | public override async Task IsExistFileAsync(string path, CancellationToken cancellationToken = default) 101 | { 102 | var file = await GetFileAsync(path); 103 | return await AmazonS3Util.DoesS3BucketExistV2Async(_client, file.Name); 104 | } 105 | /// 106 | /// open file to read or write stream 107 | /// 108 | /// 109 | /// 110 | /// 111 | /// 112 | public override async Task OpenFileAsync(string path, CancellationToken cancellationToken = default) 113 | { 114 | var file = await GetFileAsync(path); 115 | GetObjectRequest request = new GetObjectRequest 116 | { 117 | BucketName = path, 118 | Key = file.Name, 119 | }; 120 | 121 | using (GetObjectResponse response = await _client.GetObjectAsync(request)) 122 | using (Stream responseStream = response.ResponseStream) 123 | { 124 | return responseStream; 125 | } 126 | } 127 | /// 128 | /// set length of file as 0 129 | /// 130 | /// 131 | /// 132 | /// 133 | /// 134 | public override Task TruncateFileAsync(string path, CancellationToken cancellationToken = default) 135 | { 136 | throw new System.NotImplementedException(); 137 | } 138 | /// 139 | /// write stream to a file 140 | /// 141 | /// 142 | /// 143 | /// 144 | /// 145 | /// 146 | public override Task WriteStreamToFileAsync(string path, Stream stream, CancellationToken cancellationToken = default) 147 | { 148 | throw new System.NotImplementedException(); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AmazonS3/Providers/AmazonS3PathProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Providers.PathProviders; 2 | using System.IO; 3 | 4 | namespace EasyMicroservices.FileManager.AmazonS3.Providers 5 | { 6 | /// 7 | /// 8 | /// 9 | public class AmazonS3PathProvider : BasePathProvider 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | public override string Combine(params string[] paths) 17 | { 18 | return Path.Combine(paths).Replace("\\", "/").Trim('/'); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Android/EasyMicroservices.FileManager.Android.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0-android 4 | 21 5 | EasyMicroservices 6 | true 7 | 0.0.0.1 8 | Manage your files with a wrapper in everywhere. 9 | EasyMicroservice@gmail.com 10 | android,storage 11 | https://github.com/Easy-Microservise/FileManager 12 | latest 13 | true 14 | .\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.FileManager.Android.xml 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Android/Providers/AndroidDiskDirectoryProvider.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using EasyMicroservices.FileManager.Interfaces; 3 | using EasyMicroservices.FileManager.Providers.DirectoryProviders; 4 | using System.Threading.Tasks; 5 | 6 | namespace EasyMicroservices.FileManager.Android.Providers 7 | { 8 | /// 9 | /// Disk directory provider for android 10 | /// 11 | public class AndroidDiskDirectoryProvider : DiskDirectoryProvider 12 | { 13 | AndroidPermissionManager androidPermissionManager; 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public AndroidDiskDirectoryProvider(Activity activity, string root, IPathProvider pathProvider) : base(root, pathProvider) 20 | { 21 | androidPermissionManager = new AndroidPermissionManager(activity); 22 | } 23 | /// 24 | /// 25 | /// 26 | /// 27 | public AndroidDiskDirectoryProvider(Activity activity, string root) : base(root) 28 | { 29 | androidPermissionManager = new AndroidPermissionManager(activity); 30 | } 31 | 32 | /// 33 | /// check permission 34 | /// 35 | /// 36 | /// 37 | public override async Task CheckPermissionAsync(string path) 38 | { 39 | return await androidPermissionManager.GetPermission(path); 40 | } 41 | 42 | /// 43 | /// complete check permission 44 | /// 45 | /// 46 | public override void CompleteCheckPermission(bool isComplete) 47 | { 48 | androidPermissionManager.Complete(isComplete); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Android/Providers/AndroidDiskFileProvider.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using EasyMicroservices.FileManager.Interfaces; 3 | using EasyMicroservices.FileManager.Providers.FileProviders; 4 | using System.Threading.Tasks; 5 | 6 | namespace EasyMicroservices.FileManager.Android.Providers 7 | { 8 | public class AndroidDiskFileProvider : DiskFileProvider 9 | { 10 | AndroidPermissionManager androidPermissionManager; 11 | 12 | /// 13 | /// 14 | /// 15 | /// 16 | public AndroidDiskFileProvider(Activity activity, IDirectoryManagerProvider directoryManagerProvider) : base(directoryManagerProvider) 17 | { 18 | androidPermissionManager = new AndroidPermissionManager(activity); 19 | } 20 | /// 21 | /// check permission 22 | /// 23 | /// 24 | /// 25 | public override async Task CheckPermissionAsync(string path) 26 | { 27 | return await androidPermissionManager.GetPermission(path); 28 | } 29 | 30 | /// 31 | /// complete check permission 32 | /// 33 | /// 34 | public override void CompleteCheckPermission(bool isComplete) 35 | { 36 | androidPermissionManager.Complete(isComplete); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Android/Providers/AndroidPermissionManager.cs: -------------------------------------------------------------------------------- 1 | using Android; 2 | using Android.App; 3 | using Android.Content.PM; 4 | using Android.OS; 5 | using AndroidX.Core.App; 6 | using AndroidX.Core.Content; 7 | using System; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace EasyMicroservices.FileManager.Android.Providers 12 | { 13 | public class AndroidPermissionManager 14 | { 15 | /// 16 | /// request id of permission check 17 | /// 18 | public const int RequestId = 9669; 19 | readonly Activity _activity; 20 | public AndroidPermissionManager(Activity activity) 21 | { 22 | _activity = activity; 23 | var ct = new CancellationTokenSource(TimeSpan.FromSeconds(20)); 24 | ct.Token.Register(() => CompleteGetPermissionTask.TrySetCanceled(), useSynchronizationContext: false); 25 | } 26 | 27 | /// 28 | /// Wait for get permisssion 29 | /// 30 | TaskCompletionSource CompleteGetPermissionTask { get; set; } = new TaskCompletionSource(); 31 | 32 | public async Task GetPermission(string path) 33 | { 34 | if (Build.VERSION.SdkInt >= BuildVersionCodes.M) 35 | { 36 | #pragma warning disable CA1416 // Validate platform compatibility 37 | if (_activity.CheckSelfPermission(Manifest.Permission.WriteExternalStorage) == Permission.Denied) 38 | #pragma warning restore CA1416 // Validate platform compatibility 39 | { 40 | ActivityCompat.RequestPermissions(_activity, new string[] { Manifest.Permission.WriteExternalStorage }, RequestId); 41 | return await CompleteGetPermissionTask.Task; 42 | } 43 | } 44 | else 45 | { 46 | if (ContextCompat.CheckSelfPermission(_activity, Manifest.Permission.WriteExternalStorage) == Permission.Denied) 47 | { 48 | ActivityCompat.RequestPermissions(_activity, new string[] { Manifest.Permission.WriteExternalStorage }, RequestId); 49 | return await CompleteGetPermissionTask.Task; 50 | } 51 | } 52 | Complete(true); 53 | return true; 54 | } 55 | 56 | public void Complete(bool isComplete) 57 | { 58 | CompleteGetPermissionTask.TrySetResult(isComplete); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/EasyMicroservices.FileManager.AndroidTestApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net7.0-android 4 | 21 5 | Exe 6 | enable 7 | enable 8 | easymicroservices.filemanager.androidTestApp 9 | 1 10 | 1.0 11 | C:\EM\FileManager\AndroidTestApp 12 | C:\EM\FileManager\AndroidTestApp\obj\ 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App.Roles; 2 | using Android.Content; 3 | using Android.Runtime; 4 | using EasyMicroservices.FileManager.Android.Providers; 5 | using EasyMicroservices.FileManager.Interfaces; 6 | namespace EasyMicroservices.FileManager.AndroidTestApp 7 | { 8 | [Activity(Label = "@string/app_name", MainLauncher = true)] 9 | public class MainActivity : Activity 10 | { 11 | IFileManagerProvider fileManager; 12 | IDirectoryManagerProvider directoryManager; 13 | 14 | protected override void OnCreate(Bundle? savedInstanceState) 15 | { 16 | base.OnCreate(savedInstanceState); 17 | directoryManager = new AndroidDiskDirectoryProvider(this, "/"); 18 | fileManager = new AndroidDiskFileProvider(this, directoryManager); 19 | CheckCreateDirectory(); 20 | // Set our view from the "main" layout resource 21 | SetContentView(Resource.Layout.activity_main); 22 | } 23 | 24 | public async Task CheckCreateDirectory() 25 | { 26 | var create = await directoryManager.CreateDirectoryAsync("AliTest"); 27 | } 28 | 29 | protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent? data) 30 | { 31 | if (requestCode == AndroidPermissionManager.RequestId) 32 | { 33 | fileManager.CompleteCheckPermission(resultCode == Result.Ok); 34 | directoryManager.CompleteCheckPermission(resultCode == Result.Ok); 35 | } 36 | base.OnActivityResult(requestCode, resultCode, data); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.xml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.xml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "Resource" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the Resource class would expose: 26 | 27 | public class Resource { 28 | public class Drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class Layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class Strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use Resource.Drawable.icon to reference the drawable/icon.png file, or 43 | Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string 44 | to reference the first string in the dictionary file values/strings.xml. -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-anydpi-v26/appicon.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-anydpi-v26/appicon_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-hdpi/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-hdpi/appicon.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-hdpi/appicon_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-hdpi/appicon_background.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-hdpi/appicon_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-hdpi/appicon_foreground.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-mdpi/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-mdpi/appicon.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-mdpi/appicon_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-mdpi/appicon_background.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-mdpi/appicon_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-mdpi/appicon_foreground.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xhdpi/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xhdpi/appicon.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xhdpi/appicon_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xhdpi/appicon_background.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xhdpi/appicon_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xhdpi/appicon_foreground.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxhdpi/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxhdpi/appicon.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxhdpi/appicon_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxhdpi/appicon_background.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxhdpi/appicon_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxhdpi/appicon_foreground.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxxhdpi/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxxhdpi/appicon.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxxhdpi/appicon_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxxhdpi/appicon_background.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxxhdpi/appicon_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyMicroservices/FileManager/cf995781d3c95870ffe1be703f67795e3fda2486/src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/mipmap-xxxhdpi/appicon_foreground.png -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #2C3E50 4 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AndroidTestApp/Resources/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | EasyMicroservices.FileManager.AndroidTestApp 3 | Hello, Android! 4 | 5 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AzureStorageBlobs.Tests/EasyMicroservices.FileManager.AzureStorageBlobs.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | all 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AzureStorageBlobs.Tests/Providers/AzureStorageBlobsTest.cs: -------------------------------------------------------------------------------- 1 | using Azure.Storage.Blobs; 2 | using EasyMicroservices.FileManager.AzureStorageBlobs.Providers; 3 | 4 | namespace EasyMicroservices.FileManager.AzureStorageBlobs.Tests.Providers; 5 | 6 | /*public class AzureStorageBlobsTest 7 | { 8 | private readonly BlobContainerClient _blobContainerClient ; 9 | 10 | public AzureStorageBlobsTest() 11 | { 12 | 13 | _blobContainerClient = new BlobContainerClient(@"UseDevelopmentStorage=true", "sample-container"); 14 | _blobContainerClient.CreateIfNotExists(); 15 | 16 | } 17 | 18 | 19 | [Theory] 20 | [InlineData("Saba.txt")] 21 | [InlineData("Ali.txt")] 22 | [InlineData("CreateFile\\Ali.txt")] 23 | [InlineData("CreateFile\\Mahdi.txt")] 24 | public async Task CreateFile(string path) 25 | { 26 | AzureStorageBlobsProvider azureStorageBlobsProvider = new AzureStorageBlobsProvider(_blobContainerClient); 27 | 28 | if (await azureStorageBlobsProvider.IsExistFileAsync(path)) 29 | Assert.True(await azureStorageBlobsProvider.DeleteFileAsync(path)); 30 | Assert.False(await azureStorageBlobsProvider.IsExistFileAsync(path)); 31 | var createdBlob = await azureStorageBlobsProvider.CreateFileAsync(path); 32 | Assert.Equal(path, createdBlob.Name); 33 | Assert.True(await azureStorageBlobsProvider.IsExistFileAsync(path)); 34 | var file = await azureStorageBlobsProvider.GetFileAsync(path); 35 | Assert.NotEmpty(file.Name); 36 | Assert.NotEmpty(file.DirectoryPath); 37 | Assert.True(await azureStorageBlobsProvider.IsExistFileAsync(file.Name)); 38 | 39 | } 40 | 41 | [Theory] 42 | [MemberData(nameof(TestData))] 43 | public async Task WriteStreamToFile(string path, Stream stream) 44 | { 45 | AzureStorageBlobsProvider azureStorageBlobsProvider = new AzureStorageBlobsProvider(_blobContainerClient); 46 | 47 | await azureStorageBlobsProvider.WriteStreamToFileAsync(path, stream); 48 | var file = await azureStorageBlobsProvider.GetFileAsync(path); 49 | Assert.Equal(path, file.Name); 50 | Assert.True(file.Length > 0); 51 | 52 | } 53 | 54 | 55 | public static IEnumerable TestData() 56 | { 57 | yield return new object[] { "Saba.txt",GenerateStream( "this is test data for Saba.txt") }; 58 | yield return new object[] { "Ali.txt",GenerateStream( "this is test data for Ali.txt") }; 59 | yield return new object[] { "Mahdi.txt",GenerateStream( "this is test data for Mahdi.txt") }; 60 | yield return new object[] { "New.txt",GenerateStream( "this is test data for New.txt") }; 61 | } 62 | 63 | private static Stream GenerateStream(string s) 64 | { 65 | 66 | var stream = new MemoryStream(); 67 | var writer = new StreamWriter(stream); 68 | writer.Write(s); 69 | writer.Flush(); 70 | stream.Position = 0; 71 | return stream; 72 | } 73 | 74 | 75 | }*/ -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AzureStorageBlobs.Tests/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; 2 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AzureStorageBlobs/EasyMicroservices.FileManager.AzureStorageBlobs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.AzureStorageBlobs/Providers/AzureStorageBlobsProvider.cs: -------------------------------------------------------------------------------- 1 | using Azure; 2 | using Azure.Storage.Blobs; 3 | using Azure.Storage.Blobs.Models; 4 | using EasyMicroservices.FileManager.Interfaces; 5 | using EasyMicroservices.FileManager.Models; 6 | using EasyMicroservices.FileManager.Providers.FileProviders; 7 | using System.Reflection; 8 | 9 | namespace EasyMicroservices.FileManager.AzureStorageBlobs.Providers; 10 | 11 | /// 12 | /// 13 | /// 14 | public class AzureStorageBlobsProvider : BaseFileProvider 15 | { 16 | private readonly BlobContainerClient _container; 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | public AzureStorageBlobsProvider(BlobContainerClient container, IDirectoryManagerProvider directoryManagerProvider) : base(directoryManagerProvider) 23 | { 24 | _container = container; 25 | } 26 | 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | public AzureStorageBlobsProvider(string storageConnectionString, string storageContainerName, IDirectoryManagerProvider directoryManagerProvider) : base(directoryManagerProvider) 33 | { 34 | _container = new BlobContainerClient(storageConnectionString, storageContainerName); 35 | } 36 | 37 | 38 | public async Task GetFileAsync(string path) 39 | { 40 | FileDetail file = new FileDetail(this); 41 | BlobClient client = _container.GetBlobClient(path); 42 | if (await client.ExistsAsync()) 43 | { 44 | file.DirectoryPath = path; 45 | file.Name = path; 46 | Stream stream = await OpenFileAsync(path); 47 | file.Length = stream.Length; 48 | 49 | } 50 | 51 | return file; 52 | 53 | } 54 | 55 | /// 56 | /// 57 | /// 58 | /// Path is FileName for creating 59 | /// 60 | public override async Task CreateFileAsync(string path, CancellationToken cancellationToken = default) 61 | { 62 | 63 | BlobClient client = _container.GetBlobClient(path); 64 | if (await IsExistFileAsync(path)) 65 | await DeleteFileAsync(path); 66 | var response = await client.UploadAsync(Stream.Null); 67 | 68 | var objectBlob = new FileDetail(this); 69 | foreach (PropertyInfo prop in response.GetType().GetProperties()) 70 | { 71 | objectBlob.Name = path; 72 | objectBlob.DirectoryPath = path; 73 | } 74 | 75 | return objectBlob; 76 | 77 | } 78 | 79 | /// 80 | /// 81 | /// 82 | /// Path is FileName for opening 83 | /// 84 | public override async Task OpenFileAsync(string path, CancellationToken cancellationToken = default) 85 | { 86 | Stream blob = Stream.Null; 87 | 88 | BlobClient client = _container.GetBlobClient(path); 89 | 90 | if (await client.ExistsAsync()) 91 | { 92 | blob = await client.OpenReadAsync(); 93 | } 94 | 95 | return blob; 96 | } 97 | 98 | 99 | public async Task WriteStreamToFileAsync(string path, Stream stream) 100 | { 101 | BlobClient client = _container.GetBlobClient(path); 102 | 103 | await client.UploadAsync(stream, true); 104 | 105 | } 106 | 107 | /// 108 | /// 109 | /// 110 | /// Path is FileName for checking out 111 | /// 112 | public override async Task IsExistFileAsync(string path, CancellationToken cancellationToken = default) 113 | { 114 | BlobClient client = _container.GetBlobClient(path); 115 | bool exists = await client.ExistsAsync(); 116 | return exists; 117 | } 118 | 119 | /// 120 | /// 121 | /// 122 | /// Path is FileName to delete. 123 | /// 124 | public override async Task DeleteFileAsync(string path, CancellationToken cancellationToken = default) 125 | { 126 | try 127 | { 128 | BlobClient client = _container.GetBlobClient(path); 129 | await client.DeleteAsync(); 130 | } 131 | catch (RequestFailedException e) when (e.ErrorCode == BlobErrorCode.BlobNotFound) 132 | { 133 | return false; 134 | } 135 | catch (Exception e) 136 | { 137 | return false; 138 | } 139 | 140 | return true; 141 | } 142 | 143 | public override Task TruncateFileAsync(string path, CancellationToken cancellationToken = default) 144 | { 145 | BlobClient client = _container.GetBlobClient(path); 146 | 147 | throw new NotImplementedException(); 148 | } 149 | 150 | public async Task> GetListAsync() 151 | { 152 | List blobsList = new List(); 153 | await foreach (BlobItem item in _container.GetBlobsAsync()) 154 | { 155 | string name = item.Name; 156 | string uri = $"{_container.Uri.ToString()}/{name}"; 157 | blobsList.Add(new FileDetail(this) 158 | { 159 | Name = name, 160 | Length = item.Properties.ContentLength ?? 0, 161 | DirectoryPath = uri 162 | }); 163 | } 164 | 165 | return blobsList; 166 | } 167 | } 168 | 169 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/EasyMicroservices.FileManager.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1;net6.0;net7.0;net48 5 | false 6 | latest 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/Providers/DirectoryProviders/BaseDirectoryProviderTest.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using System.Threading.Tasks; 3 | using Xunit; 4 | 5 | namespace EasyMicroservices.FileManager.Tests.Providers.DirectoryProviders 6 | { 7 | public abstract class BaseDirectoryProviderTest 8 | { 9 | readonly IDirectoryManagerProvider _directoryManagerProvider; 10 | public BaseDirectoryProviderTest(IDirectoryManagerProvider directoryManagerProvider) 11 | { 12 | _directoryManagerProvider = directoryManagerProvider; 13 | } 14 | 15 | [Theory] 16 | [InlineData("Ali")] 17 | [InlineData("Mahdi")] 18 | public async Task CreateDirectory(string name) 19 | { 20 | if (await _directoryManagerProvider.IsExistDirectoryAsync(name)) 21 | Assert.True(await _directoryManagerProvider.DeleteDirectoryAsync(name, true)); 22 | Assert.False(await _directoryManagerProvider.IsExistDirectoryAsync(name)); 23 | await _directoryManagerProvider.CreateDirectoryAsync(name); 24 | Assert.True(await _directoryManagerProvider.IsExistDirectoryAsync(name)); 25 | var dir = await _directoryManagerProvider.GetDirectoryAsync(name); 26 | Assert.NotEmpty(dir.Name); 27 | Assert.NotEmpty(dir.DirectoryPath); 28 | Assert.True(await _directoryManagerProvider.IsExistDirectoryAsync(dir.FullPath)); 29 | } 30 | 31 | [Theory] 32 | [InlineData("Saeed")] 33 | [InlineData("Reza")] 34 | public async Task DeleteDirectory(string name) 35 | { 36 | Assert.False(await _directoryManagerProvider.IsExistDirectoryAsync(name)); 37 | await _directoryManagerProvider.CreateDirectoryAsync(name); 38 | Assert.True(await _directoryManagerProvider.IsExistDirectoryAsync(name)); 39 | Assert.True(await _directoryManagerProvider.DeleteDirectoryAsync(name)); 40 | Assert.False(await _directoryManagerProvider.IsExistDirectoryAsync(name)); 41 | } 42 | 43 | [Theory] 44 | [InlineData("Saeed", "Recursive")] 45 | [InlineData("Reza", "Recursive")] 46 | public async Task DeleteDirectoryRecursive(string name, string inside) 47 | { 48 | string path = _directoryManagerProvider.PathProvider.Combine(name, inside); 49 | Assert.False(await _directoryManagerProvider.IsExistDirectoryAsync(path)); 50 | await _directoryManagerProvider.CreateDirectoryAsync(path); 51 | Assert.True(await _directoryManagerProvider.IsExistDirectoryAsync(path)); 52 | Assert.True(await _directoryManagerProvider.DeleteDirectoryAsync(name, true)); 53 | Assert.False(await _directoryManagerProvider.IsExistDirectoryAsync(name)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/Providers/DirectoryProviders/DirectoryDiskProviderTest.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Providers.DirectoryProviders; 2 | using EasyMicroservices.FileManager.Providers.PathProviders; 3 | using System; 4 | using System.IO; 5 | 6 | namespace EasyMicroservices.FileManager.Tests.Providers.DirectoryProviders 7 | { 8 | public class DirectoryDiskProviderTest : BaseDirectoryProviderTest 9 | { 10 | public DirectoryDiskProviderTest() : base(new DiskDirectoryProvider(AppDomain.CurrentDomain.BaseDirectory)) 11 | { 12 | } 13 | } 14 | 15 | public class DirectoryDiskProviderSystemPathProviderTest : BaseDirectoryProviderTest 16 | { 17 | public DirectoryDiskProviderSystemPathProviderTest() : base(new DiskDirectoryProvider(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemPathProvider"), new SystemPathProvider())) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/Providers/DirectoryProviders/MemoryDiskProviderTest.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Providers.DirectoryProviders; 2 | using EasyMicroservices.FileManager.Providers.PathProviders; 3 | 4 | namespace EasyMicroservices.FileManager.Tests.Providers.DirectoryProviders 5 | { 6 | public class MemoryDiskProviderTest : BaseDirectoryProviderTest 7 | { 8 | public MemoryDiskProviderTest() : base(new MemoryDirectoryProvider("MemoryDisk")) 9 | { 10 | } 11 | } 12 | 13 | public class MemoryDiskProviderSystemPathProviderTest : BaseDirectoryProviderTest 14 | { 15 | public MemoryDiskProviderSystemPathProviderTest() : base(new MemoryDirectoryProvider("MemoryDiskSystemPathProvider", new SystemPathProvider())) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/Providers/FileProviders/AmazonS3FileProviderTest.cs: -------------------------------------------------------------------------------- 1 | using Amazon.S3; 2 | using EasyMicroservices.FileManager.AmazonS3.Providers; 3 | using EasyMicroservices.Laboratory.Constants; 4 | using EasyMicroservices.Laboratory.Engine; 5 | using EasyMicroservices.Laboratory.Engine.Net.Http; 6 | using EasyMicroservices.Laboratory.Models; 7 | using System; 8 | using System.Net.Http; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using Xunit; 12 | 13 | namespace EasyMicroservices.FileManager.Tests.Providers.FileProviders 14 | { 15 | public class AmazonS3FileProviderTest : BaseFileProviderTest 16 | { 17 | static AmazonS3FileProviderTest() 18 | { 19 | HttpHandler = new HttpHandler(ResourceManager); 20 | } 21 | 22 | const int amazonS3Port = 1801; 23 | public AmazonS3FileProviderTest() : base(new AmazonS3ObjectProvider(new AmazonS3BucketProvider(GetClient(), "mybucket/temp"))) 24 | { 25 | } 26 | 27 | static HttpHandler HttpHandler = default; 28 | static ResourceManager ResourceManager = new ResourceManager(); 29 | 30 | static IAmazonS3 GetClient() 31 | { 32 | string url = $"http://localhost:{amazonS3Port}"; 33 | var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("ATESTQTEST452TEST76L", "SecretKey"); 34 | var config = new AmazonS3Config 35 | { 36 | ServiceURL = url, 37 | }; 38 | return new AmazonS3Client(awsCredentials, config); 39 | } 40 | 41 | static bool _isInitialized = false; 42 | static SemaphoreSlim Semaphore = new SemaphoreSlim(1); 43 | public override async Task OnInitialize(string methodName) 44 | { 45 | try 46 | { 47 | await Semaphore.WaitAsync(); 48 | if (!_isInitialized) 49 | await HttpHandler.Start(amazonS3Port); 50 | _isInitialized = true; 51 | ResourceManager.Clear(); 52 | 53 | if (methodName == nameof(CreateFile)) 54 | ResourceManager.Append(CreateFileScope()); 55 | else 56 | ResourceManager.Append(DeleteFileScope()); 57 | 58 | //create file 59 | ResourceManager.Append(@"PUT *RequestSkipBody* HTTP/1.1 60 | *RequestSkipBody*" 61 | , 62 | @"HTTP/1.1 200 OK 63 | x-amz-id-2: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 64 | x-amz-request-id: 0A49CE4060975EAC 65 | x-amz-version-id: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 66 | Date: Wed, 12 Oct 2009 17:50:00 GMT 67 | ETag: ""D41D8CD98F00B204E9800998ECF8427E"" 68 | Content-Length: 0 69 | Connection: close 70 | Server: AmazonS3 71 | 72 | "); 73 | } 74 | finally 75 | { 76 | Semaphore.Release(); 77 | } 78 | } 79 | 80 | Scope CreateFileScope() 81 | { 82 | var scope = new Scope(); 83 | AppendExistFile(scope); 84 | AppendDeleteFile(scope); 85 | AppendNotExistFile(scope); 86 | AppendExistFile(scope); 87 | return scope; 88 | } 89 | 90 | Scope DeleteFileScope() 91 | { 92 | var scope = new Scope(); 93 | AppendNotExistFile(scope); 94 | AppendExistFile(scope); 95 | AppendDeleteFile(scope); 96 | AppendNotExistFile(scope); 97 | return scope; 98 | } 99 | 100 | void AppendExistFile(Scope scope) 101 | { 102 | //exist file 103 | scope.AppendNext(@"GET *RequestSkipBody*?acl HTTP/1.1 104 | *RequestSkipBody*" 105 | , 106 | @$"HTTP/1.1 200 OK 107 | x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran 108 | x-amz-request-id: 318BC8BC148832E5 109 | Date: Wed, 28 Oct 2009 22:32:00 GMT 110 | Last-Modified: Sun, 1 Jan 2006 12:00:00 GMT 111 | Content-Type: application/xml 112 | Connection: close 113 | Server: AmazonS3 114 | Content-Length: 0 115 | 116 | 117 | 118 | {Guid.NewGuid()} 119 | CustomersName@amazon.com 120 | 121 | 122 | 123 | 125 | 75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a 126 | CustomersName@amazon.com 127 | 128 | FULL_CONTROL 129 | 130 | 131 | 132 | "); 133 | } 134 | 135 | void AppendNotExistFile(Scope scope) 136 | { 137 | scope.AppendNext(@"GET *RequestSkipBody*?acl HTTP/1.1 138 | *RequestSkipBody*" 139 | , 140 | @"HTTP/1.1 404 NotFound 141 | x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran 142 | x-amz-request-id: 318BC8BC148832E5 143 | Date: Wed, 28 Oct 2009 22:32:00 GMT 144 | Last-Modified: Sun, 1 Jan 2006 12:00:00 GMT 145 | Content-Type: application/xml 146 | Connection: close 147 | Server: AmazonS3 148 | Content-Length: 0 149 | 150 | 151 | NoSuchBucket 152 | The resource you requested does not exist 153 | /mybucket/myfoto.jpg 154 | 4442587FB7D0A2F9 155 | 156 | "); 157 | } 158 | 159 | void AppendDeleteFile(Scope scope) 160 | { 161 | //delete file 162 | scope.AppendNext(@"DELETE *RequestSkipBody* HTTP/1.1 163 | *RequestSkipBody*" 164 | , 165 | @"HTTP/1.1 204 No Content 166 | x-amz-id-2: JuKZqmXuiwFeDQxhD7M8KtsKobSzWA1QEjLbTMTagkKdBX2z7Il/jGhDeJ3j6s80 167 | x-amz-request-id: 32FE2CEB32F5EE25 168 | Date: Wed, 01 Mar 2006 12:00:00 GMT 169 | Connection: close 170 | Server: AmazonS3 171 | 172 | "); 173 | } 174 | 175 | public override async Task GetException(Exception ex) 176 | { 177 | HttpClient httpClient = new HttpClient(); 178 | httpClient.DefaultRequestHeaders.Add(RequestTypeHeaderConstants.RequestTypeHeader, RequestTypeHeaderConstants.GiveMeLastFullRequestHeaderValue); 179 | var httpResponse = await httpClient.GetAsync($"http://localhost:{amazonS3Port}"); 180 | var textResponse = await httpResponse.Content.ReadAsStringAsync(); 181 | throw new Exception(textResponse, ex); 182 | } 183 | 184 | public override Task StreamWriteFile(string name) 185 | { 186 | return TaskHelper.GetCompletedTask(); 187 | } 188 | 189 | public override Task TruncateFile(string name) 190 | { 191 | return TaskHelper.GetCompletedTask(); 192 | } 193 | 194 | public override Task WriteAndReadFile(string name) 195 | { 196 | return TaskHelper.GetCompletedTask(); 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/Providers/FileProviders/BaseFileProviderTest.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using System; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Xunit; 7 | 8 | namespace EasyMicroservices.FileManager.Tests.Providers.FileProviders 9 | { 10 | public abstract class BaseFileProviderTest 11 | { 12 | protected readonly IFileManagerProvider _fileManagerProvider; 13 | public BaseFileProviderTest(IFileManagerProvider fileManagerProvider) 14 | { 15 | _fileManagerProvider = fileManagerProvider; 16 | } 17 | 18 | 19 | public virtual Task OnInitialize(string methodName) 20 | { 21 | return TaskHelper.GetCompletedTask(); 22 | } 23 | 24 | public virtual Task GetException(Exception ex) 25 | { 26 | return TaskHelper.GetCompletedTask(); 27 | } 28 | 29 | [Theory] 30 | [InlineData("Ali.txt")] 31 | [InlineData("Mahdi.txt")] 32 | [InlineData("CreateFile\\Ali.txt")] 33 | [InlineData("CreateFile\\Mahdi.txt")] 34 | public virtual async Task CreateFile(string name) 35 | { 36 | try 37 | { 38 | await OnInitialize(nameof(CreateFile)); 39 | if (await _fileManagerProvider.IsExistFileAsync(name)) 40 | Assert.True(await _fileManagerProvider.DeleteFileAsync(name)); 41 | Assert.False(await _fileManagerProvider.IsExistFileAsync(name)); 42 | await _fileManagerProvider.CreateFileAsync(name); 43 | Assert.True(await _fileManagerProvider.IsExistFileAsync(name)); 44 | var file = await _fileManagerProvider.GetFileAsync(name); 45 | Assert.NotEmpty(file.Name); 46 | Assert.NotEmpty(file.DirectoryPath); 47 | Assert.True(await _fileManagerProvider.IsExistFileAsync(file.FullPath)); 48 | } 49 | catch (Exception ex) 50 | { 51 | await GetException(ex); 52 | } 53 | } 54 | 55 | [Theory] 56 | [InlineData("Saeed.txt")] 57 | [InlineData("Reza.txt")] 58 | [InlineData("DeleteFile\\Saeed.txt")] 59 | [InlineData("DeleteFile\\Reza.txt")] 60 | public virtual async Task DeleteFile(string name) 61 | { 62 | try 63 | { 64 | await OnInitialize(nameof(DeleteFile)); 65 | Assert.False(await _fileManagerProvider.IsExistFileAsync(name)); 66 | await _fileManagerProvider.CreateFileAsync(name); 67 | Assert.True(await _fileManagerProvider.IsExistFileAsync(name)); 68 | Assert.True(await _fileManagerProvider.DeleteFileAsync(name)); 69 | Assert.False(await _fileManagerProvider.IsExistFileAsync(name)); 70 | } 71 | catch (Exception ex) 72 | { 73 | await GetException(ex); 74 | } 75 | } 76 | 77 | [Theory] 78 | [InlineData("AliTruncate.txt")] 79 | [InlineData("MahdiTruncate.txt")] 80 | [InlineData("CreateFile\\AliTruncate.txt")] 81 | [InlineData("CreateFile\\MahdiTruncate.txt")] 82 | public virtual async Task TruncateFile(string name) 83 | { 84 | await OnInitialize(nameof(TruncateFile)); 85 | if (await _fileManagerProvider.IsExistFileAsync(name)) 86 | Assert.True(await _fileManagerProvider.DeleteFileAsync(name)); 87 | Assert.False(await _fileManagerProvider.IsExistFileAsync(name)); 88 | await _fileManagerProvider.CreateFileAsync(name); 89 | await _fileManagerProvider.TruncateFileAsync(name); 90 | var file = await _fileManagerProvider.GetFileAsync(name); 91 | Assert.True(file.Length == 0); 92 | } 93 | 94 | [Theory] 95 | [InlineData("AliStreamWrite.txt")] 96 | [InlineData("MahdiStreamWrite.txt")] 97 | [InlineData("CreateFile\\AliStreamWrite.txt")] 98 | [InlineData("CreateFile\\MahdiStreamWrite.txt")] 99 | public virtual async Task StreamWriteFile(string name) 100 | { 101 | await OnInitialize(nameof(StreamWriteFile)); 102 | if (await _fileManagerProvider.IsExistFileAsync(name)) 103 | Assert.True(await _fileManagerProvider.DeleteFileAsync(name)); 104 | Assert.False(await _fileManagerProvider.IsExistFileAsync(name)); 105 | var fileSetails = await _fileManagerProvider.CreateFileAsync(name); 106 | await _fileManagerProvider.TruncateFileAsync(name); 107 | var file = await _fileManagerProvider.GetFileAsync(name); 108 | Assert.True(file.Length == 0); 109 | 110 | long length = 1024; 111 | var streamToRead = await TaskRandomStream(length); 112 | await fileSetails.WriteStreamToFileAsync(streamToRead); 113 | file = await _fileManagerProvider.GetFileAsync(name); 114 | Assert.True(file.Length == length); 115 | var readStream = await fileSetails.OpenFileAsync(); 116 | 117 | await CheckReadStream(readStream, length); 118 | } 119 | 120 | [Theory] 121 | [InlineData("AliReadWrite.txt")] 122 | [InlineData("MahdiReadWrite.txt")] 123 | [InlineData("ReadWriteFile\\Ali.txt")] 124 | [InlineData("ReadWriteFile\\Mahdi.txt")] 125 | public virtual async Task WriteAndReadFile(string name) 126 | { 127 | await OnInitialize(nameof(WriteAndReadFile)); 128 | if (await _fileManagerProvider.IsExistFileAsync(name)) 129 | await _fileManagerProvider.TruncateFileAsync(name); 130 | else 131 | await _fileManagerProvider.CreateFileAsync(name); 132 | Assert.True(await _fileManagerProvider.IsExistFileAsync(name)); 133 | string[] lines = new string[] 134 | { 135 | "line1", 136 | "line2" 137 | }; 138 | await _fileManagerProvider.WriteAllLinesAsync(name, lines); 139 | var readLines = await _fileManagerProvider.ReadAllLinesAsync(name); 140 | Assert.True(lines.SequenceEqual(readLines)); 141 | 142 | await _fileManagerProvider.TruncateFileAsync(name); 143 | var bytes = new byte[] 144 | { 145 | 1, 146 | 2, 147 | 5, 148 | 7 149 | }; 150 | await _fileManagerProvider.WriteAllBytesAsync(name, bytes); 151 | var allBytes = await _fileManagerProvider.ReadAllBytesAsync(name); 152 | Assert.True(bytes.SequenceEqual(allBytes)); 153 | 154 | await _fileManagerProvider.TruncateFileAsync(name); 155 | var text = "My name is ali"; 156 | await _fileManagerProvider.WriteAllTextAsync(name, text); 157 | var readText = await _fileManagerProvider.ReadAllTextAsync(name); 158 | Assert.Equal(text, readText); 159 | } 160 | 161 | async Task TaskRandomStream(long length) 162 | { 163 | MemoryStream stream = new MemoryStream(); 164 | byte[] bytes = new byte[length]; 165 | for (int i = 0; i < bytes.Length; i++) 166 | { 167 | bytes[i]++; 168 | } 169 | await stream.WriteAsync(bytes, 0, bytes.Length); 170 | return stream; 171 | } 172 | 173 | async Task CheckReadStream(Stream stream, long length) 174 | { 175 | stream.Seek(0, SeekOrigin.Begin); 176 | using var toStream = new MemoryStream(); 177 | var readBytes = new byte[length]; 178 | long writed = 0; 179 | while (writed < length) 180 | { 181 | int readCount; 182 | if (readBytes.Length > length - writed) 183 | readBytes = new byte[length - writed]; 184 | readCount = await stream.ReadAsync(readBytes, 0, readBytes.Length); 185 | if (readCount <= 0) 186 | throw new Exception("Client disconnected!"); 187 | await toStream.WriteAsync(readBytes, 0, readCount); 188 | writed += readCount; 189 | } 190 | 191 | toStream.Seek(0, SeekOrigin.Begin); 192 | foreach (var item in toStream.ToArray()) 193 | { 194 | Assert.True(item == 1); 195 | } 196 | } 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/Providers/FileProviders/DiskFileProviderTest.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Providers.DirectoryProviders; 2 | using EasyMicroservices.FileManager.Providers.FileProviders; 3 | using System; 4 | 5 | namespace EasyMicroservices.FileManager.Tests.Providers.FileProviders 6 | { 7 | public class DiskFileProviderTest : BaseFileProviderTest 8 | { 9 | public DiskFileProviderTest() : base(new DiskFileProvider(new DiskDirectoryProvider(AppDomain.CurrentDomain.BaseDirectory)) { BufferSize = 1024 * 1024 }) 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.Tests/Providers/FileProviders/MemoryFileProviderTest.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Providers.DirectoryProviders; 2 | using EasyMicroservices.FileManager.Providers.FileProviders; 3 | 4 | namespace EasyMicroservices.FileManager.Tests.Providers.FileProviders 5 | { 6 | public class MemoryFileProviderTest : BaseFileProviderTest 7 | { 8 | public MemoryFileProviderTest() : base(new MemoryFileProvider(new MemoryDirectoryProvider("MemoryFileProviderTest"))) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33110.190 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyMicroservices.FileManager", "EasyMicroservices.FileManager\EasyMicroservices.FileManager.csproj", "{7283E2B4-3D69-4452-B8CD-B613091DA093}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyMicroservices.FileManager.Tests", "EasyMicroservices.FileManager.Tests\EasyMicroservices.FileManager.Tests.csproj", "{E6EA90C8-E246-4E7B-AC30-F486627F54C3}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyMicroservices.FileManager.AmazonS3", "EasyMicroservices.FileManager.AmazonS3\EasyMicroservices.FileManager.AmazonS3.csproj", "{6FC00559-FF92-4504-9BF4-593A7F84CBA7}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "App", "App", "{9DA3298D-4E56-449D-8DB2-EAF50B1FC115}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Abstractions", "Abstractions", "{894741B9-8764-4AD4-AE4F-0C5A0E634F22}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Implementations", "Implementations", "{61FF353A-1041-419B-B9FE-F62B81FBD07F}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7C1D905F-7604-4842-9C72-4CF182D7ED83}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyMicroservices.FileManager.AzureStorageBlobs", "EasyMicroservices.FileManager.AzureStorageBlobs\EasyMicroservices.FileManager.AzureStorageBlobs.csproj", "{2B5A2A34-FF28-4364-BF4C-46E08724C5CA}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyMicroservices.FileManager.AzureStorageBlobs.Tests", "EasyMicroservices.FileManager.AzureStorageBlobs.Tests\EasyMicroservices.FileManager.AzureStorageBlobs.Tests.csproj", "{FE02A59D-C042-41F0-A723-481C93F5D5ED}" 23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyMicroservices.FileManager.Android", "EasyMicroservices.FileManager.Android\EasyMicroservices.FileManager.Android.csproj", "{98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}" 24 | EndProject 25 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyMicroservices.FileManager.AndroidTestApp", "EasyMicroservices.FileManager.AndroidTestApp\EasyMicroservices.FileManager.AndroidTestApp.csproj", "{7F63937D-7E1D-4005-91CE-7CD2E4C7D020}" 26 | EndProject 27 | Global 28 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 29 | Debug|Any CPU = Debug|Any CPU 30 | Debug|x64 = Debug|x64 31 | Debug|x86 = Debug|x86 32 | Release|Any CPU = Release|Any CPU 33 | Release|x64 = Release|x64 34 | Release|x86 = Release|x86 35 | EndGlobalSection 36 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 37 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Debug|x64.ActiveCfg = Debug|x64 40 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Debug|x64.Build.0 = Debug|x64 41 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Debug|x86.ActiveCfg = Debug|x86 42 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Debug|x86.Build.0 = Debug|x86 43 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Release|x64.ActiveCfg = Release|x64 46 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Release|x64.Build.0 = Release|x64 47 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Release|x86.ActiveCfg = Release|x86 48 | {7283E2B4-3D69-4452-B8CD-B613091DA093}.Release|x86.Build.0 = Release|x86 49 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 50 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Debug|Any CPU.Build.0 = Debug|Any CPU 51 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Debug|x64.ActiveCfg = Debug|Any CPU 52 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Debug|x64.Build.0 = Debug|Any CPU 53 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Debug|x86.ActiveCfg = Debug|Any CPU 54 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Debug|x86.Build.0 = Debug|Any CPU 55 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Release|Any CPU.Build.0 = Release|Any CPU 57 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Release|x64.ActiveCfg = Release|Any CPU 58 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Release|x64.Build.0 = Release|Any CPU 59 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Release|x86.ActiveCfg = Release|Any CPU 60 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3}.Release|x86.Build.0 = Release|Any CPU 61 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 62 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Debug|Any CPU.Build.0 = Debug|Any CPU 63 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Debug|x64.ActiveCfg = Debug|Any CPU 64 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Debug|x64.Build.0 = Debug|Any CPU 65 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Debug|x86.ActiveCfg = Debug|Any CPU 66 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Debug|x86.Build.0 = Debug|Any CPU 67 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Release|Any CPU.ActiveCfg = Release|Any CPU 68 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Release|Any CPU.Build.0 = Release|Any CPU 69 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Release|x64.ActiveCfg = Release|Any CPU 70 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Release|x64.Build.0 = Release|Any CPU 71 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Release|x86.ActiveCfg = Release|Any CPU 72 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7}.Release|x86.Build.0 = Release|Any CPU 73 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 74 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 75 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Debug|x64.ActiveCfg = Debug|Any CPU 76 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Debug|x64.Build.0 = Debug|Any CPU 77 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Debug|x86.ActiveCfg = Debug|Any CPU 78 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Debug|x86.Build.0 = Debug|Any CPU 79 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 80 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Release|Any CPU.Build.0 = Release|Any CPU 81 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Release|x64.ActiveCfg = Release|Any CPU 82 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Release|x64.Build.0 = Release|Any CPU 83 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Release|x86.ActiveCfg = Release|Any CPU 84 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA}.Release|x86.Build.0 = Release|Any CPU 85 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 86 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Debug|Any CPU.Build.0 = Debug|Any CPU 87 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Debug|x64.ActiveCfg = Debug|Any CPU 88 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Debug|x64.Build.0 = Debug|Any CPU 89 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Debug|x86.ActiveCfg = Debug|Any CPU 90 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Debug|x86.Build.0 = Debug|Any CPU 91 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Release|Any CPU.ActiveCfg = Release|Any CPU 92 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Release|Any CPU.Build.0 = Release|Any CPU 93 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Release|x64.ActiveCfg = Release|Any CPU 94 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Release|x64.Build.0 = Release|Any CPU 95 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Release|x86.ActiveCfg = Release|Any CPU 96 | {FE02A59D-C042-41F0-A723-481C93F5D5ED}.Release|x86.Build.0 = Release|Any CPU 97 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 98 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Debug|Any CPU.Build.0 = Debug|Any CPU 99 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Debug|x64.ActiveCfg = Debug|Any CPU 100 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Debug|x64.Build.0 = Debug|Any CPU 101 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Debug|x86.ActiveCfg = Debug|Any CPU 102 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Debug|x86.Build.0 = Debug|Any CPU 103 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Release|Any CPU.ActiveCfg = Release|Any CPU 104 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Release|Any CPU.Build.0 = Release|Any CPU 105 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Release|x64.ActiveCfg = Release|Any CPU 106 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Release|x64.Build.0 = Release|Any CPU 107 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Release|x86.ActiveCfg = Release|Any CPU 108 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74}.Release|x86.Build.0 = Release|Any CPU 109 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 110 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|Any CPU.Build.0 = Debug|Any CPU 111 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 112 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|x64.ActiveCfg = Debug|Any CPU 113 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|x64.Build.0 = Debug|Any CPU 114 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|x64.Deploy.0 = Debug|Any CPU 115 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|x86.ActiveCfg = Debug|Any CPU 116 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|x86.Build.0 = Debug|Any CPU 117 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Debug|x86.Deploy.0 = Debug|Any CPU 118 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|Any CPU.ActiveCfg = Release|Any CPU 119 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|Any CPU.Build.0 = Release|Any CPU 120 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|Any CPU.Deploy.0 = Release|Any CPU 121 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|x64.ActiveCfg = Release|Any CPU 122 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|x64.Build.0 = Release|Any CPU 123 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|x64.Deploy.0 = Release|Any CPU 124 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|x86.ActiveCfg = Release|Any CPU 125 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|x86.Build.0 = Release|Any CPU 126 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020}.Release|x86.Deploy.0 = Release|Any CPU 127 | EndGlobalSection 128 | GlobalSection(SolutionProperties) = preSolution 129 | HideSolutionNode = FALSE 130 | EndGlobalSection 131 | GlobalSection(NestedProjects) = preSolution 132 | {7283E2B4-3D69-4452-B8CD-B613091DA093} = {894741B9-8764-4AD4-AE4F-0C5A0E634F22} 133 | {E6EA90C8-E246-4E7B-AC30-F486627F54C3} = {7C1D905F-7604-4842-9C72-4CF182D7ED83} 134 | {6FC00559-FF92-4504-9BF4-593A7F84CBA7} = {61FF353A-1041-419B-B9FE-F62B81FBD07F} 135 | {894741B9-8764-4AD4-AE4F-0C5A0E634F22} = {9DA3298D-4E56-449D-8DB2-EAF50B1FC115} 136 | {61FF353A-1041-419B-B9FE-F62B81FBD07F} = {9DA3298D-4E56-449D-8DB2-EAF50B1FC115} 137 | {7C1D905F-7604-4842-9C72-4CF182D7ED83} = {9DA3298D-4E56-449D-8DB2-EAF50B1FC115} 138 | {2B5A2A34-FF28-4364-BF4C-46E08724C5CA} = {61FF353A-1041-419B-B9FE-F62B81FBD07F} 139 | {FE02A59D-C042-41F0-A723-481C93F5D5ED} = {7C1D905F-7604-4842-9C72-4CF182D7ED83} 140 | {98C1E0FF-C28F-40A8-A0CA-87A7F6E37B74} = {61FF353A-1041-419B-B9FE-F62B81FBD07F} 141 | {7F63937D-7E1D-4005-91CE-7CD2E4C7D020} = {7C1D905F-7604-4842-9C72-4CF182D7ED83} 142 | EndGlobalSection 143 | GlobalSection(ExtensibilityGlobals) = postSolution 144 | SolutionGuid = {3576EC59-EC07-40DF-9149-1C659A5464C3} 145 | EndGlobalSection 146 | EndGlobal 147 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/EasyMicroservices.FileManager.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0;netstandard2.1;net6.0;net45 5 | AnyCPU;x64;x86 6 | EasyMicroservices 7 | true 8 | 0.0.0.3 9 | Manage your files with a wrapper in everywhere. 10 | EasyMicroservice@gmail.com 11 | file,filemanager,disk,memory 12 | https://github.com/Easy-Microservise/FileManager 13 | latest 14 | true 15 | .\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.FileManager.xml 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Extensions/DirectoryExtensions.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Models; 2 | using System.Threading.Tasks; 3 | 4 | namespace EasyMicroservices.FileManager 5 | { 6 | /// 7 | /// Extensions of directory to easy of use 8 | /// 9 | public static class DirectoryExtensions 10 | { 11 | /// 12 | /// check if the directory is exist 13 | /// 14 | /// 15 | /// 16 | public static Task IsExistAsync(this DirectoryDetail directory) 17 | { 18 | return directory.Provider.IsExistDirectoryAsync(directory.FullPath); 19 | } 20 | 21 | /// 22 | /// create a directory 23 | /// 24 | /// 25 | /// 26 | public static Task CreateDirectory(this DirectoryDetail directory) 27 | { 28 | return directory.Provider.CreateDirectoryAsync(directory.FullPath); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Extensions/FileExtensions.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Models; 2 | using System.IO; 3 | using System.Threading.Tasks; 4 | 5 | namespace EasyMicroservices.FileManager 6 | { 7 | /// 8 | /// Extensions of file for easy of use 9 | /// 10 | public static class FileExtensions 11 | { 12 | /// 13 | /// check if the files is exist 14 | /// 15 | /// 16 | /// 17 | public static Task IsExistAsync(this FileDetail file) 18 | { 19 | return file.Provider.IsExistFileAsync(file.FullPath); 20 | } 21 | 22 | /// 23 | /// create new directory 24 | /// 25 | /// 26 | /// 27 | public static Task CreateDirectory(this FileDetail file) 28 | { 29 | return file.Provider.CreateFileAsync(file.FullPath); 30 | } 31 | 32 | /// 33 | /// open file stream 34 | /// 35 | /// 36 | /// 37 | public static Task OpenFileAsync(this FileDetail file) 38 | { 39 | return file.Provider.OpenFileAsync(file.FullPath); 40 | } 41 | 42 | /// 43 | /// write stream to file 44 | /// 45 | /// 46 | /// 47 | /// 48 | public static async Task WriteStreamToFileAsync(this FileDetail file, Stream stream) 49 | { 50 | await file.Provider.WriteStreamToFileAsync(file.FullPath, stream); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Interfaces/IDirectoryManagerProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Models; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace EasyMicroservices.FileManager.Interfaces 6 | { 7 | /// 8 | /// Provider of directory to manage folders stuff 9 | /// 10 | public interface IDirectoryManagerProvider 11 | { 12 | /// 13 | /// Root folder's path to save data in it 14 | /// 15 | string Root { get; set; } 16 | /// 17 | /// Path manager 18 | /// 19 | IPathProvider PathProvider { get; set; } 20 | /// 21 | /// Create new directory 22 | /// 23 | /// 24 | /// 25 | /// 26 | Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default); 27 | /// 28 | /// Get directory's details 29 | /// 30 | /// 31 | /// 32 | /// 33 | Task GetDirectoryAsync(string path, CancellationToken cancellationToken = default); 34 | /// 35 | /// check if directory is exists 36 | /// 37 | /// 38 | /// 39 | /// 40 | Task IsExistDirectoryAsync(string path, CancellationToken cancellationToken = default); 41 | /// 42 | /// delete the directory 43 | /// 44 | /// 45 | /// 46 | /// 47 | Task DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default); 48 | /// 49 | /// delete directory recursive 50 | /// 51 | /// 52 | /// 53 | /// 54 | /// 55 | Task DeleteDirectoryAsync(string path, bool recursive, CancellationToken cancellationToken = default); 56 | /// 57 | /// complete if check permission finished 58 | /// 59 | /// 60 | void CompleteCheckPermission(bool isGranted); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Interfaces/IFileManagerProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Models; 2 | using System.IO; 3 | using System.Text; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace EasyMicroservices.FileManager.Interfaces 8 | { 9 | /// 10 | /// Provider of file to manage files stuff 11 | /// 12 | public interface IFileManagerProvider 13 | { 14 | /// 15 | /// Directory manager of this file manager 16 | /// place of files 17 | /// 18 | IDirectoryManagerProvider DirectoryManagerProvider { get; set; } 19 | /// 20 | /// Path manager 21 | /// 22 | IPathProvider PathProvider { get; set; } 23 | /// 24 | /// Get file's details 25 | /// 26 | /// 27 | /// 28 | /// 29 | Task GetFileAsync(string path, CancellationToken cancellationToken = default); 30 | /// 31 | /// Create new file 32 | /// 33 | /// 34 | /// 35 | /// 36 | Task CreateFileAsync(string path, CancellationToken cancellationToken = default); 37 | /// 38 | /// open file to read or write stream 39 | /// 40 | /// 41 | /// 42 | /// 43 | Task OpenFileAsync(string path, CancellationToken cancellationToken = default); 44 | /// 45 | /// write stream to file path 46 | /// 47 | /// 48 | /// 49 | /// 50 | /// 51 | Task WriteStreamToFileAsync(string path, Stream stream, CancellationToken cancellationToken = default); 52 | /// 53 | /// check if file is exists 54 | /// 55 | /// 56 | /// 57 | /// 58 | Task IsExistFileAsync(string path, CancellationToken cancellationToken = default); 59 | /// 60 | /// delete file 61 | /// 62 | /// 63 | /// 64 | /// 65 | Task DeleteFileAsync(string path, CancellationToken cancellationToken = default); 66 | /// 67 | /// set length of file as 0 68 | /// make a file data empty 69 | /// 70 | /// 71 | /// 72 | /// 73 | Task TruncateFileAsync(string path, CancellationToken cancellationToken = default); 74 | /// 75 | /// Write bytes to a file 76 | /// 77 | /// 78 | /// 79 | /// 80 | /// 81 | Task WriteAllBytesAsync(string path, byte[] bytes, CancellationToken cancellationToken = default); 82 | /// 83 | /// Write text to a file 84 | /// 85 | /// 86 | /// 87 | /// 88 | /// 89 | /// 90 | Task WriteAllTextAsync(string path, string text, Encoding encoding, CancellationToken cancellationToken = default); 91 | /// 92 | /// Write text to a file 93 | /// 94 | /// 95 | /// 96 | /// 97 | /// 98 | Task WriteAllTextAsync(string path, string text, CancellationToken cancellationToken = default); 99 | /// 100 | /// Write text lines to a file 101 | /// 102 | /// 103 | /// 104 | /// 105 | /// 106 | /// 107 | Task WriteAllLinesAsync(string path, string[] lines, Encoding encoding, CancellationToken cancellationToken = default); 108 | /// 109 | /// Write text lines to a file 110 | /// 111 | /// 112 | /// 113 | /// 114 | /// 115 | Task WriteAllLinesAsync(string path, string[] lines, CancellationToken cancellationToken = default); 116 | /// 117 | /// read bytes from a file 118 | /// 119 | /// 120 | /// 121 | /// 122 | Task ReadAllBytesAsync(string path, CancellationToken cancellationToken = default); 123 | /// 124 | /// read all text lines from a file 125 | /// 126 | /// 127 | /// 128 | /// 129 | /// 130 | Task ReadAllLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default); 131 | /// 132 | /// read all text lines from a file 133 | /// 134 | /// 135 | /// 136 | /// 137 | Task ReadAllLinesAsync(string path, CancellationToken cancellationToken = default); 138 | /// 139 | /// read all text from a file 140 | /// 141 | /// 142 | /// 143 | /// 144 | /// 145 | Task ReadAllTextAsync(string path, Encoding encoding, CancellationToken cancellationToken = default); 146 | /// 147 | /// read all text from a file 148 | /// 149 | /// 150 | /// 151 | /// 152 | Task ReadAllTextAsync(string path, CancellationToken cancellationToken = default); 153 | /// 154 | /// complete if check permission finished 155 | /// 156 | /// 157 | void CompleteCheckPermission(bool isGranted); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Interfaces/IPathProvider.cs: -------------------------------------------------------------------------------- 1 | namespace EasyMicroservices.FileManager.Interfaces 2 | { 3 | /// 4 | /// Manage path of files and folders 5 | /// 6 | public interface IPathProvider 7 | { 8 | /// 9 | /// Combine some paths 10 | /// 11 | /// 12 | /// 13 | string Combine(params string[] paths); 14 | /// 15 | /// Get name of object 16 | /// 17 | /// 18 | /// 19 | string GetObjectName(string path); 20 | /// 21 | /// Get object parent path 22 | /// 23 | /// 24 | /// 25 | string GetObjectParentPath(string path); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Models/DirectoryDetail.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | 3 | namespace EasyMicroservices.FileManager.Models 4 | { 5 | /// 6 | /// Details of directory 7 | /// 8 | public class DirectoryDetail 9 | { 10 | /// 11 | /// 12 | /// 13 | /// 14 | public DirectoryDetail(IDirectoryManagerProvider provider) 15 | { 16 | Provider = provider; 17 | } 18 | 19 | /// 20 | /// Provider of this directory 21 | /// 22 | internal IDirectoryManagerProvider Provider { get; set; } 23 | /// 24 | /// Name of directory 25 | /// 26 | public string Name { get; set; } 27 | /// 28 | /// Path of this directory 29 | /// 30 | public string DirectoryPath { get; set; } 31 | /// 32 | /// Full directory's path 33 | /// 34 | public string FullPath 35 | { 36 | get 37 | { 38 | return Provider.PathProvider.Combine(DirectoryPath, Name); 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Models/FileDetail.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | 3 | namespace EasyMicroservices.FileManager.Models 4 | { 5 | /// 6 | /// Details of file 7 | /// 8 | public class FileDetail 9 | { 10 | /// 11 | /// 12 | /// 13 | /// 14 | public FileDetail(IFileManagerProvider provider) 15 | { 16 | Provider = provider; 17 | } 18 | 19 | /// 20 | /// Provider of file 21 | /// 22 | internal IFileManagerProvider Provider { get; set; } 23 | /// 24 | /// Name of file 25 | /// 26 | public string Name { get; set; } 27 | /// 28 | /// Directory path of this file 29 | /// 30 | public string DirectoryPath { get; set; } 31 | /// 32 | /// Length of this file 33 | /// 34 | public long Length { get; set; } 35 | /// 36 | /// Full directory's and File's name path 37 | /// 38 | public string FullPath 39 | { 40 | get 41 | { 42 | return Provider.PathProvider.Combine(DirectoryPath, Name); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/BasePathProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using System.Threading.Tasks; 3 | 4 | namespace EasyMicroservices.FileManager.Providers 5 | { 6 | /// 7 | /// Base logics of path provider 8 | /// 9 | public class BasePathProvider 10 | { 11 | /// 12 | /// Nomalize a path with the path provider 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | protected string NormalizePath(string path, IDirectoryManagerProvider directoryManagerProvider, IPathProvider pathProvider) 19 | { 20 | if (path.StartsWith(directoryManagerProvider.Root)) 21 | return path; 22 | return pathProvider.Combine(directoryManagerProvider.Root, path); 23 | } 24 | /// 25 | /// Check application has permission for a path 26 | /// 27 | /// 28 | public virtual Task CheckPermissionAsync(string path) 29 | { 30 | return Task.FromResult(true); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/DirectoryProviders/BaseDirectoryProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using EasyMicroservices.FileManager.Models; 3 | using EasyMicroservices.FileManager.Providers.PathProviders; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace EasyMicroservices.FileManager.Providers.DirectoryProviders 8 | { 9 | /// 10 | /// Base logics of the directory providers 11 | /// 12 | public abstract class BaseDirectoryProvider : BasePathProvider, IDirectoryManagerProvider 13 | { 14 | /// 15 | /// 16 | /// 17 | /// default root path 18 | /// path provider 19 | public BaseDirectoryProvider(string root, IPathProvider pathProvider) 20 | { 21 | Root = root; 22 | PathProvider = pathProvider; 23 | } 24 | /// 25 | /// 26 | /// 27 | /// 28 | public BaseDirectoryProvider(string root) 29 | { 30 | Root = root; 31 | PathProvider = new SystemPathProvider(); 32 | } 33 | 34 | /// 35 | /// Root Path's of directory 36 | /// 37 | public string Root { get; set; } 38 | /// 39 | /// Path manager 40 | /// 41 | public IPathProvider PathProvider { get; set; } 42 | /// 43 | /// normalize with the path manager 44 | /// 45 | /// 46 | /// 47 | protected string NormalizePath(string path) 48 | { 49 | return NormalizePath(path, this, PathProvider); 50 | } 51 | /// 52 | /// Create new directory 53 | /// 54 | /// 55 | /// 56 | /// 57 | public abstract Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default); 58 | /// 59 | /// Get directory's details 60 | /// 61 | /// 62 | /// 63 | /// 64 | public virtual Task GetDirectoryAsync(string path, CancellationToken cancellationToken = default) 65 | { 66 | path = NormalizePath(path); 67 | return Task.FromResult(new DirectoryDetail(this) 68 | { 69 | DirectoryPath = PathProvider.GetObjectParentPath(path), 70 | Name = PathProvider.GetObjectName(path), 71 | }); 72 | } 73 | /// 74 | /// check if directory is exists 75 | /// 76 | /// 77 | /// 78 | /// 79 | public abstract Task IsExistDirectoryAsync(string path, CancellationToken cancellationToken = default); 80 | /// 81 | /// delete the directory 82 | /// 83 | /// 84 | /// 85 | /// 86 | public virtual Task DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default) 87 | { 88 | return DeleteDirectoryAsync(path, false); 89 | } 90 | /// 91 | /// delete directory recursive 92 | /// 93 | /// 94 | /// 95 | /// 96 | /// 97 | public abstract Task DeleteDirectoryAsync(string path, bool recursive, CancellationToken cancellationToken = default); 98 | /// 99 | /// complete check permission 100 | /// 101 | /// 102 | public virtual void CompleteCheckPermission(bool isComplete) 103 | { 104 | 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/DirectoryProviders/DiskDirectoryProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using EasyMicroservices.FileManager.Models; 3 | using System; 4 | using System.IO; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace EasyMicroservices.FileManager.Providers.DirectoryProviders 9 | { 10 | /// 11 | /// Disk manager of directory on a disk 12 | /// 13 | public class DiskDirectoryProvider : BaseDirectoryProvider 14 | { 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | public DiskDirectoryProvider(string root, IPathProvider pathProvider) : base(root, pathProvider) 21 | { 22 | } 23 | /// 24 | /// 25 | /// 26 | /// 27 | public DiskDirectoryProvider(string root) : base(root) 28 | { 29 | } 30 | /// 31 | /// Create new directory 32 | /// 33 | /// 34 | /// 35 | /// 36 | public override async Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default) 37 | { 38 | path = NormalizePath(path); 39 | if (await CheckPermissionAsync(path)) 40 | Directory.CreateDirectory(path); 41 | return await GetDirectoryAsync(path); 42 | } 43 | /// 44 | /// delete the directory 45 | /// 46 | /// 47 | /// 48 | /// 49 | /// 50 | /// 51 | public override async Task DeleteDirectoryAsync(string path, bool recursive, CancellationToken cancellationToken = default) 52 | { 53 | path = NormalizePath(path); 54 | if (!path.StartsWith(Root)) 55 | throw new Exception($"Warning to delete disk folder {path}"); 56 | if (await CheckPermissionAsync(path)) 57 | Directory.Delete(path, recursive); 58 | return true; 59 | } 60 | /// 61 | /// check if directory is exists 62 | /// 63 | /// 64 | /// 65 | /// 66 | public override async Task IsExistDirectoryAsync(string path, CancellationToken cancellationToken = default) 67 | { 68 | path = NormalizePath(path); 69 | await CheckPermissionAsync(path); 70 | return Directory.Exists(path); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/DirectoryProviders/MemoryDirectoryProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using EasyMicroservices.FileManager.Models; 3 | using System.Collections.Generic; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace EasyMicroservices.FileManager.Providers.DirectoryProviders 8 | { 9 | /// 10 | /// Memory manager of directory on a disk 11 | /// 12 | public class MemoryDirectoryProvider : BaseDirectoryProvider 13 | { 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | public MemoryDirectoryProvider(string root, IPathProvider pathProvider) : base(root, pathProvider) 20 | { 21 | } 22 | /// 23 | /// 24 | /// 25 | /// 26 | public MemoryDirectoryProvider(string root) : base(root) 27 | { 28 | } 29 | 30 | HashSet Directories = new HashSet(); 31 | /// 32 | /// Create new directory 33 | /// 34 | /// 35 | /// 36 | /// 37 | public override async Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default) 38 | { 39 | string fullName = NormalizePath(path); 40 | var directory = await GetDirectoryAsync(fullName); 41 | Directories.Add(directory.FullPath); 42 | return directory; 43 | } 44 | /// 45 | /// delete the directory 46 | /// 47 | /// 48 | /// 49 | /// 50 | /// 51 | public override Task DeleteDirectoryAsync(string path, bool recursive, CancellationToken cancellationToken = default) 52 | { 53 | string fullName = NormalizePath(path); 54 | Directories.Remove(fullName); 55 | return Task.FromResult(true); 56 | } 57 | /// 58 | /// check if directory is exists 59 | /// 60 | /// 61 | /// 62 | /// 63 | public override Task IsExistDirectoryAsync(string path, CancellationToken cancellationToken = default) 64 | { 65 | string fullName = NormalizePath(path); 66 | return Task.FromResult(Directories.Contains(fullName)); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/FileProviders/BaseFileProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using EasyMicroservices.FileManager.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace EasyMicroservices.FileManager.Providers.FileProviders 11 | { 12 | /// 13 | /// Base of File provider 14 | /// 15 | public abstract class BaseFileProvider : BasePathProvider, IFileManagerProvider 16 | { 17 | /// 18 | /// 19 | /// 20 | /// 21 | public BaseFileProvider(IDirectoryManagerProvider directoryManagerProvider) 22 | { 23 | DirectoryManagerProvider = directoryManagerProvider; 24 | PathProvider = directoryManagerProvider.PathProvider; 25 | } 26 | 27 | /// 28 | /// Buffer size to read stream 29 | /// 30 | public int BufferSize { get; set; } = 1024 * 512; 31 | 32 | /// 33 | /// Directory provider to manage folders 34 | /// 35 | public IDirectoryManagerProvider DirectoryManagerProvider { get; set; } 36 | 37 | /// 38 | /// Path provider to manage paths 39 | /// 40 | public IPathProvider PathProvider { get; set; } 41 | 42 | /// 43 | /// copy a stream to another stream 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | /// 50 | /// 51 | public async Task CopyToStreamAsync(Stream fromStream, long length, Stream toStream, CancellationToken cancellationToken = default) 52 | { 53 | var stream = await StreamToBytesAsync(fromStream, length, cancellationToken); 54 | await stream.CopyToAsync(toStream); 55 | } 56 | 57 | /// 58 | /// 59 | /// 60 | /// 61 | /// 62 | /// 63 | /// 64 | /// 65 | public async Task StreamToBytesAsync(Stream fromStream, long length, CancellationToken cancellationToken = default) 66 | { 67 | MemoryStream toStream = new MemoryStream(); 68 | if (length == 0) 69 | return toStream; 70 | if (fromStream.CanSeek) 71 | fromStream.Seek(0, SeekOrigin.Begin); 72 | var readBytes = new byte[BufferSize]; 73 | long writed = 0; 74 | while (writed < length) 75 | { 76 | int readCount; 77 | if (readBytes.Length > length - writed) 78 | readBytes = new byte[length - writed]; 79 | readCount = await fromStream.ReadAsync(readBytes, 0, readBytes.Length, cancellationToken); 80 | if (readCount <= 0) 81 | throw new Exception("Client disconnected!"); 82 | await toStream.WriteAsync(readBytes, 0, readCount, cancellationToken); 83 | writed += readCount; 84 | } 85 | toStream.Seek(0, SeekOrigin.Begin); 86 | return toStream; 87 | } 88 | 89 | /// 90 | /// copy byte array to a file 91 | /// 92 | /// 93 | /// 94 | /// 95 | /// 96 | public Task Copy(byte[] bytes, string toFileName, CancellationToken cancellationToken = default) 97 | { 98 | using var stream = new MemoryStream(bytes); 99 | return Copy(stream, toFileName, cancellationToken); 100 | } 101 | 102 | /// 103 | /// open or create filename 104 | /// it creates file when it is not exist 105 | /// 106 | /// 107 | /// 108 | /// 109 | public async Task OpenOrCreateFile(string fileName, CancellationToken cancellationToken = default) 110 | { 111 | if (!await IsExistFileAsync(fileName)) 112 | await CreateFileAsync(fileName); 113 | await TruncateFileAsync(fileName); 114 | return await OpenFileAsync(fileName); 115 | } 116 | 117 | /// 118 | /// copy a stream to a file 119 | /// 120 | /// 121 | /// 122 | /// 123 | /// 124 | public async Task Copy(Stream stream, string toFileName, CancellationToken cancellationToken = default) 125 | { 126 | var toFileStream = await OpenOrCreateFile(toFileName); 127 | await CopyToStreamAsync(stream, stream.Length, toFileStream); 128 | } 129 | 130 | /// 131 | /// normalize path to fix path problems 132 | /// 133 | /// 134 | /// 135 | protected string NormalizePath(string path) 136 | { 137 | return NormalizePath(path, DirectoryManagerProvider, PathProvider); 138 | } 139 | 140 | /// 141 | /// get file details 142 | /// 143 | /// 144 | /// 145 | /// 146 | public virtual Task GetFileAsync(string path, CancellationToken cancellationToken = default) 147 | { 148 | path = NormalizePath(path); 149 | var details = new FileDetail(this) 150 | { 151 | DirectoryPath = PathProvider.GetObjectParentPath(path), 152 | Name = PathProvider.GetObjectName(path), 153 | }; 154 | return Task.FromResult(details); 155 | } 156 | 157 | /// 158 | /// Create a directory if it's not exist 159 | /// 160 | /// 161 | /// 162 | /// 163 | public async Task CreateDirectoryIfNotExist(FileDetail file, CancellationToken cancellationToken = default) 164 | { 165 | var directory = await DirectoryManagerProvider.GetDirectoryAsync(file.DirectoryPath); 166 | if (!await directory.IsExistAsync()) 167 | return await directory.CreateDirectory(); 168 | return directory; 169 | } 170 | 171 | /// 172 | /// write stream to a file 173 | /// 174 | /// 175 | /// 176 | /// 177 | /// 178 | public virtual async Task WriteStreamToFileAsync(string path, Stream stream, CancellationToken cancellationToken = default) 179 | { 180 | using var streamToWrite = await OpenOrCreateFile(path, cancellationToken); 181 | await CopyToStreamAsync(stream, stream.Length, streamToWrite); 182 | } 183 | 184 | /// 185 | /// Create new file 186 | /// 187 | /// 188 | /// 189 | /// 190 | public abstract Task CreateFileAsync(string path, CancellationToken cancellationToken = default); 191 | 192 | /// 193 | /// open file to read or write stream 194 | /// 195 | /// 196 | /// 197 | /// 198 | public abstract Task OpenFileAsync(string path, CancellationToken cancellationToken = default); 199 | 200 | /// 201 | /// check if file is exists 202 | /// 203 | /// 204 | /// 205 | /// 206 | public abstract Task IsExistFileAsync(string path, CancellationToken cancellationToken = default); 207 | 208 | /// 209 | /// delete file 210 | /// 211 | /// 212 | /// 213 | /// 214 | public abstract Task DeleteFileAsync(string path, CancellationToken cancellationToken = default); 215 | 216 | /// 217 | /// set length of file as 0 218 | /// make a file data empty 219 | /// 220 | /// 221 | /// 222 | /// 223 | public abstract Task TruncateFileAsync(string path, CancellationToken cancellationToken = default); 224 | 225 | /// 226 | /// 227 | /// 228 | /// 229 | /// 230 | /// 231 | /// 232 | /// 233 | public async Task WriteAllBytesAsync(string path, byte[] bytes, CancellationToken cancellationToken = default) 234 | { 235 | using var memoryStream = new MemoryStream(bytes); 236 | memoryStream.Seek(0, SeekOrigin.Begin); 237 | await WriteStreamToFileAsync(path, memoryStream, cancellationToken); 238 | } 239 | 240 | /// 241 | /// 242 | /// 243 | /// 244 | /// 245 | /// 246 | /// 247 | /// 248 | public async Task WriteAllTextAsync(string path, string text, Encoding encoding, CancellationToken cancellationToken = default) 249 | { 250 | using var memoryStream = new MemoryStream(); 251 | using var memoryWriterStream = new StreamWriter(memoryStream, encoding); 252 | await memoryWriterStream.WriteAsync(text); 253 | await memoryWriterStream.FlushAsync(); 254 | memoryStream.Seek(0, SeekOrigin.Begin); 255 | await WriteStreamToFileAsync(path, memoryStream, cancellationToken); 256 | } 257 | 258 | /// 259 | /// 260 | /// 261 | /// 262 | /// 263 | /// 264 | /// 265 | public Task WriteAllTextAsync(string path, string text, CancellationToken cancellationToken = default) 266 | { 267 | return WriteAllTextAsync(path, text, Encoding.UTF8, cancellationToken); 268 | } 269 | 270 | /// 271 | /// 272 | /// 273 | /// 274 | /// 275 | /// 276 | /// 277 | /// 278 | /// 279 | public Task WriteAllLinesAsync(string path, string[] lines, Encoding encoding, CancellationToken cancellationToken = default) 280 | { 281 | StringBuilder builder = new StringBuilder(); 282 | for (int i = 0; i < lines.Length; i++) 283 | { 284 | var line = lines[i]; 285 | if (i == lines.Length - 1) 286 | builder.Append(line); 287 | else 288 | builder.AppendLine(line); 289 | } 290 | return WriteAllTextAsync(path, builder.ToString(), encoding, cancellationToken); 291 | } 292 | 293 | /// 294 | /// 295 | /// 296 | /// 297 | /// 298 | /// 299 | /// 300 | /// 301 | public Task WriteAllLinesAsync(string path, string[] lines, CancellationToken cancellationToken = default) 302 | { 303 | return WriteAllLinesAsync(path, lines, Encoding.UTF8, cancellationToken); 304 | } 305 | 306 | /// 307 | /// 308 | /// 309 | /// 310 | /// 311 | /// 312 | public async Task ReadAllBytesAsync(string path, CancellationToken cancellationToken = default) 313 | { 314 | using var fileStream = await OpenFileAsync(path, cancellationToken); 315 | using var memoryStream = await StreamToBytesAsync(fileStream, fileStream.Length, cancellationToken); 316 | return memoryStream.ToArray(); 317 | } 318 | 319 | /// 320 | /// 321 | /// 322 | /// 323 | /// 324 | /// 325 | /// 326 | /// 327 | public async Task ReadAllLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default) 328 | { 329 | using var fileStream = await OpenFileAsync(path, cancellationToken); 330 | using var readerStream = new StreamReader(await StreamToBytesAsync(fileStream, fileStream.Length, cancellationToken), encoding); 331 | List lines = new List(); 332 | string line; 333 | while ((line = await readerStream.ReadLineAsync()) != null) 334 | { 335 | lines.Add(line); 336 | } 337 | return lines.ToArray(); 338 | } 339 | 340 | /// 341 | /// 342 | /// 343 | /// 344 | /// 345 | /// 346 | /// 347 | public Task ReadAllLinesAsync(string path, CancellationToken cancellationToken = default) 348 | { 349 | return ReadAllLinesAsync(path, Encoding.UTF8, cancellationToken); 350 | } 351 | 352 | /// 353 | /// 354 | /// 355 | /// 356 | /// 357 | /// 358 | /// 359 | /// 360 | public async Task ReadAllTextAsync(string path, Encoding encoding, CancellationToken cancellationToken = default) 361 | { 362 | using var fileStream = await OpenFileAsync(path, cancellationToken); 363 | using var readerStream = new StreamReader(await StreamToBytesAsync(fileStream, fileStream.Length, cancellationToken), encoding); 364 | return await readerStream.ReadToEndAsync(); 365 | } 366 | /// 367 | /// 368 | /// 369 | /// 370 | /// 371 | /// 372 | /// 373 | public Task ReadAllTextAsync(string path, CancellationToken cancellationToken = default) 374 | { 375 | return ReadAllTextAsync(path, Encoding.UTF8, cancellationToken); 376 | } 377 | 378 | /// 379 | /// complete check permission 380 | /// 381 | /// 382 | public virtual void CompleteCheckPermission(bool isComplete) 383 | { 384 | 385 | } 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/FileProviders/DiskFileProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using EasyMicroservices.FileManager.Models; 3 | using System.IO; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace EasyMicroservices.FileManager.Providers.FileProviders 8 | { 9 | /// 10 | /// Manage files from disk 11 | /// 12 | public class DiskFileProvider : BaseFileProvider 13 | { 14 | /// 15 | /// 16 | /// 17 | /// 18 | public DiskFileProvider(IDirectoryManagerProvider directoryManagerProvider) : base(directoryManagerProvider) 19 | { 20 | } 21 | /// 22 | /// Create a file 23 | /// 24 | /// 25 | /// 26 | /// 27 | public override async Task CreateFileAsync(string path, CancellationToken cancellationToken = default) 28 | { 29 | var file = await GetFileAsync(NormalizePath(path)); 30 | await CreateDirectoryIfNotExist(file); 31 | if (await CheckPermissionAsync(path)) 32 | File.Create(file.FullPath).Dispose(); 33 | return file; 34 | } 35 | /// 36 | /// get file's details 37 | /// 38 | /// 39 | /// 40 | /// 41 | public override async Task GetFileAsync(string path, CancellationToken cancellationToken = default) 42 | { 43 | var file = await base.GetFileAsync(path); 44 | if (await CheckPermissionAsync(path)) 45 | { 46 | if (await file.IsExistAsync()) 47 | { 48 | var fileInfo = new FileInfo(file.FullPath); 49 | file.Length = fileInfo.Length; 50 | } 51 | } 52 | return file; 53 | } 54 | /// 55 | /// delete file 56 | /// 57 | /// 58 | /// 59 | /// 60 | public override async Task DeleteFileAsync(string path, CancellationToken cancellationToken = default) 61 | { 62 | path = NormalizePath(path); 63 | if (await CheckPermissionAsync(path)) 64 | File.Delete(path); 65 | return true; 66 | } 67 | /// 68 | /// check if file is exists 69 | /// 70 | /// 71 | /// 72 | /// 73 | public override Task IsExistFileAsync(string path, CancellationToken cancellationToken = default) 74 | { 75 | path = NormalizePath(path); 76 | return Task.FromResult(File.Exists(path)); 77 | } 78 | /// 79 | /// open file to read or write stream 80 | /// 81 | /// 82 | /// 83 | /// 84 | public override async Task OpenFileAsync(string path, CancellationToken cancellationToken = default) 85 | { 86 | path = NormalizePath(path); 87 | await CheckPermissionAsync(path); 88 | return File.Open(path, FileMode.Open); 89 | } 90 | /// 91 | /// set length of file as 0 92 | /// make a file data empty 93 | /// 94 | /// 95 | /// 96 | /// 97 | public override async Task TruncateFileAsync(string path, CancellationToken cancellationToken = default) 98 | { 99 | path = NormalizePath(path); 100 | using var fileStream = await OpenFileAsync(path); 101 | fileStream.SetLength(0); 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/FileProviders/MemoryFileProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using EasyMicroservices.FileManager.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace EasyMicroservices.FileManager.Providers.FileProviders 10 | { 11 | /// 12 | /// Manage files in memory 13 | /// 14 | public class MemoryFileProvider : BaseFileProvider 15 | { 16 | /// 17 | /// 18 | /// 19 | /// 20 | public MemoryFileProvider(IDirectoryManagerProvider directoryManagerProvider) : base(directoryManagerProvider) 21 | { 22 | } 23 | 24 | Dictionary Files = new Dictionary(); 25 | /// 26 | /// Create new file 27 | /// 28 | /// 29 | /// 30 | /// 31 | public override async Task CreateFileAsync(string path, CancellationToken cancellationToken = default) 32 | { 33 | var file = await GetFileAsync(NormalizePath(path)); 34 | await CreateDirectoryIfNotExist(file); 35 | if (!Files.ContainsKey(file.FullPath)) 36 | Files.Add(file.FullPath, new MemoryStream()); 37 | return file; 38 | } 39 | /// 40 | /// delete file 41 | /// 42 | /// 43 | /// 44 | /// 45 | public override Task DeleteFileAsync(string path, CancellationToken cancellationToken = default) 46 | { 47 | path = NormalizePath(path); 48 | Files.Remove(path); 49 | return Task.FromResult(true); 50 | } 51 | /// 52 | /// check if file is exists 53 | /// 54 | /// 55 | /// 56 | /// 57 | public override Task IsExistFileAsync(string path, CancellationToken cancellationToken = default) 58 | { 59 | path = NormalizePath(path); 60 | return Task.FromResult(Files.ContainsKey(path)); 61 | } 62 | /// 63 | /// Get file's details 64 | /// 65 | /// 66 | /// 67 | /// 68 | public override async Task GetFileAsync(string path, CancellationToken cancellationToken = default) 69 | { 70 | var file = await base.GetFileAsync(path); 71 | if (await file.IsExistAsync()) 72 | { 73 | if (Files.TryGetValue(file.FullPath, out Stream fileStream)) 74 | { 75 | file.Length = fileStream.Length; 76 | } 77 | } 78 | return file; 79 | } 80 | /// 81 | /// write stream to file path 82 | /// 83 | /// 84 | /// 85 | /// 86 | /// 87 | public override async Task WriteStreamToFileAsync(string path, Stream stream, CancellationToken cancellationToken = default) 88 | { 89 | path = NormalizePath(path); 90 | using var file = await OpenOrCreateFile(path, cancellationToken); 91 | if (Files.TryGetValue(path, out Stream fileStream)) 92 | { 93 | await CopyToStreamAsync(stream, stream.Length, fileStream); 94 | } 95 | } 96 | /// 97 | /// open file to read or write stream 98 | /// 99 | /// 100 | /// 101 | /// 102 | /// 103 | public override async Task OpenFileAsync(string path, CancellationToken cancellationToken = default) 104 | { 105 | path = NormalizePath(path); 106 | if (Files.TryGetValue(path, out Stream fileStream)) 107 | { 108 | var memoryStream = new MemoryStream(); 109 | await CopyToStreamAsync(fileStream, fileStream.Length, memoryStream); 110 | memoryStream.Seek(0, SeekOrigin.Begin); 111 | return memoryStream; 112 | } 113 | throw new Exception($"File {path} not found!"); 114 | } 115 | /// 116 | /// set length of file as 0 117 | /// make a file data empty 118 | /// 119 | /// 120 | /// 121 | /// 122 | /// 123 | public override Task TruncateFileAsync(string path, CancellationToken cancellationToken = default) 124 | { 125 | path = NormalizePath(path); 126 | if (Files.TryGetValue(path, out Stream fileStream)) 127 | { 128 | fileStream.SetLength(0); 129 | #if(NET45) 130 | return Task.Delay(0); 131 | #else 132 | return Task.CompletedTask; 133 | #endif 134 | } 135 | throw new Exception($"File {path} not found!"); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/PathProviders/BasePathProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Text; 6 | 7 | namespace EasyMicroservices.FileManager.Providers.PathProviders 8 | { 9 | /// 10 | /// 11 | /// 12 | public abstract class BasePathProvider : IPathProvider 13 | { 14 | /// 15 | /// Combine multiple paths 16 | /// 17 | /// 18 | /// 19 | public virtual string Combine(params string[] paths) 20 | { 21 | return Path.Combine(paths); 22 | } 23 | 24 | /// 25 | /// Get object's name 26 | /// it's like File name or Directory name 27 | /// 28 | /// 29 | /// 30 | public string GetObjectName(string path) 31 | { 32 | return Path.GetFileName(path); 33 | } 34 | 35 | /// 36 | /// Get object parent's path 37 | /// it's file's directory path 38 | /// or directory's parent's directory path 39 | /// 40 | /// 41 | /// 42 | public string GetObjectParentPath(string path) 43 | { 44 | return Path.GetDirectoryName(path); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/CSharp/EasyMicroservices.FileManager/Providers/PathProviders/SystemPathProvider.cs: -------------------------------------------------------------------------------- 1 | using EasyMicroservices.FileManager.Interfaces; 2 | using System.IO; 3 | 4 | namespace EasyMicroservices.FileManager.Providers.PathProviders 5 | { 6 | /// 7 | /// System provider 8 | /// 9 | public class SystemPathProvider : BasePathProvider 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Golang/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## Current Version: 4 | 5 | - [#20 Init golang implementation](https://github.com/EasyMicroservices/FileManager/issues/20) 6 | - [#21 Implement disk managers for golang](https://github.com/EasyMicroservices/FileManager/issues/21) -------------------------------------------------------------------------------- /src/Golang/disk/lib.go: -------------------------------------------------------------------------------- 1 | package disk 2 | 3 | import ( 4 | "fmt" 5 | fm "github.com/EasyMicroservices/FileManager" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | ) 10 | 11 | type SystemPathProvider struct { 12 | } 13 | 14 | func (s *SystemPathProvider) Combine(paths ...string) (string, error) { 15 | return filepath.Join(paths...), nil 16 | } 17 | 18 | func normalizePath(path string) string { 19 | for strings.HasSuffix(path, "/") { 20 | path = strings.TrimSuffix(path, "/") 21 | } 22 | 23 | return path 24 | } 25 | 26 | func (s *SystemPathProvider) GetObjectName(path string) (string, error) { 27 | path = normalizePath(path) 28 | path, err := s.Combine(path) 29 | if err != nil { 30 | return "", err 31 | } 32 | 33 | _, file := filepath.Split(path) 34 | 35 | if file != "" { 36 | return file, nil 37 | } 38 | 39 | return "", fmt.Errorf("invalid path: %v", path) 40 | } 41 | 42 | func (s *SystemPathProvider) GetObjectParentPath(path string) (string, error) { 43 | path = normalizePath(path) 44 | path, err := s.Combine(path) 45 | if err != nil { 46 | return "", err 47 | } 48 | 49 | dir, _ := filepath.Split(path) 50 | 51 | if dir != "" { 52 | return dir, nil 53 | } 54 | 55 | return "", fmt.Errorf("invalid path: %v", path) 56 | } 57 | 58 | type DiskFileManager struct { 59 | dirManager fm.DirectoryManager 60 | } 61 | 62 | func InitDiskFileManager(dirManager fm.DirectoryManager) DiskFileManager { 63 | return DiskFileManager{ 64 | dirManager: dirManager, 65 | } 66 | } 67 | 68 | func (d *DiskFileManager) GetPathProvider() fm.PathProvider { 69 | return d.dirManager.GetPathProvider() 70 | } 71 | 72 | func (d *DiskFileManager) GetDirectoryManager() fm.DirectoryManager { 73 | return d.dirManager 74 | } 75 | 76 | func (d *DiskFileManager) CreateFile(path string) (*fm.FileDetail, error) { 77 | exists, err := d.FileExists(path) 78 | if err != nil { 79 | return nil, err 80 | } 81 | 82 | if exists { 83 | return nil, os.ErrExist 84 | } 85 | 86 | path, _ = d.GetPathProvider().Combine(path) 87 | 88 | _, err = os.Create(path) 89 | if err != nil { 90 | return nil, err 91 | } 92 | 93 | return d.GetFile(path) 94 | } 95 | 96 | func (d *DiskFileManager) GetFile(path string) (*fm.FileDetail, error) { 97 | path, err := d.GetPathProvider().Combine(path) 98 | if err != nil { 99 | return nil, err 100 | } 101 | 102 | fileInfo, err := os.Stat(path) 103 | if err != nil { 104 | return nil, err 105 | } 106 | 107 | if fileInfo.IsDir() { 108 | return nil, os.ErrInvalid 109 | } 110 | 111 | fd := fm.InitFileDetail(d) 112 | fd.Name = fileInfo.Name() 113 | fd.Length = fileInfo.Size() 114 | fd.Path, _ = d.GetPathProvider().GetObjectParentPath(path) 115 | return &fd, nil 116 | } 117 | 118 | func (d *DiskFileManager) FileExists(path string) (bool, error) { 119 | path, err := d.GetPathProvider().Combine(path) 120 | if err != nil { 121 | return false, err 122 | } 123 | _, err = os.Stat(path) 124 | 125 | if os.IsNotExist(err) { 126 | return false, nil 127 | } 128 | 129 | if err != nil { 130 | return false, err 131 | } 132 | return true, nil 133 | } 134 | 135 | func (d *DiskFileManager) DeleteFile(path string) error { 136 | exists, err := d.FileExists(path) 137 | 138 | if err != nil { 139 | return err 140 | } 141 | 142 | if !exists { 143 | return os.ErrNotExist 144 | } 145 | 146 | path, _ = d.GetPathProvider().Combine(path) 147 | 148 | return os.RemoveAll(path) 149 | } 150 | 151 | type DiskDirectoryManager struct { 152 | pathProvider fm.PathProvider 153 | } 154 | 155 | func InitDiskDirectoryManager(pathProvider fm.PathProvider) DiskDirectoryManager { 156 | return DiskDirectoryManager{ 157 | pathProvider: pathProvider, 158 | } 159 | } 160 | 161 | func (d DiskDirectoryManager) GetPathProvider() fm.PathProvider { 162 | return d.pathProvider 163 | } 164 | 165 | func (d DiskDirectoryManager) CreateDir(path string) (*fm.DirectoryDetail, error) { 166 | path, err := d.GetPathProvider().Combine(path) 167 | 168 | if err != nil { 169 | return nil, err 170 | } 171 | 172 | err = os.Mkdir(path, 0777) 173 | 174 | if err != nil { 175 | return nil, err 176 | } 177 | 178 | return d.GetDir(path) 179 | } 180 | 181 | func (d DiskDirectoryManager) GetDir(path string) (*fm.DirectoryDetail, error) { 182 | path, err := d.GetPathProvider().Combine(path) 183 | 184 | if err != nil { 185 | return nil, err 186 | } 187 | dirInfo, err := os.Stat(path) 188 | 189 | if err != nil { 190 | return nil, err 191 | } 192 | 193 | if !dirInfo.IsDir() { 194 | return nil, os.ErrInvalid 195 | } 196 | 197 | dd := fm.InitDirectoryDetail(d) 198 | dd.Name = dirInfo.Name() 199 | dd.Path, _ = d.GetPathProvider().GetObjectParentPath(path) 200 | 201 | return &dd, nil 202 | } 203 | 204 | func (d DiskDirectoryManager) DirExists(path string) (bool, error) { 205 | path, err := d.GetPathProvider().Combine(path) 206 | if err != nil { 207 | return false, err 208 | } 209 | _, err = os.Stat(path) 210 | 211 | if os.IsNotExist(err) { 212 | return false, nil 213 | } 214 | 215 | if err != nil { 216 | return false, err 217 | } 218 | return true, nil 219 | } 220 | 221 | func (d DiskDirectoryManager) DeleteDir(path string) error { 222 | exists, err := d.DirExists(path) 223 | 224 | if err != nil { 225 | return err 226 | } 227 | 228 | if !exists { 229 | return os.ErrNotExist 230 | } 231 | 232 | path, _ = d.GetPathProvider().Combine(path) 233 | 234 | return os.RemoveAll(path) 235 | } 236 | -------------------------------------------------------------------------------- /src/Golang/disk/lib_test.go: -------------------------------------------------------------------------------- 1 | package disk 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "os" 6 | "testing" 7 | ) 8 | 9 | func initDiskFileManager() *DiskFileManager { 10 | fileManager := InitDiskFileManager( 11 | initDiskDirManager(), 12 | ) 13 | 14 | return &fileManager 15 | } 16 | 17 | func initDiskDirManager() *DiskDirectoryManager { 18 | provider := SystemPathProvider{} 19 | 20 | dirManager := InitDiskDirectoryManager(&provider) 21 | return &dirManager 22 | } 23 | 24 | func TestSystemPathProvider_CombineCombine(t *testing.T) { 25 | var res string 26 | var err error 27 | provider := new(SystemPathProvider) 28 | res, err = provider.Combine("parent", "dir", "file") 29 | assert.Nil(t, err) 30 | assert.Equal(t, "parent/dir/file", res) 31 | 32 | res, err = provider.Combine("parent/dir", "file") 33 | assert.Nil(t, err) 34 | assert.Equal(t, "parent/dir/file", res) 35 | 36 | res, err = provider.Combine("parent", "dir/file") 37 | assert.Nil(t, err) 38 | assert.Equal(t, "parent/dir/file", res) 39 | 40 | res, err = provider.Combine("parent/dir/file") 41 | assert.Nil(t, err) 42 | assert.Equal(t, "parent/dir/file", res) 43 | 44 | res, err = provider.Combine("/parent", "dir", "file") 45 | assert.Nil(t, err) 46 | assert.Equal(t, "/parent/dir/file", res) 47 | 48 | res, err = provider.Combine("/parent", "/dir", "file") 49 | assert.Nil(t, err) 50 | assert.Equal(t, "/parent/dir/file", res) 51 | 52 | res, err = provider.Combine("/parent/dir/file", "../..") 53 | assert.Nil(t, err) 54 | assert.Equal(t, "/parent", res) 55 | } 56 | 57 | func TestNormalizePath(t *testing.T) { 58 | var res string 59 | 60 | res = normalizePath("dir/file") 61 | assert.Equal(t, "dir/file", res) 62 | 63 | res = normalizePath("dir/file/") 64 | assert.Equal(t, "dir/file", res) 65 | 66 | res = normalizePath("dir/file//") 67 | assert.Equal(t, "dir/file", res) 68 | } 69 | 70 | func TestSystemPathProvider_GetObjectName(t *testing.T) { 71 | var res string 72 | var err error 73 | 74 | provider := new(SystemPathProvider) 75 | res, err = provider.GetObjectName("parent/dir/file") 76 | assert.Nil(t, err) 77 | assert.Equal(t, "file", res) 78 | 79 | res, err = provider.GetObjectName("parent/dir/") 80 | assert.Nil(t, err) 81 | assert.Equal(t, "dir", res) 82 | 83 | res, err = provider.GetObjectName("parent/dir//") 84 | assert.Nil(t, err) 85 | assert.Equal(t, "dir", res) 86 | 87 | res, err = provider.GetObjectName("parent/dir/../") 88 | assert.Nil(t, err) 89 | assert.Equal(t, "parent", res) 90 | 91 | res, err = provider.GetObjectName("/") 92 | assert.Equal(t, "", res) 93 | assert.NotNil(t, res) 94 | assert.Contains(t, err.Error(), "invalid path:") 95 | } 96 | 97 | func TestSystemPathProvider_GetObjectParentPath(t *testing.T) { 98 | var res string 99 | var err error 100 | 101 | provider := new(SystemPathProvider) 102 | res, err = provider.GetObjectParentPath("parent/dir/file") 103 | assert.Nil(t, err) 104 | assert.Equal(t, "parent/dir/", res) 105 | 106 | res, err = provider.GetObjectParentPath("parent/dir/") 107 | assert.Nil(t, err) 108 | assert.Equal(t, "parent/", res) 109 | 110 | res, err = provider.GetObjectParentPath("parent/dir//") 111 | assert.Nil(t, err) 112 | assert.Equal(t, "parent/", res) 113 | 114 | res, err = provider.GetObjectParentPath("/parent/dir/../") 115 | assert.Nil(t, err) 116 | assert.Equal(t, "/", res) 117 | 118 | res, err = provider.GetObjectParentPath("/") 119 | assert.Equal(t, "", res) 120 | assert.NotNil(t, res) 121 | assert.Contains(t, err.Error(), "invalid path:") 122 | 123 | res, err = provider.GetObjectParentPath("parent/dir/../") 124 | assert.Equal(t, "", res) 125 | assert.NotNil(t, res) 126 | assert.Contains(t, err.Error(), "invalid path:") 127 | } 128 | 129 | func TestDiskFileManager_GetPathProvider(t *testing.T) { 130 | provider := SystemPathProvider{} 131 | dirManager := InitDiskDirectoryManager(&provider) 132 | 133 | fileManager := InitDiskFileManager(&dirManager) 134 | 135 | assert.Equal(t, &provider, fileManager.GetPathProvider()) 136 | } 137 | 138 | func TestDiskFileManager_GetDirectoryManager(t *testing.T) { 139 | provider := SystemPathProvider{} 140 | dirManager := InitDiskDirectoryManager(&provider) 141 | 142 | fileManager := InitDiskFileManager(&dirManager) 143 | 144 | assert.Equal(t, &dirManager, fileManager.GetDirectoryManager()) 145 | } 146 | 147 | func TestDiskFileManager_CreateFile_WhenNotExists(t *testing.T) { 148 | fm := initDiskFileManager() 149 | 150 | // Create file... 151 | tmpDir := t.TempDir() 152 | testFile, _ := fm.GetPathProvider().Combine(tmpDir, "test_file") 153 | fd, err := fm.CreateFile(testFile) 154 | assert.Nil(t, err) 155 | assert.Equal(t, "test_file", fd.Name) 156 | assert.Equal(t, tmpDir+"/", fd.Path) 157 | assert.Equal(t, int64(0), fd.Length) 158 | 159 | fullPath, err := fd.FullPath() 160 | assert.Nil(t, err) 161 | assert.Equal(t, testFile, fullPath) 162 | } 163 | 164 | func TestDiskFileManager_CreateFile_WhenExists(t *testing.T) { 165 | fm := initDiskFileManager() 166 | 167 | // Preparing file... 168 | testFile, _ := fm.GetPathProvider().Combine(t.TempDir(), "test_file") 169 | _, _ = fm.CreateFile(testFile) 170 | 171 | // Recreate same file 172 | fd, err := fm.CreateFile(testFile) 173 | assert.Nil(t, fd) 174 | assert.NotNil(t, err) 175 | assert.True(t, os.IsExist(err)) 176 | } 177 | 178 | func TestDiskFileManager_GetFile_WhenNotExists(t *testing.T) { 179 | fm := initDiskFileManager() 180 | 181 | testFile, _ := fm.GetPathProvider().Combine(t.TempDir(), "test_file") 182 | fd, err := fm.GetFile(testFile) 183 | assert.Nil(t, fd) 184 | assert.NotNil(t, err) 185 | assert.True(t, os.IsNotExist(err)) 186 | } 187 | 188 | func TestDiskFileManager_GetFile_WhenExists(t *testing.T) { 189 | fm := initDiskFileManager() 190 | 191 | // Prepare file... 192 | tmpDir := t.TempDir() 193 | testFile, _ := fm.GetPathProvider().Combine(tmpDir, "test_file") 194 | _, _ = fm.CreateFile(testFile) 195 | 196 | fd, err := fm.GetFile(testFile) 197 | assert.Nil(t, err) 198 | assert.Equal(t, "test_file", fd.Name) 199 | assert.Equal(t, tmpDir+"/", fd.Path) 200 | assert.Equal(t, int64(0), fd.Length) 201 | 202 | fullPath, err := fd.FullPath() 203 | assert.Nil(t, err) 204 | assert.Equal(t, testFile, fullPath) 205 | } 206 | 207 | func TestDiskFileManager_FileExists_WhenNotExists(t *testing.T) { 208 | fm := initDiskFileManager() 209 | 210 | testFile, _ := fm.GetPathProvider().Combine(t.TempDir(), "test_file") 211 | exists, err := fm.FileExists(testFile) 212 | assert.Nil(t, err) 213 | assert.False(t, exists) 214 | } 215 | 216 | func TestDiskFileManager_FileExists_WhenExists(t *testing.T) { 217 | fm := initDiskFileManager() 218 | 219 | // Prepare file... 220 | testFile, _ := fm.GetPathProvider().Combine(t.TempDir(), "test_file") 221 | _, _ = fm.CreateFile(testFile) 222 | 223 | exists, err := fm.FileExists(testFile) 224 | assert.Nil(t, err) 225 | assert.True(t, exists) 226 | } 227 | 228 | func TestDiskFileManager_DeleteFile_WhenNotExists(t *testing.T) { 229 | fm := initDiskFileManager() 230 | 231 | testFile, _ := fm.GetPathProvider().Combine(t.TempDir(), "test_file") 232 | err := fm.DeleteFile(testFile) 233 | assert.NotNil(t, err) 234 | assert.True(t, os.IsNotExist(err)) 235 | } 236 | 237 | func TestDiskFileManager_DeleteFile_WhenExists(t *testing.T) { 238 | fm := initDiskFileManager() 239 | 240 | // Prepare file... 241 | testFile, _ := fm.GetPathProvider().Combine(t.TempDir(), "test_file") 242 | _, _ = fm.CreateFile(testFile) 243 | 244 | err := fm.DeleteFile(testFile) 245 | assert.Nil(t, err) 246 | } 247 | 248 | func TestDiskDirectoryManager_GetPathProvider(t *testing.T) { 249 | provider := SystemPathProvider{} 250 | 251 | dm := InitDiskDirectoryManager(&provider) 252 | 253 | assert.Equal(t, &provider, dm.GetPathProvider()) 254 | } 255 | 256 | func TestDiskDirectoryManager_CreateDir_WhenNotExists(t *testing.T) { 257 | dm := initDiskDirManager() 258 | 259 | tmpDir := t.TempDir() 260 | testDir, _ := dm.GetPathProvider().Combine(tmpDir, "test_dir") 261 | dd, err := dm.CreateDir(testDir) 262 | assert.Nil(t, err) 263 | assert.Equal(t, "test_dir", dd.Name) 264 | assert.Equal(t, tmpDir+"/", dd.Path) 265 | 266 | fullPath, err := dd.FullPath() 267 | assert.Nil(t, err) 268 | assert.Equal(t, testDir, fullPath) 269 | } 270 | 271 | func TestDiskDirectoryManager_CreateDir_WhenExists(t *testing.T) { 272 | dm := initDiskDirManager() 273 | 274 | // Prepare dir... 275 | testDir, _ := dm.GetPathProvider().Combine(t.TempDir(), "test_dir") 276 | _, _ = dm.CreateDir(testDir) 277 | 278 | dd, err := dm.CreateDir(testDir) 279 | assert.Nil(t, dd) 280 | assert.NotNil(t, err) 281 | assert.True(t, os.IsExist(err)) 282 | } 283 | 284 | func TestDiskDirectoryManager_GetDir_WhenNotExists(t *testing.T) { 285 | dm := initDiskDirManager() 286 | 287 | testDir, _ := dm.GetPathProvider().Combine(t.TempDir(), "test_dir") 288 | dd, err := dm.GetDir(testDir) 289 | assert.Nil(t, dd) 290 | assert.NotNil(t, err) 291 | assert.True(t, os.IsNotExist(err)) 292 | } 293 | 294 | func TestDiskDirectoryManager_GetDir_WhenExists(t *testing.T) { 295 | dm := initDiskDirManager() 296 | 297 | // Prepare dir... 298 | tmpDir := t.TempDir() 299 | testDir, _ := dm.GetPathProvider().Combine(tmpDir, "test_dir") 300 | _, _ = dm.CreateDir(testDir) 301 | 302 | dd, err := dm.GetDir(testDir) 303 | assert.Nil(t, err) 304 | assert.Equal(t, "test_dir", dd.Name) 305 | assert.Equal(t, tmpDir+"/", dd.Path) 306 | 307 | fullPath, err := dd.FullPath() 308 | assert.Nil(t, err) 309 | assert.Equal(t, testDir, fullPath) 310 | } 311 | 312 | func TestDiskDirectoryManager_DirExists_WhenNonExists(t *testing.T) { 313 | dm := initDiskDirManager() 314 | 315 | testDir, _ := dm.GetPathProvider().Combine(t.TempDir(), "test_dir") 316 | exists, err := dm.DirExists(testDir) 317 | assert.Nil(t, err) 318 | assert.False(t, exists) 319 | } 320 | 321 | func TestDiskDirectoryManager_DirExists_WhenExists(t *testing.T) { 322 | dm := initDiskDirManager() 323 | 324 | // Prepare dir... 325 | testDir, _ := dm.GetPathProvider().Combine(t.TempDir(), "test_dir") 326 | _, _ = dm.CreateDir(testDir) 327 | 328 | exists, err := dm.DirExists(testDir) 329 | assert.Nil(t, err) 330 | assert.True(t, exists) 331 | } 332 | 333 | func TestDiskDirectoryManager_DeleteDir_WhenNotExists(t *testing.T) { 334 | dm := initDiskDirManager() 335 | 336 | testDir, _ := dm.GetPathProvider().Combine(t.TempDir(), "test_dir") 337 | err := dm.DeleteDir(testDir) 338 | assert.NotNil(t, err) 339 | assert.True(t, os.IsNotExist(err)) 340 | } 341 | 342 | func TestDiskDirectoryManager_DeleteDir_WhenExists(t *testing.T) { 343 | dm := initDiskDirManager() 344 | 345 | // Prepare dir... 346 | testDir, _ := dm.GetPathProvider().Combine(t.TempDir(), "test_dir") 347 | _, _ = dm.CreateDir(testDir) 348 | 349 | err := dm.DeleteDir(testDir) 350 | assert.Nil(t, err) 351 | } 352 | -------------------------------------------------------------------------------- /src/Golang/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/EasyMicroservices/FileManager 2 | 3 | go 1.19 4 | 5 | require github.com/stretchr/testify v1.8.1 6 | 7 | require ( 8 | github.com/davecgh/go-spew v1.1.1 // indirect 9 | github.com/pmezard/go-difflib v1.0.0 // indirect 10 | gopkg.in/yaml.v3 v3.0.1 // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /src/Golang/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 5 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 6 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 7 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 8 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 9 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 10 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 11 | github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= 12 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 13 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 14 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 15 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 16 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 17 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 18 | -------------------------------------------------------------------------------- /src/Golang/lib.go: -------------------------------------------------------------------------------- 1 | package filemanager 2 | 3 | func createDir(path string, manager DirectoryManager) (*DirectoryDetail, error) { 4 | return manager.CreateDir(path) 5 | } 6 | 7 | func getDir(path string, manager DirectoryManager) (*DirectoryDetail, error) { 8 | return manager.GetDir(path) 9 | } 10 | 11 | func dirExists(path string, manager DirectoryManager) (bool, error) { 12 | return manager.DirExists(path) 13 | } 14 | 15 | func deleteDir(path string, manager DirectoryManager) error { 16 | return manager.DeleteDir(path) 17 | } 18 | 19 | func createFile(path string, manager FileManager) (*FileDetail, error) { 20 | return manager.CreateFile(path) 21 | } 22 | 23 | func getFile(path string, manager FileManager) (*FileDetail, error) { 24 | return manager.GetFile(path) 25 | } 26 | 27 | func fileExists(path string, manager FileManager) (bool, error) { 28 | return manager.FileExists(path) 29 | } 30 | 31 | func deleteFile(path string, manager FileManager) error { 32 | return manager.DeleteFile(path) 33 | } 34 | -------------------------------------------------------------------------------- /src/Golang/models.go: -------------------------------------------------------------------------------- 1 | package filemanager 2 | 3 | type FileDetail struct { 4 | fileManager FileManager 5 | Name string 6 | Path string 7 | Length int64 8 | } 9 | 10 | func InitFileDetail(fm FileManager) FileDetail { 11 | return FileDetail{ 12 | fileManager: fm, 13 | } 14 | } 15 | 16 | func (f *FileDetail) FullPath() (string, error) { 17 | return f.fileManager.GetPathProvider().Combine( 18 | f.Path, f.Name, 19 | ) 20 | } 21 | 22 | type DirectoryDetail struct { 23 | dirManager DirectoryManager 24 | Name string 25 | Path string 26 | } 27 | 28 | func InitDirectoryDetail(dm DirectoryManager) DirectoryDetail { 29 | return DirectoryDetail{ 30 | dirManager: dm, 31 | } 32 | } 33 | 34 | func (d *DirectoryDetail) FullPath() (string, error) { 35 | return d.dirManager.GetPathProvider().Combine( 36 | d.Path, d.Name, 37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /src/Golang/providers.go: -------------------------------------------------------------------------------- 1 | package filemanager 2 | 3 | type PathProvider interface { 4 | Combine(paths ...string) (string, error) 5 | GetObjectName(path string) (string, error) 6 | GetObjectParentPath(path string) (string, error) 7 | } 8 | 9 | type DirectoryManager interface { 10 | GetPathProvider() PathProvider 11 | CreateDir(path string) (*DirectoryDetail, error) 12 | GetDir(path string) (*DirectoryDetail, error) 13 | DirExists(path string) (bool, error) 14 | DeleteDir(path string) error 15 | } 16 | 17 | type FileManager interface { 18 | GetPathProvider() PathProvider 19 | GetDirectoryManager() DirectoryManager 20 | CreateFile(path string) (*FileDetail, error) 21 | GetFile(path string) (*FileDetail, error) 22 | FileExists(path string) (bool, error) 23 | DeleteFile(path string) error 24 | } 25 | -------------------------------------------------------------------------------- /src/Rust/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## Current Version: 4 | 5 | - [#35 Add sync methods to rust project](https://github.com/EasyMicroservices/FileManager/issues/35) 6 | - [#26 Implement disk managers and providers in Rust](https://github.com/EasyMicroservices/FileManager/issues/26) 7 | - Init project in Rust and implement providers. -------------------------------------------------------------------------------- /src/Rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "anyhow" 7 | version = "1.0.68" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" 10 | 11 | [[package]] 12 | name = "async-trait" 13 | version = "0.1.60" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" 16 | dependencies = [ 17 | "proc-macro2", 18 | "quote", 19 | "syn", 20 | ] 21 | 22 | [[package]] 23 | name = "autocfg" 24 | version = "1.1.0" 25 | source = "registry+https://github.com/rust-lang/crates.io-index" 26 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 27 | 28 | [[package]] 29 | name = "bitflags" 30 | version = "1.3.2" 31 | source = "registry+https://github.com/rust-lang/crates.io-index" 32 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 33 | 34 | [[package]] 35 | name = "bytes" 36 | version = "1.3.0" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" 39 | 40 | [[package]] 41 | name = "cfg-if" 42 | version = "1.0.0" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 45 | 46 | [[package]] 47 | name = "easy_microservice" 48 | version = "0.1.0" 49 | dependencies = [ 50 | "anyhow", 51 | "async-trait", 52 | "futures", 53 | "tempfile", 54 | "tokio", 55 | ] 56 | 57 | [[package]] 58 | name = "fastrand" 59 | version = "1.8.0" 60 | source = "registry+https://github.com/rust-lang/crates.io-index" 61 | checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" 62 | dependencies = [ 63 | "instant", 64 | ] 65 | 66 | [[package]] 67 | name = "futures" 68 | version = "0.3.25" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" 71 | dependencies = [ 72 | "futures-channel", 73 | "futures-core", 74 | "futures-executor", 75 | "futures-io", 76 | "futures-sink", 77 | "futures-task", 78 | "futures-util", 79 | ] 80 | 81 | [[package]] 82 | name = "futures-channel" 83 | version = "0.3.25" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" 86 | dependencies = [ 87 | "futures-core", 88 | "futures-sink", 89 | ] 90 | 91 | [[package]] 92 | name = "futures-core" 93 | version = "0.3.25" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" 96 | 97 | [[package]] 98 | name = "futures-executor" 99 | version = "0.3.25" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" 102 | dependencies = [ 103 | "futures-core", 104 | "futures-task", 105 | "futures-util", 106 | ] 107 | 108 | [[package]] 109 | name = "futures-io" 110 | version = "0.3.25" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" 113 | 114 | [[package]] 115 | name = "futures-macro" 116 | version = "0.3.25" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" 119 | dependencies = [ 120 | "proc-macro2", 121 | "quote", 122 | "syn", 123 | ] 124 | 125 | [[package]] 126 | name = "futures-sink" 127 | version = "0.3.25" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" 130 | 131 | [[package]] 132 | name = "futures-task" 133 | version = "0.3.25" 134 | source = "registry+https://github.com/rust-lang/crates.io-index" 135 | checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" 136 | 137 | [[package]] 138 | name = "futures-util" 139 | version = "0.3.25" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" 142 | dependencies = [ 143 | "futures-channel", 144 | "futures-core", 145 | "futures-io", 146 | "futures-macro", 147 | "futures-sink", 148 | "futures-task", 149 | "memchr", 150 | "pin-project-lite", 151 | "pin-utils", 152 | "slab", 153 | ] 154 | 155 | [[package]] 156 | name = "hermit-abi" 157 | version = "0.2.6" 158 | source = "registry+https://github.com/rust-lang/crates.io-index" 159 | checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" 160 | dependencies = [ 161 | "libc", 162 | ] 163 | 164 | [[package]] 165 | name = "instant" 166 | version = "0.1.12" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" 169 | dependencies = [ 170 | "cfg-if", 171 | ] 172 | 173 | [[package]] 174 | name = "libc" 175 | version = "0.2.139" 176 | source = "registry+https://github.com/rust-lang/crates.io-index" 177 | checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" 178 | 179 | [[package]] 180 | name = "lock_api" 181 | version = "0.4.9" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" 184 | dependencies = [ 185 | "autocfg", 186 | "scopeguard", 187 | ] 188 | 189 | [[package]] 190 | name = "log" 191 | version = "0.4.17" 192 | source = "registry+https://github.com/rust-lang/crates.io-index" 193 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 194 | dependencies = [ 195 | "cfg-if", 196 | ] 197 | 198 | [[package]] 199 | name = "memchr" 200 | version = "2.5.0" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 203 | 204 | [[package]] 205 | name = "mio" 206 | version = "0.8.5" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" 209 | dependencies = [ 210 | "libc", 211 | "log", 212 | "wasi", 213 | "windows-sys", 214 | ] 215 | 216 | [[package]] 217 | name = "num_cpus" 218 | version = "1.15.0" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" 221 | dependencies = [ 222 | "hermit-abi", 223 | "libc", 224 | ] 225 | 226 | [[package]] 227 | name = "parking_lot" 228 | version = "0.12.1" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" 231 | dependencies = [ 232 | "lock_api", 233 | "parking_lot_core", 234 | ] 235 | 236 | [[package]] 237 | name = "parking_lot_core" 238 | version = "0.9.5" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" 241 | dependencies = [ 242 | "cfg-if", 243 | "libc", 244 | "redox_syscall", 245 | "smallvec", 246 | "windows-sys", 247 | ] 248 | 249 | [[package]] 250 | name = "pin-project-lite" 251 | version = "0.2.9" 252 | source = "registry+https://github.com/rust-lang/crates.io-index" 253 | checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" 254 | 255 | [[package]] 256 | name = "pin-utils" 257 | version = "0.1.0" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 260 | 261 | [[package]] 262 | name = "proc-macro2" 263 | version = "1.0.49" 264 | source = "registry+https://github.com/rust-lang/crates.io-index" 265 | checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" 266 | dependencies = [ 267 | "unicode-ident", 268 | ] 269 | 270 | [[package]] 271 | name = "quote" 272 | version = "1.0.23" 273 | source = "registry+https://github.com/rust-lang/crates.io-index" 274 | checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" 275 | dependencies = [ 276 | "proc-macro2", 277 | ] 278 | 279 | [[package]] 280 | name = "redox_syscall" 281 | version = "0.2.16" 282 | source = "registry+https://github.com/rust-lang/crates.io-index" 283 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 284 | dependencies = [ 285 | "bitflags", 286 | ] 287 | 288 | [[package]] 289 | name = "remove_dir_all" 290 | version = "0.5.3" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" 293 | dependencies = [ 294 | "winapi", 295 | ] 296 | 297 | [[package]] 298 | name = "scopeguard" 299 | version = "1.1.0" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 302 | 303 | [[package]] 304 | name = "signal-hook-registry" 305 | version = "1.4.0" 306 | source = "registry+https://github.com/rust-lang/crates.io-index" 307 | checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" 308 | dependencies = [ 309 | "libc", 310 | ] 311 | 312 | [[package]] 313 | name = "slab" 314 | version = "0.4.7" 315 | source = "registry+https://github.com/rust-lang/crates.io-index" 316 | checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" 317 | dependencies = [ 318 | "autocfg", 319 | ] 320 | 321 | [[package]] 322 | name = "smallvec" 323 | version = "1.10.0" 324 | source = "registry+https://github.com/rust-lang/crates.io-index" 325 | checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" 326 | 327 | [[package]] 328 | name = "socket2" 329 | version = "0.4.7" 330 | source = "registry+https://github.com/rust-lang/crates.io-index" 331 | checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" 332 | dependencies = [ 333 | "libc", 334 | "winapi", 335 | ] 336 | 337 | [[package]] 338 | name = "syn" 339 | version = "1.0.107" 340 | source = "registry+https://github.com/rust-lang/crates.io-index" 341 | checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" 342 | dependencies = [ 343 | "proc-macro2", 344 | "quote", 345 | "unicode-ident", 346 | ] 347 | 348 | [[package]] 349 | name = "tempfile" 350 | version = "3.3.0" 351 | source = "registry+https://github.com/rust-lang/crates.io-index" 352 | checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" 353 | dependencies = [ 354 | "cfg-if", 355 | "fastrand", 356 | "libc", 357 | "redox_syscall", 358 | "remove_dir_all", 359 | "winapi", 360 | ] 361 | 362 | [[package]] 363 | name = "tokio" 364 | version = "1.23.0" 365 | source = "registry+https://github.com/rust-lang/crates.io-index" 366 | checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" 367 | dependencies = [ 368 | "autocfg", 369 | "bytes", 370 | "libc", 371 | "memchr", 372 | "mio", 373 | "num_cpus", 374 | "parking_lot", 375 | "pin-project-lite", 376 | "signal-hook-registry", 377 | "socket2", 378 | "tokio-macros", 379 | "windows-sys", 380 | ] 381 | 382 | [[package]] 383 | name = "tokio-macros" 384 | version = "1.8.2" 385 | source = "registry+https://github.com/rust-lang/crates.io-index" 386 | checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" 387 | dependencies = [ 388 | "proc-macro2", 389 | "quote", 390 | "syn", 391 | ] 392 | 393 | [[package]] 394 | name = "unicode-ident" 395 | version = "1.0.6" 396 | source = "registry+https://github.com/rust-lang/crates.io-index" 397 | checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" 398 | 399 | [[package]] 400 | name = "wasi" 401 | version = "0.11.0+wasi-snapshot-preview1" 402 | source = "registry+https://github.com/rust-lang/crates.io-index" 403 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 404 | 405 | [[package]] 406 | name = "winapi" 407 | version = "0.3.9" 408 | source = "registry+https://github.com/rust-lang/crates.io-index" 409 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 410 | dependencies = [ 411 | "winapi-i686-pc-windows-gnu", 412 | "winapi-x86_64-pc-windows-gnu", 413 | ] 414 | 415 | [[package]] 416 | name = "winapi-i686-pc-windows-gnu" 417 | version = "0.4.0" 418 | source = "registry+https://github.com/rust-lang/crates.io-index" 419 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 420 | 421 | [[package]] 422 | name = "winapi-x86_64-pc-windows-gnu" 423 | version = "0.4.0" 424 | source = "registry+https://github.com/rust-lang/crates.io-index" 425 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 426 | 427 | [[package]] 428 | name = "windows-sys" 429 | version = "0.42.0" 430 | source = "registry+https://github.com/rust-lang/crates.io-index" 431 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" 432 | dependencies = [ 433 | "windows_aarch64_gnullvm", 434 | "windows_aarch64_msvc", 435 | "windows_i686_gnu", 436 | "windows_i686_msvc", 437 | "windows_x86_64_gnu", 438 | "windows_x86_64_gnullvm", 439 | "windows_x86_64_msvc", 440 | ] 441 | 442 | [[package]] 443 | name = "windows_aarch64_gnullvm" 444 | version = "0.42.0" 445 | source = "registry+https://github.com/rust-lang/crates.io-index" 446 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" 447 | 448 | [[package]] 449 | name = "windows_aarch64_msvc" 450 | version = "0.42.0" 451 | source = "registry+https://github.com/rust-lang/crates.io-index" 452 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" 453 | 454 | [[package]] 455 | name = "windows_i686_gnu" 456 | version = "0.42.0" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" 459 | 460 | [[package]] 461 | name = "windows_i686_msvc" 462 | version = "0.42.0" 463 | source = "registry+https://github.com/rust-lang/crates.io-index" 464 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" 465 | 466 | [[package]] 467 | name = "windows_x86_64_gnu" 468 | version = "0.42.0" 469 | source = "registry+https://github.com/rust-lang/crates.io-index" 470 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" 471 | 472 | [[package]] 473 | name = "windows_x86_64_gnullvm" 474 | version = "0.42.0" 475 | source = "registry+https://github.com/rust-lang/crates.io-index" 476 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" 477 | 478 | [[package]] 479 | name = "windows_x86_64_msvc" 480 | version = "0.42.0" 481 | source = "registry+https://github.com/rust-lang/crates.io-index" 482 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" 483 | -------------------------------------------------------------------------------- /src/Rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "easy_microservice" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | futures = "0.3" 10 | async-trait = "0.1.60" 11 | anyhow = "1.0.68" 12 | tokio = { version = "1.23.0", features = ["full"] } 13 | 14 | [dev-dependencies] 15 | tempfile = "3.3.0" -------------------------------------------------------------------------------- /src/Rust/src/disk/lib.rs: -------------------------------------------------------------------------------- 1 | use std::path; 2 | use anyhow::bail; 3 | use async_trait::async_trait; 4 | use tokio::fs; 5 | use std::fs as stdfs; 6 | use std::io as stdio; 7 | 8 | use crate::models::{DirectoryDetail, FileDetail}; 9 | use crate::providers::{PathProvider, DirectoryManager, FileManager}; 10 | 11 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] 12 | pub struct DiskFileManager 13 | where 14 | D: DirectoryManager + Send + Sync 15 | { 16 | dir_manager: D, 17 | } 18 | 19 | impl DiskFileManager 20 | where 21 | D: DirectoryManager + Send + Sync 22 | { 23 | pub fn new(dir_manager: D) -> DiskFileManager { 24 | DiskFileManager { 25 | dir_manager 26 | } 27 | } 28 | } 29 | 30 | #[async_trait] 31 | impl FileManager for DiskFileManager 32 | where 33 | D: DirectoryManager + Send + Sync 34 | { 35 | fn path_provider(&self) -> &dyn PathProvider { 36 | self.dir_manager.path_provider() 37 | } 38 | 39 | fn dir_manager(&self) -> &dyn DirectoryManager { 40 | &self.dir_manager 41 | } 42 | 43 | async fn get_file_async(&self, path: &str) -> anyhow::Result { 44 | let updated_path = self.path_provider().combine(vec![path])?; 45 | 46 | let metadata = fs::metadata(updated_path.clone()).await?; 47 | 48 | if !metadata.is_file() { 49 | return Err(std::io::Error::from(std::io::ErrorKind::NotFound).into()); 50 | } 51 | 52 | return Ok(FileDetail { 53 | file_manager: self, 54 | name: self.path_provider().get_object_name(&updated_path)?, 55 | path: self.path_provider().get_object_parent_path(&updated_path)?, 56 | len: metadata.len(), 57 | }); 58 | } 59 | 60 | async fn create_file_async(&self, path: &str) -> anyhow::Result { 61 | let exists = self.is_file_exists_async(path).await?; 62 | if exists { 63 | return Err(std::io::Error::from(std::io::ErrorKind::AlreadyExists).into()); 64 | } 65 | 66 | let updated_path = self.path_provider().combine(vec![path])?; 67 | 68 | fs::File::create(updated_path).await?; 69 | 70 | return self.get_file_async(path).await; 71 | } 72 | 73 | async fn is_file_exists_async(&self, path: &str) -> anyhow::Result { 74 | let updated_path = self.path_provider().combine(vec![path])?; 75 | 76 | let metadata = match fs::metadata(updated_path).await { 77 | Ok(v) => v, 78 | Err(e) => { 79 | if e.kind() == std::io::ErrorKind::NotFound { 80 | return Ok(false); 81 | } 82 | return Err(e.into()); 83 | } 84 | }; 85 | 86 | Ok(metadata.is_file()) 87 | } 88 | 89 | async fn delete_file_async(&self, path: &str) -> anyhow::Result<()> { 90 | let updated_path = self.path_provider().combine(vec![path])?; 91 | 92 | fs::remove_file(updated_path).await?; 93 | 94 | Ok(()) 95 | } 96 | 97 | fn get_file(&self, path: &str) -> anyhow::Result { 98 | let updated_path = self.path_provider().combine(vec![path])?; 99 | 100 | let metadata = stdfs::metadata(updated_path.clone())?; 101 | 102 | if !metadata.is_file() { 103 | return Err(stdio::Error::from(stdio::ErrorKind::NotFound).into()); 104 | } 105 | 106 | Ok(FileDetail { 107 | file_manager: self, 108 | name: self.path_provider().get_object_name(&updated_path)?, 109 | path: self.path_provider().get_object_parent_path(&updated_path)?, 110 | len: metadata.len(), 111 | }) 112 | } 113 | 114 | fn create_file(&self, path: &str) -> anyhow::Result { 115 | if self.is_file_exists(path)? { 116 | return Err(stdio::Error::from(stdio::ErrorKind::AlreadyExists).into()); 117 | } 118 | 119 | let updated_path = self.path_provider().combine(vec![path])?; 120 | 121 | stdfs::File::create(updated_path)?; 122 | 123 | self.get_file(path) 124 | } 125 | 126 | fn is_file_exists(&self, path: &str) -> anyhow::Result { 127 | let updated_path = self.path_provider().combine(vec![path])?; 128 | 129 | let metadata = match stdfs::metadata(updated_path) { 130 | Ok(v) => v, 131 | Err(e) => { 132 | if e.kind() == stdio::ErrorKind::NotFound { 133 | return Ok(false); 134 | } 135 | return Err(e.into()); 136 | } 137 | }; 138 | 139 | Ok(metadata.is_file()) 140 | } 141 | 142 | fn delete_file(&self, path: &str) -> anyhow::Result<()> { 143 | let updated_path = self.path_provider().combine(vec![path])?; 144 | 145 | stdfs::remove_file(updated_path)?; 146 | 147 | Ok(()) 148 | } 149 | } 150 | 151 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] 152 | pub struct DiskDirectoryManager

153 | where 154 | P: PathProvider + Send + Sync 155 | { 156 | path_provider: P, 157 | } 158 | 159 | impl

DiskDirectoryManager

160 | where 161 | P: PathProvider + Send + Sync 162 | { 163 | pub fn new(path_provider: P) -> DiskDirectoryManager

{ 164 | DiskDirectoryManager { 165 | path_provider 166 | } 167 | } 168 | } 169 | 170 | #[async_trait] 171 | impl

DirectoryManager for DiskDirectoryManager

172 | where 173 | P: PathProvider + Send + Sync 174 | { 175 | fn path_provider(&self) -> &dyn PathProvider { 176 | &self.path_provider 177 | } 178 | 179 | async fn create_dir_async(&self, path: &str) -> anyhow::Result { 180 | let updated_path = self.path_provider().combine(vec![path])?; 181 | 182 | fs::create_dir(updated_path).await?; 183 | 184 | self.get_dir_async(path).await 185 | } 186 | 187 | async fn get_dir_async(&self, path: &str) -> anyhow::Result { 188 | let updated_path = self.path_provider().combine(vec![path])?; 189 | 190 | let metadata = fs::metadata(updated_path.clone()).await?; 191 | 192 | if !metadata.is_dir() { 193 | return Err(std::io::Error::from(std::io::ErrorKind::AlreadyExists).into()); 194 | } 195 | 196 | Ok(DirectoryDetail { 197 | dir_manager: self, 198 | name: self.path_provider().get_object_name(&updated_path)?, 199 | path: self.path_provider().get_object_parent_path(&updated_path)?, 200 | }.clone()) 201 | } 202 | 203 | async fn is_dir_exists_async(&self, path: &str) -> anyhow::Result { 204 | let updated_path = self.path_provider().combine(vec![path])?; 205 | 206 | let metadata = fs::metadata(updated_path).await; 207 | 208 | let metadata = match metadata { 209 | Ok(v) => v, 210 | Err(e) => { 211 | if e.kind() == std::io::ErrorKind::NotFound { 212 | return Ok(false); 213 | } 214 | return Err(e.into()); 215 | } 216 | }; 217 | 218 | Ok(metadata.is_dir()) 219 | } 220 | 221 | async fn delete_dir_async(&self, path: &str, recursive: bool) -> anyhow::Result<()> { 222 | let updated_path = self.path_provider().combine(vec![path])?; 223 | 224 | if recursive { 225 | fs::remove_dir_all(updated_path).await?; 226 | } else { 227 | fs::remove_dir(updated_path).await?; 228 | } 229 | 230 | Ok(()) 231 | } 232 | 233 | fn create_dir(&self, path: &str) -> anyhow::Result { 234 | let updated_path = self.path_provider().combine(vec![path])?; 235 | 236 | stdfs::create_dir(updated_path)?; 237 | 238 | self.get_dir(path) 239 | } 240 | 241 | fn get_dir(&self, path: &str) -> anyhow::Result { 242 | let updated_path = self.path_provider().combine(vec![path])?; 243 | 244 | let metadata = stdfs::metadata(updated_path.clone())?; 245 | 246 | if !metadata.is_dir() { 247 | return Err(stdio::Error::from(stdio::ErrorKind::AlreadyExists).into()); 248 | } 249 | 250 | Ok(DirectoryDetail { 251 | dir_manager: self, 252 | name: self.path_provider().get_object_name(&updated_path)?, 253 | path: self.path_provider().get_object_parent_path(&updated_path)?, 254 | }) 255 | } 256 | 257 | fn is_dir_exists(&self, path: &str) -> anyhow::Result { 258 | let updated_path = self.path_provider().combine(vec![path])?; 259 | 260 | let metadata = match stdfs::metadata(updated_path) { 261 | Ok(v) => v, 262 | Err(e) => { 263 | if e.kind() == stdio::ErrorKind::NotFound { 264 | return Ok(false); 265 | } 266 | return Err(e.into()); 267 | } 268 | }; 269 | 270 | Ok(metadata.is_dir()) 271 | } 272 | 273 | fn delete_dir(&self, path: &str, recursive: bool) -> anyhow::Result<()> { 274 | let updated_path = self.path_provider().combine(vec![path])?; 275 | 276 | if recursive { 277 | stdfs::remove_dir_all(updated_path)?; 278 | } else { 279 | stdfs::remove_dir(updated_path)?; 280 | } 281 | 282 | Ok(()) 283 | } 284 | } 285 | 286 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] 287 | pub struct SystemPathProvider {} 288 | 289 | impl SystemPathProvider { 290 | pub fn new() -> SystemPathProvider { 291 | SystemPathProvider {} 292 | } 293 | } 294 | 295 | impl Default for SystemPathProvider { 296 | fn default() -> Self { 297 | Self::new() 298 | } 299 | } 300 | 301 | impl PathProvider for SystemPathProvider { 302 | fn combine(&self, paths: Vec<&str>) -> anyhow::Result { 303 | let mut buf = path::PathBuf::new(); 304 | 305 | for path in paths { 306 | buf.push(path) 307 | } 308 | 309 | match buf.to_str() { 310 | Some(v) => Ok(normalize_path(v.to_string())), 311 | None => bail!("empty or invalid paths"), 312 | } 313 | } 314 | 315 | fn get_object_name(&self, path: &str) -> anyhow::Result { 316 | let normalized_path = normalize_path(path.to_string()); 317 | let p = path::Path::new(&normalized_path); 318 | 319 | if let Some(v) = p.file_name() { 320 | if let Some(v) = v.to_str() { 321 | return Ok(v.to_string()); 322 | } 323 | } 324 | 325 | bail!("invalid path: {}", path) 326 | } 327 | 328 | fn get_object_parent_path(&self, path: &str) -> anyhow::Result { 329 | let normalized_path = normalize_path(path.to_string()); 330 | let p = path::Path::new(&normalized_path); 331 | 332 | if let Some(v) = p.parent() { 333 | if let Some(v) = v.to_str() { 334 | if v.is_empty() { 335 | bail!("invalid path: {}", path); 336 | } 337 | return Ok(v.to_string()); 338 | } 339 | } 340 | 341 | bail!("invalid path: {}", path) 342 | } 343 | } 344 | 345 | fn normalize_path(mut path: String) -> String { 346 | let mut i: usize = 0; 347 | while let Some(pos) = path.chars().skip(i).collect::().find("/..") { 348 | if let Some(v) = path.chars().nth(pos + 3) { 349 | if v != '/' { 350 | i = pos + 1; 351 | continue; 352 | } 353 | } 354 | 355 | let tmp_path: String = path.chars().take(pos).collect(); 356 | if let Some(parent_pos) = tmp_path.rfind('/') { 357 | let a: String = tmp_path.chars().take(parent_pos).collect::(); 358 | let b: String = path.chars().skip(pos + 3).collect::(); 359 | path = a; 360 | path.push_str(&b); 361 | } else { 362 | i = pos + 1; 363 | } 364 | } 365 | 366 | i = 0; 367 | while let Some(pos) = path.chars().skip(i).collect::().find("/.") { 368 | if let Some(v) = path.chars().nth(pos + 2) { 369 | if v == '/' { 370 | path = path.replace("/.", ""); 371 | } 372 | } else { 373 | path = path.replace("/.", ""); 374 | } 375 | i = pos + 1; 376 | } 377 | 378 | if path.is_empty() { 379 | path += "./" 380 | }; 381 | 382 | path 383 | } 384 | 385 | #[cfg(test)] 386 | #[path = "./lib_test.rs"] 387 | mod lib_test; -------------------------------------------------------------------------------- /src/Rust/src/disk/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod lib; -------------------------------------------------------------------------------- /src/Rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod providers; 2 | pub mod models; 3 | pub mod disk; 4 | 5 | use anyhow::Result; 6 | 7 | use crate::models::{DirectoryDetail, FileDetail}; 8 | use crate::providers::{FileManager, DirectoryManager}; 9 | 10 | // Async functions 11 | pub async fn create_dir_async<'a>(path: &str, dir_manager: &'a dyn DirectoryManager) -> Result> { 12 | dir_manager.create_dir_async(path).await 13 | } 14 | 15 | pub async fn get_dir_async<'a>(path: &str, dir_manager: &'a dyn DirectoryManager) -> Result> { 16 | dir_manager.get_dir_async(path).await 17 | } 18 | 19 | pub async fn is_dir_exists_async(path: &str, dir_manager: &dyn DirectoryManager) -> Result { 20 | dir_manager.is_dir_exists_async(path).await 21 | } 22 | 23 | pub async fn delete_dir_async(path: &str, recursive: bool, dir_manager: &dyn DirectoryManager) -> Result<()> { 24 | dir_manager.delete_dir_async(path, recursive).await 25 | } 26 | 27 | pub async fn get_file_async<'a>(path: &str, file_manager: &'a dyn FileManager) -> Result> { 28 | file_manager.get_file_async(path).await 29 | } 30 | 31 | pub async fn create_file_async<'a>(path: &str, file_manager: &'a dyn FileManager) -> Result> { 32 | file_manager.create_file_async(path).await 33 | } 34 | 35 | pub async fn is_file_exists_async(path: &str, file_manager: &dyn FileManager) -> Result { 36 | file_manager.is_file_exists_async(path).await 37 | } 38 | 39 | pub async fn delete_file_async(path: &str, file_manager: &dyn FileManager) -> Result<()> { 40 | file_manager.delete_file_async(path).await 41 | } 42 | 43 | // Sync functions 44 | pub fn create_dir<'a>(path: &str, dir_manager: &'a dyn DirectoryManager) -> Result> { 45 | dir_manager.create_dir(path) 46 | } 47 | 48 | pub fn get_dir<'a>(path: &str, dir_manager: &'a dyn DirectoryManager) -> Result> { 49 | dir_manager.get_dir(path) 50 | } 51 | 52 | pub fn is_dir_exists(path: &str, dir_manager: &dyn DirectoryManager) -> Result { 53 | dir_manager.is_dir_exists(path) 54 | } 55 | 56 | pub fn delete_dir(path: &str, recursive: bool, dir_manager: &dyn DirectoryManager) -> Result<()> { 57 | dir_manager.delete_dir(path, recursive) 58 | } 59 | 60 | pub fn get_file<'a>(path: &str, file_manager: &'a dyn FileManager) -> Result> { 61 | file_manager.get_file(path) 62 | } 63 | 64 | pub fn create_file<'a>(path: &str, file_manager: &'a dyn FileManager) -> Result> { 65 | file_manager.create_file(path) 66 | } 67 | 68 | pub fn is_file_exists(path: &str, file_manager: &dyn FileManager) -> Result { 69 | file_manager.is_file_exists(path) 70 | } 71 | 72 | pub fn delete_file(path: &str, file_manager: &dyn FileManager) -> Result<()> { 73 | file_manager.delete_file(path) 74 | } 75 | -------------------------------------------------------------------------------- /src/Rust/src/models.rs: -------------------------------------------------------------------------------- 1 | use anyhow::Result; 2 | 3 | use crate::{DirectoryManager, FileManager}; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct FileDetail<'a> { 7 | pub file_manager: &'a dyn FileManager, 8 | pub name: String, 9 | pub path: String, 10 | pub len: u64, 11 | } 12 | 13 | impl FileDetail<'_> { 14 | pub fn new(file_manager: &dyn FileManager) -> FileDetail { 15 | FileDetail { 16 | file_manager, 17 | name: String::new(), 18 | path: String::new(), 19 | len: 0, 20 | } 21 | } 22 | 23 | pub fn full_path(&self) -> Result { 24 | self.file_manager.path_provider().combine( 25 | vec![&self.name, &self.path] 26 | ) 27 | } 28 | } 29 | 30 | #[derive(Clone, Debug)] 31 | pub struct DirectoryDetail<'a> { 32 | pub dir_manager: &'a dyn DirectoryManager, 33 | pub name: String, 34 | pub path: String, 35 | } 36 | 37 | impl DirectoryDetail<'_> { 38 | pub fn new(dir_manager: &dyn DirectoryManager) -> DirectoryDetail { 39 | DirectoryDetail { 40 | dir_manager, 41 | name: String::new(), 42 | path: String::new(), 43 | } 44 | } 45 | 46 | pub fn full_path(&self) -> Result { 47 | self.dir_manager.path_provider().combine( 48 | vec![&self.name, &self.path] 49 | ) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Rust/src/providers.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Debug; 2 | use anyhow::Result; 3 | use async_trait::async_trait; 4 | 5 | use crate::models::{DirectoryDetail, FileDetail}; 6 | 7 | pub trait PathProvider: Send + Sync + Debug + helper::AsAny { 8 | fn combine(&self, paths: Vec<&str>) -> Result; 9 | fn get_object_name(&self, path: &str) -> Result; 10 | fn get_object_parent_path(&self, path: &str) -> Result; 11 | } 12 | 13 | #[async_trait] 14 | pub trait DirectoryManager: Send + Sync + Debug + helper::AsAny { 15 | fn path_provider(&self) -> &dyn PathProvider; 16 | // Sync methods 17 | async fn create_dir_async(&self, path: &str) -> Result; 18 | async fn get_dir_async(&self, path: &str) -> Result; 19 | async fn is_dir_exists_async(&self, path: &str) -> Result; 20 | async fn delete_dir_async(&self, path: &str, recursive: bool) -> Result<()>; 21 | // Async methods 22 | fn create_dir(&self, path: &str) -> Result; 23 | fn get_dir(&self, path: &str) -> Result; 24 | fn is_dir_exists(&self, path: &str) -> Result; 25 | fn delete_dir(&self, path: &str, recursive: bool) -> Result<()>; 26 | } 27 | 28 | #[async_trait] 29 | pub trait FileManager: Send + Sync + Debug + helper::AsAny { 30 | fn path_provider(&self) -> &dyn PathProvider; 31 | fn dir_manager(&self) -> &dyn DirectoryManager; 32 | // Async methods 33 | async fn get_file_async(&self, path: &str) -> Result; 34 | async fn create_file_async(&self, path: &str) -> Result; 35 | async fn is_file_exists_async(&self, path: &str) -> Result; 36 | async fn delete_file_async(&self, path: &str) -> Result<()>; 37 | // Sync methods 38 | fn get_file(&self, path: &str) -> Result; 39 | fn create_file(&self, path: &str) -> Result; 40 | fn is_file_exists(&self, path: &str) -> Result; 41 | fn delete_file(&self, path: &str) -> Result<()>; 42 | } 43 | 44 | 45 | mod helper { 46 | use core::any::Any; 47 | 48 | pub trait AsAny: Any { 49 | fn as_any(&self) -> &dyn Any; 50 | fn as_any_mut(&mut self) -> &mut dyn Any; 51 | } 52 | 53 | impl AsAny for T { 54 | fn as_any(&self) -> &dyn Any { 55 | self 56 | } 57 | 58 | fn as_any_mut(&mut self) -> &mut dyn Any { 59 | self 60 | } 61 | } 62 | } --------------------------------------------------------------------------------