Skip to content

Commit 409d480

Browse files
committed
Add capability to directly get language pack resources from GH repos
1 parent 99c4bc5 commit 409d480

21 files changed

Lines changed: 917 additions & 500 deletions

Server/Core/CheckGithubTask.cs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,56 @@
77

88
namespace Connect.LanguagePackManager.Core
99
{
10-
public class CheckGithubTask : SchedulerClient
10+
public class CheckGithubTask : SchedulerClient
11+
{
12+
public CheckGithubTask(ScheduleHistoryItem history)
1113
{
12-
public CheckGithubTask(ScheduleHistoryItem history)
13-
{
14-
this.ScheduleHistoryItem = history;
15-
}
14+
this.ScheduleHistoryItem = history;
15+
}
1616

17-
public StringBuilder Log { get; set; } = new StringBuilder();
18-
public DateTime Start { get; private set; } = DateTime.Now;
17+
public StringBuilder Log { get; set; } = new StringBuilder();
18+
public DateTime Start { get; private set; } = DateTime.Now;
1919

20-
public override void DoWork()
21-
{
22-
try
23-
{
24-
AddLogLine($"Cleaning up temp folder");
25-
Common.Globals.CleanupTempFolder();
20+
public override void DoWork()
21+
{
22+
try
23+
{
24+
AddLogLine($"Cleaning up temp folder");
25+
Common.Globals.CleanupTempFolder();
2626

27-
var links = PackageLinkRepository.Instance.GetPackageLinks();
28-
foreach (var link in links)
29-
{
30-
AddLogLine($"Checking {link.Name}");
31-
GithubController.CheckPackage(link);
32-
AddLogLine($"Finished checking {link.Name}");
33-
}
27+
var links = PackageLinkRepository.Instance.GetPackageLinks();
28+
foreach (var link in links)
29+
{
30+
AddLogLine($"Checking {link.Name}");
31+
if (link.IsResourcesRepo)
32+
{
33+
GithubController.CheckResourcesRepo(link);
34+
}
35+
else
36+
{
37+
GithubController.CheckPackage(link);
38+
}
39+
AddLogLine($"Finished checking {link.Name}");
40+
}
3441

35-
Data.Sprocs.RefreshNrTexts();
36-
AddLogLine($"Refreshed Nr Texts");
42+
Data.Sprocs.RefreshNrTexts();
43+
AddLogLine($"Refreshed Nr Texts");
3744

38-
ScheduleHistoryItem.Succeeded = true;
39-
ScheduleHistoryItem.AddLogNote(Log.ToString().Replace(Environment.NewLine, "<br />"));
40-
}
41-
catch (Exception ex)
42-
{
43-
ScheduleHistoryItem.Succeeded = false;
44-
ScheduleHistoryItem.AddLogNote($"Failed: {ex.Message} ({ex.StackTrace}) <br />{Log.ToString().Replace(Environment.NewLine, "<br />")}");
45-
Errored(ref ex);
46-
Exceptions.LogException(ex);
47-
}
48-
}
45+
ScheduleHistoryItem.Succeeded = true;
46+
ScheduleHistoryItem.AddLogNote(Log.ToString().Replace(Environment.NewLine, "<br />"));
47+
}
48+
catch (Exception ex)
49+
{
50+
ScheduleHistoryItem.Succeeded = false;
51+
ScheduleHistoryItem.AddLogNote($"Failed: {ex.Message} ({ex.StackTrace}) <br />{Log.ToString().Replace(Environment.NewLine, "<br />")}");
52+
Errored(ref ex);
53+
Exceptions.LogException(ex);
54+
}
55+
}
4956

50-
private void AddLogLine(string line)
51-
{
52-
Log.AppendLine($"{Start.ToString("HH:mm:ss")} {line}");
53-
}
57+
private void AddLogLine(string line)
58+
{
59+
Log.AppendLine($"{Start.ToString("HH:mm:ss")} {line}");
5460
}
61+
}
5562
}

Server/Core/Helpers/UnzipResult.cs

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,50 @@
55

