Exemple #1
0
        // Read file and return its path
        public string FilePath(HttpPostedFileBase file)
        {
            var path = "";

            try
            {
                // Get file name
                var fileName = _pathReader.GetFileNameWithoutExtension(file.FileName);
                if (String.IsNullOrEmpty(fileName))
                {
                    return("Error parsing file name.");
                }

                // Create new file name
                fileName = fileName + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv";

                // Create path for new file name
                var mapPath = _pathReader.MapPath("~/Csvs");
                path = _pathReader.Combine(mapPath, fileName);
                if (String.IsNullOrEmpty(path))
                {
                    return("Error parsing file path.");
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(path);
        }
        public Solution Parse(string path)
        {
            var projects = new List <Project>();

            var lines = _fileReader.ReadAllLines(path);


            foreach (var line in lines)
            {
                var baseDirectory = _pathReader.GetDirectoryName(path);

                var match = Regex.Match(line, PROJECT_INCLUDE_REGEX);
                if (match.Success)
                {
                    var result = match.Value.Split('"')[5];

                    while (result.Contains(FOLDER_UP_ONE_LEVEL))
                    {
                        var index = result.IndexOf(FOLDER_UP_ONE_LEVEL, StringComparison.Ordinal);
                        result        = result.Remove(index, FOLDER_UP_ONE_LEVEL.Length);
                        baseDirectory = _directoryReader.GetParent(baseDirectory);
                    }

                    Debug.Assert(baseDirectory != null, nameof(baseDirectory) + " != null");

                    result = _pathReader.Combine(baseDirectory, result);

                    projects.Add(new Project(result, null));
                }
            }

            var solution = new Solution(path)
            {
                Projects = projects
            };

            return(solution);
        }