Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Documentation and Code compliance #183

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions File_Engine/Compute/WriteToJsonFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
/***************************************************/

[Description("Write a JSON-serialised file with the input data or objects.")]
[Input("objects", "Objects to write to the file.")]
[Input("filePath", "Path to the file.")]
[Input("replace", "If the file exists, you need to set this to true in order to allow overwriting it.")]
[Input("active", "Boolean used to trigger the function.")]
public static bool WriteToJsonFile(List<object> objects, string filePath, bool replace = false, bool active = false)

Check warning on line 48 in File_Engine/Compute/WriteToJsonFile.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

File_Engine/Compute/WriteToJsonFile.cs#L48

Method must contain an Output or MultiOutput attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/HasOutputAttribute
{
if (!active || objects == null)
return false;
Expand Down
2 changes: 1 addition & 1 deletion File_Engine/Modify/ChangeDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static partial class Modify
/***************************************************/

[Description("Move a file or directory to a new parent directory.")]
[Input("file", "The file (or directory) to move.")]
[Input("fileOrDir", "The file or directory to move.")]
[Input("to", "The new parent Directory.")]
[Output("The moved file object.")]
public static IFSContainer ChangeDirectory(this oM.Adapters.File.IFSContainer fileOrDir, oM.Adapters.File.FSDirectory to)
Expand Down
27 changes: 13 additions & 14 deletions File_Engine/Modify/ProcessFileDirRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,36 @@
/***************************************************/

[Description("Get the contents of the file as a string, reading from its location.")]
[Input("file", "The file to get the contents of.")]
[Input("encoding", "The encoding to use to decode the data. If null (default) discovery will be attempted; defaults to UTF-8 if it can't be discovered.")]
[Output("The contents of the file.")]
public static bool ProcessFileDirRequest(this FileDirRequest fdr, out WildcardPattern wildcardPattern)
[Input("fileDirectoryRequest", "The file directory request to process.")]
[Output("success", "True if the wildcard pattern is valid.")]
public static bool ProcessFileDirRequest(this FileDirRequest fileDirectoryRequest, out WildcardPattern wildcardPattern)

Check warning on line 45 in File_Engine/Modify/ProcessFileDirRequest.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

File_Engine/Modify/ProcessFileDirRequest.cs#L45

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent
{
wildcardPattern = null;

if (WildcardPattern.ContainsWildcardCharacters(fdr.Location))
if (WildcardPattern.ContainsWildcardCharacters(fileDirectoryRequest.Location))
{
if (WildcardPattern.ContainsWildcardCharacters(fdr.Location))
if (WildcardPattern.ContainsWildcardCharacters(fileDirectoryRequest.Location))
{
string allButLastSegment = fdr.Location.Remove(fdr.Location.Count() - Path.GetFileName(fdr.Location).Count());
string allButLastSegment = fileDirectoryRequest.Location.Remove(fileDirectoryRequest.Location.Count() - Path.GetFileName(fileDirectoryRequest.Location).Count());
if (WildcardPattern.ContainsWildcardCharacters(allButLastSegment))
{
BH.Engine.Base.Compute.RecordError("Wildcards are only allowed in the last segment of the path.");
return false;
}
else
wildcardPattern = new WildcardPattern(Path.GetFileName(fdr.Location));
wildcardPattern = new WildcardPattern(Path.GetFileName(fileDirectoryRequest.Location));
}

if (fdr.IncludeDirectories)
if (fileDirectoryRequest.IncludeDirectories)
{
BH.Engine.Base.Compute.RecordWarning($"The usage of Wildcards is limited to file retrievals: " +
$"\ncannot have `{nameof(FileDirRequest)}.{nameof(fdr.IncludeDirectories)}` set to true while a Wildcard is specified in the path." +
$"\nDefaulting `{nameof(fdr.IncludeDirectories)}` to false and continuing.");
fdr.IncludeDirectories = false;
$"\ncannot have `{nameof(FileDirRequest)}.{nameof(fileDirectoryRequest.IncludeDirectories)}` set to true while a Wildcard is specified in the path." +
$"\nDefaulting `{nameof(fileDirectoryRequest.IncludeDirectories)}` to false and continuing.");
fileDirectoryRequest.IncludeDirectories = false;
}

if (fdr.IncludeFileContents)
BH.Engine.Base.Compute.RecordNote($"Note that `{nameof(fdr.IncludeFileContents)}` works only for BHoM-serialized JSON files.");
if (fileDirectoryRequest.IncludeFileContents)
BH.Engine.Base.Compute.RecordNote($"Note that `{nameof(fileDirectoryRequest.IncludeFileContents)}` works only for BHoM-serialized JSON files.");
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions File_Engine/Modify/RelativiseUserPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/***************************************************/

[Description("If an user path is specified – e.g. containing `C:/Users/SomeUser` – modifies SomeUser to match the current user.")]
public static string RelativiseUserPath(string path)

Check warning on line 44 in File_Engine/Modify/RelativiseUserPath.cs

View check run for this annotation

BHoMBot-CI / code-compliance

File_Engine/Modify/RelativiseUserPath.cs#L44

Modify methods should return void, or their return type should be different to the input type of their first parameter - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/ModifyReturnsDifferentType

Check warning on line 44 in File_Engine/Modify/RelativiseUserPath.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

File_Engine/Modify/RelativiseUserPath.cs#L44

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent Method must contain an Output or MultiOutput attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/HasOutputAttribute
{
string relativisedPath = path;
char separator = '\\';
Expand All @@ -63,6 +63,8 @@
return relativisedPath;
}

/***************************************************/

// Get the user folder, in the form of C:\Users\UserName.
// Written to work also for Windows versions prior to 10.
private static string GetUserPath()
Expand Down
24 changes: 21 additions & 3 deletions File_Engine/Modify/Rename.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,46 @@ public static partial class Modify
/***************************************************/

[Description("Rename a file or directory.")]
[Input("file", "The file (or directory) to rename.")]
[Input("fileOrDir", "The file or directory to rename.")]
[Input("name", "The new name.")]
[Output("The moved file object.")]
[PreviousVersion("7.1", "BH.Engine.Adapters.File.Modify.Rename(BH.oM.Adapters.File.FSFile, System.String)")]
[PreviousVersion("7.1", "BH.Engine.Adapters.File.Modify.Rename(BH.oM.Adapters.File.FSDirectory, System.String)")]
public static IFSContainer IRename(this oM.Adapters.File.IFSContainer fileOrDir, string name)
{
fileOrDir = BH.Engine.Base.Query.ShallowClone(fileOrDir);
return Rename(fileOrDir as dynamic, name);
}

/***************************************************/
/**** Private interface methods ****/
/***************************************************/

public static IFSContainer Rename(this FSFile file, string name)
private static IFSContainer Rename(this FSFile file, string name)
{
file.Name = name;
return file;
}

public static IFSContainer Rename(this FSDirectory directory, string name)
/***************************************************/

private static IFSContainer Rename(this FSDirectory directory, string name)
FraserGreenroyd marked this conversation as resolved.
Show resolved Hide resolved
{
directory.Name = name;
return directory;
}

/***************************************************/
/**** Private interface methods - fallback ****/
/***************************************************/

private static IFSContainer Rename(this IFSContainer container, string name)
{
BH.Engine.Base.Compute.RecordError($"Cannot rename FSContainers of type: {container.GetType().FullName}, please provide either an FSFile or FSDirectory object.");
return null;
}

/***************************************************/
}
}

