public static void RemoveRoles(string solutionDirectory) { var classPath = ClassPathHelper.DomainEnumClassPath(solutionDirectory, "Role.cs"); if (!Directory.Exists(classPath.ClassDirectory)) { throw new DirectoryNotFoundException($"The `{classPath.ClassDirectory}` directory could not be found."); } if (!File.Exists(classPath.FullClassPath)) { throw new FileNotFoundException($"The `{classPath.FullClassPath}` file could not be found."); } File.Delete(classPath.FullClassPath); }
public static void CreateRoles(string solutionDirectory, List <string> roles) { try { var classPath = ClassPathHelper.DomainEnumClassPath(solutionDirectory, $"Role.cs"); if (!Directory.Exists(classPath.ClassDirectory)) { Directory.CreateDirectory(classPath.ClassDirectory); } if (File.Exists(classPath.FullClassPath)) { File.Delete(classPath.FullClassPath); } using (FileStream fs = File.Create(classPath.FullClassPath)) { var data = ""; data = GetRoleFileText(classPath.ClassNamespace, roles); fs.Write(Encoding.UTF8.GetBytes(data)); } GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", "")); } catch (FileAlreadyExistsException e) { WriteError(e.Message); throw; } catch (Exception e) { WriteError($"An unhandled exception occured when running the API command.\nThe error details are: \n{e.Message}"); throw; } }