Skip to content

Commit 0f6b75c

Browse files
committed
Translate into english
1 parent c17f3da commit 0f6b75c

File tree

6 files changed

+248
-242
lines changed

6 files changed

+248
-242
lines changed

DateiNode.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

DateiHelper.cs renamed to FileHelper.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77

88
namespace DependencieResolver
99
{
10-
static class DateiHelper
10+
static class FileHelper
1111
{
12-
public static Dictionary<string, IList<string>> DepsAufDatei = new Dictionary<string, IList<string>>();
12+
public static Dictionary<string, IList<string>> DepsToFile = new Dictionary<string, IList<string>>();
1313

14-
public static string LiesGanzeImportZeile(string aktuelleZeile, StreamReader sr)
14+
public static string ReadFullImportLine(string aktuelleZeile, StreamReader sr)
1515
{
16-
var istEinzeiligerImport = DateiHelper.IstImportZeile(aktuelleZeile) && DateiHelper.IstImportZeileEnde(aktuelleZeile) || IstZeileUnspezifischerImport(aktuelleZeile);
16+
var istEinzeiligerImport = FileHelper.IsImportLine(aktuelleZeile) && FileHelper.IstImportZeileEnde(aktuelleZeile) || IstZeileUnspezifischerImport(aktuelleZeile);
1717
if (istEinzeiligerImport)
1818
{
1919
return aktuelleZeile;
2020
}
2121

2222
var zusammengesetzteZeile = new StringBuilder();
23-
while (aktuelleZeile != null && !DateiHelper.IstImportZeileEnde(aktuelleZeile))
23+
while (aktuelleZeile != null && !FileHelper.IstImportZeileEnde(aktuelleZeile))
2424
{
2525
zusammengesetzteZeile.Append(aktuelleZeile);
2626
try
@@ -37,7 +37,7 @@ public static string LiesGanzeImportZeile(string aktuelleZeile, StreamReader sr)
3737
return zusammengesetzteZeile.ToString();
3838
}
3939

40-
public static bool IstImportZeile(string zeile)
40+
public static bool IsImportLine(string zeile)
4141
{
4242
return zeile?.Trim().StartsWith("import ") ?? false;
4343
}
@@ -55,7 +55,7 @@ public static bool IstZeileUnspezifischerImport(string zeile)
5555
return importRegel.IsMatch(zeile);
5656
}
5757

58-
public static string LiesImportZielAus(string zeile)
58+
public static string ReadImportDestination(string zeile)
5959
{
6060
if (IstZeileUnspezifischerImport(zeile))
6161
{
@@ -72,7 +72,7 @@ public static string LiesImportZielAus(string zeile)
7272
return fromPfad;
7373
}
7474

75-
public static string ErsetzeRelativePfade(string zeile, IList<string> orderBisZurDatei)
75+
public static string ReplaceRelativePaths(string zeile, IList<string> orderBisZurDatei)
7676
{
7777
var zeileEnthaeltRelativePfade = zeile.Contains('.') || zeile.Contains("..");
7878
if (!zeileEnthaeltRelativePfade)

FileNode.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
6+
namespace DependencieResolver
7+
{
8+
class FileNode
9+
{
10+
public string PathToFile { get; }
11+
public IList<string> DependencyPaths { get; set; } // => [root/Foo/Bar.ts]
12+
13+
private IList<string> FolderHierarchie
14+
{
15+
get
16+
{
17+
var pathInclFile = PathToFile.Split(Path.DirectorySeparatorChar).ToList();
18+
pathInclFile.RemoveAt(pathInclFile.Count - 1); // Delete current file
19+
return pathInclFile;
20+
}
21+
}
22+
23+
public FileNode(string path)
24+
{
25+
DependencyPaths = new List<string>();
26+
PathToFile = path;
27+
28+
if (!File.Exists(PathToFile))
29+
{
30+
throw new IOException("Path doesn't exist!");
31+
}
32+
}
33+
34+
public void AnalyzeImportPaths()
35+
{
36+
DependencyPaths = new List<string>();
37+
38+
using StreamReader sr = new StreamReader(PathToFile);
39+
var line = sr.ReadLine();
40+
41+
while (line != null)
42+
{
43+
var lineIsEmpty = String.IsNullOrEmpty(line.Trim());
44+
if (lineIsEmpty)
45+
{
46+
line = sr.ReadLine();
47+
continue;
48+
}
49+
50+
if (!FileHelper.IsImportLine(line))
51+
{
52+
break;
53+
}
54+
55+
var importLine = FileHelper.ReadFullImportLine(line, sr);
56+
var importDestination = FileHelper.ReadImportDestination(importLine);
57+
58+
importDestination = FileHelper.ReplaceRelativePaths(importDestination, FolderHierarchie);
59+
60+
DependencyPaths.Add(importDestination);
61+
62+
line = sr.ReadLine();
63+
}
64+
}
65+
66+
public void BuildDepGraph(bool loadRecursive = false)
67+
{
68+
if (!DependencyPaths.Any())
69+
{
70+
AnalyzeImportPaths();
71+
}
72+
73+
FillDepGraph();
74+
75+
if (!loadRecursive)
76+
{
77+
return;
78+
}
79+
80+
foreach (var dependencyPfad in DependencyPaths)
81+
{
82+
var depAsFile = new FileNode(dependencyPfad);
83+
depAsFile.BuildDepGraph(true);
84+
}
85+
}
86+
87+
private void FillDepGraph()
88+
{
89+
foreach (var dependency in DependencyPaths)
90+
{
91+
if (FileHelper.DepsToFile.TryGetValue(dependency, out var externalDep))
92+
{
93+
if (!externalDep.Contains(PathToFile))
94+
{
95+
externalDep.Add(PathToFile);
96+
}
97+
}
98+
else
99+
{
100+
FileHelper.DepsToFile.Add(dependency, new List<string> { PathToFile });
101+
}
102+
}
103+
104+
}
105+
}
106+
}

FolderNode.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
5+
namespace DependencieResolver
6+
{
7+
class FolderNode
8+
{
9+
public string FolderPath { get; set; }
10+
public List<FileNode> Files { get; set; }
11+
public List<FolderNode> SubDictionaries { get; set; }
12+
13+
public IList<string> AllDependencies
14+
{
15+
get
16+
{
17+
var list = new List<string>();
18+
list.AddRange(Files.SelectMany(d => d.DependencyPaths).ToList());
19+
list.AddRange(SubDictionaries.SelectMany(u => u.AllDependencies.ToList()));
20+
return list;
21+
}
22+
}
23+
24+
public IList<FileNode> AllFilesRecursive
25+
{
26+
get
27+
{
28+
var list = new List<FileNode>();
29+
list.AddRange(Files.ToList());
30+
list.AddRange(SubDictionaries.SelectMany(u => u.AllFilesRecursive.ToList()));
31+
return list;
32+
}
33+
}
34+
35+
public FolderNode(string path)
36+
{
37+
FolderPath = path;
38+
Files = new List<FileNode>();
39+
SubDictionaries = new List<FolderNode>();
40+
41+
if (!Directory.Exists(path))
42+
{
43+
throw new IOException("Path to folder doesn't exist.");
44+
}
45+
}
46+
47+
public void AnalyzeFiles(bool readSubDictionaries = true)
48+
{
49+
string[] fileEntries = Directory.GetFiles(FolderPath);
50+
51+
var fileNodes = fileEntries
52+
.Select(filePath =>
53+
{
54+
var node = new FileNode(filePath);
55+
node.BuildDepGraph();
56+
return node;
57+
})
58+
.ToList();
59+
60+
Files.AddRange(fileNodes);
61+
62+
if (!readSubDictionaries)
63+
{
64+
return;
65+
}
66+
67+
IList<string> subdirectoryEntries = Directory.GetDirectories(FolderPath)
68+
.Where(e => !e.Contains('.') && !e.Contains("node_modules"))
69+
.ToList();
70+
71+
var subFolderNodes = subdirectoryEntries.Select(subDirPath =>
72+
{
73+
var node = new FolderNode(subDirPath);
74+
node.AnalyzeFiles();
75+
return node;
76+
}).ToList();
77+
78+
SubDictionaries.AddRange(subFolderNodes);
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)