66
namespace Connect.LanguagePackManager.Core.Helpers
77
{
8-
public class UnzipResult
8+
public class UnzipResult
9+
{
10+
public class FoundFile
911
{
10-
public class FoundFile
11-
{
12-
public string FilePath { get; set; }
13-
public string FilePathLowered { get; set; }
14-
public string HashedName { get; set; }
15-
}
16-
17-
public string UnzipDirectory { get; set; } = Path.Combine(Globals.GetLpmFolder(-1, "Temp"), (Guid.NewGuid()).ToString());
18-
public SortedDictionary<string, FoundFile> ResourceFiles { get; set; } = new SortedDictionary<string, FoundFile>();
19-
public SortedDictionary<string, FoundFile> ZipFiles { get; set; } = new SortedDictionary<string, FoundFile>();
20-
public string ManifestFile { get; set; }
21-
public Version DnnVersion { get; set; }
22-
public string BasePath { get; set; }
12+
public string FilePath { get; set; }
13+
public string FilePathLowered { get; set; }
14+
public string HashedName { get; set; }
15+
}
2316

24-
public UnzipResult(string basePath)
25-
{
26-
this.BasePath = basePath;
27-
Directory.CreateDirectory(UnzipDirectory);
28-
}
17+
public string UnzipDirectory { get; set; } = Path.Combine(Globals.GetLpmFolder(-1, "Temp"), (Guid.NewGuid()).ToString());
18+
public SortedDictionary<string, FoundFile> ResourceFiles { get; set; } = new SortedDictionary<string, FoundFile>();
19+
public SortedDictionary<string, FoundFile> ZipFiles { get; set; } = new SortedDictionary<string, FoundFile>();
20+
public string ManifestFile { get; set; }
21+
public string ManifestFilePath { get; set; } = "";
22+
public Version DnnVersion { get; set; }
23+
public string BasePath { get; set; }
2924

30-
public void AddResourceFile(string filePath, string hashedName)
31-
{
32-
var f = new FoundFile()
33-
{
34-
FilePath = filePath,
35-
FilePathLowered = filePath.ToLower(),
36-
HashedName = hashedName
37-
};
38-
this.ResourceFiles.Add(f.FilePathLowered, f);
39-
}
25+
public UnzipResult(string basePath)
26+
{
27+
this.BasePath = basePath;
28+
Directory.CreateDirectory(UnzipDirectory);
29+
}
4030

41-
public void AddZipFile(string filePath, string hashedName)
42-
{
43-
var f = new FoundFile()
44-
{
45-
FilePath = filePath,
46-
FilePathLowered = filePath.ToLower(),
47-
HashedName = hashedName
48-
};
49-
this.ZipFiles.Add(f.FilePathLowered, f);
50-
}
31+
public void AddResourceFile(string filePath, string hashedName)
32+
{
33+
var f = new FoundFile()
34+
{
35+
FilePath = filePath,
36+
FilePathLowered = filePath.ToLower(),
37+
HashedName = hashedName
38+
};
39+
this.ResourceFiles.Add(f.FilePathLowered, f);
40+
}
5141

42+
public void AddZipFile(string filePath, string hashedName)
43+
{
44+
var f = new FoundFile()
45+
{
46+
FilePath = filePath,
47+
FilePathLowered = filePath.ToLower(),
48+
HashedName = hashedName
49+
};
50+
this.ZipFiles.Add(f.FilePathLowered, f);
5251
}
52+
53+
}
5354
}

Server/Core/Helpers/ZipHelper.cs

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,79 @@
11
using Connect.LanguagePackManager.Core.Common;
22
using System.IO;
33
using System.IO.Compression;
4+
using System.Runtime.CompilerServices;
45
using System.Text.RegularExpressions;
56

