Exemplo n.º 1
0
        public static void CreateApplicationServiceExtension(string solutionDirectory, IFileSystem fileSystem)
        {
            try
            {
                var classPath = ClassPathHelper.ApplicationProjectRootClassPath(solutionDirectory, $"ServiceExtensions.cs");

                if (!fileSystem.Directory.Exists(classPath.ClassDirectory))
                {
                    fileSystem.Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (fileSystem.File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (var fs = fileSystem.File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetServiceExtensionText(classPath.ClassNamespace);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{fileSystem.Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }