-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from luuksommers/hotfix/Issue-1
Hotfix/issue 1
- Loading branch information
Showing
13 changed files
with
443 additions
and
70 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,14 @@ | ||
using System; | ||
|
||
namespace YmlTransform | ||
{ | ||
class TransformItem | ||
{ | ||
public string Path { get; set; } | ||
public string Type { get; set; } | ||
public string Languages { get; set; } | ||
public Guid FieldId { get; set; } | ||
public string Value { get; set; } | ||
public string Hint { get; set; } | ||
} | ||
} |
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,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Rainbow.Model; | ||
using Rainbow.Storage.Yaml; | ||
|
||
namespace YmlTransform | ||
{ | ||
public static class YmlTransformer | ||
{ | ||
public static void TransformFile(string fileToTransform, string transformFile) | ||
{ | ||
var transformation = GetTransformation(transformFile); | ||
TransformSingle(transformation, fileToTransform); | ||
} | ||
|
||
|
||
public static void TransformPath(string path, string transformFile, bool recursive) | ||
{ | ||
var transformations = GetTransformation(transformFile); | ||
var files = Directory.GetFiles(path, "*.yml", | ||
recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); | ||
|
||
foreach (var file in files) | ||
{ | ||
TransformSingle(transformations, file); | ||
} | ||
} | ||
|
||
private static List<TransformItem> GetTransformation(string transformFile) | ||
{ | ||
var transformation = | ||
Newtonsoft.Json.JsonConvert.DeserializeObject<List<TransformItem>>(File.ReadAllText(transformFile)); | ||
return transformation; | ||
} | ||
|
||
private static void TransformSingle(List<TransformItem> transformations, string file) | ||
{ | ||
using (var fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) | ||
{ | ||
var transformed = false; | ||
var formatter = new YamlSerializationFormatter(null, null); | ||
var item = new ProxyItem(formatter.ReadSerializedItem(fs, Path.GetFileName(file))); | ||
|
||
foreach (var transform in transformations) | ||
{ | ||
if (item.Path == transform.Path) | ||
{ | ||
if (transform.Type == "Shared") | ||
{ | ||
if (item.SharedFields.FirstOrDefault(a => a.FieldId == transform.FieldId) is ProxyFieldValue field) | ||
{ | ||
Console.WriteLine( | ||
$"Updating file {file} section {transform.Type} id {transform.FieldId} to {transform.Value}"); | ||
field.Value = transform.Value; | ||
transformed = true; | ||
} | ||
} | ||
else if (transform.Type == "Languages") | ||
{ | ||
var fields = item.Versions | ||
.Where(a => transform.Languages == "*") | ||
.SelectMany(a => a.Fields) | ||
.Where(a => a.FieldId == transform.FieldId); | ||
|
||
foreach (var itemFieldValue in fields) | ||
{ | ||
var field = (ProxyFieldValue) itemFieldValue; | ||
Console.WriteLine( | ||
$"Updating file {file} section {transform.Type} id {transform.FieldId} to {transform.Value}"); | ||
field.Value = transform.Value; | ||
transformed = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
if (transformed) | ||
{ | ||
Console.WriteLine($"Transformed: {file}"); | ||
fs.SetLength(0); | ||
formatter.WriteSerializedItem(item, fs); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,47 @@ | ||
--- | ||
ID: "2a65abb0-3123-469f-a603-5f3b1804713c" | ||
Parent: "756fff26-90f2-4889-bace-da656e66b9c1" | ||
Template: "013bc834-c0f6-4377-924e-0de185abfbe7" | ||
Path: /sitecore/content/Home/MultiLanguage | ||
DB: master | ||
Languages: | ||
- Language: de | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: "German Field1" | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: "German Field2" | ||
- Language: en | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: "English Field1" | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: "English Field2" | ||
- Language: fr | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: "French Field1" | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: "French Field2" | ||
- Language: nl | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: "Dutch Field1" | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: "Dutch Field2" |
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,47 @@ | ||
--- | ||
ID: "2a65abb0-3123-469f-a603-5f3b1804713c" | ||
Parent: "756fff26-90f2-4889-bace-da656e66b9c1" | ||
Template: "013bc834-c0f6-4377-924e-0de185abfbe7" | ||
Path: /sitecore/content/Home/MultiLanguage | ||
DB: master | ||
Languages: | ||
- Language: de | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: TransformedField1 | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: TransformedField2 | ||
- Language: en | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: TransformedField1 | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: TransformedField2 | ||
- Language: fr | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: TransformedField1 | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: TransformedField2 | ||
- Language: nl | ||
Versions: | ||
- Version: 1 | ||
Fields: | ||
- ID: "00000000-0000-0000-0000-000000000000" | ||
Hint: Field1 | ||
Value: TransformedField1 | ||
- ID: "00000000-0000-0000-0000-000000000001" | ||
Hint: Field2 | ||
Value: TransformedField2 |
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,18 @@ | ||
[ | ||
{ | ||
"FieldId": "00000000-0000-0000-0000-000000000000", | ||
"Hint": "Field1", | ||
"Languages": "*", | ||
"Path": "/sitecore/content/Home/MultiLanguage", | ||
"Type": "Languages", | ||
"Value": "TransformedField1" | ||
}, | ||
{ | ||
"FieldId": "00000000-0000-0000-0000-000000000001", | ||
"Hint": "Field2", | ||
"Languages": "*", | ||
"Path": "/sitecore/content/Home/MultiLanguage", | ||
"Type": "Languages", | ||
"Value": "TransformedField2" | ||
} | ||
] |
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,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("YmlTransform.Tests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("YmlTransform.Tests")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("bb5287ae-b720-4c65-80b0-15f4eb459ba4")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.