-
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.
- Loading branch information
Luuk Sommers
committed
Sep 15, 2017
1 parent
a18b403
commit 59cfbe6
Showing
7 changed files
with
296 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26430.13 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YmlTransform", "src\YmlTransform\YmlTransform.csproj", "{00EC6644-0EBF-44A8-8EDF-F73D06787377}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{00EC6644-0EBF-44A8-8EDF-F73D06787377}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{00EC6644-0EBF-44A8-8EDF-F73D06787377}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{00EC6644-0EBF-44A8-8EDF-F73D06787377}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{00EC6644-0EBF-44A8-8EDF-F73D06787377}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="nuget.org" protocolVersion="3" value="https://api.nuget.org/v3/index.json"/> | ||
<add key="Sitecore" value="https://sitecore.myget.org/F/sc-packages/api/v3/index.json"/> | ||
<add key="Allego Shared" value="https://allego.pkgs.visualstudio.com/_packaging/Allego/nuget/v3/index.json"/> | ||
</packageSources> | ||
</configuration> |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> | ||
</startup> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
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,105 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using CommandLine; | ||
using Rainbow.Model; | ||
using Rainbow.Storage.Yaml; | ||
|
||
namespace YmlTransform | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var options = new Options(); | ||
var isValid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options); | ||
if (isValid) | ||
{ | ||
var transformation = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TransformItem>>(File.ReadAllText(options.TransformFile)); | ||
|
||
Transform(options.Path, transformation, options.Recursive); | ||
} | ||
} | ||
|
||
private static void Transform(string path, List<TransformItem> transformations, bool recursive) | ||
{ | ||
var files = Directory.GetFiles(path, "*.yml", | ||
recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); | ||
|
||
foreach (var file in files) | ||
{ | ||
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 t in transformations) | ||
{ | ||
if (item.Path == t.Path) | ||
{ | ||
if (t.Type == "Shared") | ||
{ | ||
var field = item.SharedFields.FirstOrDefault(a => a.FieldId == t.FieldId) as ProxyFieldValue; | ||
if (field != null) | ||
{ | ||
Console.WriteLine($"Updating file {file} section {t.Type} id {t.FieldId} to {t.Value}"); | ||
field.Value = t.Value; | ||
transformed = true; | ||
} | ||
} | ||
else if (t.Type == "Languages") | ||
{ | ||
var field = item.Versions | ||
.Where(a => t.Languages == "*") | ||
.SelectMany(a => a.Fields) | ||
.FirstOrDefault(a => a.FieldId == t.FieldId) as ProxyFieldValue; | ||
if (field != null) | ||
{ | ||
Console.WriteLine($"Updating file {file} section {t.Type} id {t.FieldId} to {t.Value}"); | ||
field.Value = t.Value; | ||
transformed = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
if (transformed) | ||
{ | ||
Console.WriteLine($"Transformed: {file}"); | ||
fs.SetLength(0); | ||
formatter.WriteSerializedItem(item, fs); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
class Options | ||
{ | ||
[Option('p', "path", Required = true, HelpText = "Path to process")] | ||
public string Path { get; set; } | ||
|
||
[Option('r', "recursive", Required = false, HelpText = "Loop recursively", DefaultValue = false)] | ||
public bool Recursive { get; set; } | ||
|
||
[Option('t', "transform", Required = true, HelpText = "Transformation file")] | ||
public string TransformFile { get; set; } | ||
} | ||
|
||
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
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")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("YmlTransform")] | ||
[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("00ec6644-0ebf-44a8-8edf-f73d06787377")] | ||
|
||
// 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")] |
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,90 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{00EC6644-0EBF-44A8-8EDF-F73D06787377}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>YmlTransform</RootNamespace> | ||
<AssemblyName>YmlTransform</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rainbow, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Rainbow.Core.1.4.2\lib\net452\Rainbow.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rainbow.Storage.Yaml, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Rainbow.Storage.Yaml.1.4.2\lib\net452\Rainbow.Storage.Yaml.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Sitecore.Kernel, Version=10.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Sitecore.Kernel.NoReferences.8.2.170407\lib\NET452\Sitecore.Kernel.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.ComponentModel.Composition" /> | ||
<Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Reflection, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Reflection.TypeExtensions, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\System.Reflection.TypeExtensions.4.4.0-preview1-25305-02\lib\net461\System.Reflection.TypeExtensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="CommandLineParser" version="1.9.71" targetFramework="net462" /> | ||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net462" /> | ||
<package id="Rainbow.Core" version="1.4.2" targetFramework="net462" /> | ||
<package id="Rainbow.Storage.Yaml" version="1.4.2" targetFramework="net462" /> | ||
<package id="Sitecore.Kernel.NoReferences" version="8.2.170407" targetFramework="net462" developmentDependency="true" /> | ||
<package id="System.Collections" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Console" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Globalization" version="4.0.11-rc2-24027" targetFramework="net462" /> | ||
<package id="System.IO" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Linq" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Reflection" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Reflection.TypeExtensions" version="4.4.0-preview1-25305-02" targetFramework="net462" /> | ||
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Runtime" version="4.3.0" targetFramework="net462" /> | ||
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net462" /> | ||
</packages> |