phattanuki
phattanuki
CC#
Created by phattanuki on 1/29/2023 in #help
✅ Design pattern for a method feels incorrect
I have made a small CLI application that does a few things related to my job. The CLI downloads the latest software packages from a NuGet feed and organizes them into the applications target directory in a neat way. The recent command that I've implemented was a clean-up one, where it would delete the different test versions of our tools, files an folders alike. After spending some time a design bubbled-up in the main private method of the command. Did I make a mistake here? Is this a design pattern that I should follow or should I refactor the code to something else? It feels like that this is "not clean", as one method is basically a pipeline of different methods, with exit conditions. I welcome any advice on the topic.
private static async Task RunCleanUp(EriManager configuration, string selectedTool) {
List<Tool> loadedTools = LoadValidTools(configuration, selectedTool); //private helper method to load the valid tools from our local configuration, selectedTool can be "all" to load all valid tools
if (loadedTools.Count == 0) return;

LogManager.EnviromentMessage("Setting up environment for [bold]collecting folder structure[/]\n");

List<(string Tool, DirectoryInfo Directories)>? directories = DirectoryManager.GenerateFolderListForRemoval(configuration, loadedTools); //private static class to generate folder that are matching to a tool type
if (directories is null || directories.Count == 0) return;

Tree ansiTree = GenerateTreeForDirectories(loadedTools, directories);
//In the Table each column is one Tool, where each row is a folder to be deleted.

if (ansiTree is null) return;

AnsiConsole.WriteLine();
AnsiConsole.Write(ansiTree);

if (LogManager.ConfirmationMessage("Delete the requested folder(s)?")) await RemovalProcess(directories);
}
private static async Task RunCleanUp(EriManager configuration, string selectedTool) {
List<Tool> loadedTools = LoadValidTools(configuration, selectedTool); //private helper method to load the valid tools from our local configuration, selectedTool can be "all" to load all valid tools
if (loadedTools.Count == 0) return;

LogManager.EnviromentMessage("Setting up environment for [bold]collecting folder structure[/]\n");

List<(string Tool, DirectoryInfo Directories)>? directories = DirectoryManager.GenerateFolderListForRemoval(configuration, loadedTools); //private static class to generate folder that are matching to a tool type
if (directories is null || directories.Count == 0) return;

Tree ansiTree = GenerateTreeForDirectories(loadedTools, directories);
//In the Table each column is one Tool, where each row is a folder to be deleted.

if (ansiTree is null) return;

AnsiConsole.WriteLine();
AnsiConsole.Write(ansiTree);

if (LogManager.ConfirmationMessage("Delete the requested folder(s)?")) await RemovalProcess(directories);
}
11 replies
CC#
Created by phattanuki on 1/10/2023 in #help
✅ Inherited a class but the compiler does not accept it?
I've created two classes, Head and Knot. Head inherits Knot with another caveat of having an additional method on it, yet the compiler gives the error of "There is no argument given that corresponds to the required parameter '_coordinate' of 'Knot.Knot(Point)'". Am I misunderstanding something here?
//This is only to make the code more readable
public class Knot{
public Point Coordinate{get;set;}

public Knot(Point _coordinate){
Coordinate = _coordinate;
}

//This method checks if the current knot is touching the previous knot in the rope in any way in a 3X3 grid
//If true, the current knot is not supposed to move
public bool Touch(Knot head){
for(int scanX = -1; scanX < 2; scanX++){
for(int scanY = -1; scanY < 2; scanY++){
Point check = new Point(this.Coordinate.X + scanX, this.Coordinate.Y + scanY);
if(check == head.Coordinate) return true;
}
}
return false;
}
}

public class Head : Knot{

void moveHead(string direction){
//move head one step at a time
if(direction is "U") Coordinate.X--;
if(direction is "D") Coordinate.X++;
if(direction is "L") Coordinate.Y--;
if(direction is "R") Coordinate.Y++;
}
}
//This is only to make the code more readable
public class Knot{
public Point Coordinate{get;set;}

public Knot(Point _coordinate){
Coordinate = _coordinate;
}

//This method checks if the current knot is touching the previous knot in the rope in any way in a 3X3 grid
//If true, the current knot is not supposed to move
public bool Touch(Knot head){
for(int scanX = -1; scanX < 2; scanX++){
for(int scanY = -1; scanY < 2; scanY++){
Point check = new Point(this.Coordinate.X + scanX, this.Coordinate.Y + scanY);
if(check == head.Coordinate) return true;
}
}
return false;
}
}

public class Head : Knot{

void moveHead(string direction){
//move head one step at a time
if(direction is "U") Coordinate.X--;
if(direction is "D") Coordinate.X++;
if(direction is "L") Coordinate.Y--;
if(direction is "R") Coordinate.Y++;
}
}
20 replies
CC#
Created by phattanuki on 9/25/2022 in #help
Should you assert input arguments ins
19 replies
CC#
Created by phattanuki on 8/13/2022 in #help
Why is the generic delegate does not accept my method?
20 replies
CC#
Created by phattanuki on 8/13/2022 in #help
Refactoring provider crashes
1 replies