-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/Support_conditions_related_to_IO_(#561)' into d…
…evelop
- Loading branch information
Showing
20 changed files
with
494 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.IO; | ||
using NBi.Core.Decoration.IO; | ||
using System.Diagnostics; | ||
using NBi.Extensibility; | ||
|
||
namespace NBi.Core.Decoration.IO.Conditions | ||
{ | ||
class FileExistsCondition : IDecorationCondition | ||
{ | ||
private FileExistsConditionArgs Args { get; } | ||
|
||
public string Message { get; private set; } | ||
|
||
public FileExistsCondition(FileExistsConditionArgs args) => Args = args; | ||
|
||
public bool Validate() | ||
{ | ||
var fullPath = PathExtensions.CombineOrRoot(Args.BasePath, Args.FolderName.Execute(), Args.FileName.Execute()); | ||
|
||
var conditions = new List<Func<string, (bool, string)>>() { ExistsCondition }; | ||
if (Args.NotEmpty.Execute()) | ||
conditions.Add(IsNotEmptyCondition); | ||
|
||
var result = true; | ||
var enumerator = conditions.GetEnumerator(); | ||
while (result && enumerator.MoveNext()) | ||
(result, Message) = enumerator.Current.Invoke(fullPath); | ||
return result; | ||
} | ||
|
||
protected (bool, string) ExistsCondition(string fullPath) | ||
=> (File.Exists(fullPath), $"The file '{fullPath}' doesn't exists."); | ||
|
||
protected (bool, string) IsNotEmptyCondition(string fullPath) | ||
=> (new FileInfo(fullPath).Length > 0, $"The file '{fullPath}' has a size of 0 byte."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using NBi.Core.Scalar.Resolver; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NBi.Core.Decoration.IO | ||
{ | ||
public class FileExistsConditionArgs : IIoConditionArgs | ||
{ | ||
public string BasePath { get; } | ||
public IScalarResolver<string> FolderName { get; } | ||
public IScalarResolver<string> FileName { get; } | ||
public IScalarResolver<bool> NotEmpty { get; } | ||
|
||
public FileExistsConditionArgs(string basePath, IScalarResolver<string> folderName, IScalarResolver<string> fileName, IScalarResolver<bool> notEmpty) | ||
=> (BasePath, FolderName, FileName, NotEmpty) = (basePath, folderName, fileName, notEmpty); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using NBi.Core.Decoration.IO; | ||
using NBi.Core.Decoration.IO.Conditions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NBi.Core.Decoration.Process | ||
{ | ||
class IoConditionFactory | ||
{ | ||
public IDecorationCondition Instantiate(IIoConditionArgs args) | ||
{ | ||
switch (args) | ||
{ | ||
case FolderExistsConditionArgs folderExistsArgs: return new FolderExistsCondition(folderExistsArgs); | ||
case FileExistsConditionArgs fileExistsArgs: return new FileExistsCondition(fileExistsArgs); | ||
default: throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.