-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Amberg/workitems/v2.0.0
Workitems v2.0.0
- Loading branch information
Showing
23 changed files
with
584 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using DocxTemplater.Images; | ||
|
||
namespace DocxTemplater.Test | ||
{ | ||
internal class ComplexTemplateTest | ||
{ | ||
[Test] | ||
public void ProcessComplexTemplate() | ||
{ | ||
|
||
var imageBytes = File.ReadAllBytes("Resources/testImage.jpg"); | ||
using var fileStream = File.OpenRead("Resources/ComplexTemplate.docx"); | ||
var docTemplate = new DocxTemplate(fileStream); | ||
docTemplate.RegisterFormatter(new ImageFormatter()); | ||
|
||
var model = CreateModel(imageBytes); | ||
docTemplate.BindModel("ds", model); | ||
|
||
var result = docTemplate.Process(); | ||
docTemplate.Validate(); | ||
result.Position = 0; | ||
result.SaveAsFileAndOpenInWord(); | ||
} | ||
|
||
private object CreateModel(byte[] imageBytes) | ||
{ | ||
var items = new List<WarehouseItem> | ||
{ | ||
new() | ||
{ | ||
IsHw = true, | ||
Name = "Item 1", | ||
HardwareRevisions = new List<VersionInfo> | ||
{ | ||
new() {IsMajor = true, Version = "1.0"}, | ||
new() {IsMajor = false, Version = "1.1"}, | ||
new() {IsMajor = false, Version = "1.2"}, | ||
new() {IsMajor = false, Version = "1.3"}, | ||
} | ||
}, | ||
new() | ||
{ | ||
IsHw = true, | ||
Name = "Item 2", | ||
SoftwareVersions = new List<VersionInfo> | ||
{ | ||
new() {IsMajor = true, Version = "1.0"}, | ||
new() {IsMajor = false, Version = "1.1"}, | ||
new() {IsMajor = false, Version = "1.2"}, | ||
new() {IsMajor = false, Version = "1.3"}, | ||
} | ||
}, | ||
new() | ||
{ | ||
IsHw = false, | ||
Name = "Item 3", | ||
SoftwareVersions = new List<VersionInfo> | ||
{ | ||
new() {IsMajor = true, Version = "1.0"}, | ||
new() {IsMajor = false, Version = "1.1"}, | ||
new() {IsMajor = false, Version = "1.2"}, | ||
new() {IsMajor = false, Version = "1.3"}, | ||
} | ||
}, | ||
new() | ||
{ | ||
IsHw = false, | ||
Name = "Item 4", | ||
SoftwareVersions = new List<VersionInfo> | ||
{ | ||
new() {IsMajor = true, Version = "42.0"}, | ||
}, | ||
HardwareRevisions = new List<VersionInfo> | ||
{ | ||
new() {IsMajor = true, Version = "1.0"}, | ||
new() {IsMajor = false, Version = "1.1"}, | ||
new() {IsMajor = false, Version = "1.2"}, | ||
new() {IsMajor = false, Version = "1.3"}, | ||
} | ||
} | ||
}; | ||
|
||
var images = new List<byte[]> | ||
{ | ||
imageBytes, | ||
imageBytes, | ||
imageBytes | ||
}; | ||
|
||
return new ComplexTemplateModel | ||
{ | ||
Items = items, | ||
Images = images | ||
}; | ||
} | ||
|
||
private class ComplexTemplateModel | ||
{ | ||
public IReadOnlyCollection<WarehouseItem> Items { get; set; } | ||
|
||
public IReadOnlyCollection<byte[]> Images { get; set; } | ||
} | ||
|
||
private class WarehouseItem | ||
{ | ||
public bool IsHw { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public IReadOnlyCollection<VersionInfo> HardwareRevisions { get; set; } | ||
|
||
public IReadOnlyCollection<VersionInfo> SoftwareVersions { get; set; } | ||
|
||
} | ||
|
||
private class VersionInfo | ||
{ | ||
public bool IsMajor { get; set; } | ||
|
||
public string Version { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return IsMajor ? $"Major Version: {Version}" : $"Minor Version: {Version}"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.