Ejemplo n.º 1
0
        /// <summary>
        /// This method parses the target application project and sets the
        /// appropriate metadata as part of the <see cref="ProjectDefinition"/>
        /// </summary>
        /// <param name="projectPath">The project path can be an absolute or a relative path to the
        /// target application project directory or the application project file.</param>
        /// <returns><see cref="ProjectDefinition"/></returns>
        public async Task <ProjectDefinition> Parse(string projectPath)
        {
            if (_directoryManager.Exists(projectPath))
            {
                projectPath = _directoryManager.GetDirectoryInfo(projectPath).FullName;
                var files = _directoryManager.GetFiles(projectPath, "*.csproj");
                if (files.Length == 1)
                {
                    projectPath = Path.Combine(projectPath, files[0]);
                }
                else if (files.Length == 0)
                {
                    files = _directoryManager.GetFiles(projectPath, "*.fsproj");
                    if (files.Length == 1)
                    {
                        projectPath = Path.Combine(projectPath, files[0]);
                    }
                }
            }

            if (!_fileManager.Exists(projectPath))
            {
                throw new ProjectFileNotFoundException(projectPath);
            }

            var xmlProjectFile = new XmlDocument();

            xmlProjectFile.LoadXml(await _fileManager.ReadAllTextAsync(projectPath));

            var projectDefinition = new ProjectDefinition(
                xmlProjectFile,
                projectPath,
                await GetProjectSolutionFile(projectPath),
                xmlProjectFile.DocumentElement?.Attributes["Sdk"]?.Value ??
                throw new InvalidProjectDefinitionException(
                    "The project file that is being referenced does not contain and 'Sdk' attribute.")
                );

            var targetFramework = xmlProjectFile.GetElementsByTagName("TargetFramework");

            if (targetFramework.Count > 0)
            {
                projectDefinition.TargetFramework = targetFramework[0]?.InnerText;
            }

            var assemblyName = xmlProjectFile.GetElementsByTagName("AssemblyName");

            if (assemblyName.Count > 0)
            {
                projectDefinition.AssemblyName = (string.IsNullOrWhiteSpace(assemblyName[0]?.InnerText) ? Path.GetFileNameWithoutExtension(projectPath) : assemblyName[0]?.InnerText);
            }
            else
            {
                projectDefinition.AssemblyName = Path.GetFileNameWithoutExtension(projectPath);
            }

            return(projectDefinition);
        }
        /// <summary>
        /// This method takes a root directory path and recursively searches all its sub-directories for custom recipe paths.
        /// However, it ignores any recipe file located inside a "bin" folder.
        /// </summary>
        /// <param name="rootDirectoryPath">The absolute path of the root directory.</param>
        /// <returns>A list of recipe definition paths.</returns>
        private List <string> GetRecipePathsFromRootDirectory(string?rootDirectoryPath)
        {
            var recipePaths = new List <string>();

            if (!string.IsNullOrEmpty(rootDirectoryPath) && _directoryManager.Exists(rootDirectoryPath))
            {
                foreach (var recipeFilePath in _directoryManager.GetFiles(rootDirectoryPath, "*.recipe", SearchOption.AllDirectories))
                {
                    if (recipeFilePath.Contains(_ignorePathSubstring))
                    {
                        continue;
                    }
                    recipePaths.Add(_directoryManager.GetDirectoryInfo(recipeFilePath).Parent.FullName);
                }
            }
            return(recipePaths);
        }
Ejemplo n.º 3
0
        public string DetermineProjectRootDirectory(string sourceFilePath)
        {
            if (!_fileManager.Exists(sourceFilePath))
            {
                return(string.Empty);
            }

            var directoryPath = _directoryManager.GetDirectoryName(sourceFilePath);

            while (!string.IsNullOrEmpty(directoryPath))
            {
                if (_directoryManager.GetFiles(directoryPath, "*.csproj").Length == 1)
                {
                    return(directoryPath);
                }
                directoryPath = _directoryManager.GetDirectoryName(directoryPath);
            }

            return(string.Empty);
        }
Ejemplo n.º 4
0
        // get the FULL paths of all directories and files under a specific directory

        public static void GetDirsAndFiles(this IDirectoryManager manager,
                                           string rootFullPath, out IEnumerable <string> dirs, out IEnumerable <string> files)
        {
            try
            {
                dirs  = manager.GetDirectories(rootFullPath);
                files = manager.GetFiles(rootFullPath);
            }
            catch (Exception ex)
            {
                dirs = null; files = null;
                throw new ApplicationException($"Cannot get dorectory info in \"{rootFullPath}\"", ex);
            }
        }
Ejemplo n.º 5
0
        public IActionResult ReadDecesion()
        {
            try
            {
                var decisions = new List<DecesionViewModel>(
                    _repoWrapper.Decesion
                    .Include(x => x.DecesionTarget, x => x.Organization)
                    .Take(200)
                    .Select(decesion => new DecesionViewModel
                    {
                        Decesion = decesion
                    })
                    .ToList());
                foreach (var decesion in decisions)
                {
                    string path = _appEnvironment.WebRootPath + DecesionsDocumentFolder + decesion.Decesion.ID;
                    if (!decesion.Decesion.HaveFile || !_directoryManager.Exists(path))
                    {
                        continue;
                    }
                    var files = _directoryManager.GetFiles(path);

                    if (files.Length == 0)
                    {
                        throw new ArgumentException($"File count in '{path}' is 0");
                    }

                    decesion.Filename = Path.GetFileName(files.First());
                }
                return View(Tuple.Create(CreateDecesion(), decisions));
            }
            catch
            {
                return RedirectToAction("HandleError", "Error");
            }
        }
Ejemplo n.º 6
0
        public async Task <ProjectDefinition> Parse(string projectPath)
        {
            try
            {
                return(await _projectDefinitionParser.Parse(projectPath));
            }
            catch (ProjectFileNotFoundException ex)
            {
                var files        = _directoryManager.GetFiles(projectPath, "*.sln");
                var errorMessage = string.Empty;

                if (files.Any())
                {
                    errorMessage = "This directory contains a solution file, but the tool requires a project file. " +
                                   "Please run the tool from the directory that contains a .csproj/.fsproj or provide a path to the .csproj/.fsproj via --project-path flag.";
                }
                else
                {
                    errorMessage = $"A project was not found at the path {projectPath}";
                }

                throw new FailedToFindDeployableTargetException(errorMessage, ex);
            }
        }