Permalink
Browse files

Localization tool pre init verssion

  • Loading branch information...
vssilin committed Jun 23, 2017
1 parent 43e3017 commit 7067c4165054baee269469fae29ed896aad3fcb5
View
@@ -256,3 +256,4 @@ paket-files/
.idea/
*.sln.iml
templates/_composition/_shared/Page.Chart.SampleDataService/Services/SampleDataService_postaction.cs
/myModel.vsdx
View
@@ -0,0 +1,25 @@

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}") = "Localization", "tools\Localization\Localization.csproj", "{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Analyze|Any CPU = Analyze|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Analyze|Any CPU.ActiveCfg = Analyze|Any CPU
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Analyze|Any CPU.Build.0 = Analyze|Any CPU
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Localization
{
internal delegate void OnCommand(ToolCommandInfo commandInfo);
internal class ToolCommandHandler
{
private const string splitPattern = @"(""[a-zA-Z0-9\s_@:.;\-^!#$%&+={}\(\)\[\]\\\/]*?"")|([a-zA-Z0-9]+)";
private Dictionary<string, List<OnCommand>> handlers;
internal void Listen()
{
ToolCommandInfo commandInfo;
string commandLine;
string[] commandParts;
while (1 == 1)
{
Console.Write(">> ");
commandLine = Console.ReadLine().Trim();
MatchCollection matches = Regex.Matches(commandLine, splitPattern);
commandParts = new string[matches.Count];
int i = 0;
foreach (Match match in matches)
{
commandParts[i++] = match.Value.Trim("\"".ToCharArray());
}
if (commandParts.Length > 0)
{
string[] arguments = commandParts.Length > 1 ? new string[commandParts.Length - 1] : new string[] { };
if (commandParts.Length > 1)
Array.ConstrainedCopy(commandParts, 1, arguments, 0, arguments.Length);
commandInfo = new ToolCommandInfo(commandParts[0].Trim().ToLower(), arguments);
if (commandInfo.Command == "exit")
break;
if (this.handlers != null && this.handlers.ContainsKey(commandInfo.Command) && this.handlers[commandInfo.Command].Count > 0)
{
foreach (OnCommand handler in this.handlers[commandInfo.Command])
{
try
{
handler.Invoke(commandInfo);
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error executing command {commandInfo.Command.ToUpper()}:");
Console.Error.WriteLine(ex.ToString());
}
}
}
else
{
Console.WriteLine("Command unknown. Type HELP for help.");
}
}
}
}
internal void SubscribeOnCommand(string command, OnCommand handler)
{
command = command.ToLower();
if (this.handlers == null)
this.handlers = new Dictionary<string, List<OnCommand>>();
if (!this.handlers.ContainsKey(command))
this.handlers.Add(command, new List<OnCommand>());
this.handlers[command].Add(handler);
}
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Localization
{
internal class ToolCommandInfo
{
internal string Command { get; private set; }
internal string[] Arguments { get; private set; }
internal ToolCommandInfo(string command, string[] arguments)
{
this.Command = command;
this.Arguments = arguments;
}
}
}
@@ -0,0 +1,80 @@
<?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>{84900DD1-8F31-4D6F-8C8A-0BAAC25829DA}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Localization</RootNamespace>
<AssemblyName>Localization</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</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>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Analyze|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Analyze\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<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="..\..\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<Compile Include="ClientInterface\ToolCommandHandler.cs" />
<Compile Include="Logic\LocalizableItemsExtractor.cs" />
<Compile Include="Logic\LocalizationTool.cs" />
<Compile Include="Logic\XmlUtility.cs" />
<Compile Include="Program.cs" />
<Compile Include="Logic\ProjectTemplateGenerator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ClientInterface\ToolCommandInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\StyleCop.json">
<Link>StyleCop.json</Link>
</None>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Localization
{
internal class LocalizableItemsExtractor
{
private DirectoryInfo sourceDir;
private DirectoryInfo destinationDir;
private const string projectTemplateFileNamePattern = "CSharp.UWP.VS2017.Solution.vstemplate";
private const string projectTemplateDirNamePattern = "CSharp.UWP.2017.{0}.Solution";
private const string projectTemplateRootDirPath = "ProjectTemplates";
internal LocalizableItemsExtractor(string sourceDirPath, string destinationDirPath)
{
this.sourceDir = new DirectoryInfo(sourceDirPath);
if (!this.sourceDir.Exists)
throw new DirectoryNotFoundException($"Source directory \"{sourceDirPath}\" not found.");
this.destinationDir = new DirectoryInfo(destinationDirPath);
if (!this.destinationDir.Exists)
this.destinationDir.Create();
}
internal bool ExtractProjectTemplate(string culture)
{
DirectoryInfo templateDesDirectory = new DirectoryInfo(Path.Combine(this.destinationDir.FullName, projectTemplateRootDirPath, string.Format(projectTemplateDirNamePattern, culture)));
if (templateDesDirectory.Exists)
return false;
templateDesDirectory.Create();
DirectoryInfo templateSrcDirectory = new DirectoryInfo(Path.Combine(this.sourceDir.FullName, projectTemplateRootDirPath, string.Format(projectTemplateDirNamePattern, culture)));
if (!templateSrcDirectory.Exists)
throw new DirectoryNotFoundException($"Source directory \"{templateSrcDirectory.FullName}\" not found.");
FileInfo file = new FileInfo(Path.Combine(templateSrcDirectory.FullName, projectTemplateFileNamePattern));
if (!file.Exists)
throw new FileNotFoundException($"File \"{file.FullName}\" not found.");
file.CopyTo(Path.Combine(templateDesDirectory.FullName, projectTemplateFileNamePattern));
return true;
}
}
}
@@ -0,0 +1,64 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Localization
{
internal class LocalizationTool
{
public LocalizationTool()
{
}
public void GenerateProjectTemplatesHandler(ToolCommandInfo commandInfo)
{
if (commandInfo.Arguments == null || commandInfo.Arguments.Length < 3)
{
throw new Exception("Error executing command. Too few arguments.");
}
string sourceDirectory = commandInfo.Arguments[0];
string destinationDirectory = commandInfo.Arguments[1];
List<string> cultures = new List<string>(commandInfo.Arguments[2].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
ProjectTemplateGenerator projectTemplateGenerator = new ProjectTemplateGenerator(sourceDirectory, destinationDirectory);
foreach (string culture in cultures)
{
projectTemplateGenerator.GenerateProjectTemplate(culture);
}
}
public void ExtractLocalizableItems(ToolCommandInfo commandInfo)
{
if (commandInfo.Arguments == null || commandInfo.Arguments.Length < 3)
{
throw new Exception("Error executing command. Too few arguments.");
}
string sourceDirectory = commandInfo.Arguments[0];
string destinationDirectory = commandInfo.Arguments[1];
List<string> cultures = new List<string>(commandInfo.Arguments[2].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
LocalizableItemsExtractor extractor = new LocalizableItemsExtractor(sourceDirectory, destinationDirectory);
foreach (string culture in cultures)
{
extractor.ExtractProjectTemplate(culture);
}
// CSharp.UWP.2017.{culture}.Solution/CSharp.UWP.VS2017.Solution.vstemplate
// TemplateEngine Json
// TemplateEngine Md
// Wts Json
// Wts Md
}
}
}
Oops, something went wrong.

0 comments on commit 7067c41

Please sign in to comment.