/// <summary> /// Runs the command with the given name using the given arguments. /// </summary> /// <param name="commandName">Name of the command.</param> /// <param name="arguments">Arguments of the command.</param> /// <param name="reportErrorsToConsole">True to print exceptions in the console. False to throw the exception.</param> public async Task RunCommand(string commandName, IEnumerable <string> arguments, bool reportErrorsToConsole = false, IFileSystem FileSystem = null) { var command = AllCommands.Where(c => String.Compare(c.Key, commandName, StringComparison.CurrentCultureIgnoreCase) == 0).Select(c => c.Value).SingleOrDefault(); if (FileSystem != null && CurrentPluginManager.CanCreateInstance(command.GetType())) { command = CurrentPluginManager.CreateNewInstance(command, FileSystem) as ConsoleCommand; } await RunCommand(command, arguments, reportErrorsToConsole); }
/// <summary> /// Creates a file inside the given directory /// </summary> /// <param name="parentPath">Project directory inside which the file will be created</param> /// <param name="name">Name of the new file</param> /// <param name="fileType">Type of the new file</param> public virtual async Task CreateFile(string parentPath, string name, Type fileType) { if (!ReflectionHelpers.IsOfType(fileType, typeof(ICreatableFile).GetTypeInfo())) { throw new ArgumentException(string.Format(Properties.Resources.Reflection_ErrorInvalidType, nameof(ICreatableFile)), nameof(fileType)); } if (!DirectoryExists(parentPath)) { CreateDirectory(parentPath); } var fixedPath = FixPath(parentPath); ICreatableFile fileObj = CurrentPluginManager.CreateInstance(fileType.GetTypeInfo()) as ICreatableFile; fileObj.CreateFile(name); fileObj.Filename = Path.Combine(Path.GetDirectoryName(this.Filename), parentPath.Replace("/", "\\").TrimStart("\\".ToCharArray()), name); await fileObj.Save(CurrentPluginManager.CurrentFileSystem); AddItem(fixedPath + "/" + name, new ProjectFileWrapper(this.Filename, Path.Combine(parentPath.Replace("/", "\\").TrimStart("\\".ToCharArray()), name), fileObj)); }