67
namespace Connect.LanguagePackManager.Core.Helpers
78
{
8-
public class ZipHelper
9+
public class ZipHelper
10+
{
11+
public static UnzipResult Unzip(Stream fileStream, string packageBasePath, bool allowTranslations)
912
{
10-
public static UnzipResult Unzip(Stream fileStream, string packageBasePath, bool allowTranslations)
13+
var result = new UnzipResult(packageBasePath);
14+
using (var objZipInputStream = new ZipArchive(fileStream, ZipArchiveMode.Read))
15+
{
16+
foreach (var entry in objZipInputStream.Entries)
1117
{
12-
var result = new UnzipResult(packageBasePath);
13-
using (var objZipInputStream = new ZipArchive(fileStream, ZipArchiveMode.Read))
14-
{
15-
foreach (var entry in objZipInputStream.Entries)
18+
var fullName = entry.FullName.Trim('/').ToLowerInvariant();
19+
var ext = Path.GetExtension(fullName);
20+
switch (ext)
21+
{
22+
case ".dnn":
23+
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, entry.Name), true);
24+
result.ManifestFile = entry.Name;
25+
result.ManifestFilePath = Path.GetDirectoryName(entry.FullName);
26+
break;
27+
case ".dll":
28+
if (entry.Name.ToLowerInvariant() == "dotnetnuke.dll")
29+
{
30+
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, entry.Name), true);
31+
result.DnnVersion = Globals.GetAssemblyVersion(Path.Combine(result.UnzipDirectory, entry.Name));
32+
try
1633
{
17-
var fullName = entry.FullName.Trim('/').ToLowerInvariant();
18-
var ext = Path.GetExtension(fullName);
19-
switch (ext)
20-
{
21-
case ".dnn":
22-
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, entry.Name), true);
23-
result.ManifestFile = entry.Name;
24-
break;
25-
case ".dll":
26-
if (entry.Name.ToLowerInvariant() == "dotnetnuke.dll")
27-
{
28-
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, entry.Name), true);
29-
result.DnnVersion = Globals.GetAssemblyVersion(Path.Combine(result.UnzipDirectory, entry.Name));
30-
try
31-
{
32-
File.Delete(Path.Combine(result.UnzipDirectory, entry.Name));
33-
}
34-
catch
35-
{
36-
}
37-
}
38-
break;
39-
case ".resx":
40-
var fileName = fullName.ToMD5Hash();
41-
var m = Regex.Match(entry.Name, @"\.(\w{2,3}-\w\w)\.");
42-
if (allowTranslations || !m.Success || m.Groups[1].Value.ToLower() == "en-us") // filter out all files that are not default locale
43-
{
44-
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, fileName));
45-
result.AddResourceFile(fullName, fileName);
46-
}
47-
break;
48-
case ".resources":
49-
case ".zip":
50-
var zipName = fullName.ToMD5Hash();
51-
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, zipName));
52-
result.AddZipFile(fullName, zipName);
53-
break;
54-
}
34+
File.Delete(Path.Combine(result.UnzipDirectory, entry.Name));
5535
}
56-
}
57-
return result;
36+
catch
37+
{
38+
}
39+
}
40+
break;
41+
case ".resx":
42+
var fileName = fullName.ToMD5Hash();
43+
var m = Regex.Match(entry.Name, @"\.(\w{2,3}-\w\w)\.");
44+
if (allowTranslations || !m.Success || m.Groups[1].Value.ToLower() == "en-us") // filter out all files that are not default locale
45+
{
46+
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, fileName));
47+
result.AddResourceFile(fullName, fileName);
48+
}
49+
break;
50+
case ".resources":
51+
case ".zip":
52+
var zipName = fullName.ToMD5Hash();
53+
entry.ExtractToFile(Path.Combine(result.UnzipDirectory, zipName));
54+
result.AddZipFile(fullName, zipName);
55+
break;
56+
}
5857
}
59-
60-
public static UnzipResult Unzip(string filePath, string packageBasePath, bool allowTranslations)
58+
}
59+
if (!string.IsNullOrEmpty(result.ManifestFilePath))
60+
{
61+
var l = result.ManifestFilePath.Length + 1;
62+
foreach (var resx in result.ResourceFiles.Values)
6163
{
62-
using (var fileStrm = File.Open(filePath, FileMode.Open, FileAccess.Read))
63-
{
64-
return Unzip(fileStrm, packageBasePath, allowTranslations);
65-
}
64+
resx.FilePath = resx.FilePath.Remove(0, l);
65+
resx.FilePathLowered = resx.FilePathLowered.Remove(0, l);
6666
}
67+
}
68+
return result;
69+
}
70+
71+
public static UnzipResult Unzip(string filePath, string packageBasePath, bool allowTranslations)
72+
{
73+
using (var fileStrm = File.Open(filePath, FileMode.Open, FileAccess.Read))
74+
{
75+
return Unzip(fileStrm, packageBasePath, allowTranslations);
76+
}
6777
}
78+
}
6879
}