Expand Down
6 changes: 3 additions & 3 deletions File_Engine/Query/Contents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static partial class Query
[Description("Get the contents of the file as a string, reading from its location.")]
[Input("file", "The file to get the contents of.")]
[Input("encoding", "The encoding to use to decode the data. If null (default) discovery will be attempted; defaults to UTF-8 if it can't be discovered.")]
[Output("The contents of the file.")]
[Output("contents", "The contents of the file.")]
public static string ContentsAsString(this FSFile file, Encodings encoding = Encodings.FromFile)
{
byte[] contents = file.ContentsAsByteArray();
Expand All @@ -63,8 +63,8 @@ public static string ContentsAsString(this FSFile file, Encodings encoding = Enc


[Description("Get the contents of the file as a byteArray, reading from its location.")]
[Input("file", "The file to get the contents of.")]
[Output("The contents of the file.")]
[Input("bhomFile", "The BHoM file to get the contents of.")]
[Output("contents", "The contents of the file.")]
public static byte[] ContentsAsByteArray(this FSFile bhomFile)
{
byte[] contents = null;
Expand Down
15 changes: 14 additions & 1 deletion File_Engine/Query/FullPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@

[Description("Get the full path. " +
"If the input is a string path containing wildcard symbols, return only the upper portion of the path that doesn't have any.")]
public static string IFullPath(this object obj)

Check warning on line 44 in File_Engine/Query/FullPath.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

File_Engine/Query/FullPath.cs#L44

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent Method must contain an Output or MultiOutput attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/HasOutputAttribute
{
return obj != null ? FullPath(obj as dynamic) ?? "" : "";
}

/***************************************************/
/**** Private interface methods ****/
/***************************************************/

private static string FullPath(this IFSInfo baseInfo)
{
if (baseInfo.ParentDirectory == null)
Expand All @@ -57,11 +61,15 @@
return baseInfo.ToString();
}

/***************************************************/

private static string FullPath(this IResourceRequest fdr)
{
return FullPath(fdr.Location);
}

/***************************************************/

private static string FullPath(this ILocatableResource fdr)
{
if (fdr?.Location == null)
Expand All @@ -78,6 +86,8 @@
return location;
}

/***************************************************/

private static string FullPath(this string path)
{
if (string.IsNullOrWhiteSpace(path))
Expand Down Expand Up @@ -128,7 +138,10 @@
return null;
}

//Fallback
/***************************************************/
/**** Private interface methods - Fallback ****/
/***************************************************/

private static string FullPath(object fileOrDir)
{
BH.Engine.Base.Compute.RecordError($"Can not compute the FullPath for an object of type `{fileOrDir.GetType().Name}`.");
Expand Down
4 changes: 3 additions & 1 deletion File_Engine/Query/NestingDepth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public static partial class Query
/***************************************************/

[Description("Get the nesting depth of the input File or Directory, which is the total number of parent folders.")]
public static int NestingDepth(oM.Adapters.File.IFSInfo fileOrDir)
[Input("fileOrDir", "The file or directory to get the depth of.")]
[Output("count", "The number of parent folders that the file or directory has.")]
public static int NestingDepth(this oM.Adapters.File.IFSInfo fileOrDir)
{
int count = 0;
while (fileOrDir.ParentDirectory != null)
Expand Down
9 changes: 7 additions & 2 deletions File_Engine/Query/PathCombine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ public static partial class Query
/***************************************************/

[Description("Combines two paths.")]
public static string PathCombine(string path1, string path2)
[Input("path1", "The left half of the path.")]
[Input("path2", "The right half of the path.")]
[Output("path", "The combined path.")]
public static string PathCombine(this string path1, string path2)
{
return Path.Combine(path1, path2);
}

/***************************************************/

[Description("Combines multiple string paths.")]
public static string PathCombine(List<string> paths)
[Input("paths", "The list of paths to combine, in order.")]
[Output("path", "The combined path.")]
public static string PathCombine(this List<string> paths)
{
return Path.Combine(paths.ToArray());
}
Expand Down