Server/Core/Models/PackageLinks/PackageLinkBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public PackageLinkBase()
3636
public DateTime? LastChecked { get; set; }
3737
[DataMember]
3838
public string LastDownloadedVersion { get; set; }
39+
[DataMember]
40+
public bool IsResourcesRepo { get; set; }
3941
#endregion
4042

4143
#region Methods
@@ -65,6 +67,8 @@ public void ReadPackageLinkBase(PackageLinkBase packageLink)
6567
if (!String.IsNullOrEmpty(packageLink.LastDownloadedVersion))
6668
LastDownloadedVersion = packageLink.LastDownloadedVersion;
6769

70+
IsResourcesRepo = packageLink.IsResourcesRepo;
71+
6872
}
6973
#endregion
7074

Server/Core/Models/PackageLinks/PackageLinkBase_Interfaces.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public virtual void Fill(IDataReader dr)
2424
AssetRegex = Convert.ToString(Null.SetNull(dr["AssetRegex"], AssetRegex));
2525
LastChecked = (DateTime)(Null.SetNull(dr["LastChecked"], LastChecked));
2626
LastDownloadedVersion = Convert.ToString(Null.SetNull(dr["LastDownloadedVersion"], LastDownloadedVersion));
27+
IsResourcesRepo = Convert.ToBoolean(Null.SetNull(dr["IsResourcesRepo"], IsResourcesRepo));
2728
}
2829

2930
[IgnoreColumn()]
@@ -63,6 +64,8 @@ public virtual string GetProperty(string strPropertyName, string strFormat, Syst
6364
return "";
6465
};
6566
return PropertyAccess.FormatString(LastDownloadedVersion, strFormat);
67+
case "isresourcesrepo": // Bit
68+
return IsResourcesRepo.ToString();
6669
default:
6770
propertyNotFound = true;
6871
break;

Server/Core/Models/PackageLinks/PackageLink_Declaration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public PackageLinkBase GetPackageLinkBase()
3939
res.AssetRegex = AssetRegex;
4040
res.LastChecked = LastChecked;
4141
res.LastDownloadedVersion = LastDownloadedVersion;
42+
res.IsResourcesRepo = IsResourcesRepo;
4243
res.CreatedByUserID = CreatedByUserID;
4344
res.CreatedOnDate = CreatedOnDate;
4445
res.LastModifiedByUserID = LastModifiedByUserID;
@@ -56,6 +57,7 @@ public PackageLink Clone()
5657
res.AssetRegex = AssetRegex;
5758
res.LastChecked = LastChecked;
5859
res.LastDownloadedVersion = LastDownloadedVersion;
60+
res.IsResourcesRepo = IsResourcesRepo;
5961
res.PortalID = PortalID;
6062
res.CreatedByUser = CreatedByUser;
6163
res.ModifiedByUser = ModifiedByUser;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Connect.LanguagePackManager.Core.Services.Github
2+
{
3+
using System.Runtime.Serialization;
4+
5+
[DataContract]
6+
public class GithubBlob
7+
{
8+
[DataMember(Name = "content")]
9+
public string Content { get; set; }
10+
11+
[DataMember(Name = "encoding")]
12+
public string Encoding { get; set; }
13+
14+
[DataMember(Name = "sha")]
15+
public string Sha { get; set; }
16+
17+
[DataMember(Name = "size")]
18+
public int Size { get; set; }
19+
}
20+
}

0 commit comments

Comments
 (0)