Remove external modules and copy them to 'Windows/tools'
This commit is contained in:
parent
a1c05e9ec5
commit
02b77f894b
9
.gitmodules
vendored
9
.gitmodules
vendored
|
@ -1,9 +0,0 @@
|
||||||
[submodule "SmartIrc4net"]
|
|
||||||
path = SmartIrc4net
|
|
||||||
url = git://git.qnetp.net/smartirc4net.git
|
|
||||||
[submodule "tools/TextTemplating"]
|
|
||||||
path = tools/TextTemplating
|
|
||||||
url = git://github.com/wimh/TextTemplating.git
|
|
||||||
[submodule "tools/gettext-cs-utils"]
|
|
||||||
path = tools/gettext-cs-utils
|
|
||||||
url = git://github.com/wimh/gettext-cs-utils.git
|
|
BIN
SparkleShare/Windows/sparkleshare.ico
Normal file
BIN
SparkleShare/Windows/sparkleshare.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
2
SparkleShare/Windows/tools/TextTemplating/.gitattributes
vendored
Normal file
2
SparkleShare/Windows/tools/TextTemplating/.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.gitattributes eol=lf
|
||||||
|
.gitmodules eol=lf
|
11
SparkleShare/Windows/tools/TextTemplating/.gitignore
vendored
Normal file
11
SparkleShare/Windows/tools/TextTemplating/.gitignore
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
*~
|
||||||
|
*.bak
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.sln.cache
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
_ReSharper.*/
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup/
|
||||||
|
UpgradeLog.XML
|
9
SparkleShare/Windows/tools/TextTemplating/ChangeLog
Normal file
9
SparkleShare/Windows/tools/TextTemplating/ChangeLog
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
2009-08-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Makefile.am:
|
||||||
|
* TextTransform:
|
||||||
|
* Mono.TextTemplating:
|
||||||
|
* Mono.TextTemplating.Tests:
|
||||||
|
* MonoDevelop.TextTemplating: Include the ASP.NET MVC and
|
||||||
|
TextTemplating addins in the main solution and build.
|
||||||
|
|
4
SparkleShare/Windows/tools/TextTemplating/Makefile.am
Normal file
4
SparkleShare/Windows/tools/TextTemplating/Makefile.am
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
SUBDIRS = \
|
||||||
|
Mono.TextTemplating \
|
||||||
|
TextTransform \
|
||||||
|
MonoDevelop.TextTemplating
|
|
@ -0,0 +1,65 @@
|
||||||
|
2009-12-11 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Don't local-copy nunit.
|
||||||
|
|
||||||
|
2009-11-27 Olivier Dagenais <olivier.dagenais@gmail.com>
|
||||||
|
|
||||||
|
* GenerationTests.cs: Make tests independent of the runtime
|
||||||
|
they are running under by stripping the "autogenerated"
|
||||||
|
comment (i.e. the first 9 lines).
|
||||||
|
|
||||||
|
2009-10-29 Lluis Sanchez Gual <lluis@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Flush.
|
||||||
|
|
||||||
|
2009-08-13 Lluis Sanchez Gual <lluis@novell.com>
|
||||||
|
|
||||||
|
* DummyHost.cs: Fix windows build.
|
||||||
|
|
||||||
|
2009-08-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Use assembly refs for
|
||||||
|
nunit.
|
||||||
|
|
||||||
|
2009-08-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Include the ASP.NET MVC
|
||||||
|
and TextTemplating addins in the main solution and build.
|
||||||
|
|
||||||
|
2009-04-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* GenerationTests.cs: Add tests for Windows/Mac newlines.
|
||||||
|
|
||||||
|
2009-04-03 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Updated.
|
||||||
|
|
||||||
|
* GenerationTests.cs: Add test for C# output.
|
||||||
|
|
||||||
|
* ParsingTests.cs: Track dummy host name change.
|
||||||
|
|
||||||
|
* DummyHost.cs: Add more functionality to dummy host.
|
||||||
|
|
||||||
|
2009-03-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Move output dir from
|
||||||
|
../bin to ../build.
|
||||||
|
|
||||||
|
2009-03-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Fix output directory.
|
||||||
|
|
||||||
|
2009-03-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Updated.
|
||||||
|
|
||||||
|
* ParsingTests.cs: Add parser test.
|
||||||
|
|
||||||
|
* DummyHost.cs: Dummy templating host.
|
||||||
|
|
||||||
|
2009-03-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.Tests.csproj: Add tests.
|
||||||
|
|
||||||
|
* ParsingTests.cs: Tokeniser state/value/location test.
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
//
|
||||||
|
// IncludeFileProviderHost.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating.Tests
|
||||||
|
{
|
||||||
|
|
||||||
|
public class DummyHost : ITextTemplatingEngineHost
|
||||||
|
{
|
||||||
|
public readonly Dictionary<string, string> Locations = new Dictionary<string, string> ();
|
||||||
|
public readonly Dictionary<string, string> Contents = new Dictionary<string, string> ();
|
||||||
|
public readonly Dictionary<string, object> HostOptions = new Dictionary<string, object> ();
|
||||||
|
List<string> standardAssemblyReferences = new List<string> ();
|
||||||
|
List<string> standardImports = new List<string> ();
|
||||||
|
public readonly CompilerErrorCollection Errors = new CompilerErrorCollection ();
|
||||||
|
public readonly Dictionary<string, Type> DirectiveProcessors = new Dictionary<string, Type> ();
|
||||||
|
|
||||||
|
public virtual object GetHostOption (string optionName)
|
||||||
|
{
|
||||||
|
object o;
|
||||||
|
HostOptions.TryGetValue (optionName, out o);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool LoadIncludeText (string requestFileName, out string content, out string location)
|
||||||
|
{
|
||||||
|
content = null;
|
||||||
|
return Locations.TryGetValue (requestFileName, out location)
|
||||||
|
&& Contents.TryGetValue (requestFileName, out content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void LogErrors (CompilerErrorCollection errors)
|
||||||
|
{
|
||||||
|
Errors.AddRange (errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual AppDomain ProvideTemplatingAppDomain (string content)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string ResolveAssemblyReference (string assemblyReference)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Type ResolveDirectiveProcessor (string processorName)
|
||||||
|
{
|
||||||
|
Type t;
|
||||||
|
DirectiveProcessors.TryGetValue (processorName, out t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string ResolveParameterValue (string directiveId, string processorName, string parameterName)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string ResolvePath (string path)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void SetFileExtension (string extension)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void SetOutputEncoding (System.Text.Encoding encoding, bool fromOutputDirective)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual IList<string> StandardAssemblyReferences {
|
||||||
|
get { return standardAssemblyReferences; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual IList<string> StandardImports {
|
||||||
|
get { return standardImports; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string TemplateFile {
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,171 @@
|
||||||
|
//
|
||||||
|
// GenerationTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating.Tests
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class GenerationTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Generate ()
|
||||||
|
{
|
||||||
|
string Input = ParsingTests.ParseSample1;
|
||||||
|
string Output = OutputSample1;
|
||||||
|
Generate (Input, Output, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GenerateMacNewlines ()
|
||||||
|
{
|
||||||
|
string MacInput = ParsingTests.ParseSample1.Replace ("\n", "\r");
|
||||||
|
string MacOutput = OutputSample1.Replace ("\\n", "\\r").Replace ("\n", "\r");;
|
||||||
|
Generate (MacInput, MacOutput, "\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GenerateWindowsNewlines ()
|
||||||
|
{
|
||||||
|
string WinInput = ParsingTests.ParseSample1.Replace ("\n", "\r\n");
|
||||||
|
string WinOutput = OutputSample1.Replace ("\\n", "\\r\\n").Replace ("\n", "\r\n");
|
||||||
|
Generate (WinInput, WinOutput, "\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//NOTE: we set the newline property on the code generator so that the whole files has matching newlines,
|
||||||
|
// in order to match the newlines in the verbatim code blocks
|
||||||
|
void Generate (string input, string expectedOutput, string newline)
|
||||||
|
{
|
||||||
|
DummyHost host = new DummyHost ();
|
||||||
|
string className = "GeneratedTextTransformation4f504ca0";
|
||||||
|
string code = GenerateCode (host, input, className, newline);
|
||||||
|
Assert.AreEqual (0, host.Errors.Count);
|
||||||
|
Assert.AreEqual (expectedOutput, TemplatingEngineHelper.StripHeader (code, newline));
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
string GenerateCode (ITextTemplatingEngineHost host, string content, string name, string generatorNewline)
|
||||||
|
{
|
||||||
|
ParsedTemplate pt = ParsedTemplate.FromText (content, host);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateSettings settings = TemplatingEngine.GetSettings (host, pt);
|
||||||
|
if (name != null)
|
||||||
|
settings.Name = name;
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ccu = TemplatingEngine.GenerateCompileUnit (host, content, pt, settings);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var opts = new System.CodeDom.Compiler.CodeGeneratorOptions ();
|
||||||
|
using (var writer = new System.IO.StringWriter ()) {
|
||||||
|
writer.NewLine = generatorNewline;
|
||||||
|
settings.Provider.GenerateCodeFromCompileUnit (ccu, writer, opts);
|
||||||
|
return writer.ToString ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Expected output strings
|
||||||
|
|
||||||
|
public static string OutputSample1 =
|
||||||
|
@"
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class GeneratedTextTransformation4f504ca0 : global::Microsoft.VisualStudio.TextTemplating.TextTransformation {
|
||||||
|
|
||||||
|
|
||||||
|
#line 9 """"
|
||||||
|
|
||||||
|
baz \#>
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
public override string TransformText() {
|
||||||
|
this.GenerationEnvironment = null;
|
||||||
|
|
||||||
|
#line 2 """"
|
||||||
|
this.Write(""Line One\nLine Two\n"");
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 4 """"
|
||||||
|
|
||||||
|
foo
|
||||||
|
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 7 """"
|
||||||
|
this.Write(""Line Three "");
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 7 """"
|
||||||
|
this.Write(global::Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture( bar ));
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 7 """"
|
||||||
|
this.Write(""\nLine Four\n"");
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
return this.GenerationEnvironment.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Initialize() {
|
||||||
|
base.Initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{CB590106-8331-4CBE-8131-B154E7BF79E1}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AssemblyName>Mono.TextTemplating.Tests</AssemblyName>
|
||||||
|
<RootNamespace>Mono.TextTemplating.Tests</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>..\bin</OutputPath>
|
||||||
|
<DefineConstants>DEBUG</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>none</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>..\bin</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="nunit.core">
|
||||||
|
<HintPath>..\NUnit\lib\nunit.core.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="nunit.framework">
|
||||||
|
<HintPath>..\NUnit\lib\nunit.framework.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="ParsingTests.cs" />
|
||||||
|
<Compile Include="DummyHost.cs" />
|
||||||
|
<Compile Include="GenerationTests.cs" />
|
||||||
|
<Compile Include="TemplatingEngineHelper.cs" />
|
||||||
|
<Compile Include="TemplateEnginePreprocessTemplateTests.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Mono.TextTemplating\Mono.TextTemplating.csproj">
|
||||||
|
<Project>{A2364D6A-00EF-417C-80A6-815726C70032}</Project>
|
||||||
|
<Name>Mono.TextTemplating</Name>
|
||||||
|
<Private>False</Private>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -0,0 +1,191 @@
|
||||||
|
//
|
||||||
|
// Test.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating.Tests
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class ParsingTests
|
||||||
|
{
|
||||||
|
public static string ParseSample1 =
|
||||||
|
@"<#@ template language=""C#v3.5"" #>
|
||||||
|
Line One
|
||||||
|
Line Two
|
||||||
|
<#
|
||||||
|
foo
|
||||||
|
#>
|
||||||
|
Line Three <#= bar #>
|
||||||
|
Line Four
|
||||||
|
<#+
|
||||||
|
baz \#>
|
||||||
|
#>
|
||||||
|
";
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TokenTest ()
|
||||||
|
{
|
||||||
|
string tf = "test.input";
|
||||||
|
Tokeniser tk = new Tokeniser (tf, ParseSample1);
|
||||||
|
|
||||||
|
//line 1
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 1, 1), tk.Location);
|
||||||
|
Assert.AreEqual (State.Content, tk.State);
|
||||||
|
Assert.AreEqual ("", tk.Value);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (State.Directive, tk.State);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 1, 5), tk.Location);
|
||||||
|
Assert.AreEqual (State.DirectiveName, tk.State);
|
||||||
|
Assert.AreEqual ("template", tk.Value);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (State.Directive, tk.State);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 1, 14), tk.Location);
|
||||||
|
Assert.AreEqual (State.DirectiveName, tk.State);
|
||||||
|
Assert.AreEqual ("language", tk.Value);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (State.Directive, tk.State);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (State.DirectiveValue, tk.State);
|
||||||
|
Assert.AreEqual (new Location (tf, 1, 23), tk.Location);
|
||||||
|
Assert.AreEqual ("C#v3.5", tk.Value);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (State.Directive, tk.State);
|
||||||
|
|
||||||
|
//line 2, 3
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 2, 1), tk.Location);
|
||||||
|
Assert.AreEqual (State.Content, tk.State);
|
||||||
|
Assert.AreEqual ("Line One\nLine Two\n", tk.Value);
|
||||||
|
|
||||||
|
//line 4, 5, 6
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 4, 1), tk.TagStartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 4, 3), tk.Location);
|
||||||
|
Assert.AreEqual (new Location (tf, 6, 3), tk.TagEndLocation);
|
||||||
|
Assert.AreEqual (State.Block, tk.State);
|
||||||
|
Assert.AreEqual ("\nfoo\n", tk.Value);
|
||||||
|
|
||||||
|
//line 7
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 1), tk.Location);
|
||||||
|
Assert.AreEqual (State.Content, tk.State);
|
||||||
|
Assert.AreEqual ("Line Three ", tk.Value);
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 12), tk.TagStartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 15), tk.Location);
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 22), tk.TagEndLocation);
|
||||||
|
Assert.AreEqual (State.Expression, tk.State);
|
||||||
|
Assert.AreEqual (" bar ", tk.Value);
|
||||||
|
|
||||||
|
//line 8
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 22), tk.Location);
|
||||||
|
Assert.AreEqual (State.Content, tk.State);
|
||||||
|
Assert.AreEqual ("\nLine Four\n", tk.Value);
|
||||||
|
|
||||||
|
//line 9, 10, 11
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 9, 1), tk.TagStartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 9, 4), tk.Location);
|
||||||
|
Assert.AreEqual (new Location (tf, 11, 3), tk.TagEndLocation);
|
||||||
|
Assert.AreEqual (State.Helper, tk.State);
|
||||||
|
Assert.AreEqual (" \nbaz \\#>\n", tk.Value);
|
||||||
|
|
||||||
|
//line 12
|
||||||
|
Assert.IsTrue (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 12, 1), tk.Location);
|
||||||
|
Assert.AreEqual (State.Content, tk.State);
|
||||||
|
Assert.AreEqual ("", tk.Value);
|
||||||
|
|
||||||
|
//EOF
|
||||||
|
Assert.IsFalse (tk.Advance ());
|
||||||
|
Assert.AreEqual (new Location (tf, 12, 1), tk.Location);
|
||||||
|
Assert.AreEqual (State.EOF, tk.State);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ParseTest ()
|
||||||
|
{
|
||||||
|
string tf = "test.input";
|
||||||
|
|
||||||
|
ParsedTemplate pt = new ParsedTemplate ("test.input");
|
||||||
|
Tokeniser tk = new Tokeniser (tf, ParseSample1);
|
||||||
|
DummyHost host = new DummyHost ();
|
||||||
|
pt.Parse (host, tk);
|
||||||
|
|
||||||
|
Assert.AreEqual (0, pt.Errors.Count);
|
||||||
|
var content = new List<TemplateSegment> (pt.Content);
|
||||||
|
var dirs = new List<Directive> (pt.Directives);
|
||||||
|
|
||||||
|
Assert.AreEqual (1, dirs.Count);
|
||||||
|
Assert.AreEqual (6, content.Count);
|
||||||
|
|
||||||
|
Assert.AreEqual ("template", dirs[0].Name);
|
||||||
|
Assert.AreEqual (1, dirs[0].Attributes.Count);
|
||||||
|
Assert.AreEqual ("C#v3.5", dirs[0].Attributes["language"]);
|
||||||
|
Assert.AreEqual (new Location (tf, 1, 1), dirs[0].TagStartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 1, 34), dirs[0].EndLocation);
|
||||||
|
|
||||||
|
Assert.AreEqual ("Line One\nLine Two\n", content[0].Text);
|
||||||
|
Assert.AreEqual ("\nfoo\n", content[1].Text);
|
||||||
|
Assert.AreEqual ("Line Three ", content[2].Text);
|
||||||
|
Assert.AreEqual (" bar ", content[3].Text);
|
||||||
|
Assert.AreEqual ("\nLine Four\n", content[4].Text);
|
||||||
|
Assert.AreEqual (" \nbaz \\#>\n", content[5].Text);
|
||||||
|
|
||||||
|
Assert.AreEqual (SegmentType.Content, content[0].Type);
|
||||||
|
Assert.AreEqual (SegmentType.Block, content[1].Type);
|
||||||
|
Assert.AreEqual (SegmentType.Content, content[2].Type);
|
||||||
|
Assert.AreEqual (SegmentType.Expression, content[3].Type);
|
||||||
|
Assert.AreEqual (SegmentType.Content, content[4].Type);
|
||||||
|
Assert.AreEqual (SegmentType.Helper, content[5].Type);
|
||||||
|
|
||||||
|
Assert.AreEqual (new Location (tf, 4, 1), content[1].TagStartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 12), content[3].TagStartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 9, 1), content[5].TagStartLocation);
|
||||||
|
|
||||||
|
Assert.AreEqual (new Location (tf, 2, 1), content[0].StartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 4, 3), content[1].StartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 1), content[2].StartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 15), content[3].StartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 22), content[4].StartLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 9, 4), content[5].StartLocation);
|
||||||
|
|
||||||
|
Assert.AreEqual (new Location (tf, 6, 3), content[1].EndLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 7, 22), content[3].EndLocation);
|
||||||
|
Assert.AreEqual (new Location (tf, 11, 3), content[5].EndLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,246 @@
|
||||||
|
//
|
||||||
|
// TemplateEnginePreprocessTemplateTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Matt Ward
|
||||||
|
//
|
||||||
|
// Copyright (c) 2010 Matt Ward
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TemplateEnginePreprocessTemplateTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Preprocess ()
|
||||||
|
{
|
||||||
|
string input =
|
||||||
|
"<#@ template language=\"C#\" #>\r\n" +
|
||||||
|
"Test\r\n";
|
||||||
|
|
||||||
|
string expectedOutput = OutputSample1;
|
||||||
|
string output = Preprocess (input);
|
||||||
|
|
||||||
|
Assert.AreEqual (expectedOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
string Preprocess (string input)
|
||||||
|
{
|
||||||
|
DummyHost host = new DummyHost ();
|
||||||
|
string className = "PreprocessedTemplate";
|
||||||
|
string classNamespace = "Templating";
|
||||||
|
string language = null;
|
||||||
|
string[] references = null;
|
||||||
|
|
||||||
|
TemplatingEngine engine = new TemplatingEngine ();
|
||||||
|
string output = engine.PreprocessTemplate (input, host, className, classNamespace, out language, out references);
|
||||||
|
output = output.Replace ("\r\n", "\n");
|
||||||
|
return TemplatingEngineHelper.StripHeader (output, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Expected output strings
|
||||||
|
|
||||||
|
public static string OutputSample1 =
|
||||||
|
@"
|
||||||
|
namespace Templating {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class PreprocessedTemplate : PreprocessedTemplateBase {
|
||||||
|
|
||||||
|
public virtual string TransformText() {
|
||||||
|
this.GenerationEnvironment = null;
|
||||||
|
|
||||||
|
#line 2 """"
|
||||||
|
this.Write(""Test\r\n"");
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
return this.GenerationEnvironment.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Initialize() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PreprocessedTemplateBase {
|
||||||
|
|
||||||
|
private global::System.Text.StringBuilder builder;
|
||||||
|
|
||||||
|
private global::System.Collections.Generic.IDictionary<string, object> session;
|
||||||
|
|
||||||
|
private global::System.CodeDom.Compiler.CompilerErrorCollection errors;
|
||||||
|
|
||||||
|
private string currentIndent = string.Empty;
|
||||||
|
|
||||||
|
private global::System.Collections.Generic.Stack<int> indents;
|
||||||
|
|
||||||
|
private ToStringInstanceHelper _toStringHelper = new ToStringInstanceHelper();
|
||||||
|
|
||||||
|
public virtual global::System.Collections.Generic.IDictionary<string, object> Session {
|
||||||
|
get {
|
||||||
|
return this.session;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this.session = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public global::System.Text.StringBuilder GenerationEnvironment {
|
||||||
|
get {
|
||||||
|
if ((this.builder == null)) {
|
||||||
|
this.builder = new global::System.Text.StringBuilder();
|
||||||
|
}
|
||||||
|
return this.builder;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this.builder = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected global::System.CodeDom.Compiler.CompilerErrorCollection Errors {
|
||||||
|
get {
|
||||||
|
if ((this.errors == null)) {
|
||||||
|
this.errors = new global::System.CodeDom.Compiler.CompilerErrorCollection();
|
||||||
|
}
|
||||||
|
return this.errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CurrentIndent {
|
||||||
|
get {
|
||||||
|
return this.currentIndent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private global::System.Collections.Generic.Stack<int> Indents {
|
||||||
|
get {
|
||||||
|
if ((this.indents == null)) {
|
||||||
|
this.indents = new global::System.Collections.Generic.Stack<int>();
|
||||||
|
}
|
||||||
|
return this.indents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToStringInstanceHelper ToStringHelper {
|
||||||
|
get {
|
||||||
|
return this._toStringHelper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(string message) {
|
||||||
|
this.Errors.Add(new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Warning(string message) {
|
||||||
|
global::System.CodeDom.Compiler.CompilerError val = new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message);
|
||||||
|
val.IsWarning = true;
|
||||||
|
this.Errors.Add(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PopIndent() {
|
||||||
|
if ((this.Indents.Count == 0)) {
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
int lastPos = (this.currentIndent.Length - this.Indents.Pop());
|
||||||
|
string last = this.currentIndent.Substring(lastPos);
|
||||||
|
this.currentIndent = this.currentIndent.Substring(0, lastPos);
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PushIndent(string indent) {
|
||||||
|
this.Indents.Push(indent.Length);
|
||||||
|
this.currentIndent = (this.currentIndent + indent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearIndent() {
|
||||||
|
this.currentIndent = string.Empty;
|
||||||
|
this.Indents.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(string textToAppend) {
|
||||||
|
this.GenerationEnvironment.Append(textToAppend);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(string format, params object[] args) {
|
||||||
|
this.GenerationEnvironment.AppendFormat(format, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteLine(string textToAppend) {
|
||||||
|
this.GenerationEnvironment.Append(this.currentIndent);
|
||||||
|
this.GenerationEnvironment.AppendLine(textToAppend);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteLine(string format, params object[] args) {
|
||||||
|
this.GenerationEnvironment.Append(this.currentIndent);
|
||||||
|
this.GenerationEnvironment.AppendFormat(format, args);
|
||||||
|
this.GenerationEnvironment.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ToStringInstanceHelper {
|
||||||
|
|
||||||
|
private global::System.IFormatProvider formatProvider = global::System.Globalization.CultureInfo.InvariantCulture;
|
||||||
|
|
||||||
|
public global::System.IFormatProvider FormatProvider {
|
||||||
|
get {
|
||||||
|
return this.formatProvider;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if ((this.formatProvider == null)) {
|
||||||
|
throw new global::System.ArgumentNullException(""formatProvider"");
|
||||||
|
}
|
||||||
|
this.formatProvider = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ToStringWithCulture(object objectToConvert) {
|
||||||
|
if ((objectToConvert == null)) {
|
||||||
|
throw new global::System.ArgumentNullException(""objectToConvert"");
|
||||||
|
}
|
||||||
|
global::System.Type type = objectToConvert.GetType();
|
||||||
|
global::System.Type iConvertibleType = typeof(global::System.IConvertible);
|
||||||
|
if (iConvertibleType.IsAssignableFrom(type)) {
|
||||||
|
return ((global::System.IConvertible)(objectToConvert)).ToString(this.formatProvider);
|
||||||
|
}
|
||||||
|
global::System.Reflection.MethodInfo methInfo = type.GetMethod(""ToString"", new global::System.Type[] {
|
||||||
|
iConvertibleType});
|
||||||
|
if ((methInfo != null)) {
|
||||||
|
return ((string)(methInfo.Invoke(objectToConvert, new object[] {
|
||||||
|
this.formatProvider})));
|
||||||
|
}
|
||||||
|
return objectToConvert.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
//
|
||||||
|
// Test.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating.Tests
|
||||||
|
{
|
||||||
|
public static class TemplatingEngineHelper
|
||||||
|
{
|
||||||
|
public static string StripHeader (string input, string newLine)
|
||||||
|
{
|
||||||
|
using (var writer = new StringWriter ()) {
|
||||||
|
using (var reader = new StringReader (input)) {
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
reader.ReadLine ();
|
||||||
|
}
|
||||||
|
string line;
|
||||||
|
while ((line = reader.ReadLine ()) != null) {
|
||||||
|
writer.Write (line);
|
||||||
|
writer.Write (newLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return writer.ToString ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
//
|
||||||
|
// AssemblyInfo.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("Mono.TextTemplating")]
|
||||||
|
[assembly: AssemblyDescription("An implementation of Visual Studio's T4 text templating")]
|
||||||
|
[assembly: AssemblyCompany("The Mono Project")]
|
||||||
|
[assembly: AssemblyProduct("MonoDevelop")]
|
||||||
|
[assembly: AssemblyCopyright("MIT/X11")]
|
||||||
|
[assembly: CLSCompliant (true)]
|
||||||
|
|
||||||
|
//[assembly: AssemblyVersion("1.0.0.0")]
|
|
@ -0,0 +1,212 @@
|
||||||
|
2010-03-15 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplateGenerator.cs: Expose OutputFile
|
||||||
|
for custom tool to access.
|
||||||
|
|
||||||
|
2010-03-01 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/CrossAppDomainAssemblyResolver.cs: A
|
||||||
|
handler for AssemblyResolve events that looks them up in the
|
||||||
|
domain that created the resolver.
|
||||||
|
|
||||||
|
* Makefile.am:
|
||||||
|
* Mono.TextTemplating.csproj: Added file.
|
||||||
|
|
||||||
|
2009-11-27 Olivier Dagenais <olivier.dagenais@gmail.com>
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Fixed a bug where the
|
||||||
|
location of an error was being ignored.
|
||||||
|
|
||||||
|
2009-11-27 Olivier Dagenais <olivier.dagenais@gmail.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplatingEngine.cs: Mark the generated
|
||||||
|
type as partial.
|
||||||
|
|
||||||
|
2009-11-25 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Don't check if
|
||||||
|
included file exists before trying to resolve it from the
|
||||||
|
host, because host may use include paths. Patch from Aaron
|
||||||
|
Bockover.
|
||||||
|
|
||||||
|
2009-08-17 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplatingEngine.cs: Fix NRE when
|
||||||
|
template fails to compile.
|
||||||
|
|
||||||
|
2009-08-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Makefile.am:
|
||||||
|
* Mono.TextTemplating.csproj: Include the ASP.NET MVC and
|
||||||
|
TextTemplating addins in the main solution and build.
|
||||||
|
|
||||||
|
2009-08-11 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.csproj:
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs:
|
||||||
|
* Mono.TextTemplating/CompiledTemplate.cs:
|
||||||
|
* Mono.TextTemplating/TemplatingEngine.cs:
|
||||||
|
* Mono.TextTemplating/TemplateGenerator.cs:
|
||||||
|
* Mono.TextTemplating/IExtendedTextTemplatingEngineHost.cs:
|
||||||
|
Add support for caching compiled templates, and a couple of
|
||||||
|
bugfixes. Patch from Nathan Baulch
|
||||||
|
(nathan.baulch@gmail.com).
|
||||||
|
|
||||||
|
2009-06-25 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplatingEngine.cs: Handle expressions
|
||||||
|
and content in helpers, based on patch from Nathan Baulch.
|
||||||
|
Liberally add C# 3 sugar to neaten up CodeDOM usage.
|
||||||
|
|
||||||
|
2009-06-25 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplateGenerator.cs: Added overload for
|
||||||
|
Process template that uses input/output strings directly,
|
||||||
|
avoiding file read/write. Expose engine to subclasses.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs: Remove outdated TODO.
|
||||||
|
|
||||||
|
2009-04-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/ToStringHelper.cs: Use
|
||||||
|
IConvertible.ToString (formatProvider) when possible.
|
||||||
|
|
||||||
|
Thanks to Stuart Carnie for this patch.
|
||||||
|
|
||||||
|
2009-04-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs: Add support for Mac and
|
||||||
|
Windows newlines.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplatingEngine.cs: Keep temp files
|
||||||
|
when in debug mode, so that the generated code can be
|
||||||
|
debugged.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Fixes for csc
|
||||||
|
compilation.
|
||||||
|
|
||||||
|
Thanks to Stuart Carnie for this patch.
|
||||||
|
|
||||||
|
2009-04-03 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.csproj:
|
||||||
|
* Mono.TextTemplating/TemplatingEngine.cs:
|
||||||
|
* Mono.TextTemplating/TemplateSettings.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/Engine.cs: Move the
|
||||||
|
real engine into the Mono.TextTemplating namespace and
|
||||||
|
expose helper methods so that they can be tested.
|
||||||
|
|
||||||
|
2009-03-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.csproj: Move output dir from ../bin to
|
||||||
|
../build.
|
||||||
|
|
||||||
|
2009-03-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs: Tweaked location of next
|
||||||
|
state after directive.
|
||||||
|
|
||||||
|
2009-03-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs: Location tweaks within
|
||||||
|
directives.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Make Location
|
||||||
|
equatable.
|
||||||
|
|
||||||
|
2009-03-10 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs:
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Fix end location
|
||||||
|
capture after newline handling changes.
|
||||||
|
|
||||||
|
2009-03-10 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/Engine.cs: Match T4's
|
||||||
|
newline handling.
|
||||||
|
|
||||||
|
2009-03-10 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Fix logic that
|
||||||
|
prevented adding directives.
|
||||||
|
|
||||||
|
2009-03-09 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs:
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: More accurate
|
||||||
|
location captures. Capture start of tags as well as start of
|
||||||
|
content.
|
||||||
|
|
||||||
|
2009-03-09 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplateGenerator.cs: Report exceptions
|
||||||
|
in errors.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs: Make API public.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Unify segment types.
|
||||||
|
Track end locations. Make API public. Allow parsing without
|
||||||
|
includes.
|
||||||
|
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/Engine.cs: Track
|
||||||
|
location API.
|
||||||
|
|
||||||
|
2009-03-06 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplateGenerator.cs: Fix
|
||||||
|
SetFileExtension.
|
||||||
|
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/Engine.cs: Capture
|
||||||
|
hostspecific attribute from template directive.
|
||||||
|
|
||||||
|
2009-03-05 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplateGenerator.cs: Fix output
|
||||||
|
extension changing.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs: Fix helper regions.
|
||||||
|
|
||||||
|
2009-03-05 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Mono.TextTemplating.csproj: Updated.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/TemplateGenerator.cs: Simple template
|
||||||
|
host implementation. Doesn't handle everything yet.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs: Fix a number of offset
|
||||||
|
issues that broke most captures. Only allow EOF in content
|
||||||
|
regions, and in this case capture the last content. Track
|
||||||
|
current column, for error reporting.
|
||||||
|
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs: Overhaul location
|
||||||
|
tracking for error reporting. Don't record empty segments.
|
||||||
|
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/Engine.cs: Use run
|
||||||
|
method instead of runner, since the whole thing's done in
|
||||||
|
the appdomain now. Catch errors from the runner. Use host's
|
||||||
|
default assemblies and imports. Track ParsedTemplate error
|
||||||
|
reporting changes. Filter out content regions with only a
|
||||||
|
single newline.
|
||||||
|
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/ToStringHelper.cs:
|
||||||
|
Don't cache delegates; this won't work for instances. Maybe
|
||||||
|
IL generation is called for.
|
||||||
|
|
||||||
|
2009-03-04 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* AssemblyInfo.cs:
|
||||||
|
* Mono.TextTemplating:
|
||||||
|
* Mono.TextTemplating.csproj:
|
||||||
|
* Mono.TextTemplating/Tokeniser.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating:
|
||||||
|
* Mono.TextTemplating/ParsedTemplate.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/Engine.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/ToStringHelper.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/DirectiveProcessor.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/TextTransformation.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/ITextTemplatingEngineHost.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/DirectiveProcessorException.cs:
|
||||||
|
* Microsoft.VisualStudio.TextTemplating/RequiresProvidesDirectiveProcessor.cs:
|
||||||
|
Move T4 implementation to its own assembly. Tweak some
|
||||||
|
appdomain stuff.
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
ADDIN_BUILD = $(top_builddir)/build/AddIns/MonoDevelop.TextTemplating
|
||||||
|
ASSEMBLY = $(ADDIN_BUILD)/Mono.TextTemplating.dll
|
||||||
|
|
||||||
|
DEPS =
|
||||||
|
|
||||||
|
REFS = \
|
||||||
|
-r:System \
|
||||||
|
-r:System.Core
|
||||||
|
|
||||||
|
FILES = \
|
||||||
|
AssemblyInfo.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/AssemblyCacheMonitor.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/DirectiveProcessor.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/DirectiveProcessorException.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/EncodingHelper.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/Engine.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/Interfaces.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/ParameterDirectiveProcessor.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/RequiresProvidesDirectiveProcessor.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/TextTemplatingSession.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/TextTransformation.cs \
|
||||||
|
Microsoft.VisualStudio.TextTemplating/ToStringHelper.cs \
|
||||||
|
Mono.TextTemplating/CompiledTemplate.cs \
|
||||||
|
Mono.TextTemplating/CrossAppDomainAssemblyResolver.cs \
|
||||||
|
Mono.TextTemplating/ParsedTemplate.cs \
|
||||||
|
Mono.TextTemplating/TemplateGenerator.cs \
|
||||||
|
Mono.TextTemplating/TemplateSettings.cs \
|
||||||
|
Mono.TextTemplating/TemplatingEngine.cs \
|
||||||
|
Mono.TextTemplating/Tokeniser.cs
|
||||||
|
|
||||||
|
RES =
|
||||||
|
|
||||||
|
all: $(ASSEMBLY) $(ASSEMBLY).mdb $(DATA_FILE_BUILD)
|
||||||
|
|
||||||
|
$(ASSEMBLY): $(build_sources) $(build_resources) $(DEPS)
|
||||||
|
mkdir -p $(ADDIN_BUILD)
|
||||||
|
$(CSC) $(CSC_FLAGS) -debug -out:$@ -target:library $(REFS) $(build_deps) \
|
||||||
|
$(build_resources:%=/resource:%) $(build_sources)
|
||||||
|
|
||||||
|
$(ASSEMBLY).mdb: $(ASSEMBLY)
|
||||||
|
|
||||||
|
$(DATA_FILE_BUILD): $(srcdir)$(subst $(ADDIN_BUILD),, $@)
|
||||||
|
mkdir -p $(ADDIN_BUILD)/Schemas
|
||||||
|
cp $(srcdir)/$(subst $(ADDIN_BUILD),,$@) $@
|
||||||
|
|
||||||
|
check: all
|
||||||
|
|
||||||
|
assemblydir = $(MD_ADDIN_DIR)/MonoDevelop.TextTemplating
|
||||||
|
assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb
|
||||||
|
|
||||||
|
CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb
|
||||||
|
EXTRA_DIST = $(FILES) $(RES)
|
||||||
|
|
||||||
|
include $(top_srcdir)/Makefile.include
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
//
|
||||||
|
// AssemblyCacheMonitor.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2010 Novell, Inc.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public sealed class AssemblyCacheMonitor : MarshalByRefObject
|
||||||
|
{
|
||||||
|
public AssemblyCacheMonitor ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStaleAssembliesCount (TimeSpan assemblyStaleTime)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
//
|
||||||
|
// DirectiveProcessor.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public abstract class DirectiveProcessor
|
||||||
|
{
|
||||||
|
protected DirectiveProcessor ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Initialize (ITextTemplatingEngineHost host)
|
||||||
|
{
|
||||||
|
if (host == null)
|
||||||
|
throw new ArgumentNullException ("host");
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void StartProcessingRun (CodeDomProvider languageProvider, string templateContents, CompilerErrorCollection errors)
|
||||||
|
{
|
||||||
|
if (languageProvider == null)
|
||||||
|
throw new ArgumentNullException ("languageProvider");
|
||||||
|
this.Errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void FinishProcessingRun ();
|
||||||
|
public abstract string GetClassCodeForProcessingRun ();
|
||||||
|
public abstract string[] GetImportsForProcessingRun ();
|
||||||
|
public abstract string GetPostInitializationCodeForProcessingRun ();
|
||||||
|
public abstract string GetPreInitializationCodeForProcessingRun ();
|
||||||
|
public abstract string[] GetReferencesForProcessingRun ();
|
||||||
|
public abstract bool IsDirectiveSupported (string directiveName);
|
||||||
|
public abstract void ProcessDirective (string directiveName, IDictionary<string, string> arguments);
|
||||||
|
|
||||||
|
protected CompilerErrorCollection Errors { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
//
|
||||||
|
// DirectiveProcessorException.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class DirectiveProcessorException : Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public DirectiveProcessorException ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirectiveProcessorException (string message)
|
||||||
|
: base (message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirectiveProcessorException (SerializationInfo info, StreamingContext context)
|
||||||
|
: base (info, context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirectiveProcessorException (string message, Exception inner)
|
||||||
|
: base (message, inner)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// EncodingHelper.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2010 Novell, Inc.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public static class EncodingHelper
|
||||||
|
{
|
||||||
|
public static Encoding GetEncoding (string filePath)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
//
|
||||||
|
// Engine.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.CodeDom;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using Mono.TextTemplating;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public class Engine : ITextTemplatingEngine
|
||||||
|
{
|
||||||
|
TemplatingEngine engine = new TemplatingEngine ();
|
||||||
|
|
||||||
|
public Engine ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ProcessTemplate (string content, ITextTemplatingEngineHost host)
|
||||||
|
{
|
||||||
|
return engine.ProcessTemplate (content, host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PreprocessTemplate (string content, ITextTemplatingEngineHost host, string className,
|
||||||
|
string classNamespace, out string language, out string[] references)
|
||||||
|
{
|
||||||
|
return engine.PreprocessTemplate (content, host, className, classNamespace, out language, out references);
|
||||||
|
}
|
||||||
|
|
||||||
|
public const string CacheAssembliesOptionString = "CacheAssemblies";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
//
|
||||||
|
// ITextTemplatingEngineHost.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009-2010 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public interface IRecognizeHostSpecific
|
||||||
|
{
|
||||||
|
void SetProcessingRunIsHostSpecific (bool hostSpecific);
|
||||||
|
bool RequiresProcessingRunIsHostSpecific { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[CLSCompliant(true)]
|
||||||
|
public interface ITextTemplatingEngine
|
||||||
|
{
|
||||||
|
string ProcessTemplate (string content, ITextTemplatingEngineHost host);
|
||||||
|
string PreprocessTemplate (string content, ITextTemplatingEngineHost host, string className,
|
||||||
|
string classNamespace, out string language, out string[] references);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CLSCompliant(true)]
|
||||||
|
public interface ITextTemplatingEngineHost
|
||||||
|
{
|
||||||
|
object GetHostOption (string optionName);
|
||||||
|
bool LoadIncludeText (string requestFileName, out string content, out string location);
|
||||||
|
void LogErrors (CompilerErrorCollection errors);
|
||||||
|
AppDomain ProvideTemplatingAppDomain (string content);
|
||||||
|
string ResolveAssemblyReference (string assemblyReference);
|
||||||
|
Type ResolveDirectiveProcessor (string processorName);
|
||||||
|
string ResolveParameterValue (string directiveId, string processorName, string parameterName);
|
||||||
|
string ResolvePath (string path);
|
||||||
|
void SetFileExtension (string extension);
|
||||||
|
void SetOutputEncoding (Encoding encoding, bool fromOutputDirective);
|
||||||
|
IList<string> StandardAssemblyReferences { get; }
|
||||||
|
IList<string> StandardImports { get; }
|
||||||
|
string TemplateFile { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[CLSCompliant(true)]
|
||||||
|
public interface ITextTemplatingSession :
|
||||||
|
IEquatable<ITextTemplatingSession>, IEquatable<Guid>, IDictionary<string, Object>,
|
||||||
|
ICollection<KeyValuePair<string, Object>>,
|
||||||
|
IEnumerable<KeyValuePair<string, Object>>,
|
||||||
|
IEnumerable, ISerializable
|
||||||
|
{
|
||||||
|
Guid Id { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[CLSCompliant(true)]
|
||||||
|
public interface ITextTemplatingSessionHost
|
||||||
|
{
|
||||||
|
ITextTemplatingSession CreateSession ();
|
||||||
|
ITextTemplatingSession Session { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,268 @@
|
||||||
|
//
|
||||||
|
// ParameterDirectiveProcessor.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2010 Novell, Inc.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.CodeDom;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public sealed class ParameterDirectiveProcessor : DirectiveProcessor, IRecognizeHostSpecific
|
||||||
|
{
|
||||||
|
CodeDomProvider provider;
|
||||||
|
bool isCSharp;
|
||||||
|
bool useMonoHack;
|
||||||
|
|
||||||
|
bool hostSpecific;
|
||||||
|
List<CodeStatement> postStatements = new List<CodeStatement> ();
|
||||||
|
CodeTypeMemberCollection members = new CodeTypeMemberCollection ();
|
||||||
|
|
||||||
|
public ParameterDirectiveProcessor ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void StartProcessingRun (CodeDomProvider languageProvider, string templateContents, CompilerErrorCollection errors)
|
||||||
|
{
|
||||||
|
base.StartProcessingRun (languageProvider, templateContents, errors);
|
||||||
|
this.provider = languageProvider;
|
||||||
|
//HACK: Mono as of 2.10.2 doesn't implement GenerateCodeFromMember
|
||||||
|
if (Type.GetType ("Mono.Runtime") != null)
|
||||||
|
useMonoHack = true;
|
||||||
|
if (languageProvider is Microsoft.CSharp.CSharpCodeProvider)
|
||||||
|
isCSharp = true;
|
||||||
|
postStatements.Clear ();
|
||||||
|
members.Clear ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FinishProcessingRun ()
|
||||||
|
{
|
||||||
|
var statement = new CodeConditionStatement (
|
||||||
|
new CodeBinaryOperatorExpression (
|
||||||
|
new CodePropertyReferenceExpression (
|
||||||
|
new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "Errors"), "HasErrors"),
|
||||||
|
CodeBinaryOperatorType.ValueEquality,
|
||||||
|
new CodePrimitiveExpression (false)),
|
||||||
|
postStatements.ToArray ());
|
||||||
|
|
||||||
|
postStatements.Clear ();
|
||||||
|
postStatements.Add (statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetClassCodeForProcessingRun ()
|
||||||
|
{
|
||||||
|
var options = new CodeGeneratorOptions ();
|
||||||
|
using (var sw = new StringWriter ()) {
|
||||||
|
GenerateCodeFromMembers (sw, options);
|
||||||
|
return Indent (sw.ToString (), " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string Indent (string s, string indent)
|
||||||
|
{
|
||||||
|
if (isCSharp)
|
||||||
|
return Mono.TextTemplating.TemplatingEngine.IndentSnippetText (s, indent);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] GetImportsForProcessingRun ()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetPostInitializationCodeForProcessingRun ()
|
||||||
|
{
|
||||||
|
return Indent (StatementsToCode (postStatements), " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetPreInitializationCodeForProcessingRun ()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string StatementsToCode (List<CodeStatement> statements)
|
||||||
|
{
|
||||||
|
var options = new CodeGeneratorOptions ();
|
||||||
|
using (var sw = new StringWriter ()) {
|
||||||
|
foreach (var statement in statements)
|
||||||
|
provider.GenerateCodeFromStatement (statement, sw, options);
|
||||||
|
return sw.ToString ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] GetReferencesForProcessingRun ()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsDirectiveSupported (string directiveName)
|
||||||
|
{
|
||||||
|
return directiveName == "parameter";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ProcessDirective (string directiveName, IDictionary<string, string> arguments)
|
||||||
|
{
|
||||||
|
string name = arguments["name"];
|
||||||
|
string type = arguments["type"];
|
||||||
|
if (string.IsNullOrEmpty (name))
|
||||||
|
throw new DirectiveProcessorException ("Parameter directive has no name argument");
|
||||||
|
if (string.IsNullOrEmpty (type))
|
||||||
|
throw new DirectiveProcessorException ("Parameter directive has no type argument");
|
||||||
|
|
||||||
|
string fieldName = "_" + name + "Field";
|
||||||
|
var typeRef = new CodeTypeReference (type);
|
||||||
|
var thisRef = new CodeThisReferenceExpression ();
|
||||||
|
var fieldRef = new CodeFieldReferenceExpression (thisRef, fieldName);
|
||||||
|
|
||||||
|
var property = new CodeMemberProperty () {
|
||||||
|
Name = name,
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
HasGet = true,
|
||||||
|
HasSet = false,
|
||||||
|
Type = typeRef
|
||||||
|
};
|
||||||
|
property.GetStatements.Add (new CodeMethodReturnStatement (fieldRef));
|
||||||
|
members.Add (new CodeMemberField (typeRef, fieldName));
|
||||||
|
members.Add (property);
|
||||||
|
|
||||||
|
string acquiredName = "_" + name + "Acquired";
|
||||||
|
var valRef = new CodeVariableReferenceExpression ("data");
|
||||||
|
var namePrimitive = new CodePrimitiveExpression (name);
|
||||||
|
var sessionRef = new CodePropertyReferenceExpression (thisRef, "Session");
|
||||||
|
var callContextTypeRefExpr = new CodeTypeReferenceExpression ("System.Runtime.Remoting.Messaging.CallContext");
|
||||||
|
var nullPrim = new CodePrimitiveExpression (null);
|
||||||
|
|
||||||
|
var acquiredVariable = new CodeVariableDeclarationStatement (typeof (bool), acquiredName, new CodePrimitiveExpression (false));
|
||||||
|
var acquiredVariableRef = new CodeVariableReferenceExpression (acquiredVariable.Name);
|
||||||
|
this.postStatements.Add (acquiredVariable);
|
||||||
|
|
||||||
|
//checks the local called "data" can be cast and assigned to the field, and if successful, sets acquiredVariable to true
|
||||||
|
var checkCastThenAssignVal = new CodeConditionStatement (
|
||||||
|
new CodeMethodInvokeExpression (
|
||||||
|
new CodeTypeOfExpression (typeRef), "IsAssignableFrom", new CodeMethodInvokeExpression (valRef, "GetType")),
|
||||||
|
new CodeStatement[] {
|
||||||
|
new CodeAssignStatement (fieldRef, new CodeCastExpression (typeRef, valRef)),
|
||||||
|
new CodeAssignStatement (acquiredVariableRef, new CodePrimitiveExpression (true)),
|
||||||
|
},
|
||||||
|
new CodeStatement[] {
|
||||||
|
new CodeExpressionStatement (new CodeMethodInvokeExpression (thisRef, "Error",
|
||||||
|
new CodePrimitiveExpression ("The type '" + type + "' of the parameter '" + name +
|
||||||
|
"' did not match the type passed to the template"))),
|
||||||
|
});
|
||||||
|
|
||||||
|
//tries to gets the value from the session
|
||||||
|
var checkSession = new CodeConditionStatement (
|
||||||
|
new CodeBinaryOperatorExpression (NotNull (sessionRef), CodeBinaryOperatorType.BooleanAnd,
|
||||||
|
new CodeMethodInvokeExpression (sessionRef, "ContainsKey", namePrimitive)),
|
||||||
|
new CodeVariableDeclarationStatement (typeof (object), "data", new CodeIndexerExpression (sessionRef, namePrimitive)),
|
||||||
|
checkCastThenAssignVal);
|
||||||
|
|
||||||
|
this.postStatements.Add (checkSession);
|
||||||
|
|
||||||
|
//if acquiredVariable is false, tries to gets the value from the host
|
||||||
|
if (hostSpecific) {
|
||||||
|
var hostRef = new CodePropertyReferenceExpression (thisRef, "Host");
|
||||||
|
var checkHost = new CodeConditionStatement (
|
||||||
|
BooleanAnd (IsFalse (acquiredVariableRef), NotNull (hostRef)),
|
||||||
|
new CodeVariableDeclarationStatement (typeof (string), "data",
|
||||||
|
new CodeMethodInvokeExpression (hostRef, "ResolveParameterValue", nullPrim, nullPrim, namePrimitive)),
|
||||||
|
new CodeConditionStatement (NotNull (valRef), checkCastThenAssignVal));
|
||||||
|
|
||||||
|
this.postStatements.Add (checkHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if acquiredVariable is false, tries to gets the value from the call context
|
||||||
|
var checkCallContext = new CodeConditionStatement (
|
||||||
|
IsFalse (acquiredVariableRef),
|
||||||
|
new CodeVariableDeclarationStatement (typeof (object), "data",
|
||||||
|
new CodeMethodInvokeExpression (callContextTypeRefExpr, "LogicalGetData", namePrimitive)),
|
||||||
|
new CodeConditionStatement (NotNull (valRef), checkCastThenAssignVal));
|
||||||
|
|
||||||
|
this.postStatements.Add (checkCallContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeBinaryOperatorExpression NotNull (CodeExpression reference)
|
||||||
|
{
|
||||||
|
return new CodeBinaryOperatorExpression (reference, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression (null));
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeBinaryOperatorExpression IsFalse (CodeExpression expr)
|
||||||
|
{
|
||||||
|
return new CodeBinaryOperatorExpression (expr, CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression (false));
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeBinaryOperatorExpression BooleanAnd (CodeExpression expr1, CodeExpression expr2)
|
||||||
|
{
|
||||||
|
return new CodeBinaryOperatorExpression (expr1, CodeBinaryOperatorType.BooleanAnd, expr2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRecognizeHostSpecific.SetProcessingRunIsHostSpecific (bool hostSpecific)
|
||||||
|
{
|
||||||
|
this.hostSpecific = hostSpecific;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RequiresProcessingRunIsHostSpecific {
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateCodeFromMembers (StringWriter sw, CodeGeneratorOptions options)
|
||||||
|
{
|
||||||
|
if (!useMonoHack) {
|
||||||
|
foreach (CodeTypeMember member in members)
|
||||||
|
provider.GenerateCodeFromMember (member, sw, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
var cgType = typeof (CodeGenerator);
|
||||||
|
var cgInit = cgType.GetMethod ("InitOutput", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
var cgFieldGen = cgType.GetMethod ("GenerateField", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
var cgPropGen = cgType.GetMethod ("GenerateProperty", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
|
||||||
|
#pragma warning disable 0618
|
||||||
|
var generator = (CodeGenerator) provider.CreateGenerator ();
|
||||||
|
#pragma warning restore 0618
|
||||||
|
var dummy = new CodeTypeDeclaration ("Foo");
|
||||||
|
|
||||||
|
foreach (CodeTypeMember member in members) {
|
||||||
|
var f = member as CodeMemberField;
|
||||||
|
if (f != null) {
|
||||||
|
cgInit.Invoke (generator, new object[] { sw, options });
|
||||||
|
cgFieldGen.Invoke (generator, new object[] { f });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var p = member as CodeMemberProperty;
|
||||||
|
if (p != null) {
|
||||||
|
cgInit.Invoke (generator, new object[] { sw, options });
|
||||||
|
cgPropGen.Invoke (generator, new object[] { p, dummy });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,196 @@
|
||||||
|
//
|
||||||
|
// RequiresProvidesDirectiveProcessor.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class RequiresProvidesDirectiveProcessor : DirectiveProcessor
|
||||||
|
{
|
||||||
|
bool isInProcessingRun;
|
||||||
|
ITextTemplatingEngineHost host;
|
||||||
|
StringBuilder preInitBuffer = new StringBuilder ();
|
||||||
|
StringBuilder postInitBuffer = new StringBuilder ();
|
||||||
|
StringBuilder codeBuffer = new StringBuilder ();
|
||||||
|
CodeDomProvider languageProvider;
|
||||||
|
|
||||||
|
protected RequiresProvidesDirectiveProcessor ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize (ITextTemplatingEngineHost host)
|
||||||
|
{
|
||||||
|
base.Initialize (host);
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void InitializeProvidesDictionary (string directiveName, IDictionary<string, string> providesDictionary);
|
||||||
|
protected abstract void InitializeRequiresDictionary (string directiveName, IDictionary<string, string> requiresDictionary);
|
||||||
|
protected abstract string FriendlyName { get; }
|
||||||
|
|
||||||
|
protected abstract void GeneratePostInitializationCode (string directiveName, StringBuilder codeBuffer, CodeDomProvider languageProvider,
|
||||||
|
IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments);
|
||||||
|
protected abstract void GeneratePreInitializationCode (string directiveName, StringBuilder codeBuffer, CodeDomProvider languageProvider,
|
||||||
|
IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments);
|
||||||
|
protected abstract void GenerateTransformCode (string directiveName, StringBuilder codeBuffer, CodeDomProvider languageProvider,
|
||||||
|
IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments);
|
||||||
|
|
||||||
|
protected virtual void PostProcessArguments (string directiveName, IDictionary<string, string> requiresArguments,
|
||||||
|
IDictionary<string, string> providesArguments)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetClassCodeForProcessingRun ()
|
||||||
|
{
|
||||||
|
AssertNotProcessing ();
|
||||||
|
return codeBuffer.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] GetImportsForProcessingRun ()
|
||||||
|
{
|
||||||
|
AssertNotProcessing ();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] GetReferencesForProcessingRun ()
|
||||||
|
{
|
||||||
|
AssertNotProcessing ();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetPostInitializationCodeForProcessingRun ()
|
||||||
|
{
|
||||||
|
AssertNotProcessing ();
|
||||||
|
return postInitBuffer.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetPreInitializationCodeForProcessingRun ()
|
||||||
|
{
|
||||||
|
AssertNotProcessing ();
|
||||||
|
return preInitBuffer.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void StartProcessingRun (CodeDomProvider languageProvider, string templateContents, CompilerErrorCollection errors)
|
||||||
|
{
|
||||||
|
AssertNotProcessing ();
|
||||||
|
isInProcessingRun = true;
|
||||||
|
base.StartProcessingRun (languageProvider, templateContents, errors);
|
||||||
|
|
||||||
|
this.languageProvider = languageProvider;
|
||||||
|
codeBuffer.Length = 0;
|
||||||
|
preInitBuffer.Length = 0;
|
||||||
|
postInitBuffer.Length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FinishProcessingRun ()
|
||||||
|
{
|
||||||
|
isInProcessingRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertNotProcessing ()
|
||||||
|
{
|
||||||
|
if (isInProcessingRun)
|
||||||
|
throw new InvalidOperationException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME: handle escaping
|
||||||
|
IEnumerable<KeyValuePair<string,string>> ParseArgs (string args)
|
||||||
|
{
|
||||||
|
var pairs = args.Split (';');
|
||||||
|
foreach (var p in pairs) {
|
||||||
|
int eq = p.IndexOf ('=');
|
||||||
|
var k = p.Substring (0, eq);
|
||||||
|
var v = p.Substring (eq);
|
||||||
|
yield return new KeyValuePair<string, string> (k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ProcessDirective (string directiveName, IDictionary<string, string> arguments)
|
||||||
|
{
|
||||||
|
if (directiveName == null)
|
||||||
|
throw new ArgumentNullException ("directiveName");
|
||||||
|
if (arguments == null)
|
||||||
|
throw new ArgumentNullException ("arguments");
|
||||||
|
|
||||||
|
var providesDictionary = new Dictionary<string,string> ();
|
||||||
|
var requiresDictionary = new Dictionary<string,string> ();
|
||||||
|
|
||||||
|
string provides;
|
||||||
|
if (arguments.TryGetValue ("provides", out provides)) {
|
||||||
|
foreach (var arg in ParseArgs (provides)) {
|
||||||
|
providesDictionary.Add (arg.Key, arg.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string requires;
|
||||||
|
if (arguments.TryGetValue ("requires", out requires)) {
|
||||||
|
foreach (var arg in ParseArgs (requires)) {
|
||||||
|
requiresDictionary.Add (arg.Key, arg.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InitializeRequiresDictionary (directiveName, requiresDictionary);
|
||||||
|
InitializeProvidesDictionary (directiveName, providesDictionary);
|
||||||
|
|
||||||
|
var id = ProvideUniqueId (directiveName, arguments, requiresDictionary, providesDictionary);
|
||||||
|
|
||||||
|
foreach (var req in requiresDictionary) {
|
||||||
|
var val = host.ResolveParameterValue (id, FriendlyName, req.Key);
|
||||||
|
if (val != null)
|
||||||
|
requiresDictionary[req.Key] = val;
|
||||||
|
else if (req.Value == null)
|
||||||
|
throw new DirectiveProcessorException ("Could not resolve required value '" + req.Key + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var req in providesDictionary) {
|
||||||
|
var val = host.ResolveParameterValue (id, FriendlyName, req.Key);
|
||||||
|
if (val != null)
|
||||||
|
providesDictionary[req.Key] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
PostProcessArguments (directiveName, requiresDictionary, providesDictionary);
|
||||||
|
|
||||||
|
GeneratePreInitializationCode (directiveName, preInitBuffer, languageProvider, requiresDictionary, providesDictionary);
|
||||||
|
GeneratePostInitializationCode (directiveName, postInitBuffer, languageProvider, requiresDictionary, providesDictionary);
|
||||||
|
GenerateTransformCode (directiveName, codeBuffer, languageProvider, requiresDictionary, providesDictionary);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual string ProvideUniqueId (string directiveName, IDictionary<string, string> arguments,
|
||||||
|
IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments)
|
||||||
|
{
|
||||||
|
return directiveName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITextTemplatingEngineHost Host {
|
||||||
|
get { return host; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
//
|
||||||
|
// TextTemplatingSession.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2010 Novell, Inc.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public sealed class TextTemplatingSession : Dictionary<string, Object>, ITextTemplatingSession
|
||||||
|
{
|
||||||
|
public TextTemplatingSession () : this (Guid.NewGuid ())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextTemplatingSession (Guid id)
|
||||||
|
{
|
||||||
|
this.Id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Guid Id {
|
||||||
|
get; private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode ()
|
||||||
|
{
|
||||||
|
return Id.GetHashCode ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals (object obj)
|
||||||
|
{
|
||||||
|
var o = obj as TextTemplatingSession;
|
||||||
|
return o != null && o.Equals (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals (Guid other)
|
||||||
|
{
|
||||||
|
return other.Equals (Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals (ITextTemplatingSession other)
|
||||||
|
{
|
||||||
|
return other != null && other.Id == this.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,219 @@
|
||||||
|
//
|
||||||
|
// TextTransformation.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public abstract class TextTransformation : IDisposable
|
||||||
|
{
|
||||||
|
Stack<int> indents;
|
||||||
|
string currentIndent = string.Empty;
|
||||||
|
CompilerErrorCollection errors;
|
||||||
|
StringBuilder builder;
|
||||||
|
bool endsWithNewline;
|
||||||
|
|
||||||
|
public TextTransformation ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected internal virtual void Initialize ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract string TransformText ();
|
||||||
|
|
||||||
|
public virtual IDictionary<string, object> Session { get; set; }
|
||||||
|
|
||||||
|
#region Errors
|
||||||
|
|
||||||
|
public void Error (string message)
|
||||||
|
{
|
||||||
|
Errors.Add (new CompilerError (null, -1, -1, null, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Warning (string message)
|
||||||
|
{
|
||||||
|
var err = new CompilerError (null, -1, -1, null, message) {
|
||||||
|
IsWarning = true,
|
||||||
|
};
|
||||||
|
Errors.Add (err);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected internal CompilerErrorCollection Errors {
|
||||||
|
get {
|
||||||
|
if (errors == null)
|
||||||
|
errors = new CompilerErrorCollection ();
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Stack<int> Indents {
|
||||||
|
get {
|
||||||
|
if (indents == null)
|
||||||
|
indents = new Stack<int> ();
|
||||||
|
return indents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Indents
|
||||||
|
|
||||||
|
public string PopIndent ()
|
||||||
|
{
|
||||||
|
if (Indents.Count == 0)
|
||||||
|
return "";
|
||||||
|
int lastPos = currentIndent.Length - Indents.Pop ();
|
||||||
|
string last = currentIndent.Substring (lastPos);
|
||||||
|
currentIndent = currentIndent.Substring (0, lastPos);
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PushIndent (string indent)
|
||||||
|
{
|
||||||
|
if (indent == null)
|
||||||
|
throw new ArgumentNullException ("indent");
|
||||||
|
Indents.Push (indent.Length);
|
||||||
|
currentIndent += indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearIndent ()
|
||||||
|
{
|
||||||
|
currentIndent = string.Empty;
|
||||||
|
Indents.Clear ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CurrentIndent {
|
||||||
|
get { return currentIndent; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Writing
|
||||||
|
|
||||||
|
protected StringBuilder GenerationEnvironment {
|
||||||
|
get {
|
||||||
|
if (builder == null)
|
||||||
|
builder = new StringBuilder ();
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
builder = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write (string textToAppend)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty (textToAppend))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((GenerationEnvironment.Length == 0 || endsWithNewline) && CurrentIndent.Length > 0) {
|
||||||
|
GenerationEnvironment.Append (CurrentIndent);
|
||||||
|
}
|
||||||
|
endsWithNewline = false;
|
||||||
|
|
||||||
|
char last = textToAppend[textToAppend.Length-1];
|
||||||
|
if (last == '\n' || last == '\r') {
|
||||||
|
endsWithNewline = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CurrentIndent.Length == 0) {
|
||||||
|
GenerationEnvironment.Append (textToAppend);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//insert CurrentIndent after every newline (\n, \r, \r\n)
|
||||||
|
//but if there's one at the end of the string, ignore it, it'll be handled next time thanks to endsWithNewline
|
||||||
|
int lastNewline = 0;
|
||||||
|
for (int i = 0; i < textToAppend.Length - 1; i++) {
|
||||||
|
char c = textToAppend[i];
|
||||||
|
if (c == '\r') {
|
||||||
|
if (textToAppend[i + 1] == '\n') {
|
||||||
|
i++;
|
||||||
|
if (i == textToAppend.Length - 1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (c != '\n') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
int len = i - lastNewline;
|
||||||
|
if (len > 0) {
|
||||||
|
GenerationEnvironment.Append (textToAppend, lastNewline, i - lastNewline);
|
||||||
|
}
|
||||||
|
GenerationEnvironment.Append (CurrentIndent);
|
||||||
|
lastNewline = i;
|
||||||
|
}
|
||||||
|
if (lastNewline > 0)
|
||||||
|
GenerationEnvironment.Append (textToAppend, lastNewline, textToAppend.Length - lastNewline);
|
||||||
|
else
|
||||||
|
GenerationEnvironment.Append (textToAppend);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write (string format, params object[] args)
|
||||||
|
{
|
||||||
|
Write (string.Format (format, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteLine (string textToAppend)
|
||||||
|
{
|
||||||
|
Write (textToAppend);
|
||||||
|
GenerationEnvironment.AppendLine ();
|
||||||
|
endsWithNewline = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteLine (string format, params object[] args)
|
||||||
|
{
|
||||||
|
WriteLine (string.Format (format, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Dispose
|
||||||
|
|
||||||
|
public void Dispose ()
|
||||||
|
{
|
||||||
|
Dispose (true);
|
||||||
|
GC.SuppressFinalize (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose (bool disposing)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~TextTransformation ()
|
||||||
|
{
|
||||||
|
Dispose (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
//
|
||||||
|
// ToStringHelper.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Microsoft.VisualStudio.TextTemplating
|
||||||
|
{
|
||||||
|
public static class ToStringHelper
|
||||||
|
{
|
||||||
|
static object [] formatProviderAsParameterArray;
|
||||||
|
|
||||||
|
static IFormatProvider formatProvider = System.Globalization.CultureInfo.InvariantCulture;
|
||||||
|
|
||||||
|
static ToStringHelper ()
|
||||||
|
{
|
||||||
|
formatProviderAsParameterArray = new object[] { formatProvider };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ToStringWithCulture (object objectToConvert)
|
||||||
|
{
|
||||||
|
if (objectToConvert == null)
|
||||||
|
throw new ArgumentNullException ("objectToConvert");
|
||||||
|
|
||||||
|
IConvertible conv = objectToConvert as IConvertible;
|
||||||
|
if (conv != null)
|
||||||
|
return conv.ToString (formatProvider);
|
||||||
|
|
||||||
|
var str = objectToConvert as string;
|
||||||
|
if (str != null)
|
||||||
|
return str;
|
||||||
|
|
||||||
|
//TODO: implement a cache of types and DynamicMethods
|
||||||
|
MethodInfo mi = objectToConvert.GetType ().GetMethod ("ToString", new Type[] { typeof (IFormatProvider) });
|
||||||
|
if (mi != null)
|
||||||
|
return (string) mi.Invoke (objectToConvert, formatProviderAsParameterArray);
|
||||||
|
return objectToConvert.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IFormatProvider FormatProvider {
|
||||||
|
get { return (IFormatProvider)formatProviderAsParameterArray[0]; }
|
||||||
|
set { formatProviderAsParameterArray[0] = formatProvider = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{A2364D6A-00EF-417C-80A6-815726C70032}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<RootNamespace>Mono.TextTemplating</RootNamespace>
|
||||||
|
<AssemblyName>Mono.TextTemplating</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>..\bin</OutputPath>
|
||||||
|
<DefineConstants>DEBUG</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ConsolePause>false</ConsolePause>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>none</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>..\bin</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ConsolePause>false</ConsolePause>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\DirectiveProcessor.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\DirectiveProcessorException.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\Engine.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\RequiresProvidesDirectiveProcessor.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\TextTransformation.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\ToStringHelper.cs" />
|
||||||
|
<Compile Include="Mono.TextTemplating\CompiledTemplate.cs" />
|
||||||
|
<Compile Include="Mono.TextTemplating\ParsedTemplate.cs" />
|
||||||
|
<Compile Include="Mono.TextTemplating\Tokeniser.cs" />
|
||||||
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Mono.TextTemplating\TemplateGenerator.cs" />
|
||||||
|
<Compile Include="Mono.TextTemplating\TemplatingEngine.cs" />
|
||||||
|
<Compile Include="Mono.TextTemplating\TemplateSettings.cs" />
|
||||||
|
<Compile Include="Mono.TextTemplating\CrossAppDomainAssemblyResolver.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\AssemblyCacheMonitor.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\EncodingHelper.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\ParameterDirectiveProcessor.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\TextTemplatingSession.cs" />
|
||||||
|
<Compile Include="Microsoft.VisualStudio.TextTemplating\Interfaces.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Microsoft.VisualStudio.TextTemplating\" />
|
||||||
|
<Folder Include="Mono.TextTemplating\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ProjectExtensions>
|
||||||
|
<MonoDevelop>
|
||||||
|
<Properties>
|
||||||
|
<Policies>
|
||||||
|
<DotNetNamingPolicy DirectoryNamespaceAssociation="Flat" ResourceNamePolicy="FileName" />
|
||||||
|
</Policies>
|
||||||
|
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am" BuildTargetName="" CleanTargetName="" SyncReferences="true" IsAutotoolsProject="true" RelativeConfigureInPath="..">
|
||||||
|
<BuildFilesVar Sync="true" Name="FILES" />
|
||||||
|
<DeployFilesVar />
|
||||||
|
<ResourcesVar Sync="true" Name="RES" />
|
||||||
|
<OthersVar />
|
||||||
|
<GacRefVar Sync="true" Name="REFS" Prefix="-r:" />
|
||||||
|
<AsmRefVar Sync="true" Name="REFS" Prefix="-r:" />
|
||||||
|
<ProjectRefVar Sync="true" Name="DEPS" />
|
||||||
|
</MonoDevelop.Autotools.MakefileInfo>
|
||||||
|
</Properties>
|
||||||
|
</MonoDevelop>
|
||||||
|
</ProjectExtensions>
|
||||||
|
</Project>
|
|
@ -0,0 +1,113 @@
|
||||||
|
//
|
||||||
|
// CompiledTemplate.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Nathan Baulch <nathan.baulch@gmail.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Nathan Baulch
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
public sealed class CompiledTemplate : MarshalByRefObject, IDisposable
|
||||||
|
{
|
||||||
|
ITextTemplatingEngineHost host;
|
||||||
|
TextTransformation tt;
|
||||||
|
CultureInfo culture;
|
||||||
|
string[] assemblyFiles;
|
||||||
|
|
||||||
|
public CompiledTemplate (ITextTemplatingEngineHost host, CompilerResults results, string fullName, CultureInfo culture,
|
||||||
|
string[] assemblyFiles)
|
||||||
|
{
|
||||||
|
AppDomain.CurrentDomain.AssemblyResolve += ResolveReferencedAssemblies;
|
||||||
|
this.host = host;
|
||||||
|
this.culture = culture;
|
||||||
|
this.assemblyFiles = assemblyFiles;
|
||||||
|
Load (results, fullName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load (CompilerResults results, string fullName)
|
||||||
|
{
|
||||||
|
var assembly = results.CompiledAssembly;
|
||||||
|
Type transformType = assembly.GetType (fullName);
|
||||||
|
tt = (TextTransformation) Activator.CreateInstance (transformType);
|
||||||
|
|
||||||
|
//set the host property if it exists
|
||||||
|
var hostProp = transformType.GetProperty ("Host", typeof (ITextTemplatingEngineHost));
|
||||||
|
if (hostProp != null && hostProp.CanWrite)
|
||||||
|
hostProp.SetValue (tt, host, null);
|
||||||
|
|
||||||
|
var sessionHost = host as ITextTemplatingSessionHost;
|
||||||
|
if (sessionHost != null) {
|
||||||
|
//FIXME: should we create a session if it's null?
|
||||||
|
tt.Session = sessionHost.Session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Process ()
|
||||||
|
{
|
||||||
|
tt.Errors.Clear ();
|
||||||
|
|
||||||
|
//set the culture
|
||||||
|
if (culture != null)
|
||||||
|
ToStringHelper.FormatProvider = culture;
|
||||||
|
else
|
||||||
|
ToStringHelper.FormatProvider = CultureInfo.InvariantCulture;
|
||||||
|
|
||||||
|
tt.Initialize ();
|
||||||
|
|
||||||
|
string output = null;
|
||||||
|
try {
|
||||||
|
output = tt.TransformText ();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
tt.Error ("Error running transform: " + ex.ToString ());
|
||||||
|
}
|
||||||
|
host.LogErrors (tt.Errors);
|
||||||
|
|
||||||
|
ToStringHelper.FormatProvider = CultureInfo.InvariantCulture;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Reflection.Assembly ResolveReferencedAssemblies (object sender, ResolveEventArgs args)
|
||||||
|
{
|
||||||
|
System.Reflection.Assembly asm = null;
|
||||||
|
foreach (var asmFile in assemblyFiles) {
|
||||||
|
var name = System.IO.Path.GetFileNameWithoutExtension (asmFile);
|
||||||
|
if (args.Name.StartsWith (name))
|
||||||
|
asm = System.Reflection.Assembly.LoadFrom (asmFile);
|
||||||
|
}
|
||||||
|
return asm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose ()
|
||||||
|
{
|
||||||
|
if (host != null) {
|
||||||
|
host = null;
|
||||||
|
AppDomain.CurrentDomain.AssemblyResolve -= ResolveReferencedAssemblies;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
//
|
||||||
|
// CrossAppDomainAssemblyResolver.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2010 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a handler for AssemblyResolve events that looks them up in the domain that created the resolver.
|
||||||
|
/// </summary>
|
||||||
|
public class CrossAppDomainAssemblyResolver
|
||||||
|
{
|
||||||
|
ParentDomainLookup parent = new ParentDomainLookup ();
|
||||||
|
|
||||||
|
public System.Reflection.Assembly Resolve (object sender, ResolveEventArgs args)
|
||||||
|
{
|
||||||
|
var location = parent.GetAssemblyPath (args.Name);
|
||||||
|
if (location != null)
|
||||||
|
return System.Reflection.Assembly.LoadFrom (location);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ParentDomainLookup : MarshalByRefObject
|
||||||
|
{
|
||||||
|
public string GetAssemblyPath (string name)
|
||||||
|
{
|
||||||
|
var assem = System.Reflection.Assembly.Load (name);
|
||||||
|
if (assem != null)
|
||||||
|
return assem.Location;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,320 @@
|
||||||
|
//
|
||||||
|
// Template.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public class ParsedTemplate
|
||||||
|
{
|
||||||
|
List<ISegment> segments = new List<ISegment> ();
|
||||||
|
CompilerErrorCollection errors = new CompilerErrorCollection ();
|
||||||
|
string rootFileName;
|
||||||
|
|
||||||
|
public ParsedTemplate (string rootFileName)
|
||||||
|
{
|
||||||
|
this.rootFileName = rootFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ISegment> RawSegments {
|
||||||
|
get { return segments; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Directive> Directives {
|
||||||
|
get {
|
||||||
|
foreach (ISegment seg in segments) {
|
||||||
|
Directive dir = seg as Directive;
|
||||||
|
if (dir != null)
|
||||||
|
yield return dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<TemplateSegment> Content {
|
||||||
|
get {
|
||||||
|
foreach (ISegment seg in segments) {
|
||||||
|
TemplateSegment ts = seg as TemplateSegment;
|
||||||
|
if (ts != null)
|
||||||
|
yield return ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompilerErrorCollection Errors {
|
||||||
|
get { return errors; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ParsedTemplate FromText (string content, ITextTemplatingEngineHost host)
|
||||||
|
{
|
||||||
|
ParsedTemplate template = new ParsedTemplate (host.TemplateFile);
|
||||||
|
try {
|
||||||
|
template.Parse (host, new Tokeniser (host.TemplateFile, content));
|
||||||
|
} catch (ParserException ex) {
|
||||||
|
template.LogError (ex.Message, ex.Location);
|
||||||
|
}
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Parse (ITextTemplatingEngineHost host, Tokeniser tokeniser)
|
||||||
|
{
|
||||||
|
Parse (host, tokeniser, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ParseWithoutIncludes (Tokeniser tokeniser)
|
||||||
|
{
|
||||||
|
Parse (null, tokeniser, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Parse (ITextTemplatingEngineHost host, Tokeniser tokeniser, bool parseIncludes)
|
||||||
|
{
|
||||||
|
bool skip = false;
|
||||||
|
while ((skip || tokeniser.Advance ()) && tokeniser.State != State.EOF) {
|
||||||
|
skip = false;
|
||||||
|
ISegment seg = null;
|
||||||
|
switch (tokeniser.State) {
|
||||||
|
case State.Block:
|
||||||
|
if (!String.IsNullOrEmpty (tokeniser.Value))
|
||||||
|
seg = new TemplateSegment (SegmentType.Block, tokeniser.Value, tokeniser.Location);
|
||||||
|
break;
|
||||||
|
case State.Content:
|
||||||
|
if (!String.IsNullOrEmpty (tokeniser.Value))
|
||||||
|
seg = new TemplateSegment (SegmentType.Content, tokeniser.Value, tokeniser.Location);
|
||||||
|
break;
|
||||||
|
case State.Expression:
|
||||||
|
if (!String.IsNullOrEmpty (tokeniser.Value))
|
||||||
|
seg = new TemplateSegment (SegmentType.Expression, tokeniser.Value, tokeniser.Location);
|
||||||
|
break;
|
||||||
|
case State.Helper:
|
||||||
|
if (!String.IsNullOrEmpty (tokeniser.Value))
|
||||||
|
seg = new TemplateSegment (SegmentType.Helper, tokeniser.Value, tokeniser.Location);
|
||||||
|
break;
|
||||||
|
case State.Directive:
|
||||||
|
Directive directive = null;
|
||||||
|
string attName = null;
|
||||||
|
while (!skip && tokeniser.Advance ()) {
|
||||||
|
switch (tokeniser.State) {
|
||||||
|
case State.DirectiveName:
|
||||||
|
if (directive == null) {
|
||||||
|
directive = new Directive (tokeniser.Value.ToLower (), tokeniser.Location);
|
||||||
|
directive.TagStartLocation = tokeniser.TagStartLocation;
|
||||||
|
if (!parseIncludes || directive.Name != "include")
|
||||||
|
segments.Add (directive);
|
||||||
|
} else
|
||||||
|
attName = tokeniser.Value;
|
||||||
|
break;
|
||||||
|
case State.DirectiveValue:
|
||||||
|
if (attName != null && directive != null)
|
||||||
|
directive.Attributes[attName.ToLower ()] = tokeniser.Value;
|
||||||
|
else
|
||||||
|
LogError ("Directive value without name", tokeniser.Location);
|
||||||
|
attName = null;
|
||||||
|
break;
|
||||||
|
case State.Directive:
|
||||||
|
if (directive != null)
|
||||||
|
directive.EndLocation = tokeniser.TagEndLocation;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
skip = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parseIncludes && directive.Name == "include")
|
||||||
|
Import (host, directive, Path.GetDirectoryName (tokeniser.Location.FileName));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException ();
|
||||||
|
}
|
||||||
|
if (seg != null) {
|
||||||
|
seg.TagStartLocation = tokeniser.TagStartLocation;
|
||||||
|
seg.EndLocation = tokeniser.TagEndLocation;
|
||||||
|
segments.Add (seg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Import (ITextTemplatingEngineHost host, Directive includeDirective, string relativeToDirectory)
|
||||||
|
{
|
||||||
|
string fileName;
|
||||||
|
if (includeDirective.Attributes.Count > 1 || !includeDirective.Attributes.TryGetValue ("file", out fileName)) {
|
||||||
|
LogError ("Unexpected attributes in include directive", includeDirective.StartLocation);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//try to resolve path relative to the file that included it
|
||||||
|
if (!Path.IsPathRooted (fileName)) {
|
||||||
|
string possible = Path.Combine (relativeToDirectory, fileName);
|
||||||
|
if (File.Exists (possible))
|
||||||
|
fileName = possible;
|
||||||
|
}
|
||||||
|
|
||||||
|
string content, resolvedName;
|
||||||
|
if (host.LoadIncludeText (fileName, out content, out resolvedName))
|
||||||
|
Parse (host, new Tokeniser (resolvedName, content), true);
|
||||||
|
else
|
||||||
|
LogError ("Could not resolve include file '" + fileName + "'.", includeDirective.StartLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogError (string message, Location location, bool isWarning)
|
||||||
|
{
|
||||||
|
CompilerError err = new CompilerError ();
|
||||||
|
err.ErrorText = message;
|
||||||
|
if (location.FileName != null) {
|
||||||
|
err.Line = location.Line;
|
||||||
|
err.Column = location.Column;
|
||||||
|
err.FileName = location.FileName ?? string.Empty;
|
||||||
|
} else {
|
||||||
|
err.FileName = rootFileName ?? string.Empty;
|
||||||
|
}
|
||||||
|
err.IsWarning = isWarning;
|
||||||
|
errors.Add (err);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogError (string message)
|
||||||
|
{
|
||||||
|
LogError (message, Location.Empty, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogWarning (string message)
|
||||||
|
{
|
||||||
|
LogError (message, Location.Empty, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogError (string message, Location location)
|
||||||
|
{
|
||||||
|
LogError (message, location, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogWarning (string message, Location location)
|
||||||
|
{
|
||||||
|
LogError (message, location, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ISegment
|
||||||
|
{
|
||||||
|
Location StartLocation { get; }
|
||||||
|
Location EndLocation { get; set; }
|
||||||
|
Location TagStartLocation {get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TemplateSegment : ISegment
|
||||||
|
{
|
||||||
|
public TemplateSegment (SegmentType type, string text, Location start)
|
||||||
|
{
|
||||||
|
this.Type = type;
|
||||||
|
this.StartLocation = start;
|
||||||
|
this.Text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SegmentType Type { get; private set; }
|
||||||
|
public string Text { get; private set; }
|
||||||
|
public Location TagStartLocation { get; set; }
|
||||||
|
public Location StartLocation { get; private set; }
|
||||||
|
public Location EndLocation { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Directive : ISegment
|
||||||
|
{
|
||||||
|
public Directive (string name, Location start)
|
||||||
|
{
|
||||||
|
this.Name = name;
|
||||||
|
this.Attributes = new Dictionary<string, string> ();
|
||||||
|
this.StartLocation = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public Dictionary<string,string> Attributes { get; private set; }
|
||||||
|
public Location TagStartLocation { get; set; }
|
||||||
|
public Location StartLocation { get; private set; }
|
||||||
|
public Location EndLocation { get; set; }
|
||||||
|
|
||||||
|
public string Extract (string key)
|
||||||
|
{
|
||||||
|
string value;
|
||||||
|
if (!Attributes.TryGetValue (key, out value))
|
||||||
|
return null;
|
||||||
|
Attributes.Remove (key);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SegmentType
|
||||||
|
{
|
||||||
|
Block,
|
||||||
|
Expression,
|
||||||
|
Content,
|
||||||
|
Helper
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct Location : IEquatable<Location>
|
||||||
|
{
|
||||||
|
public Location (string fileName, int line, int column) : this()
|
||||||
|
{
|
||||||
|
FileName = fileName;
|
||||||
|
Column = column;
|
||||||
|
Line = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Line { get; private set; }
|
||||||
|
public int Column { get; private set; }
|
||||||
|
public string FileName { get; private set; }
|
||||||
|
|
||||||
|
public static Location Empty {
|
||||||
|
get { return new Location (null, -1, -1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location AddLine ()
|
||||||
|
{
|
||||||
|
return new Location (this.FileName, this.Line + 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location AddCol ()
|
||||||
|
{
|
||||||
|
return AddCols (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location AddCols (int number)
|
||||||
|
{
|
||||||
|
return new Location (this.FileName, this.Line, this.Column + number);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString ()
|
||||||
|
{
|
||||||
|
return string.Format("[{0} ({1},{2})]", FileName, Line, Column);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals (Location other)
|
||||||
|
{
|
||||||
|
return other.Line == Line && other.Column == Column && other.FileName == FileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,373 @@
|
||||||
|
//
|
||||||
|
// TemplatingHost.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
public class TemplateGenerator : MarshalByRefObject, ITextTemplatingEngineHost
|
||||||
|
{
|
||||||
|
//re-usable
|
||||||
|
TemplatingEngine engine;
|
||||||
|
|
||||||
|
//per-run variables
|
||||||
|
string inputFile, outputFile;
|
||||||
|
Encoding encoding;
|
||||||
|
|
||||||
|
//host fields
|
||||||
|
CompilerErrorCollection errors = new CompilerErrorCollection ();
|
||||||
|
List<string> refs = new List<string> ();
|
||||||
|
List<string> imports = new List<string> ();
|
||||||
|
List<string> includePaths = new List<string> ();
|
||||||
|
List<string> referencePaths = new List<string> ();
|
||||||
|
|
||||||
|
//host properties for consumers to access
|
||||||
|
public CompilerErrorCollection Errors { get { return errors; } }
|
||||||
|
public List<string> Refs { get { return refs; } }
|
||||||
|
public List<string> Imports { get { return imports; } }
|
||||||
|
public List<string> IncludePaths { get { return includePaths; } }
|
||||||
|
public List<string> ReferencePaths { get { return referencePaths; } }
|
||||||
|
public string OutputFile { get { return outputFile; } }
|
||||||
|
|
||||||
|
public TemplateGenerator ()
|
||||||
|
{
|
||||||
|
Refs.Add (typeof (TextTransformation).Assembly.Location);
|
||||||
|
Refs.Add (typeof(System.Uri).Assembly.Location);
|
||||||
|
Imports.Add ("System");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompiledTemplate CompileTemplate (string content)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty (content))
|
||||||
|
throw new ArgumentNullException ("content");
|
||||||
|
|
||||||
|
errors.Clear ();
|
||||||
|
encoding = Encoding.UTF8;
|
||||||
|
|
||||||
|
return Engine.CompileTemplate (content, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TemplatingEngine Engine {
|
||||||
|
get {
|
||||||
|
if (engine == null)
|
||||||
|
engine = new TemplatingEngine ();
|
||||||
|
return engine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ProcessTemplate (string inputFile, string outputFile)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty (inputFile))
|
||||||
|
throw new ArgumentNullException ("inputFile");
|
||||||
|
if (String.IsNullOrEmpty (outputFile))
|
||||||
|
throw new ArgumentNullException ("outputFile");
|
||||||
|
|
||||||
|
string content;
|
||||||
|
try {
|
||||||
|
content = File.ReadAllText (inputFile);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
errors.Clear ();
|
||||||
|
AddError ("Could not read input file '" + inputFile + "':\n" + ex.ToString ());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string output;
|
||||||
|
ProcessTemplate (inputFile, content, ref outputFile, out output);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!errors.HasErrors)
|
||||||
|
File.WriteAllText (outputFile, output, encoding);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
AddError ("Could not write output file '" + outputFile + "':\n" + ex.ToString ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return !errors.HasErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ProcessTemplate (string inputFileName, string inputContent, ref string outputFileName, out string outputContent)
|
||||||
|
{
|
||||||
|
errors.Clear ();
|
||||||
|
encoding = Encoding.UTF8;
|
||||||
|
|
||||||
|
this.outputFile = outputFileName;
|
||||||
|
this.inputFile = inputFileName;
|
||||||
|
outputContent = Engine.ProcessTemplate (inputContent, this);
|
||||||
|
outputFileName = this.outputFile;
|
||||||
|
|
||||||
|
return !errors.HasErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PreprocessTemplate (string inputFile, string className, string classNamespace,
|
||||||
|
string outputFile, System.Text.Encoding encoding, out string language, out string[] references)
|
||||||
|
{
|
||||||
|
language = null;
|
||||||
|
references = null;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty (inputFile))
|
||||||
|
throw new ArgumentNullException ("inputFile");
|
||||||
|
if (string.IsNullOrEmpty (outputFile))
|
||||||
|
throw new ArgumentNullException ("outputFile");
|
||||||
|
|
||||||
|
string content;
|
||||||
|
try {
|
||||||
|
content = File.ReadAllText (inputFile);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
errors.Clear ();
|
||||||
|
AddError ("Could not read input file '" + inputFile + "':\n" + ex.ToString ());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string output;
|
||||||
|
PreprocessTemplate (inputFile, className, classNamespace, content, out language, out references, out output);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!errors.HasErrors)
|
||||||
|
File.WriteAllText (outputFile, output, encoding);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
AddError ("Could not write output file '" + outputFile + "':\n" + ex.ToString ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return !errors.HasErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PreprocessTemplate (string inputFileName, string className, string classNamespace, string inputContent,
|
||||||
|
out string language, out string[] references, out string outputContent)
|
||||||
|
{
|
||||||
|
errors.Clear ();
|
||||||
|
encoding = Encoding.UTF8;
|
||||||
|
|
||||||
|
this.inputFile = inputFileName;
|
||||||
|
outputContent = Engine.PreprocessTemplate (inputContent, this, className, classNamespace, out language, out references);
|
||||||
|
|
||||||
|
return !errors.HasErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompilerError AddError (string error)
|
||||||
|
{
|
||||||
|
CompilerError err = new CompilerError ();
|
||||||
|
err.ErrorText = error;
|
||||||
|
Errors.Add (err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Virtual members
|
||||||
|
|
||||||
|
public virtual object GetHostOption (string optionName)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual AppDomain ProvideTemplatingAppDomain (string content)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME: implement
|
||||||
|
protected virtual string ResolveAssemblyReference (string assemblyReference)
|
||||||
|
{
|
||||||
|
//foreach (string referencePath in ReferencePaths) {
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
return assemblyReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual string ResolveParameterValue (string directiveId, string processorName, string parameterName)
|
||||||
|
{
|
||||||
|
var key = new ParameterKey (processorName, directiveId, parameterName);
|
||||||
|
string value;
|
||||||
|
if (parameters.TryGetValue (key, out value))
|
||||||
|
return value;
|
||||||
|
if (processorName != null || directiveId != null)
|
||||||
|
return ResolveParameterValue (null, null, parameterName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual Type ResolveDirectiveProcessor (string processorName)
|
||||||
|
{
|
||||||
|
KeyValuePair<string,string> value;
|
||||||
|
if (!directiveProcessors.TryGetValue (processorName, out value))
|
||||||
|
throw new Exception (string.Format ("No directive processor registered as '{0}'", processorName));
|
||||||
|
var asmPath = ResolveAssemblyReference (value.Value);
|
||||||
|
if (asmPath == null)
|
||||||
|
throw new Exception (string.Format ("Could not resolve assembly '{0}' for directive processor '{1}'", value.Value, processorName));
|
||||||
|
var asm = System.Reflection.Assembly.LoadFrom (asmPath);
|
||||||
|
return asm.GetType (value.Key, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual string ResolvePath (string path)
|
||||||
|
{
|
||||||
|
path = System.Environment.ExpandEnvironmentVariables (path);
|
||||||
|
if (Path.IsPathRooted (path))
|
||||||
|
return path;
|
||||||
|
var dir = Path.GetDirectoryName (inputFile);
|
||||||
|
var test = Path.Combine (dir, path);
|
||||||
|
if (File.Exists (test))
|
||||||
|
return test;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
Dictionary<ParameterKey,string> parameters = new Dictionary<ParameterKey, string> ();
|
||||||
|
Dictionary<string,KeyValuePair<string,string>> directiveProcessors = new Dictionary<string, KeyValuePair<string,string>> ();
|
||||||
|
|
||||||
|
public void AddDirectiveProcessor (string name, string klass, string assembly)
|
||||||
|
{
|
||||||
|
directiveProcessors.Add (name, new KeyValuePair<string,string> (klass,assembly));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddParameter (string processorName, string directiveName, string parameterName, string value)
|
||||||
|
{
|
||||||
|
parameters.Add (new ParameterKey (processorName, directiveName, parameterName), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual bool LoadIncludeText (string requestFileName, out string content, out string location)
|
||||||
|
{
|
||||||
|
content = "";
|
||||||
|
location = ResolvePath (requestFileName);
|
||||||
|
|
||||||
|
if (location == null) {
|
||||||
|
foreach (string path in includePaths) {
|
||||||
|
string f = Path.Combine (path, requestFileName);
|
||||||
|
if (File.Exists (f)) {
|
||||||
|
location = f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
content = File.ReadAllText (location);
|
||||||
|
return true;
|
||||||
|
} catch (IOException ex) {
|
||||||
|
AddError ("Could not read included file '" + location + "':\n" + ex.ToString ());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Explicit ITextTemplatingEngineHost implementation
|
||||||
|
|
||||||
|
bool ITextTemplatingEngineHost.LoadIncludeText (string requestFileName, out string content, out string location)
|
||||||
|
{
|
||||||
|
return LoadIncludeText (requestFileName, out content, out location);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITextTemplatingEngineHost.LogErrors (CompilerErrorCollection errors)
|
||||||
|
{
|
||||||
|
this.errors.AddRange (errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
string ITextTemplatingEngineHost.ResolveAssemblyReference (string assemblyReference)
|
||||||
|
{
|
||||||
|
return ResolveAssemblyReference (assemblyReference);
|
||||||
|
}
|
||||||
|
|
||||||
|
string ITextTemplatingEngineHost.ResolveParameterValue (string directiveId, string processorName, string parameterName)
|
||||||
|
{
|
||||||
|
return ResolveParameterValue (directiveId, processorName, parameterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Type ITextTemplatingEngineHost.ResolveDirectiveProcessor (string processorName)
|
||||||
|
{
|
||||||
|
return ResolveDirectiveProcessor (processorName);
|
||||||
|
}
|
||||||
|
|
||||||
|
string ITextTemplatingEngineHost.ResolvePath (string path)
|
||||||
|
{
|
||||||
|
return ResolvePath (path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITextTemplatingEngineHost.SetFileExtension (string extension)
|
||||||
|
{
|
||||||
|
extension = extension.TrimStart ('.');
|
||||||
|
if (Path.HasExtension (outputFile)) {
|
||||||
|
outputFile = Path.ChangeExtension (outputFile, extension);
|
||||||
|
} else {
|
||||||
|
outputFile = outputFile + "." + extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITextTemplatingEngineHost.SetOutputEncoding (System.Text.Encoding encoding, bool fromOutputDirective)
|
||||||
|
{
|
||||||
|
this.encoding = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
IList<string> ITextTemplatingEngineHost.StandardAssemblyReferences {
|
||||||
|
get { return refs; }
|
||||||
|
}
|
||||||
|
|
||||||
|
IList<string> ITextTemplatingEngineHost.StandardImports {
|
||||||
|
get { return imports; }
|
||||||
|
}
|
||||||
|
|
||||||
|
string ITextTemplatingEngineHost.TemplateFile {
|
||||||
|
get { return inputFile; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
struct ParameterKey : IEquatable<ParameterKey>
|
||||||
|
{
|
||||||
|
public ParameterKey (string processorName, string directiveName, string parameterName)
|
||||||
|
{
|
||||||
|
this.processorName = processorName ?? "";
|
||||||
|
this.directiveName = directiveName ?? "";
|
||||||
|
this.parameterName = parameterName ?? "";
|
||||||
|
unchecked {
|
||||||
|
hashCode = this.processorName.GetHashCode ()
|
||||||
|
^ this.directiveName.GetHashCode ()
|
||||||
|
^ this.parameterName.GetHashCode ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string processorName, directiveName, parameterName;
|
||||||
|
int hashCode;
|
||||||
|
|
||||||
|
public override bool Equals (object obj)
|
||||||
|
{
|
||||||
|
return obj != null && obj is ParameterKey && Equals ((ParameterKey)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals (ParameterKey other)
|
||||||
|
{
|
||||||
|
return processorName == other.processorName && directiveName == other.directiveName && parameterName == other.parameterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode ()
|
||||||
|
{
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
//
|
||||||
|
// TemplateSettings.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
|
||||||
|
public class TemplateSettings
|
||||||
|
{
|
||||||
|
public TemplateSettings ()
|
||||||
|
{
|
||||||
|
Imports = new HashSet<string> ();
|
||||||
|
Assemblies = new HashSet<string> ();
|
||||||
|
CustomDirectives = new List<CustomDirective> ();
|
||||||
|
DirectiveProcessors = new Dictionary<string, DirectiveProcessor> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HostSpecific { get; set; }
|
||||||
|
public bool Debug { get; set; }
|
||||||
|
public string Inherits { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Namespace { get; set; }
|
||||||
|
public HashSet<string> Imports { get; private set; }
|
||||||
|
public HashSet<string> Assemblies { get; private set; }
|
||||||
|
public System.CodeDom.Compiler.CodeDomProvider Provider { get; set; }
|
||||||
|
public string Language { get; set; }
|
||||||
|
public string CompilerOptions { get; set; }
|
||||||
|
public Encoding Encoding { get; set; }
|
||||||
|
public string Extension { get; set; }
|
||||||
|
public System.Globalization.CultureInfo Culture { get; set; }
|
||||||
|
public List<CustomDirective> CustomDirectives { get; private set; }
|
||||||
|
public Dictionary<string,DirectiveProcessor> DirectiveProcessors { get; private set; }
|
||||||
|
public bool IncludePreprocessingHelpers { get; set; }
|
||||||
|
public bool IsPreprocessed { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CustomDirective
|
||||||
|
{
|
||||||
|
public CustomDirective (string processorName, Directive directive)
|
||||||
|
{
|
||||||
|
this.ProcessorName = processorName;
|
||||||
|
this.Directive = directive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ProcessorName { get; set; }
|
||||||
|
public Directive Directive { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,963 @@
|
||||||
|
//
|
||||||
|
// Engine.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.CodeDom;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using Microsoft.CSharp;
|
||||||
|
using Microsoft.VisualStudio.TextTemplating;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
public class TemplatingEngine : MarshalByRefObject, Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngine
|
||||||
|
{
|
||||||
|
public string ProcessTemplate (string content, ITextTemplatingEngineHost host)
|
||||||
|
{
|
||||||
|
var tpl = CompileTemplate (content, host);
|
||||||
|
try {
|
||||||
|
if (tpl != null)
|
||||||
|
return tpl.Process ();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (tpl != null)
|
||||||
|
tpl.Dispose ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PreprocessTemplate (string content, ITextTemplatingEngineHost host, string className,
|
||||||
|
string classNamespace, out string language, out string[] references)
|
||||||
|
{
|
||||||
|
if (content == null)
|
||||||
|
throw new ArgumentNullException ("content");
|
||||||
|
if (host == null)
|
||||||
|
throw new ArgumentNullException ("host");
|
||||||
|
if (className == null)
|
||||||
|
throw new ArgumentNullException ("className");
|
||||||
|
if (classNamespace == null)
|
||||||
|
throw new ArgumentNullException ("classNamespace");
|
||||||
|
|
||||||
|
language = null;
|
||||||
|
references = null;
|
||||||
|
|
||||||
|
var pt = ParsedTemplate.FromText (content, host);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var settings = GetSettings (host, pt);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
settings.Name = className;
|
||||||
|
settings.Namespace = classNamespace;
|
||||||
|
settings.IncludePreprocessingHelpers = string.IsNullOrEmpty (settings.Inherits);
|
||||||
|
settings.IsPreprocessed = true;
|
||||||
|
language = settings.Language;
|
||||||
|
|
||||||
|
var ccu = GenerateCompileUnit (host, content, pt, settings);
|
||||||
|
references = ProcessReferences (host, pt, settings).ToArray ();
|
||||||
|
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = new CodeGeneratorOptions ();
|
||||||
|
using (var sw = new StringWriter ()) {
|
||||||
|
settings.Provider.GenerateCodeFromCompileUnit (ccu, sw, options);
|
||||||
|
return sw.ToString ();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompiledTemplate CompileTemplate (string content, ITextTemplatingEngineHost host)
|
||||||
|
{
|
||||||
|
if (content == null)
|
||||||
|
throw new ArgumentNullException ("content");
|
||||||
|
if (host == null)
|
||||||
|
throw new ArgumentNullException ("host");
|
||||||
|
|
||||||
|
var pt = ParsedTemplate.FromText (content, host);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var settings = GetSettings (host, pt);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty (settings.Extension)) {
|
||||||
|
host.SetFileExtension (settings.Extension);
|
||||||
|
}
|
||||||
|
if (settings.Encoding != null) {
|
||||||
|
//FIXME: when is this called with false?
|
||||||
|
host.SetOutputEncoding (settings.Encoding, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ccu = GenerateCompileUnit (host, content, pt, settings);
|
||||||
|
var references = ProcessReferences (host, pt, settings);
|
||||||
|
if (pt.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var results = GenerateCode (host, references, settings, ccu);
|
||||||
|
if (results.Errors.HasErrors) {
|
||||||
|
host.LogErrors (pt.Errors);
|
||||||
|
host.LogErrors (results.Errors);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var templateClassFullName = settings.Namespace + "." + settings.Name;
|
||||||
|
var domain = host.ProvideTemplatingAppDomain (content);
|
||||||
|
if (domain != null) {
|
||||||
|
var type = typeof (CompiledTemplate);
|
||||||
|
var obj = domain.CreateInstanceAndUnwrap (type.Assembly.FullName, type.FullName, false,
|
||||||
|
BindingFlags.CreateInstance, null,
|
||||||
|
new object[] { host, results, templateClassFullName, settings.Culture, references.ToArray () },
|
||||||
|
null, null);
|
||||||
|
return (CompiledTemplate) obj;
|
||||||
|
} else {
|
||||||
|
return new CompiledTemplate (host, results, templateClassFullName, settings.Culture, references.ToArray ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static CompilerResults GenerateCode (ITextTemplatingEngineHost host, IEnumerable<string> references, TemplateSettings settings, CodeCompileUnit ccu)
|
||||||
|
{
|
||||||
|
var pars = new CompilerParameters () {
|
||||||
|
GenerateExecutable = false,
|
||||||
|
CompilerOptions = settings.CompilerOptions,
|
||||||
|
IncludeDebugInformation = settings.Debug,
|
||||||
|
GenerateInMemory = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var r in references)
|
||||||
|
pars.ReferencedAssemblies.Add (r);
|
||||||
|
|
||||||
|
if (settings.Debug)
|
||||||
|
pars.TempFiles.KeepFiles = true;
|
||||||
|
|
||||||
|
return settings.Provider.CompileAssemblyFromDom (pars, ccu);
|
||||||
|
}
|
||||||
|
|
||||||
|
static HashSet<string> ProcessReferences (ITextTemplatingEngineHost host, ParsedTemplate pt, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
var resolved = new HashSet<string> ();
|
||||||
|
|
||||||
|
foreach (string assem in settings.Assemblies.Union (host.StandardAssemblyReferences)) {
|
||||||
|
if (resolved.Contains (assem))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string resolvedAssem = host.ResolveAssemblyReference (assem);
|
||||||
|
if (!string.IsNullOrEmpty (resolvedAssem)) {
|
||||||
|
resolved.Add (resolvedAssem);
|
||||||
|
} else {
|
||||||
|
pt.LogError ("Could not resolve assembly reference '" + assem + "'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TemplateSettings GetSettings (ITextTemplatingEngineHost host, ParsedTemplate pt)
|
||||||
|
{
|
||||||
|
var settings = new TemplateSettings ();
|
||||||
|
|
||||||
|
foreach (Directive dt in pt.Directives) {
|
||||||
|
switch (dt.Name) {
|
||||||
|
case "template":
|
||||||
|
string val = dt.Extract ("language");
|
||||||
|
if (val != null)
|
||||||
|
settings.Language = val;
|
||||||
|
val = dt.Extract ("debug");
|
||||||
|
if (val != null)
|
||||||
|
settings.Debug = string.Compare (val, "true", StringComparison.OrdinalIgnoreCase) == 0;
|
||||||
|
val = dt.Extract ("inherits");
|
||||||
|
if (val != null)
|
||||||
|
settings.Inherits = val;
|
||||||
|
val = dt.Extract ("culture");
|
||||||
|
if (val != null) {
|
||||||
|
System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo (val);
|
||||||
|
if (culture == null)
|
||||||
|
pt.LogWarning ("Could not find culture '" + val + "'", dt.StartLocation);
|
||||||
|
else
|
||||||
|
settings.Culture = culture;
|
||||||
|
}
|
||||||
|
val = dt.Extract ("hostspecific");
|
||||||
|
if (val != null) {
|
||||||
|
settings.HostSpecific = string.Compare (val, "true", StringComparison.OrdinalIgnoreCase) == 0;
|
||||||
|
}
|
||||||
|
val = dt.Extract ("CompilerOptions");
|
||||||
|
if (val != null) {
|
||||||
|
settings.CompilerOptions = val;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "assembly":
|
||||||
|
string name = dt.Extract ("name");
|
||||||
|
if (name == null)
|
||||||
|
pt.LogError ("Missing name attribute in assembly directive", dt.StartLocation);
|
||||||
|
else
|
||||||
|
settings.Assemblies.Add (name);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "import":
|
||||||
|
string namespac = dt.Extract ("namespace");
|
||||||
|
if (namespac == null)
|
||||||
|
pt.LogError ("Missing namespace attribute in import directive", dt.StartLocation);
|
||||||
|
else
|
||||||
|
settings.Imports.Add (namespac);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "output":
|
||||||
|
settings.Extension = dt.Extract ("extension");
|
||||||
|
string encoding = dt.Extract ("encoding");
|
||||||
|
if (encoding != null)
|
||||||
|
settings.Encoding = Encoding.GetEncoding (encoding);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "include":
|
||||||
|
throw new InvalidOperationException ("Include is handled in the parser");
|
||||||
|
|
||||||
|
case "parameter":
|
||||||
|
AddDirective (settings, host, "ParameterDirectiveProcessor", dt);
|
||||||
|
continue;
|
||||||
|
|
||||||
|
default:
|
||||||
|
string processorName = dt.Extract ("Processor");
|
||||||
|
if (processorName == null)
|
||||||
|
throw new InvalidOperationException ("Custom directive '" + dt.Name + "' does not specify a processor");
|
||||||
|
|
||||||
|
AddDirective (settings, host, processorName, dt);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ComplainExcessAttributes (dt, pt);
|
||||||
|
}
|
||||||
|
|
||||||
|
//initialize the custom processors
|
||||||
|
foreach (var kv in settings.DirectiveProcessors) {
|
||||||
|
kv.Value.Initialize (host);
|
||||||
|
var hs = kv.Value as IRecognizeHostSpecific;
|
||||||
|
if (hs == null)
|
||||||
|
continue;
|
||||||
|
if (hs.RequiresProcessingRunIsHostSpecific && !settings.HostSpecific) {
|
||||||
|
settings.HostSpecific = true;
|
||||||
|
pt.LogWarning ("Directive processor '" + kv.Key + "' requires hostspecific=true, forcing on.");
|
||||||
|
}
|
||||||
|
hs.SetProcessingRunIsHostSpecific (settings.HostSpecific);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.Name == null)
|
||||||
|
settings.Name = string.Format ("GeneratedTextTransformation{0:x}", new System.Random ().Next ());
|
||||||
|
if (settings.Namespace == null)
|
||||||
|
settings.Namespace = typeof (TextTransformation).Namespace;
|
||||||
|
|
||||||
|
//resolve the CodeDOM provider
|
||||||
|
if (String.IsNullOrEmpty (settings.Language)) {
|
||||||
|
pt.LogError ("No language was specified for the template");
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.Language == "C#v3.5") {
|
||||||
|
Dictionary<string, string> providerOptions = new Dictionary<string, string> ();
|
||||||
|
providerOptions.Add ("CompilerVersion", "v3.5");
|
||||||
|
settings.Provider = new CSharpCodeProvider (providerOptions);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
settings.Provider = CodeDomProvider.CreateProvider (settings.Language);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.Provider == null) {
|
||||||
|
pt.LogError ("A provider could not be found for the language '" + settings.Language + "'");
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string IndentSnippetText (string text, string indent)
|
||||||
|
{
|
||||||
|
var builder = new StringBuilder (text.Length);
|
||||||
|
builder.Append (indent);
|
||||||
|
int lastNewline = 0;
|
||||||
|
for (int i = 0; i < text.Length - 1; i++) {
|
||||||
|
char c = text[i];
|
||||||
|
if (c == '\r') {
|
||||||
|
if (text[i + 1] == '\n') {
|
||||||
|
i++;
|
||||||
|
if (i == text.Length - 1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (c != '\n') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
int len = i - lastNewline;
|
||||||
|
if (len > 0) {
|
||||||
|
builder.Append (text, lastNewline, i - lastNewline);
|
||||||
|
}
|
||||||
|
builder.Append (indent);
|
||||||
|
lastNewline = i;
|
||||||
|
}
|
||||||
|
if (lastNewline > 0)
|
||||||
|
builder.Append (text, lastNewline, text.Length - lastNewline);
|
||||||
|
else
|
||||||
|
builder.Append (text);
|
||||||
|
return builder.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddDirective (TemplateSettings settings, ITextTemplatingEngineHost host, string processorName, Directive directive)
|
||||||
|
{
|
||||||
|
DirectiveProcessor processor;
|
||||||
|
if (!settings.DirectiveProcessors.TryGetValue (processorName, out processor)) {
|
||||||
|
switch (processorName) {
|
||||||
|
case "ParameterDirectiveProcessor":
|
||||||
|
processor = new ParameterDirectiveProcessor ();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Type processorType = host.ResolveDirectiveProcessor (processorName);
|
||||||
|
processor = (DirectiveProcessor) Activator.CreateInstance (processorType);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!processor.IsDirectiveSupported (directive.Name))
|
||||||
|
throw new InvalidOperationException ("Directive processor '" + processorName + "' does not support directive '" + directive.Name + "'");
|
||||||
|
|
||||||
|
settings.DirectiveProcessors [processorName] = processor;
|
||||||
|
}
|
||||||
|
settings.CustomDirectives.Add (new CustomDirective (processorName, directive));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ComplainExcessAttributes (Directive dt, ParsedTemplate pt)
|
||||||
|
{
|
||||||
|
if (dt.Attributes.Count == 0)
|
||||||
|
return false;
|
||||||
|
StringBuilder sb = new StringBuilder ("Unknown attributes ");
|
||||||
|
bool first = true;
|
||||||
|
foreach (string key in dt.Attributes.Keys) {
|
||||||
|
if (!first) {
|
||||||
|
sb.Append (", ");
|
||||||
|
} else {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
sb.Append (key);
|
||||||
|
}
|
||||||
|
sb.Append (" found in ");
|
||||||
|
sb.Append (dt.Name);
|
||||||
|
sb.Append (" directive.");
|
||||||
|
pt.LogWarning (sb.ToString (), dt.StartLocation);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ProcessDirectives (ITextTemplatingEngineHost host, string content, ParsedTemplate pt, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
foreach (var processor in settings.DirectiveProcessors.Values) {
|
||||||
|
processor.StartProcessingRun (settings.Provider, content, pt.Errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var dt in settings.CustomDirectives) {
|
||||||
|
var processor = settings.DirectiveProcessors[dt.ProcessorName];
|
||||||
|
|
||||||
|
if (processor is RequiresProvidesDirectiveProcessor)
|
||||||
|
throw new NotImplementedException ("RequiresProvidesDirectiveProcessor");
|
||||||
|
|
||||||
|
processor.ProcessDirective (dt.Directive.Name, dt.Directive.Attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var processor in settings.DirectiveProcessors.Values) {
|
||||||
|
processor.FinishProcessingRun ();
|
||||||
|
|
||||||
|
var imports = processor.GetImportsForProcessingRun ();
|
||||||
|
if (imports != null)
|
||||||
|
settings.Imports.UnionWith (imports);
|
||||||
|
var references = processor.GetReferencesForProcessingRun ();
|
||||||
|
if (references != null)
|
||||||
|
settings.Assemblies.UnionWith (references);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CodeCompileUnit GenerateCompileUnit (ITextTemplatingEngineHost host, string content, ParsedTemplate pt, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
ProcessDirectives (host, content, pt, settings);
|
||||||
|
|
||||||
|
//prep the compile unit
|
||||||
|
var ccu = new CodeCompileUnit ();
|
||||||
|
var namespac = new CodeNamespace (settings.Namespace);
|
||||||
|
ccu.Namespaces.Add (namespac);
|
||||||
|
|
||||||
|
foreach (string ns in settings.Imports.Union (host.StandardImports))
|
||||||
|
namespac.Imports.Add (new CodeNamespaceImport (ns));
|
||||||
|
|
||||||
|
//prep the type
|
||||||
|
var type = new CodeTypeDeclaration (settings.Name);
|
||||||
|
type.IsPartial = true;
|
||||||
|
if (!string.IsNullOrEmpty (settings.Inherits)) {
|
||||||
|
type.BaseTypes.Add (new CodeTypeReference (settings.Inherits));
|
||||||
|
} else if (!settings.IncludePreprocessingHelpers) {
|
||||||
|
type.BaseTypes.Add (TypeRef<TextTransformation> ());
|
||||||
|
} else {
|
||||||
|
type.BaseTypes.Add (new CodeTypeReference (settings.Name + "Base"));
|
||||||
|
}
|
||||||
|
namespac.Types.Add (type);
|
||||||
|
|
||||||
|
//prep the transform method
|
||||||
|
var transformMeth = new CodeMemberMethod () {
|
||||||
|
Name = "TransformText",
|
||||||
|
ReturnType = new CodeTypeReference (typeof (String)),
|
||||||
|
Attributes = MemberAttributes.Public,
|
||||||
|
};
|
||||||
|
if (!settings.IncludePreprocessingHelpers)
|
||||||
|
transformMeth.Attributes |= MemberAttributes.Override;
|
||||||
|
|
||||||
|
transformMeth.Statements.Add (new CodeAssignStatement (
|
||||||
|
new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "GenerationEnvironment"),
|
||||||
|
new CodePrimitiveExpression (null)));
|
||||||
|
|
||||||
|
CodeExpression toStringHelper;
|
||||||
|
if (settings.IsPreprocessed) {
|
||||||
|
toStringHelper = new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "ToStringHelper");
|
||||||
|
} else {
|
||||||
|
toStringHelper = new CodeTypeReferenceExpression (
|
||||||
|
new CodeTypeReference (typeof (ToStringHelper), CodeTypeReferenceOptions.GlobalReference));
|
||||||
|
}
|
||||||
|
|
||||||
|
//method references that will need to be used multiple times
|
||||||
|
var writeMeth = new CodeMethodReferenceExpression (new CodeThisReferenceExpression (), "Write");
|
||||||
|
var toStringMeth = new CodeMethodReferenceExpression (toStringHelper, "ToStringWithCulture");
|
||||||
|
bool helperMode = false;
|
||||||
|
|
||||||
|
//build the code from the segments
|
||||||
|
foreach (TemplateSegment seg in pt.Content) {
|
||||||
|
CodeStatement st = null;
|
||||||
|
var location = new CodeLinePragma (seg.StartLocation.FileName ?? host.TemplateFile, seg.StartLocation.Line);
|
||||||
|
switch (seg.Type) {
|
||||||
|
case SegmentType.Block:
|
||||||
|
if (helperMode)
|
||||||
|
//TODO: are blocks permitted after helpers?
|
||||||
|
throw new ParserException ("Blocks are not permitted after helpers", seg.StartLocation);
|
||||||
|
st = new CodeSnippetStatement (seg.Text);
|
||||||
|
break;
|
||||||
|
case SegmentType.Expression:
|
||||||
|
st = new CodeExpressionStatement (
|
||||||
|
new CodeMethodInvokeExpression (writeMeth,
|
||||||
|
new CodeMethodInvokeExpression (toStringMeth, new CodeSnippetExpression (seg.Text))));
|
||||||
|
break;
|
||||||
|
case SegmentType.Content:
|
||||||
|
st = new CodeExpressionStatement (new CodeMethodInvokeExpression (writeMeth, new CodePrimitiveExpression (seg.Text)));
|
||||||
|
break;
|
||||||
|
case SegmentType.Helper:
|
||||||
|
type.Members.Add (new CodeSnippetTypeMember (seg.Text) { LinePragma = location });
|
||||||
|
helperMode = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException ();
|
||||||
|
}
|
||||||
|
if (st != null) {
|
||||||
|
if (helperMode) {
|
||||||
|
//convert the statement into a snippet member and attach it to the top level type
|
||||||
|
//TODO: is there a way to do this for languages that use indentation for blocks, e.g. python?
|
||||||
|
using (var writer = new StringWriter ()) {
|
||||||
|
settings.Provider.GenerateCodeFromStatement (st, writer, null);
|
||||||
|
type.Members.Add (new CodeSnippetTypeMember (writer.ToString ()) { LinePragma = location });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
st.LinePragma = location;
|
||||||
|
transformMeth.Statements.Add (st);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//complete the transform method
|
||||||
|
transformMeth.Statements.Add (new CodeMethodReturnStatement (
|
||||||
|
new CodeMethodInvokeExpression (
|
||||||
|
new CodePropertyReferenceExpression (
|
||||||
|
new CodeThisReferenceExpression (),
|
||||||
|
"GenerationEnvironment"),
|
||||||
|
"ToString")));
|
||||||
|
type.Members.Add (transformMeth);
|
||||||
|
|
||||||
|
//class code from processors
|
||||||
|
foreach (var processor in settings.DirectiveProcessors.Values) {
|
||||||
|
string classCode = processor.GetClassCodeForProcessingRun ();
|
||||||
|
if (classCode != null)
|
||||||
|
type.Members.Add (new CodeSnippetTypeMember (classCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
//generate the Host property if needed
|
||||||
|
if (settings.HostSpecific) {
|
||||||
|
GenerateHostProperty (type, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
GenerateInitializationMethod (type, settings);
|
||||||
|
|
||||||
|
if (settings.IncludePreprocessingHelpers) {
|
||||||
|
var baseClass = new CodeTypeDeclaration (settings.Name + "Base");
|
||||||
|
GenerateProcessingHelpers (baseClass, settings);
|
||||||
|
AddToStringHelper (baseClass, settings);
|
||||||
|
namespac.Types.Add (baseClass);
|
||||||
|
}
|
||||||
|
return ccu;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenerateHostProperty (CodeTypeDeclaration type, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
var hostField = new CodeMemberField (TypeRef<ITextTemplatingEngineHost> (), "hostValue");
|
||||||
|
hostField.Attributes = (hostField.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Private;
|
||||||
|
type.Members.Add (hostField);
|
||||||
|
|
||||||
|
var hostProp = GenerateGetterSetterProperty ("Host", hostField);
|
||||||
|
hostProp.Attributes = MemberAttributes.Public | MemberAttributes.Final;
|
||||||
|
type.Members.Add (hostProp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenerateInitializationMethod (CodeTypeDeclaration type, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
//initialization method
|
||||||
|
var initializeMeth = new CodeMemberMethod () {
|
||||||
|
Name = "Initialize",
|
||||||
|
ReturnType = new CodeTypeReference (typeof (void), CodeTypeReferenceOptions.GlobalReference),
|
||||||
|
Attributes = MemberAttributes.Family
|
||||||
|
};
|
||||||
|
if (!settings.IncludePreprocessingHelpers)
|
||||||
|
initializeMeth.Attributes |= MemberAttributes.Override;
|
||||||
|
|
||||||
|
//pre-init code from processors
|
||||||
|
foreach (var processor in settings.DirectiveProcessors.Values) {
|
||||||
|
string code = processor.GetPreInitializationCodeForProcessingRun ();
|
||||||
|
if (code != null)
|
||||||
|
initializeMeth.Statements.Add (new CodeSnippetStatement (code));
|
||||||
|
}
|
||||||
|
|
||||||
|
//base call
|
||||||
|
if (!settings.IncludePreprocessingHelpers) {
|
||||||
|
initializeMeth.Statements.Add (
|
||||||
|
new CodeMethodInvokeExpression (
|
||||||
|
new CodeMethodReferenceExpression (
|
||||||
|
new CodeBaseReferenceExpression (),
|
||||||
|
"Initialize")));
|
||||||
|
}
|
||||||
|
|
||||||
|
//post-init code from processors
|
||||||
|
foreach (var processor in settings.DirectiveProcessors.Values) {
|
||||||
|
string code = processor.GetPostInitializationCodeForProcessingRun ();
|
||||||
|
if (code != null)
|
||||||
|
initializeMeth.Statements.Add (new CodeSnippetStatement (code));
|
||||||
|
}
|
||||||
|
|
||||||
|
type.Members.Add (initializeMeth);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenerateProcessingHelpers (CodeTypeDeclaration type, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
var thisRef = new CodeThisReferenceExpression ();
|
||||||
|
var sbTypeRef = TypeRef<StringBuilder> ();
|
||||||
|
|
||||||
|
var sessionField = PrivateField (TypeRef<IDictionary<string,object>> (), "session");
|
||||||
|
var sessionProp = GenerateGetterSetterProperty ("Session", sessionField);
|
||||||
|
sessionProp.Attributes = MemberAttributes.Public;
|
||||||
|
|
||||||
|
var builderField = PrivateField (sbTypeRef, "builder");
|
||||||
|
var builderFieldRef = new CodeFieldReferenceExpression (thisRef, builderField.Name);
|
||||||
|
|
||||||
|
var generationEnvironmentProp = GenerateGetterSetterProperty ("GenerationEnvironment", builderField);
|
||||||
|
AddPropertyGetterInitializationIfFieldIsNull (generationEnvironmentProp, builderFieldRef, TypeRef<StringBuilder> ());
|
||||||
|
|
||||||
|
type.Members.Add (builderField);
|
||||||
|
type.Members.Add (sessionField);
|
||||||
|
type.Members.Add (sessionProp);
|
||||||
|
type.Members.Add (generationEnvironmentProp);
|
||||||
|
|
||||||
|
AddErrorHelpers (type, settings);
|
||||||
|
AddIndentHelpers (type, settings);
|
||||||
|
AddWriteHelpers (type, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddPropertyGetterInitializationIfFieldIsNull (CodeMemberProperty property, CodeFieldReferenceExpression fieldRef, CodeTypeReference typeRef)
|
||||||
|
{
|
||||||
|
var fieldInit = FieldInitializationIfNull (fieldRef, typeRef);
|
||||||
|
property.GetStatements.Insert (0, fieldInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeConditionStatement FieldInitializationIfNull (CodeFieldReferenceExpression fieldRef, CodeTypeReference typeRef)
|
||||||
|
{
|
||||||
|
return new CodeConditionStatement (
|
||||||
|
new CodeBinaryOperatorExpression (fieldRef,
|
||||||
|
CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression (null)),
|
||||||
|
new CodeAssignStatement (fieldRef, new CodeObjectCreateExpression (typeRef)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddErrorHelpers (CodeTypeDeclaration type, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
var cecTypeRef = TypeRef<CompilerErrorCollection> ();
|
||||||
|
var thisRef = new CodeThisReferenceExpression ();
|
||||||
|
var stringTypeRef = TypeRef<string> ();
|
||||||
|
var nullPrim = new CodePrimitiveExpression (null);
|
||||||
|
var minusOnePrim = new CodePrimitiveExpression (-1);
|
||||||
|
|
||||||
|
var errorsField = PrivateField (cecTypeRef, "errors");
|
||||||
|
var errorsFieldRef = new CodeFieldReferenceExpression (thisRef, errorsField.Name);
|
||||||
|
|
||||||
|
var errorsProp = GenerateGetterProperty ("Errors", errorsField);
|
||||||
|
errorsProp.Attributes = MemberAttributes.Family | MemberAttributes.Final;
|
||||||
|
errorsProp.GetStatements.Insert (0, FieldInitializationIfNull (errorsFieldRef, TypeRef<CompilerErrorCollection>()));
|
||||||
|
|
||||||
|
var errorsPropRef = new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "Errors");
|
||||||
|
|
||||||
|
var compilerErrorTypeRef = TypeRef<CompilerError> ();
|
||||||
|
var errorMeth = new CodeMemberMethod () {
|
||||||
|
Name = "Error",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
errorMeth.Parameters.Add (new CodeParameterDeclarationExpression (stringTypeRef, "message"));
|
||||||
|
errorMeth.Statements.Add (new CodeMethodInvokeExpression (errorsPropRef, "Add",
|
||||||
|
new CodeObjectCreateExpression (compilerErrorTypeRef, nullPrim, minusOnePrim, minusOnePrim, nullPrim,
|
||||||
|
new CodeArgumentReferenceExpression ("message"))));
|
||||||
|
|
||||||
|
var warningMeth = new CodeMemberMethod () {
|
||||||
|
Name = "Warning",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
warningMeth.Parameters.Add (new CodeParameterDeclarationExpression (stringTypeRef, "message"));
|
||||||
|
warningMeth.Statements.Add (new CodeVariableDeclarationStatement (compilerErrorTypeRef, "val",
|
||||||
|
new CodeObjectCreateExpression (compilerErrorTypeRef, nullPrim, minusOnePrim, minusOnePrim, nullPrim,
|
||||||
|
new CodeArgumentReferenceExpression ("message"))));
|
||||||
|
warningMeth.Statements.Add (new CodeAssignStatement (new CodePropertyReferenceExpression (
|
||||||
|
new CodeVariableReferenceExpression ("val"), "IsWarning"), new CodePrimitiveExpression (true)));
|
||||||
|
warningMeth.Statements.Add (new CodeMethodInvokeExpression (errorsPropRef, "Add",
|
||||||
|
new CodeVariableReferenceExpression ("val")));
|
||||||
|
|
||||||
|
type.Members.Add (errorsField);
|
||||||
|
type.Members.Add (errorMeth);
|
||||||
|
type.Members.Add (warningMeth);
|
||||||
|
type.Members.Add (errorsProp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddIndentHelpers (CodeTypeDeclaration type, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
var stringTypeRef = TypeRef<string> ();
|
||||||
|
var thisRef = new CodeThisReferenceExpression ();
|
||||||
|
var zeroPrim = new CodePrimitiveExpression (0);
|
||||||
|
var stringEmptyRef = new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (stringTypeRef), "Empty");
|
||||||
|
var intTypeRef = TypeRef<int> ();
|
||||||
|
var stackIntTypeRef = TypeRef<Stack<int>> ();
|
||||||
|
|
||||||
|
var indentsField = PrivateField (stackIntTypeRef, "indents");
|
||||||
|
var indentsFieldRef = new CodeFieldReferenceExpression (thisRef, indentsField.Name);
|
||||||
|
|
||||||
|
var indentsProp = GenerateGetterProperty ("Indents", indentsField);
|
||||||
|
indentsProp.Attributes = MemberAttributes.Private;
|
||||||
|
AddPropertyGetterInitializationIfFieldIsNull (indentsProp, indentsFieldRef, TypeRef<Stack<int>> ());
|
||||||
|
|
||||||
|
var indentsPropRef = new CodeFieldReferenceExpression (thisRef, indentsProp.Name);
|
||||||
|
|
||||||
|
var currentIndentField = PrivateField (stringTypeRef, "currentIndent");
|
||||||
|
currentIndentField.InitExpression = stringEmptyRef;
|
||||||
|
var currentIndentFieldRef = new CodeFieldReferenceExpression (thisRef, currentIndentField.Name);
|
||||||
|
|
||||||
|
var popIndentMeth = new CodeMemberMethod () {
|
||||||
|
Name = "PopIndent",
|
||||||
|
ReturnType = stringTypeRef,
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
popIndentMeth.Statements.Add (new CodeConditionStatement (
|
||||||
|
new CodeBinaryOperatorExpression (new CodePropertyReferenceExpression (indentsPropRef, "Count"),
|
||||||
|
CodeBinaryOperatorType.ValueEquality, zeroPrim),
|
||||||
|
new CodeMethodReturnStatement (stringEmptyRef)));
|
||||||
|
popIndentMeth.Statements.Add (new CodeVariableDeclarationStatement (intTypeRef, "lastPos",
|
||||||
|
new CodeBinaryOperatorExpression (
|
||||||
|
new CodePropertyReferenceExpression (currentIndentFieldRef, "Length"),
|
||||||
|
CodeBinaryOperatorType.Subtract,
|
||||||
|
new CodeMethodInvokeExpression (indentsPropRef, "Pop"))));
|
||||||
|
popIndentMeth.Statements.Add (new CodeVariableDeclarationStatement (stringTypeRef, "last",
|
||||||
|
new CodeMethodInvokeExpression (currentIndentFieldRef, "Substring", new CodeVariableReferenceExpression ("lastPos"))));
|
||||||
|
popIndentMeth.Statements.Add (new CodeAssignStatement (currentIndentFieldRef,
|
||||||
|
new CodeMethodInvokeExpression (currentIndentFieldRef, "Substring", zeroPrim, new CodeVariableReferenceExpression ("lastPos"))));
|
||||||
|
popIndentMeth.Statements.Add (new CodeMethodReturnStatement (new CodeVariableReferenceExpression ("last")));
|
||||||
|
|
||||||
|
var pushIndentMeth = new CodeMemberMethod () {
|
||||||
|
Name = "PushIndent",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
pushIndentMeth.Parameters.Add (new CodeParameterDeclarationExpression (stringTypeRef, "indent"));
|
||||||
|
pushIndentMeth.Statements.Add (new CodeMethodInvokeExpression (indentsPropRef, "Push",
|
||||||
|
new CodePropertyReferenceExpression (new CodeArgumentReferenceExpression ("indent"), "Length")));
|
||||||
|
pushIndentMeth.Statements.Add (new CodeAssignStatement (currentIndentFieldRef,
|
||||||
|
new CodeBinaryOperatorExpression (currentIndentFieldRef, CodeBinaryOperatorType.Add, new CodeArgumentReferenceExpression ("indent"))));
|
||||||
|
|
||||||
|
var clearIndentMeth = new CodeMemberMethod () {
|
||||||
|
Name = "ClearIndent",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
clearIndentMeth.Statements.Add (new CodeAssignStatement (currentIndentFieldRef, stringEmptyRef));
|
||||||
|
clearIndentMeth.Statements.Add (new CodeMethodInvokeExpression (indentsPropRef, "Clear"));
|
||||||
|
|
||||||
|
var currentIndentProp = GenerateGetterProperty ("CurrentIndent", currentIndentField);
|
||||||
|
type.Members.Add (currentIndentField);
|
||||||
|
type.Members.Add (indentsField);
|
||||||
|
type.Members.Add (popIndentMeth);
|
||||||
|
type.Members.Add (pushIndentMeth);
|
||||||
|
type.Members.Add (clearIndentMeth);
|
||||||
|
type.Members.Add (currentIndentProp);
|
||||||
|
type.Members.Add (indentsProp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddWriteHelpers (CodeTypeDeclaration type, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
var stringTypeRef = TypeRef<string> ();
|
||||||
|
var thisRef = new CodeThisReferenceExpression ();
|
||||||
|
var genEnvPropRef = new CodePropertyReferenceExpression (thisRef, "GenerationEnvironment");
|
||||||
|
var currentIndentFieldRef = new CodeFieldReferenceExpression (thisRef, "currentIndent");
|
||||||
|
|
||||||
|
var textToAppendParam = new CodeParameterDeclarationExpression (stringTypeRef, "textToAppend");
|
||||||
|
var formatParam = new CodeParameterDeclarationExpression (stringTypeRef, "format");
|
||||||
|
var argsParam = new CodeParameterDeclarationExpression (TypeRef<object[]> (), "args");
|
||||||
|
argsParam.CustomAttributes.Add (new CodeAttributeDeclaration (TypeRef<System.ParamArrayAttribute> ()));
|
||||||
|
|
||||||
|
var textToAppendParamRef = new CodeArgumentReferenceExpression ("textToAppend");
|
||||||
|
var formatParamRef = new CodeArgumentReferenceExpression ("format");
|
||||||
|
var argsParamRef = new CodeArgumentReferenceExpression ("args");
|
||||||
|
|
||||||
|
var writeMeth = new CodeMemberMethod () {
|
||||||
|
Name = "Write",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
writeMeth.Parameters.Add (textToAppendParam);
|
||||||
|
writeMeth.Statements.Add (new CodeMethodInvokeExpression (genEnvPropRef, "Append", new CodeArgumentReferenceExpression ("textToAppend")));
|
||||||
|
|
||||||
|
var writeArgsMeth = new CodeMemberMethod () {
|
||||||
|
Name = "Write",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
writeArgsMeth.Parameters.Add (formatParam);
|
||||||
|
writeArgsMeth.Parameters.Add (argsParam);
|
||||||
|
writeArgsMeth.Statements.Add (new CodeMethodInvokeExpression (genEnvPropRef, "AppendFormat", formatParamRef, argsParamRef));
|
||||||
|
|
||||||
|
var writeLineMeth = new CodeMemberMethod () {
|
||||||
|
Name = "WriteLine",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
writeLineMeth.Parameters.Add (textToAppendParam);
|
||||||
|
writeLineMeth.Statements.Add (new CodeMethodInvokeExpression (genEnvPropRef, "Append", currentIndentFieldRef));
|
||||||
|
writeLineMeth.Statements.Add (new CodeMethodInvokeExpression (genEnvPropRef, "AppendLine", textToAppendParamRef));
|
||||||
|
|
||||||
|
var writeLineArgsMeth = new CodeMemberMethod () {
|
||||||
|
Name = "WriteLine",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
};
|
||||||
|
writeLineArgsMeth.Parameters.Add (formatParam);
|
||||||
|
writeLineArgsMeth.Parameters.Add (argsParam);
|
||||||
|
writeLineArgsMeth.Statements.Add (new CodeMethodInvokeExpression (genEnvPropRef, "Append", currentIndentFieldRef));
|
||||||
|
writeLineArgsMeth.Statements.Add (new CodeMethodInvokeExpression (genEnvPropRef, "AppendFormat", formatParamRef, argsParamRef));
|
||||||
|
writeLineArgsMeth.Statements.Add (new CodeMethodInvokeExpression (genEnvPropRef, "AppendLine"));
|
||||||
|
|
||||||
|
type.Members.Add (writeMeth);
|
||||||
|
type.Members.Add (writeArgsMeth);
|
||||||
|
type.Members.Add (writeLineMeth);
|
||||||
|
type.Members.Add (writeLineArgsMeth);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddToStringHelper (CodeTypeDeclaration type, TemplateSettings settings)
|
||||||
|
{
|
||||||
|
var helperCls = new CodeTypeDeclaration ("ToStringInstanceHelper") {
|
||||||
|
IsClass = true,
|
||||||
|
TypeAttributes = System.Reflection.TypeAttributes.NestedPublic,
|
||||||
|
};
|
||||||
|
|
||||||
|
var formatProviderField = PrivateField (TypeRef<IFormatProvider> (), "formatProvider");
|
||||||
|
formatProviderField.InitExpression = new CodePropertyReferenceExpression (
|
||||||
|
new CodeTypeReferenceExpression (TypeRef<System.Globalization.CultureInfo> ()), "InvariantCulture");
|
||||||
|
var formatProviderFieldRef = new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), formatProviderField.Name);
|
||||||
|
|
||||||
|
var formatProviderProp = GenerateGetterSetterProperty ("FormatProvider", formatProviderField);
|
||||||
|
AddSetterNullCheck (formatProviderProp, formatProviderFieldRef);
|
||||||
|
|
||||||
|
helperCls.Members.Add (formatProviderField);
|
||||||
|
helperCls.Members.Add (formatProviderProp);
|
||||||
|
|
||||||
|
var meth = new CodeMemberMethod () {
|
||||||
|
Name = "ToStringWithCulture",
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
ReturnType = TypeRef<string> (),
|
||||||
|
};
|
||||||
|
meth.Parameters.Add (new CodeParameterDeclarationExpression (TypeRef<object> (), "objectToConvert"));
|
||||||
|
var paramRef = new CodeArgumentReferenceExpression ("objectToConvert");
|
||||||
|
|
||||||
|
meth.Statements.Add (NullCheck (paramRef, paramRef.ParameterName));
|
||||||
|
|
||||||
|
var typeLocal = new CodeVariableDeclarationStatement (TypeRef<Type> (), "type", new CodeMethodInvokeExpression (paramRef, "GetType"));
|
||||||
|
var typeLocalRef = new CodeVariableReferenceExpression (typeLocal.Name);
|
||||||
|
meth.Statements.Add (typeLocal);
|
||||||
|
|
||||||
|
var iConvertibleTypeLocal = new CodeVariableDeclarationStatement (TypeRef<Type> (), "iConvertibleType",
|
||||||
|
new CodeTypeOfExpression (TypeRef<IConvertible> ()));
|
||||||
|
var iConvertibleTypeLocalRef = new CodeVariableReferenceExpression (iConvertibleTypeLocal.Name);
|
||||||
|
meth.Statements.Add (iConvertibleTypeLocal);
|
||||||
|
|
||||||
|
meth.Statements.Add (new CodeConditionStatement (
|
||||||
|
new CodeMethodInvokeExpression (iConvertibleTypeLocalRef, "IsAssignableFrom", typeLocalRef),
|
||||||
|
new CodeMethodReturnStatement (new CodeMethodInvokeExpression (
|
||||||
|
new CodeCastExpression (TypeRef<IConvertible> (), paramRef), "ToString", formatProviderFieldRef))));
|
||||||
|
|
||||||
|
var methInfoLocal = new CodeVariableDeclarationStatement (TypeRef<MethodInfo> (), "methInfo",
|
||||||
|
new CodeMethodInvokeExpression (typeLocalRef, "GetMethod",
|
||||||
|
new CodePrimitiveExpression ("ToString"),
|
||||||
|
new CodeArrayCreateExpression (TypeRef<Type> (), new CodeExpression [] { iConvertibleTypeLocalRef })));
|
||||||
|
meth.Statements.Add (methInfoLocal);
|
||||||
|
var methInfoLocalRef = new CodeVariableReferenceExpression (methInfoLocal.Name);
|
||||||
|
meth.Statements.Add (new CodeConditionStatement (NotNull (methInfoLocalRef),
|
||||||
|
new CodeMethodReturnStatement (new CodeCastExpression (TypeRef<string> (),
|
||||||
|
new CodeMethodInvokeExpression (
|
||||||
|
methInfoLocalRef, "Invoke", paramRef,
|
||||||
|
new CodeArrayCreateExpression (TypeRef<object> (), new CodeExpression [] { formatProviderFieldRef } ))))));
|
||||||
|
|
||||||
|
meth.Statements.Add (new CodeMethodReturnStatement (new CodeMethodInvokeExpression (paramRef, "ToString")));
|
||||||
|
|
||||||
|
helperCls.Members.Add (meth);
|
||||||
|
|
||||||
|
|
||||||
|
var helperFieldName = settings.Provider.CreateValidIdentifier ("_toStringHelper");
|
||||||
|
var helperField = PrivateField (new CodeTypeReference (helperCls.Name), helperFieldName);
|
||||||
|
helperField.InitExpression = new CodeObjectCreateExpression (helperField.Type);
|
||||||
|
type.Members.Add (helperField);
|
||||||
|
type.Members.Add (GenerateGetterProperty ("ToStringHelper", helperField));
|
||||||
|
type.Members.Add (helperCls);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region CodeDom helpers
|
||||||
|
|
||||||
|
static CodeTypeReference TypeRef<T> ()
|
||||||
|
{
|
||||||
|
return new CodeTypeReference (typeof (T), CodeTypeReferenceOptions.GlobalReference);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeMemberProperty GenerateGetterSetterProperty (string propertyName, CodeMemberField field)
|
||||||
|
{
|
||||||
|
var prop = new CodeMemberProperty () {
|
||||||
|
Name = propertyName,
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
Type = field.Type
|
||||||
|
};
|
||||||
|
var fieldRef = new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), field.Name);
|
||||||
|
AddGetter (prop, fieldRef);
|
||||||
|
AddSetter (prop, fieldRef);
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeMemberProperty GenerateGetterProperty (string propertyName, CodeMemberField field)
|
||||||
|
{
|
||||||
|
var prop = new CodeMemberProperty () {
|
||||||
|
Name = propertyName,
|
||||||
|
Attributes = MemberAttributes.Public | MemberAttributes.Final,
|
||||||
|
HasSet = false,
|
||||||
|
Type = field.Type
|
||||||
|
};
|
||||||
|
var fieldRef = new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), field.Name);
|
||||||
|
AddGetter (prop, fieldRef);
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddSetter (CodeMemberProperty property, CodeFieldReferenceExpression fieldRef)
|
||||||
|
{
|
||||||
|
property.HasSet = true;
|
||||||
|
property.SetStatements.Add (new CodeAssignStatement (fieldRef, new CodePropertySetValueReferenceExpression ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddGetter (CodeMemberProperty property, CodeFieldReferenceExpression fieldRef)
|
||||||
|
{
|
||||||
|
property.HasGet = true;
|
||||||
|
property.GetStatements.Add (new CodeMethodReturnStatement (fieldRef));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void MakeGetterLazy (CodeMemberProperty property, CodeFieldReferenceExpression fieldRef, CodeExpression initExpression)
|
||||||
|
{
|
||||||
|
property.GetStatements.Insert (0, new CodeConditionStatement (
|
||||||
|
NotNull (fieldRef),
|
||||||
|
new CodeAssignStatement (fieldRef, initExpression))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddSetterNullCheck (CodeMemberProperty property, CodeFieldReferenceExpression fieldRef)
|
||||||
|
{
|
||||||
|
property.SetStatements.Insert (0, NullCheck (fieldRef, fieldRef.FieldName));
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeStatement NullCheck (CodeExpression expr, string exceptionMessage)
|
||||||
|
{
|
||||||
|
return new CodeConditionStatement (
|
||||||
|
IsNull (expr),
|
||||||
|
new CodeThrowExceptionStatement (new CodeObjectCreateExpression (
|
||||||
|
new CodeTypeReference (typeof (ArgumentNullException), CodeTypeReferenceOptions.GlobalReference),
|
||||||
|
new CodePrimitiveExpression (exceptionMessage)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeBinaryOperatorExpression NotNull (CodeExpression reference)
|
||||||
|
{
|
||||||
|
return new CodeBinaryOperatorExpression (reference, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression (null));
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeBinaryOperatorExpression IsNull (CodeExpression reference)
|
||||||
|
{
|
||||||
|
return new CodeBinaryOperatorExpression (reference, CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression (null));
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeBinaryOperatorExpression IsFalse (CodeExpression expr)
|
||||||
|
{
|
||||||
|
return new CodeBinaryOperatorExpression (expr, CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression (false));
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeBinaryOperatorExpression BooleanAnd (CodeExpression expr1, CodeExpression expr2)
|
||||||
|
{
|
||||||
|
return new CodeBinaryOperatorExpression (expr1, CodeBinaryOperatorType.BooleanAnd, expr2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeStatement ArgNullCheck (CodeExpression value, params CodeExpression[] argNullExcArgs)
|
||||||
|
{
|
||||||
|
return new CodeConditionStatement (
|
||||||
|
new CodeBinaryOperatorExpression (value,
|
||||||
|
CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression (null)),
|
||||||
|
new CodeThrowExceptionStatement (new CodeObjectCreateExpression (typeof (ArgumentNullException), argNullExcArgs)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static CodeMemberField PrivateField (CodeTypeReference typeRef, string name)
|
||||||
|
{
|
||||||
|
return new CodeMemberField (typeRef, name) {
|
||||||
|
Attributes = MemberAttributes.Private
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,295 @@
|
||||||
|
//
|
||||||
|
// Tokeniser.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
|
||||||
|
public class Tokeniser
|
||||||
|
{
|
||||||
|
string content;
|
||||||
|
int position = 0;
|
||||||
|
string value;
|
||||||
|
State nextState = State.Content;
|
||||||
|
Location nextStateLocation;
|
||||||
|
Location nextStateTagStartLocation;
|
||||||
|
|
||||||
|
public Tokeniser (string fileName, string content)
|
||||||
|
{
|
||||||
|
State = State.Content;
|
||||||
|
this.content = content;
|
||||||
|
this.Location = this.nextStateLocation = this.nextStateTagStartLocation = new Location (fileName, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Advance ()
|
||||||
|
{
|
||||||
|
value = null;
|
||||||
|
State = nextState;
|
||||||
|
Location = nextStateLocation;
|
||||||
|
TagStartLocation = nextStateTagStartLocation;
|
||||||
|
if (nextState == State.EOF)
|
||||||
|
return false;
|
||||||
|
nextState = GetNextStateAndCurrentValue ();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
State GetNextStateAndCurrentValue ()
|
||||||
|
{
|
||||||
|
switch (State) {
|
||||||
|
case State.Block:
|
||||||
|
case State.Expression:
|
||||||
|
case State.Helper:
|
||||||
|
return GetBlockEnd ();
|
||||||
|
|
||||||
|
case State.Directive:
|
||||||
|
return NextStateInDirective ();
|
||||||
|
|
||||||
|
case State.Content:
|
||||||
|
return NextStateInContent ();
|
||||||
|
|
||||||
|
case State.DirectiveName:
|
||||||
|
return GetDirectiveName ();
|
||||||
|
|
||||||
|
case State.DirectiveValue:
|
||||||
|
return GetDirectiveValue ();
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException ("Unexpected state '" + State.ToString () + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
State GetBlockEnd ()
|
||||||
|
{
|
||||||
|
int start = position;
|
||||||
|
for (; position < content.Length; position++) {
|
||||||
|
char c = content[position];
|
||||||
|
nextStateTagStartLocation = nextStateLocation;
|
||||||
|
nextStateLocation = nextStateLocation.AddCol ();
|
||||||
|
if (c == '\r') {
|
||||||
|
if (position + 1 < content.Length && content[position + 1] == '\n')
|
||||||
|
position++;
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
} else if (c == '\n') {
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
} else if (c =='>' && content[position-1] == '#' && content[position-2] != '\\') {
|
||||||
|
value = content.Substring (start, position - start - 1);
|
||||||
|
position++;
|
||||||
|
TagEndLocation = nextStateLocation;
|
||||||
|
|
||||||
|
//skip newlines directly after blocks, unless they're expressions
|
||||||
|
if (State != State.Expression && (position += IsNewLine()) > 0) {
|
||||||
|
nextStateLocation = nextStateLocation.AddLine ();
|
||||||
|
}
|
||||||
|
return State.Content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ParserException ("Unexpected end of file.", nextStateLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
State GetDirectiveName ()
|
||||||
|
{
|
||||||
|
int start = position;
|
||||||
|
for (; position < content.Length; position++) {
|
||||||
|
char c = content[position];
|
||||||
|
if (!Char.IsLetterOrDigit (c)) {
|
||||||
|
value = content.Substring (start, position - start);
|
||||||
|
return State.Directive;
|
||||||
|
} else {
|
||||||
|
nextStateLocation = nextStateLocation.AddCol ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ParserException ("Unexpected end of file.", nextStateLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
State GetDirectiveValue ()
|
||||||
|
{
|
||||||
|
int start = position;
|
||||||
|
int delimiter = '\0';
|
||||||
|
for (; position < content.Length; position++) {
|
||||||
|
char c = content[position];
|
||||||
|
nextStateLocation = nextStateLocation.AddCol ();
|
||||||
|
if (c == '\r') {
|
||||||
|
if (position + 1 < content.Length && content[position + 1] == '\n')
|
||||||
|
position++;
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
} else if (c == '\n')
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
if (delimiter == '\0') {
|
||||||
|
if (c == '\'' || c == '"') {
|
||||||
|
start = position;
|
||||||
|
delimiter = c;
|
||||||
|
} else if (!Char.IsWhiteSpace (c)) {
|
||||||
|
throw new ParserException ("Unexpected character '" + c + "'. Expecting attribute value.", nextStateLocation);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c == delimiter) {
|
||||||
|
value = content.Substring (start + 1, position - start - 1);
|
||||||
|
position++;
|
||||||
|
return State.Directive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ParserException ("Unexpected end of file.", nextStateLocation);;
|
||||||
|
}
|
||||||
|
|
||||||
|
State NextStateInContent ()
|
||||||
|
{
|
||||||
|
int start = position;
|
||||||
|
for (; position < content.Length; position++) {
|
||||||
|
char c = content[position];
|
||||||
|
nextStateTagStartLocation = nextStateLocation;
|
||||||
|
nextStateLocation = nextStateLocation.AddCol ();
|
||||||
|
if (c == '\r') {
|
||||||
|
if (position + 1 < content.Length && content[position + 1] == '\n')
|
||||||
|
position++;
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
} else if (c == '\n') {
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
} else if (c =='<' && position + 2 < content.Length && content[position+1] == '#') {
|
||||||
|
TagEndLocation = nextStateLocation;
|
||||||
|
char type = content[position+2];
|
||||||
|
if (type == '@') {
|
||||||
|
nextStateLocation = nextStateLocation.AddCols (2);
|
||||||
|
value = content.Substring (start, position - start);
|
||||||
|
position += 3;
|
||||||
|
return State.Directive;
|
||||||
|
} else if (type == '=') {
|
||||||
|
nextStateLocation = nextStateLocation.AddCols (2);
|
||||||
|
value = content.Substring (start, position - start);
|
||||||
|
position += 3;
|
||||||
|
return State.Expression;
|
||||||
|
} else if (type == '+') {
|
||||||
|
nextStateLocation = nextStateLocation.AddCols (2);
|
||||||
|
value = content.Substring (start, position - start);
|
||||||
|
position += 3;
|
||||||
|
return State.Helper;
|
||||||
|
} else {
|
||||||
|
value = content.Substring (start, position - start);
|
||||||
|
nextStateLocation = nextStateLocation.AddCol ();
|
||||||
|
position += 2;
|
||||||
|
return State.Block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//EOF is only valid when we're in content
|
||||||
|
value = content.Substring (start);
|
||||||
|
return State.EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
int IsNewLine() {
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
if (position < content.Length && content[position] == '\r') {
|
||||||
|
found++;
|
||||||
|
}
|
||||||
|
if (position+found < content.Length && content[position+found] == '\n') {
|
||||||
|
found++;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
State NextStateInDirective () {
|
||||||
|
for (; position < content.Length; position++) {
|
||||||
|
char c = content[position];
|
||||||
|
if (c == '\r') {
|
||||||
|
if (position + 1 < content.Length && content[position + 1] == '\n')
|
||||||
|
position++;
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
} else if (c == '\n') {
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
} else if (Char.IsLetter (c)) {
|
||||||
|
return State.DirectiveName;
|
||||||
|
} else if (c == '=') {
|
||||||
|
nextStateLocation = nextStateLocation.AddCol ();
|
||||||
|
position++;
|
||||||
|
return State.DirectiveValue;
|
||||||
|
} else if (c == '#' && position + 1 < content.Length && content[position+1] == '>') {
|
||||||
|
position+=2;
|
||||||
|
TagEndLocation = nextStateLocation.AddCols (2);
|
||||||
|
nextStateLocation = nextStateLocation.AddCols (3);
|
||||||
|
|
||||||
|
//skip newlines directly after directives
|
||||||
|
if ((position += IsNewLine()) > 0) {
|
||||||
|
nextStateLocation = nextStateLocation.AddLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
return State.Content;
|
||||||
|
} else if (!Char.IsWhiteSpace (c)) {
|
||||||
|
throw new ParserException ("Directive ended unexpectedly with character '" + c + "'", nextStateLocation);
|
||||||
|
} else {
|
||||||
|
nextStateLocation = nextStateLocation.AddCol ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ParserException ("Unexpected end of file.", nextStateLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public State State {
|
||||||
|
get; private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Position {
|
||||||
|
get { return position; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Content {
|
||||||
|
get { return content; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Value {
|
||||||
|
get { return value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location Location { get; private set; }
|
||||||
|
public Location TagStartLocation { get; private set; }
|
||||||
|
public Location TagEndLocation { get; private set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum State
|
||||||
|
{
|
||||||
|
Content = 0,
|
||||||
|
Directive,
|
||||||
|
Expression,
|
||||||
|
Block,
|
||||||
|
Helper,
|
||||||
|
DirectiveName,
|
||||||
|
DirectiveValue,
|
||||||
|
Name,
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ParserException : Exception
|
||||||
|
{
|
||||||
|
public ParserException (string message, Location location) : base (message)
|
||||||
|
{
|
||||||
|
Location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location Location { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
19
SparkleShare/Windows/tools/TextTemplating/README.md
Normal file
19
SparkleShare/Windows/tools/TextTemplating/README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
TextTemplating
|
||||||
|
==============
|
||||||
|
|
||||||
|
This is the TextTemplating tool inluded in MonoDevelop.
|
||||||
|
The original location of these files is
|
||||||
|
https://github.com/mono/monodevelop/tree/master/main/src/addins/TextTemplating
|
||||||
|
|
||||||
|
Building on Windows
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Run build.cmd or open TextTemplating.sln in visual studio 2010
|
||||||
|
Dotnet framework 4 must be installed.
|
||||||
|
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
Licensed under the MIT/X11 license: http://www.opensource.org/licenses/mit-license.php
|
||||||
|
|
26
SparkleShare/Windows/tools/TextTemplating/TextTemplating.sln
Normal file
26
SparkleShare/Windows/tools/TextTemplating/TextTemplating.sln
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||||
|
# Visual Studio 2010
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.TextTemplating", "Mono.TextTemplating\Mono.TextTemplating.csproj", "{A2364D6A-00EF-417C-80A6-815726C70032}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextTransform", "TextTransform\TextTransform.csproj", "{D1D35409-C814-47F6-B038-B9B5BF0FE490}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{A2364D6A-00EF-417C-80A6-815726C70032}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{A2364D6A-00EF-417C-80A6-815726C70032}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{A2364D6A-00EF-417C-80A6-815726C70032}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{A2364D6A-00EF-417C-80A6-815726C70032}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D1D35409-C814-47F6-B038-B9B5BF0FE490}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D1D35409-C814-47F6-B038-B9B5BF0FE490}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D1D35409-C814-47F6-B038-B9B5BF0FE490}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D1D35409-C814-47F6-B038-B9B5BF0FE490}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
|
@ -0,0 +1,39 @@
|
||||||
|
//
|
||||||
|
// AssemblyInfo.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("TextTransform")]
|
||||||
|
[assembly: AssemblyDescription("T4 text transformation tool")]
|
||||||
|
[assembly: AssemblyCompany("The Mono Project")]
|
||||||
|
[assembly: AssemblyProduct("MonoDevelop")]
|
||||||
|
[assembly: AssemblyCopyright("MIT/X11")]
|
||||||
|
|
||||||
|
//[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
2009-08-12 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Makefile.am:
|
||||||
|
* TextTransform.csproj: Include the ASP.NET MVC and
|
||||||
|
TextTemplating addins in the main solution and build.
|
||||||
|
|
||||||
|
2009-03-13 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* TextTransform.csproj: Move output dir from ../bin to
|
||||||
|
../build.
|
||||||
|
|
||||||
|
2009-03-05 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* TextTransform.csproj: Updated.
|
||||||
|
|
||||||
|
* TextTransform.cs: Complete the runner implementation.
|
||||||
|
|
||||||
|
2009-03-04 Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
|
||||||
|
* Options.cs:
|
||||||
|
* AssemblyInfo.cs:
|
||||||
|
* TextTransform.cs:
|
||||||
|
* TextTransform.csproj: Stub out the command-line
|
||||||
|
TextTransform tool.
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
ADDIN_BUILD = $(top_builddir)/build/AddIns/MonoDevelop.TextTemplating
|
||||||
|
ASSEMBLY = $(ADDIN_BUILD)/TextTransform.exe
|
||||||
|
|
||||||
|
DEPS = $(top_builddir)/build/AddIns/MonoDevelop.TextTemplating/Mono.TextTemplating.dll
|
||||||
|
|
||||||
|
REFS = \
|
||||||
|
-r:System \
|
||||||
|
-r:System.Core
|
||||||
|
|
||||||
|
FILES = \
|
||||||
|
AssemblyInfo.cs \
|
||||||
|
Options.cs \
|
||||||
|
TextTransform.cs
|
||||||
|
|
||||||
|
RES =
|
||||||
|
|
||||||
|
all: $(ASSEMBLY) $(ASSEMBLY).mdb $(DATA_FILE_BUILD)
|
||||||
|
|
||||||
|
$(ASSEMBLY): $(build_sources) $(build_resources) $(DEPS)
|
||||||
|
mkdir -p $(ADDIN_BUILD)
|
||||||
|
$(CSC) $(CSC_FLAGS) -debug -out:$@ -target:exe $(REFS) $(build_deps) \
|
||||||
|
$(build_resources:%=/resource:%) $(build_sources)
|
||||||
|
|
||||||
|
$(ASSEMBLY).mdb: $(ASSEMBLY)
|
||||||
|
|
||||||
|
check: all
|
||||||
|
|
||||||
|
assemblydir = $(MD_ADDIN_DIR)/MonoDevelop.TextTemplating
|
||||||
|
assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb
|
||||||
|
|
||||||
|
CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb
|
||||||
|
EXTRA_DIST = $(FILES) $(RES)
|
||||||
|
|
||||||
|
include $(top_srcdir)/Makefile.include
|
||||||
|
|
1112
SparkleShare/Windows/tools/TextTemplating/TextTransform/Options.cs
Normal file
1112
SparkleShare/Windows/tools/TextTemplating/TextTransform/Options.cs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,174 @@
|
||||||
|
//
|
||||||
|
// Main.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Michael Hutchinson <mhutchinson@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Mono.Options;
|
||||||
|
|
||||||
|
namespace Mono.TextTemplating
|
||||||
|
{
|
||||||
|
class TextTransform
|
||||||
|
{
|
||||||
|
static OptionSet optionSet;
|
||||||
|
const string name ="TextTransform.exe";
|
||||||
|
|
||||||
|
public static int Main (string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length == 0) {
|
||||||
|
ShowHelp (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var generator = new TemplateGenerator ();
|
||||||
|
string outputFile = null, inputFile = null;
|
||||||
|
var directives = new List<string> ();
|
||||||
|
var parameters = new List<string> ();
|
||||||
|
var session = new Microsoft.VisualStudio.TextTemplating.TextTemplatingSession ();
|
||||||
|
string preprocess = null;
|
||||||
|
|
||||||
|
optionSet = new OptionSet () {
|
||||||
|
{ "o=|out=", "The name of the output {file}", s => outputFile = s },
|
||||||
|
{ "r=", "Assemblies to reference", s => generator.Refs.Add (s) },
|
||||||
|
{ "u=", "Namespaces to import <{0:namespace}>", s => generator.Imports.Add (s) },
|
||||||
|
{ "I=", "Paths to search for included files", s => generator.IncludePaths.Add (s) },
|
||||||
|
{ "P=", "Paths to search for referenced assemblies", s => generator.ReferencePaths.Add (s) },
|
||||||
|
{ "dp=", "Directive processor (name!class!assembly)", s => directives.Add (s) },
|
||||||
|
{ "a=", "Parameters ([processorName]![directiveName]!name!value)", s => parameters.Add (s) },
|
||||||
|
{ "h|?|help", "Show help", s => ShowHelp (false) },
|
||||||
|
// { "k=,", "Session {key},{value} pairs", (s, t) => session.Add (s, t) },
|
||||||
|
{ "c=", "Preprocess the template into {0:class}", (s) => preprocess = s },
|
||||||
|
};
|
||||||
|
|
||||||
|
var remainingArgs = optionSet.Parse (args);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty (outputFile)) {
|
||||||
|
Console.Error.WriteLine ("No output file specified.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remainingArgs.Count != 1) {
|
||||||
|
Console.Error.WriteLine ("No input file specified.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
inputFile = remainingArgs [0];
|
||||||
|
|
||||||
|
if (!File.Exists (inputFile)) {
|
||||||
|
Console.Error.WriteLine ("Input file '{0}' does not exist.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME: implement quoting and escaping for values
|
||||||
|
foreach (var par in parameters) {
|
||||||
|
var split = par.Split ('!');
|
||||||
|
if (split.Length < 2) {
|
||||||
|
Console.Error.WriteLine ("Parameter does not have enough values: {0}", par);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (split.Length > 2) {
|
||||||
|
Console.Error.WriteLine ("Parameter has too many values: {0}", par);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
string name = split[split.Length-2];
|
||||||
|
string val = split[split.Length-1];
|
||||||
|
if (string.IsNullOrEmpty (name)) {
|
||||||
|
Console.Error.WriteLine ("Parameter has no name: {0}", par);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
generator.AddParameter (split.Length > 3? split[0] : null, split.Length > 2? split[split.Length-3] : null, name, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var dir in directives) {
|
||||||
|
var split = dir.Split ('!');
|
||||||
|
if (split.Length != 3) {
|
||||||
|
Console.Error.WriteLine ("Directive does not have correct number of values: {0}", dir);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
foreach (var s in split) {
|
||||||
|
if (string.IsNullOrEmpty (s)) {
|
||||||
|
Console.Error.WriteLine ("Directive has missing value: {0}", dir);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
generator.AddDirectiveProcessor (split[0], split[1], split[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preprocess == null) {
|
||||||
|
Console.Write ("Processing '{0}'... ", inputFile);
|
||||||
|
generator.ProcessTemplate (inputFile, outputFile);
|
||||||
|
if (generator.Errors.HasErrors) {
|
||||||
|
Console.WriteLine ("failed.");
|
||||||
|
} else {
|
||||||
|
Console.WriteLine ("completed successfully.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
string className = preprocess;
|
||||||
|
string classNamespace = null;
|
||||||
|
int s = preprocess.LastIndexOf ('.');
|
||||||
|
if (s > 0) {
|
||||||
|
classNamespace = preprocess.Substring (0, s);
|
||||||
|
className = preprocess.Substring (s + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Write ("Preprocessing '{0}' into class '{1}.{2}'... ", inputFile, classNamespace, className);
|
||||||
|
string language;
|
||||||
|
string[] references;
|
||||||
|
generator.PreprocessTemplate (inputFile, className, classNamespace, outputFile, System.Text.Encoding.UTF8,
|
||||||
|
out language, out references);
|
||||||
|
if (generator.Errors.HasErrors) {
|
||||||
|
Console.WriteLine ("failed.");
|
||||||
|
} else {
|
||||||
|
Console.WriteLine ("completed successfully:");
|
||||||
|
Console.WriteLine (" Language: {0}", language);
|
||||||
|
if (references != null && references.Length > 0) {
|
||||||
|
Console.WriteLine (" References:");
|
||||||
|
foreach (string r in references)
|
||||||
|
Console.WriteLine (" {0}", r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (System.CodeDom.Compiler.CompilerError err in generator.Errors)
|
||||||
|
Console.Error.WriteLine ("{0}({1},{2}): {3} {4}", err.FileName, err.Line, err.Column,
|
||||||
|
err.IsWarning? "WARNING" : "ERROR", err.ErrorText);
|
||||||
|
|
||||||
|
return generator.Errors.HasErrors? -1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShowHelp (bool concise)
|
||||||
|
{
|
||||||
|
Console.WriteLine ("TextTransform command line T4 processor");
|
||||||
|
Console.WriteLine ("Usage: {0} [options] input-file", name);
|
||||||
|
if (concise) {
|
||||||
|
Console.WriteLine ("Use --help to display options.");
|
||||||
|
} else {
|
||||||
|
Console.WriteLine ("Options:");
|
||||||
|
optionSet.WriteOptionDescriptions (System.Console.Out);
|
||||||
|
}
|
||||||
|
Console.WriteLine ();
|
||||||
|
Environment.Exit (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{D1D35409-C814-47F6-B038-B9B5BF0FE490}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AssemblyName>TextTransform</AssemblyName>
|
||||||
|
<RootNamespace>Mono.TextTemplating</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>..\bin</OutputPath>
|
||||||
|
<DefineConstants>DEBUG</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Commandlineparameters>-o:out.txt in.tt</Commandlineparameters>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>none</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>..\bin</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="TextTransform.cs" />
|
||||||
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Options.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Mono.TextTemplating\Mono.TextTemplating.csproj">
|
||||||
|
<Project>{A2364D6A-00EF-417C-80A6-815726C70032}</Project>
|
||||||
|
<Name>Mono.TextTemplating</Name>
|
||||||
|
<Private>False</Private>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<ProjectExtensions>
|
||||||
|
<MonoDevelop>
|
||||||
|
<Properties>
|
||||||
|
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am" BuildTargetName="" CleanTargetName="" SyncReferences="true" IsAutotoolsProject="true" RelativeConfigureInPath="..">
|
||||||
|
<BuildFilesVar Sync="true" Name="FILES" />
|
||||||
|
<DeployFilesVar />
|
||||||
|
<ResourcesVar Sync="true" Name="RES" />
|
||||||
|
<OthersVar />
|
||||||
|
<GacRefVar Sync="true" Name="REFS" Prefix="-r:" />
|
||||||
|
<AsmRefVar Sync="true" Name="REFS" Prefix="-r:" />
|
||||||
|
<ProjectRefVar Sync="true" Name="DEPS" />
|
||||||
|
</MonoDevelop.Autotools.MakefileInfo>
|
||||||
|
</Properties>
|
||||||
|
</MonoDevelop>
|
||||||
|
</ProjectExtensions>
|
||||||
|
</Project>
|
5
SparkleShare/Windows/tools/TextTemplating/build.cmd
Normal file
5
SparkleShare/Windows/tools/TextTemplating/build.cmd
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
@echo off
|
||||||
|
set WinDirNet=%WinDir%\Microsoft.NET\Framework
|
||||||
|
set msbuild="%WinDirNet%\v4.0.30319\msbuild.exe"
|
||||||
|
|
||||||
|
%msbuild% /t:Rebuild /p:Configuration=Release /p:Platform="Any CPU" %~dp0\TextTemplating.sln
|
|
@ -0,0 +1,67 @@
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{C4B4300B-5B96-4F43-BD7D-517A29693B30}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Gettext.Cs.Tests</RootNamespace>
|
||||||
|
<AssemblyName>Gettext.Cs.Tests</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<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' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.configuration" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="PoParserTest.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Gettext.Cs\Gettext.Cs.csproj">
|
||||||
|
<Project>{D8869765-AB47-4C03-B2C5-E5498A55CA79}</Project>
|
||||||
|
<Name>Gettext.Cs</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
using Gettext.Cs;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Gettext.Cs.Tests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///This is a test class for PoParserTest and is intended
|
||||||
|
///to contain all PoParserTest Unit Tests
|
||||||
|
///</summary>
|
||||||
|
[TestClass()]
|
||||||
|
public class PoParserTest
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
/// Tests slashes in parsed strings
|
||||||
|
/// <see href="http://code.google.com/p/gettext-cs-utils/issues/detail?id=1"/>
|
||||||
|
///</summary>
|
||||||
|
[TestMethod()]
|
||||||
|
public void ParseIntoDictionaryStringWithSlashesTest()
|
||||||
|
{
|
||||||
|
string msgid = @"The type of parameter \""${0}\"" is not supported";
|
||||||
|
string msgstr = @"Il tipo del parametro \""${0}\"" non è supportato";
|
||||||
|
|
||||||
|
string parsedMsgid = @"The type of parameter ""${0}"" is not supported";
|
||||||
|
string parsedMsgstr = @"Il tipo del parametro ""${0}"" non è supportato";
|
||||||
|
|
||||||
|
PoParser target = new PoParser();
|
||||||
|
TextReader reader = new StringReader(String.Format(@"
|
||||||
|
msgid ""{0}""
|
||||||
|
msgstr ""{1}""
|
||||||
|
", msgid, msgstr));
|
||||||
|
|
||||||
|
var actual = target.ParseIntoDictionary(reader);
|
||||||
|
|
||||||
|
Assert.AreEqual(1, actual.Count, "Parsed dictionary entries count do not match");
|
||||||
|
Assert.AreEqual(parsedMsgid, actual.Keys.ToArray()[0], "Key does not match");
|
||||||
|
Assert.AreEqual(parsedMsgstr, actual.Values.ToArray()[0], "Value does not match");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
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("Gettext.Cs.Tests")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("Gettext.Cs.Tests")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM componenets. 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("532f2d56-549a-474c-b46b-82fc90f1db64")]
|
||||||
|
|
||||||
|
// 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 Revision and Build Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System.Web.UI;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Gettext.Cs.Web
|
||||||
|
{
|
||||||
|
[ParseChildren(false)]
|
||||||
|
public abstract class AspTranslate : Control
|
||||||
|
{
|
||||||
|
string content;
|
||||||
|
|
||||||
|
protected override void AddParsedSubObject(object obj)
|
||||||
|
{
|
||||||
|
if (obj is LiteralControl)
|
||||||
|
{
|
||||||
|
content = Translate(((LiteralControl)obj).Text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Render(HtmlTextWriter writer)
|
||||||
|
{
|
||||||
|
writer.Write(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract string Translate(string text);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.30729</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{38474466-DA21-4D19-A4D8-E2E7918480D6}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Gettext.Cs.Web</RootNamespace>
|
||||||
|
<AssemblyName>Gettext.Cs.Web</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<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' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Web" />
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Controls\AspTranslate.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
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("Gettext.Cs.Web")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("Gettext.Cs.Web")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
|
||||||
|
[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("efc9a6d8-33cd-4cc5-8984-90847fea390e")]
|
||||||
|
|
||||||
|
// 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")]
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{D8869765-AB47-4C03-B2C5-E5498A55CA79}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Gettext.Cs</RootNamespace>
|
||||||
|
<AssemblyName>Gettext.Cs</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<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' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.configuration" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Resource\DatabaseResourceManager.cs" />
|
||||||
|
<Compile Include="Resource\DatabaseResourceReader.cs" />
|
||||||
|
<Compile Include="Resource\DatabaseResourceSet.cs" />
|
||||||
|
<Compile Include="Resource\FileBasedResourceManager.cs" />
|
||||||
|
<Compile Include="Parser\ParserRequestor.cs" />
|
||||||
|
<Compile Include="Parser\PoParser.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Resource\GettextResourceManager.cs" />
|
||||||
|
<Compile Include="Resource\GettextResourceReader.cs" />
|
||||||
|
<Compile Include="Resource\GettextResourceSet.cs" />
|
||||||
|
<Compile Include="Templates\Strings.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Strings.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Templates\Strings.tt">
|
||||||
|
<Generator>TextTemplatingFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Strings.cs</LastGenOutput>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for retrieving data from the parser.
|
||||||
|
/// </summary>
|
||||||
|
public interface IGettextParserRequestor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles a key value pair parsed from the po file.
|
||||||
|
/// </summary>
|
||||||
|
void Handle(string key, string value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Collects data from the parser into a dictionary.
|
||||||
|
/// </summary>
|
||||||
|
public class DictionaryGettextParserRequestor : Dictionary<String, String>, IGettextParserRequestor
|
||||||
|
{
|
||||||
|
#region IGettextParserRequestor Members
|
||||||
|
|
||||||
|
public void Handle(string key, string value)
|
||||||
|
{
|
||||||
|
this[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,149 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Parses standard po files.
|
||||||
|
/// </summary>
|
||||||
|
public class PoParser
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Parses an input po file.
|
||||||
|
/// </summary>
|
||||||
|
public void Parse(TextReader reader, IGettextParserRequestor requestor)
|
||||||
|
{
|
||||||
|
const int StateWaitingKey = 1;
|
||||||
|
const int StateConsumingKey = 2;
|
||||||
|
const int StateConsumingValue = 3;
|
||||||
|
|
||||||
|
int state = StateWaitingKey;
|
||||||
|
|
||||||
|
StringBuilder currentKey = null;
|
||||||
|
StringBuilder currentValue = null;
|
||||||
|
|
||||||
|
string line;
|
||||||
|
while(true) {
|
||||||
|
line = reader.ReadLine();
|
||||||
|
line = line == null ? null : line.Trim();
|
||||||
|
if (line == null || line.Length == 0)
|
||||||
|
{
|
||||||
|
if (state == StateConsumingValue &&
|
||||||
|
currentKey != null &&
|
||||||
|
currentValue != null)
|
||||||
|
{
|
||||||
|
requestor.Handle(currentKey.ToString().Replace("\\n", "\n").Replace("\\\"", "\""),
|
||||||
|
currentValue.ToString().Replace("\\n", "\n").Replace("\\\"", "\""));
|
||||||
|
currentKey = null;
|
||||||
|
currentValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
state = StateWaitingKey;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (line[0] == '#')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMsgId = line.StartsWith("msgid ");
|
||||||
|
bool isMsgStr = !isMsgId && line.StartsWith("msgstr ");
|
||||||
|
|
||||||
|
if (isMsgId || isMsgStr)
|
||||||
|
{
|
||||||
|
state = isMsgId ? StateConsumingKey : StateConsumingValue;
|
||||||
|
|
||||||
|
int firstQuote = line.IndexOf('"');
|
||||||
|
if (firstQuote == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int secondQuote = line.IndexOf('"', firstQuote + 1);
|
||||||
|
while (secondQuote != -1 && line[secondQuote - 1] == '\\')
|
||||||
|
secondQuote = line.IndexOf('"', secondQuote + 1);
|
||||||
|
if (secondQuote == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string piece = line.Substring(firstQuote + 1, secondQuote - firstQuote - 1);
|
||||||
|
|
||||||
|
if (isMsgId)
|
||||||
|
{
|
||||||
|
currentKey = new StringBuilder();
|
||||||
|
currentKey.Append(piece);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentValue = new StringBuilder();
|
||||||
|
currentValue.Append(piece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (line[0] == '"')
|
||||||
|
{
|
||||||
|
if (line[line.Length - 1] == '"')
|
||||||
|
{
|
||||||
|
line = line.Substring(1, line.Length - 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line = line.Substring(1, line.Length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case StateConsumingKey:
|
||||||
|
currentKey.Append(line);
|
||||||
|
break;
|
||||||
|
case StateConsumingValue:
|
||||||
|
currentValue.Append(line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses an input po file.
|
||||||
|
/// </summary>
|
||||||
|
public void Parse(string text, IGettextParserRequestor requestor)
|
||||||
|
{
|
||||||
|
Parse(new StringReader(text), requestor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses an input po file into a dictionary.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<String, String> ParseIntoDictionary(TextReader reader)
|
||||||
|
{
|
||||||
|
var requestor = new DictionaryGettextParserRequestor();
|
||||||
|
Parse(reader, requestor);
|
||||||
|
return requestor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
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("Gettext.Cs")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("Gettext.Cs")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
|
||||||
|
[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("1c3b8e32-0c8d-4d0f-ae9b-d38e4b45690a")]
|
||||||
|
|
||||||
|
// 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")]
|
|
@ -0,0 +1,86 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
public class DatabaseResourceManager : System.Resources.ResourceManager
|
||||||
|
{
|
||||||
|
private string dsn;
|
||||||
|
private string sp;
|
||||||
|
|
||||||
|
public DatabaseResourceManager()
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
this.dsn = ConfigurationManager.AppSettings["Gettext.ConnectionString"] ?? ConfigurationManager.ConnectionStrings["Gettext"].ConnectionString;
|
||||||
|
ResourceSets = new System.Collections.Hashtable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseResourceManager(string storedProcedure)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
this.sp = storedProcedure;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hack: kept for compatibility
|
||||||
|
public DatabaseResourceManager(string name, string path, string fileformat)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
|
||||||
|
{
|
||||||
|
DatabaseResourceSet rs = null;
|
||||||
|
|
||||||
|
if (ResourceSets.Contains(culture.Name))
|
||||||
|
{
|
||||||
|
rs = ResourceSets[culture.Name] as DatabaseResourceSet;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lock (ResourceSets)
|
||||||
|
{
|
||||||
|
// Check hash table once again after lock is set
|
||||||
|
if (ResourceSets.Contains(culture.Name))
|
||||||
|
{
|
||||||
|
rs = ResourceSets[culture.Name] as DatabaseResourceSet;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rs = new DatabaseResourceSet(dsn, culture, sp);
|
||||||
|
ResourceSets.Add(culture.Name, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
public class DatabaseResourceReader : IResourceReader
|
||||||
|
{
|
||||||
|
private string dsn;
|
||||||
|
private string language;
|
||||||
|
private string sp;
|
||||||
|
|
||||||
|
public DatabaseResourceReader(string dsn, CultureInfo culture)
|
||||||
|
{
|
||||||
|
this.dsn = dsn;
|
||||||
|
this.language = culture.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseResourceReader(string dsn, CultureInfo culture, string sp)
|
||||||
|
{
|
||||||
|
this.sp = sp;
|
||||||
|
this.dsn = dsn;
|
||||||
|
this.language = culture.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Collections.IDictionaryEnumerator GetEnumerator()
|
||||||
|
{
|
||||||
|
Hashtable dict = new Hashtable();
|
||||||
|
|
||||||
|
SqlConnection connection = new SqlConnection(dsn);
|
||||||
|
SqlCommand command = connection.CreateCommand();
|
||||||
|
|
||||||
|
if (language == "")
|
||||||
|
language = CultureInfo.InvariantCulture.Name;
|
||||||
|
|
||||||
|
// Use stored procedure or plain text
|
||||||
|
if (sp == null)
|
||||||
|
{
|
||||||
|
command.CommandText = string.Format("SELECT MessageKey, MessageValue FROM Message WHERE Culture = '{0}'", language);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
command.CommandText = sp;
|
||||||
|
command.CommandType = System.Data.CommandType.StoredProcedure;
|
||||||
|
command.Parameters.AddWithValue("@culture", language);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
using (SqlDataReader reader = command.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
if (reader.GetValue(1) != System.DBNull.Value)
|
||||||
|
{
|
||||||
|
dict[reader.GetString(0)] = reader.GetString(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
bool raise = false;
|
||||||
|
if (bool.TryParse(ConfigurationManager.AppSettings["Gettext.Throw"], out raise) && raise)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
connection.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return dict.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return this.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDisposable.Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
public class DatabaseResourceSet : ResourceSet
|
||||||
|
{
|
||||||
|
internal DatabaseResourceSet(string dsn, CultureInfo culture)
|
||||||
|
: base (new DatabaseResourceReader(dsn, culture))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
internal DatabaseResourceSet(string dsn, CultureInfo culture, string sp)
|
||||||
|
: base(new DatabaseResourceReader(dsn, culture, sp))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Type GetDefaultReader()
|
||||||
|
{
|
||||||
|
return typeof(DatabaseResourceReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,295 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extendable file based resource manager.
|
||||||
|
/// </summary>
|
||||||
|
public class FileBasedResourceManager : System.Resources.ResourceManager
|
||||||
|
{
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
string path;
|
||||||
|
string fileformat;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Path to retrieve the files from.
|
||||||
|
/// </summary>
|
||||||
|
public string Path
|
||||||
|
{
|
||||||
|
get { return path; }
|
||||||
|
set { path = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Format of the resource set po file based on {{culture}} and {{resource}} placeholders.
|
||||||
|
/// </summary>
|
||||||
|
public string FileFormat
|
||||||
|
{
|
||||||
|
get { return fileformat; }
|
||||||
|
set { fileformat = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Notification Events
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Arguments for events related to the creation, successful or not, of a resource set.
|
||||||
|
/// </summary>
|
||||||
|
public class ResourceSetCreationEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Exception in case of error, null on success.
|
||||||
|
/// </summary>
|
||||||
|
public Exception Exception { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FileName from where the resource set was loaded.
|
||||||
|
/// </summary>
|
||||||
|
public String FileName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Type of the resource set being initialized.
|
||||||
|
/// </summary>
|
||||||
|
public Type ResourceSetType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instance of the resource set created, may be null on error.
|
||||||
|
/// </summary>
|
||||||
|
public System.Resources.ResourceSet ResourceSet { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the creation was successful.
|
||||||
|
/// </summary>
|
||||||
|
public bool Success { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that notifies the successful creation of a resource set.
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<ResourceSetCreationEventArgs> CreatedResourceSet;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that notifies an error creating a resource set.
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<ResourceSetCreationEventArgs> FailedResourceSet;
|
||||||
|
|
||||||
|
protected void RaiseCreatedResourceSet(string filename, System.Resources.ResourceSet set)
|
||||||
|
{
|
||||||
|
var handler = CreatedResourceSet;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
handler(this, new ResourceSetCreationEventArgs
|
||||||
|
{
|
||||||
|
FileName = filename,
|
||||||
|
ResourceSet = set,
|
||||||
|
ResourceSetType = this.ResourceSetType,
|
||||||
|
Success = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void RaiseFailedResourceSet(string filename, Exception ex)
|
||||||
|
{
|
||||||
|
var handler = FailedResourceSet;
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
handler(this, new ResourceSetCreationEventArgs
|
||||||
|
{
|
||||||
|
FileName = filename,
|
||||||
|
ResourceSet = null,
|
||||||
|
ResourceSetType = this.ResourceSetType,
|
||||||
|
Success = false,
|
||||||
|
Exception = ex
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the resource</param>
|
||||||
|
/// <param name="path">Path to retrieve the files from</param>
|
||||||
|
/// <param name="fileformat">Format of the file name using {{resource}} and {{culture}} placeholders.</param>
|
||||||
|
public FileBasedResourceManager(string name, string path, string fileformat)
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
this.path = path;
|
||||||
|
this.fileformat = fileformat;
|
||||||
|
this.BaseNameField = name;
|
||||||
|
|
||||||
|
base.IgnoreCase = false;
|
||||||
|
base.ResourceSets = new System.Collections.Hashtable();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GetResourceFileName(System.Globalization.CultureInfo culture)
|
||||||
|
{
|
||||||
|
return fileformat.Replace("{{culture}}", culture.Name).Replace("{{resource}}", BaseNameField);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override System.Resources.ResourceSet InternalGetResourceSet(System.Globalization.CultureInfo culture, bool createIfNotExists, bool tryParents)
|
||||||
|
{
|
||||||
|
if (path == null && fileformat == null) return null;
|
||||||
|
if (culture == null || culture.Equals(CultureInfo.InvariantCulture)) return null;
|
||||||
|
|
||||||
|
System.Resources.ResourceSet rs = null;
|
||||||
|
Hashtable resourceSets = this.ResourceSets;
|
||||||
|
|
||||||
|
if (!TryFetchResourceSet(resourceSets, culture, out rs))
|
||||||
|
{
|
||||||
|
string resourceFileName = this.FindResourceFile(culture);
|
||||||
|
if (resourceFileName == null)
|
||||||
|
{
|
||||||
|
if (tryParents)
|
||||||
|
{
|
||||||
|
CultureInfo parent = culture.Parent;
|
||||||
|
rs = this.InternalGetResourceSet(parent, createIfNotExists, tryParents);
|
||||||
|
AddResourceSet(resourceSets, culture, ref rs);
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rs = this.CreateResourceSet(resourceFileName);
|
||||||
|
AddResourceSet(resourceSets, culture, ref rs);
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual System.Resources.ResourceSet InternalCreateResourceSet(string resourceFileName)
|
||||||
|
{
|
||||||
|
object[] args = new object[] { resourceFileName };
|
||||||
|
return (System.Resources.ResourceSet)Activator.CreateInstance(this.ResourceSetType, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private System.Resources.ResourceSet CreateResourceSet(string resourceFileName)
|
||||||
|
{
|
||||||
|
System.Resources.ResourceSet set = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
set = InternalCreateResourceSet(resourceFileName);
|
||||||
|
RaiseCreatedResourceSet(resourceFileName, set);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
RaiseFailedResourceSet(resourceFileName, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FindResourceFile(CultureInfo culture)
|
||||||
|
{
|
||||||
|
string resourceFileName = this.GetResourceFileName(culture);
|
||||||
|
string path = this.path ?? String.Empty;
|
||||||
|
|
||||||
|
// Try with simple path + filename combination
|
||||||
|
string fullpath = System.IO.Path.Combine(path, resourceFileName);
|
||||||
|
if (File.Exists(fullpath)) return fullpath;
|
||||||
|
|
||||||
|
// If path is relative, attempt different directories
|
||||||
|
if (path == String.Empty || !System.IO.Path.IsPathRooted(path))
|
||||||
|
{
|
||||||
|
// Try the entry assembly dir
|
||||||
|
if (Assembly.GetEntryAssembly() != null)
|
||||||
|
{
|
||||||
|
string dir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), path);
|
||||||
|
fullpath = System.IO.Path.Combine(dir, resourceFileName);
|
||||||
|
if (File.Exists(fullpath)) return fullpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else try the executing assembly dir
|
||||||
|
if (Assembly.GetExecutingAssembly() != null)
|
||||||
|
{
|
||||||
|
if (Assembly.GetEntryAssembly() == null || System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) != System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
|
||||||
|
{
|
||||||
|
string dir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path);
|
||||||
|
fullpath = System.IO.Path.Combine(dir, resourceFileName);
|
||||||
|
if (File.Exists(fullpath)) return fullpath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddResourceSet(Hashtable localResourceSets, CultureInfo culture, ref System.Resources.ResourceSet rs)
|
||||||
|
{
|
||||||
|
lock (localResourceSets)
|
||||||
|
{
|
||||||
|
if (localResourceSets.Contains(culture))
|
||||||
|
{
|
||||||
|
var existing = (System.Resources.ResourceSet)localResourceSets[culture];
|
||||||
|
|
||||||
|
if (existing != null && !object.Equals(existing, rs))
|
||||||
|
{
|
||||||
|
rs.Dispose();
|
||||||
|
rs = existing;
|
||||||
|
var a = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationManager.GetSection("appSettings");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
localResourceSets.Add(culture, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryFetchResourceSet(Hashtable localResourceSets, CultureInfo culture, out System.Resources.ResourceSet set)
|
||||||
|
{
|
||||||
|
lock (localResourceSets)
|
||||||
|
{
|
||||||
|
if (ResourceSets.Contains(culture))
|
||||||
|
{
|
||||||
|
set = (System.Resources.ResourceSet)ResourceSets[culture];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
set = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ValidateGetResourceSet(CultureInfo culture)
|
||||||
|
{
|
||||||
|
return !(culture == null || culture.Equals(CultureInfo.InvariantCulture) || String.IsNullOrEmpty(culture.Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,150 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Security.Permissions;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gettext based resource manager that reads from po files.
|
||||||
|
/// </summary>
|
||||||
|
public class GettextResourceManager : FileBasedResourceManager
|
||||||
|
{
|
||||||
|
#region Defaults
|
||||||
|
|
||||||
|
const string defaultFileFormat = "{{culture}}\\{{resource}}.po";
|
||||||
|
const string defaultPath = "";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the Gettext resource set type used.
|
||||||
|
/// </summary>
|
||||||
|
public override Type ResourceSetType
|
||||||
|
{
|
||||||
|
get { return typeof(GettextResourceSet); }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructos
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the resource</param>
|
||||||
|
/// <param name="path">Path to retrieve the files from</param>
|
||||||
|
/// <param name="fileformat">Format of the file name using {{resource}} and {{culture}} placeholders.</param>
|
||||||
|
public GettextResourceManager(string name, string path, string fileformat)
|
||||||
|
: base(name, path, fileformat)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance using local path and "{{culture}}\{{resource}}.po" file format.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the resource</param>
|
||||||
|
public GettextResourceManager(string name)
|
||||||
|
: base(name, defaultPath, defaultFileFormat)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Configuration
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the named configuration section and retrieves file format and path from "fileformat" and "path" settings.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="section">Name of the section to retrieve.</param>
|
||||||
|
/// <returns>True if the configuration section was loaded.</returns>
|
||||||
|
public bool LoadConfiguration(string section)
|
||||||
|
{
|
||||||
|
var config = ConfigurationManager.GetSection(section) as NameValueCollection;
|
||||||
|
|
||||||
|
if (config == null) return false;
|
||||||
|
|
||||||
|
this.FileFormat = config["fileformat"] ?? FileFormat;
|
||||||
|
this.Path = config["path"] ?? Path;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance retrieving path and fileformat from the specified configuration section.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the resource</param>
|
||||||
|
/// <param name="section">Name of the configuration section</param>
|
||||||
|
/// <returns>New instance of ResourceManager</returns>
|
||||||
|
public static FileBasedResourceManager CreateFromConfiguration(string name, string section)
|
||||||
|
{
|
||||||
|
return CreateFromConfiguration(name, section, defaultFileFormat, defaultPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance retrieving path and fileformat from the specified configuration section.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of the resource</param>
|
||||||
|
/// <param name="section">Name of the configuration section with fileformat and path settings</param>
|
||||||
|
/// <param name="fallbackFileFormat">File format to be used if configuration could not be retrieved</param>
|
||||||
|
/// <param name="fallbackPath">Path to be used if configuration could not be retrieved</param>
|
||||||
|
/// <returns>New instance of ResourceManager</returns>
|
||||||
|
public static FileBasedResourceManager CreateFromConfiguration(string name, string section, string fallbackFileFormat, string fallbackPath)
|
||||||
|
{
|
||||||
|
var config = ConfigurationManager.GetSection(section) as NameValueCollection;
|
||||||
|
|
||||||
|
string fileformat = null;
|
||||||
|
string path = null;
|
||||||
|
|
||||||
|
if (config == null)
|
||||||
|
{
|
||||||
|
fileformat = fallbackFileFormat;
|
||||||
|
path = fallbackPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fileformat = config["fileformat"] ?? fallbackFileFormat;
|
||||||
|
path = config["path"] ?? fallbackPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FileBasedResourceManager(name, path, fileformat);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Resources;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
public class GettextResourceReader : IResourceReader
|
||||||
|
{
|
||||||
|
Stream stream;
|
||||||
|
|
||||||
|
public GettextResourceReader(Stream stream)
|
||||||
|
{
|
||||||
|
this.stream = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IResourceReader Members
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
if (stream != null)
|
||||||
|
{
|
||||||
|
this.stream.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Collections.IDictionaryEnumerator GetEnumerator()
|
||||||
|
{
|
||||||
|
if (stream == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Input stream cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var reader = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
return new PoParser().ParseIntoDictionary(reader).GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IEnumerable Members
|
||||||
|
|
||||||
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return this.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisposable Members
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (stream != null)
|
||||||
|
{
|
||||||
|
stream.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Gettext.Cs
|
||||||
|
{
|
||||||
|
public class GettextResourceSet : System.Resources.ResourceSet
|
||||||
|
{
|
||||||
|
public GettextResourceSet(string filename)
|
||||||
|
: base(new GettextResourceReader(File.OpenRead(filename)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public GettextResourceSet(Stream stream)
|
||||||
|
: base(new GettextResourceReader(stream))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Type GetDefaultReader()
|
||||||
|
{
|
||||||
|
return typeof(Gettext.Cs.GettextResourceReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,166 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
// <autogenerated>
|
||||||
|
// This code was generated by a tool. Any changes made manually will be lost
|
||||||
|
// the next time this code is regenerated.
|
||||||
|
// </autogenerated>
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Gettext
|
||||||
|
{
|
||||||
|
public class Strings
|
||||||
|
{
|
||||||
|
private static Object resourceManLock = new Object();
|
||||||
|
private static System.Resources.ResourceManager resourceMan;
|
||||||
|
private static System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
public const string ResourceName = "Strings";
|
||||||
|
|
||||||
|
private static string resourcesDir = GetSetting("ResourcesDir", "Po");
|
||||||
|
private static string fileFormat = GetSetting("ResourcesFileFormat", "{{culture}}/{{resource}}.po");
|
||||||
|
|
||||||
|
private static string GetSetting(string setting, string defaultValue)
|
||||||
|
{
|
||||||
|
var section = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationManager.GetSection("appSettings");
|
||||||
|
if (section == null) return defaultValue;
|
||||||
|
else return section[setting] ?? defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resources directory used to retrieve files from.
|
||||||
|
/// </summary>
|
||||||
|
public static string ResourcesDirectory
|
||||||
|
{
|
||||||
|
get { return resourcesDir; }
|
||||||
|
set { resourcesDir = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Format of the file based on culture and resource name.
|
||||||
|
/// </summary>
|
||||||
|
public static string FileFormat
|
||||||
|
{
|
||||||
|
get { return fileFormat; }
|
||||||
|
set { fileFormat = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceManager ResourceManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
lock (resourceManLock)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
var directory = resourcesDir;
|
||||||
|
var mgr = new global::Gettext.Cs.GettextResourceManager(ResourceName, directory, fileFormat);
|
||||||
|
resourceMan = mgr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Globalization.CultureInfo Culture
|
||||||
|
{
|
||||||
|
get { return resourceCulture; }
|
||||||
|
set { resourceCulture = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t)
|
||||||
|
{
|
||||||
|
return T(null, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
var translated = ResourceManager.GetString(t, info ?? resourceCulture);
|
||||||
|
return String.IsNullOrEmpty(translated) ? t : translated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
return T(null, t, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
return String.Format(T(info, t), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks a string for future translation, does not translate it now.
|
||||||
|
/// </summary>
|
||||||
|
public static string M(string t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the resource set available for the specified culture.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceSet GetResourceSet(CultureInfo culture)
|
||||||
|
{
|
||||||
|
return ResourceManager.GetResourceSet(culture, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,196 @@
|
||||||
|
<#@ template language="C#v3.5" hostspecific="True" #>
|
||||||
|
// <autogenerated>
|
||||||
|
// This code was generated by a tool. Any changes made manually will be lost
|
||||||
|
// the next time this code is regenerated.
|
||||||
|
// </autogenerated>
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace <#= this.NamespaceName #>
|
||||||
|
{
|
||||||
|
public class <#= this.ClassName #>
|
||||||
|
{
|
||||||
|
private static Object resourceManLock = new Object();
|
||||||
|
private static System.Resources.ResourceManager resourceMan;
|
||||||
|
private static System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
public const string ResourceName = "<#= this.ResourceName #>";
|
||||||
|
|
||||||
|
<# if (!UseDatabase) { #>
|
||||||
|
private static string resourcesDir = GetSetting("ResourcesDir", "<#= this.DefaultResourceDir #>");
|
||||||
|
private static string fileFormat = GetSetting("ResourcesFileFormat", "<#= this.DefaultFileFormat #>");
|
||||||
|
<# } #>
|
||||||
|
|
||||||
|
private static string GetSetting(string setting, string defaultValue)
|
||||||
|
{
|
||||||
|
var section = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationManager.GetSection("<#= this.ConfigurationSection #>");
|
||||||
|
if (section == null) return defaultValue;
|
||||||
|
else return section[setting] ?? defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
<# if (!UseDatabase) { #>
|
||||||
|
/// <summary>
|
||||||
|
/// Resources directory used to retrieve files from.
|
||||||
|
/// </summary>
|
||||||
|
public static string ResourcesDirectory
|
||||||
|
{
|
||||||
|
get { return resourcesDir; }
|
||||||
|
set { resourcesDir = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Format of the file based on culture and resource name.
|
||||||
|
/// </summary>
|
||||||
|
public static string FileFormat
|
||||||
|
{
|
||||||
|
get { return fileFormat; }
|
||||||
|
set { fileFormat = value; }
|
||||||
|
}
|
||||||
|
<# } #>
|
||||||
|
|
||||||
|
<# if (ResourceManagerExpires) { #>
|
||||||
|
private static DateTime resourceManagerLoadedAt = DateTime.Now;
|
||||||
|
<# } #>
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceManager ResourceManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
<# if (ResourceManagerExpires) { #>
|
||||||
|
if (resourceMan != null && DateTime.Now.Subtract(resourceManagerLoadedAt).TotalMinutes >= <#= ResourceManagerTTL #>)
|
||||||
|
{
|
||||||
|
lock (resourceManLock)
|
||||||
|
{
|
||||||
|
if (resourceMan != null && DateTime.Now.Subtract(resourceManagerLoadedAt).TotalMinutes >= <#= ResourceManagerTTL #>)
|
||||||
|
{
|
||||||
|
resourceMan.ReleaseAllResources();
|
||||||
|
resourceMan = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<# } #>
|
||||||
|
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
lock (resourceManLock)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
<# if (UseDatabase) { #>
|
||||||
|
var mgr = new global::Gettext.Cs.DatabaseResourceManager("<#= this.StoredProcedureName #>");
|
||||||
|
<# } else { #>
|
||||||
|
var directory = resourcesDir;
|
||||||
|
<# if (ServerMapPath) { #>
|
||||||
|
if (System.Web.HttpContext.Current != null)
|
||||||
|
directory = System.Web.HttpContext.Current.Server.MapPath(directory);
|
||||||
|
<# } #>
|
||||||
|
var mgr = <#= String.Format(this.ResourceManagerCtor, this.ResourceManagerType) #>;
|
||||||
|
<# if (ResourceManagerExpires) { #>
|
||||||
|
resourceManagerLoadedAt = DateTime.Now;
|
||||||
|
<# } #>
|
||||||
|
<# } #>
|
||||||
|
resourceMan = mgr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Globalization.CultureInfo Culture
|
||||||
|
{
|
||||||
|
get { return resourceCulture; }
|
||||||
|
set { resourceCulture = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t)
|
||||||
|
{
|
||||||
|
return T(null, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
var translated = ResourceManager.GetString(t, info ?? resourceCulture);
|
||||||
|
return String.IsNullOrEmpty(translated) ? t : translated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
return T(null, t, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
return String.Format(T(info, t), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks a string for future translation, does not translate it now.
|
||||||
|
/// </summary>
|
||||||
|
public static string M(string t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the resource set available for the specified culture.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceSet GetResourceSet(CultureInfo culture)
|
||||||
|
{
|
||||||
|
return ResourceManager.GetResourceSet(culture, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<#+
|
||||||
|
// Template parameters
|
||||||
|
|
||||||
|
string ClassName = "Strings";
|
||||||
|
string ResourceName = "Strings";
|
||||||
|
string NamespaceName = "Gettext";
|
||||||
|
|
||||||
|
string ResourceManagerType = "global::Gettext.Cs.GettextResourceManager";
|
||||||
|
string ResourceManagerCtor = "new {0}(ResourceName, directory, fileFormat)";
|
||||||
|
string DefaultResourceDir = "Po";
|
||||||
|
string DefaultFileFormat = "{{culture}}/{{resource}}.po";
|
||||||
|
|
||||||
|
string ConfigurationSection = "appSettings";
|
||||||
|
bool ServerMapPath = false;
|
||||||
|
|
||||||
|
bool ResourceManagerExpires = false;
|
||||||
|
int ResourceManagerTTL = 0;
|
||||||
|
|
||||||
|
bool UseDatabase = false;
|
||||||
|
string StoredProcedureName = "GettextGetResourceSet";
|
||||||
|
#>
|
|
@ -0,0 +1,125 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||||
|
# Visual Studio 2008
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{FD8EF9F6-9B97-456A-98E0-E94DB2BD3EED}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{64737816-54EF-4891-A58D-0642F07F09AD}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gnu.Getopt", "Lib\Gnu.Getopt\Gnu.Getopt.csproj", "{379BC478-7D84-4E0E-A4B8-197905C824AE}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.AspExtract", "Tools\Gettext.AspExtract\Gettext.AspExtract.csproj", "{88A09FE2-5DE0-4C6E-9C4C-BB5E8A490CF5}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Msgfmt", "Tools\Gettext.Msgfmt\Gettext.Msgfmt.csproj", "{F72A7CBA-E656-4ECA-97F9-2B601E0BCDF9}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.ResourcesReplacer", "Tools\Gettext.ResourcesReplacer\Gettext.ResourcesReplacer.csproj", "{11BDD346-EDFA-439D-A42D-A1D4FDB64C9A}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{380A3584-88CB-4153-9BC1-C18CFAE9EF26}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Cs", "Core\Gettext.Cs\Gettext.Cs.csproj", "{D8869765-AB47-4C03-B2C5-E5498A55CA79}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gnu.Gettext", "Lib\Gnu.Gettext\Gnu.Gettext.csproj", "{859A653A-7728-4F02-BAF2-A5CD8F991916}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Cs.Web", "Core\Gettext.Cs.Web\Gettext.Cs.Web.csproj", "{38474466-DA21-4D19-A4D8-E2E7918480D6}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.DatabaseResourceGenerator", "Tools\Gettext.DatabaseResourceGenerator\Gettext.DatabaseResourceGenerator.csproj", "{B19D8863-C5C2-4A13-B24A-566EB7498D17}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{DF21B331-8022-4958-AEF7-D7897814038A}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Samples.Console", "Samples\Gettext.Samples.Console\Gettext.Samples.Console.csproj", "{470FDBA5-04E5-4A9F-80EA-987D1F8D9074}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Cs.Tests", "Core\Gettext.Cs.Tests\Gettext.Cs.Tests.csproj", "{C4B4300B-5B96-4F43-BD7D-517A29693B30}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Iconv", "Tools\Gettext.Iconv\Gettext.Iconv.csproj", "{7578444A-E104-4D72-94B5-DDCB1DA0D63F}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Samples.Mvc", "Samples\Gettext.Samples.Mvc\Gettext.Samples.Mvc.csproj", "{208D43F3-84E6-45B9-B6CC-6E3F48E42A82}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Samples.Database", "Samples\Gettext.Samples.Database\Gettext.Samples.Database.csproj", "{9FBD5BA7-BCE6-48FE-9FB7-396F377D1313}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gettext.Samples.Spanish", "Samples\Gettext.Samples.Spanish\Gettext.Samples.Spanish.csproj", "{7404A86D-53FA-4B1B-B6FC-D84EB6F5E2D5}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(TestCaseManagementSettings) = postSolution
|
||||||
|
CategoryFile = Gettext.CsUtils.vsmdi
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{379BC478-7D84-4E0E-A4B8-197905C824AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{379BC478-7D84-4E0E-A4B8-197905C824AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{379BC478-7D84-4E0E-A4B8-197905C824AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{379BC478-7D84-4E0E-A4B8-197905C824AE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{88A09FE2-5DE0-4C6E-9C4C-BB5E8A490CF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{88A09FE2-5DE0-4C6E-9C4C-BB5E8A490CF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{88A09FE2-5DE0-4C6E-9C4C-BB5E8A490CF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{88A09FE2-5DE0-4C6E-9C4C-BB5E8A490CF5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{F72A7CBA-E656-4ECA-97F9-2B601E0BCDF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{F72A7CBA-E656-4ECA-97F9-2B601E0BCDF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F72A7CBA-E656-4ECA-97F9-2B601E0BCDF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{F72A7CBA-E656-4ECA-97F9-2B601E0BCDF9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{11BDD346-EDFA-439D-A42D-A1D4FDB64C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{11BDD346-EDFA-439D-A42D-A1D4FDB64C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{11BDD346-EDFA-439D-A42D-A1D4FDB64C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{11BDD346-EDFA-439D-A42D-A1D4FDB64C9A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D8869765-AB47-4C03-B2C5-E5498A55CA79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D8869765-AB47-4C03-B2C5-E5498A55CA79}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D8869765-AB47-4C03-B2C5-E5498A55CA79}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D8869765-AB47-4C03-B2C5-E5498A55CA79}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{859A653A-7728-4F02-BAF2-A5CD8F991916}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{859A653A-7728-4F02-BAF2-A5CD8F991916}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{859A653A-7728-4F02-BAF2-A5CD8F991916}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{859A653A-7728-4F02-BAF2-A5CD8F991916}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{38474466-DA21-4D19-A4D8-E2E7918480D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{38474466-DA21-4D19-A4D8-E2E7918480D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{38474466-DA21-4D19-A4D8-E2E7918480D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{38474466-DA21-4D19-A4D8-E2E7918480D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B19D8863-C5C2-4A13-B24A-566EB7498D17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B19D8863-C5C2-4A13-B24A-566EB7498D17}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B19D8863-C5C2-4A13-B24A-566EB7498D17}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B19D8863-C5C2-4A13-B24A-566EB7498D17}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{470FDBA5-04E5-4A9F-80EA-987D1F8D9074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{470FDBA5-04E5-4A9F-80EA-987D1F8D9074}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{470FDBA5-04E5-4A9F-80EA-987D1F8D9074}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{470FDBA5-04E5-4A9F-80EA-987D1F8D9074}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C4B4300B-5B96-4F43-BD7D-517A29693B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C4B4300B-5B96-4F43-BD7D-517A29693B30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C4B4300B-5B96-4F43-BD7D-517A29693B30}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C4B4300B-5B96-4F43-BD7D-517A29693B30}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7578444A-E104-4D72-94B5-DDCB1DA0D63F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7578444A-E104-4D72-94B5-DDCB1DA0D63F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7578444A-E104-4D72-94B5-DDCB1DA0D63F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7578444A-E104-4D72-94B5-DDCB1DA0D63F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{208D43F3-84E6-45B9-B6CC-6E3F48E42A82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{208D43F3-84E6-45B9-B6CC-6E3F48E42A82}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{208D43F3-84E6-45B9-B6CC-6E3F48E42A82}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{208D43F3-84E6-45B9-B6CC-6E3F48E42A82}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9FBD5BA7-BCE6-48FE-9FB7-396F377D1313}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9FBD5BA7-BCE6-48FE-9FB7-396F377D1313}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9FBD5BA7-BCE6-48FE-9FB7-396F377D1313}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9FBD5BA7-BCE6-48FE-9FB7-396F377D1313}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7404A86D-53FA-4B1B-B6FC-D84EB6F5E2D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7404A86D-53FA-4B1B-B6FC-D84EB6F5E2D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7404A86D-53FA-4B1B-B6FC-D84EB6F5E2D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7404A86D-53FA-4B1B-B6FC-D84EB6F5E2D5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{88A09FE2-5DE0-4C6E-9C4C-BB5E8A490CF5} = {FD8EF9F6-9B97-456A-98E0-E94DB2BD3EED}
|
||||||
|
{F72A7CBA-E656-4ECA-97F9-2B601E0BCDF9} = {FD8EF9F6-9B97-456A-98E0-E94DB2BD3EED}
|
||||||
|
{11BDD346-EDFA-439D-A42D-A1D4FDB64C9A} = {FD8EF9F6-9B97-456A-98E0-E94DB2BD3EED}
|
||||||
|
{B19D8863-C5C2-4A13-B24A-566EB7498D17} = {FD8EF9F6-9B97-456A-98E0-E94DB2BD3EED}
|
||||||
|
{7578444A-E104-4D72-94B5-DDCB1DA0D63F} = {FD8EF9F6-9B97-456A-98E0-E94DB2BD3EED}
|
||||||
|
{379BC478-7D84-4E0E-A4B8-197905C824AE} = {64737816-54EF-4891-A58D-0642F07F09AD}
|
||||||
|
{859A653A-7728-4F02-BAF2-A5CD8F991916} = {64737816-54EF-4891-A58D-0642F07F09AD}
|
||||||
|
{D8869765-AB47-4C03-B2C5-E5498A55CA79} = {380A3584-88CB-4153-9BC1-C18CFAE9EF26}
|
||||||
|
{38474466-DA21-4D19-A4D8-E2E7918480D6} = {380A3584-88CB-4153-9BC1-C18CFAE9EF26}
|
||||||
|
{C4B4300B-5B96-4F43-BD7D-517A29693B30} = {380A3584-88CB-4153-9BC1-C18CFAE9EF26}
|
||||||
|
{470FDBA5-04E5-4A9F-80EA-987D1F8D9074} = {DF21B331-8022-4958-AEF7-D7897814038A}
|
||||||
|
{208D43F3-84E6-45B9-B6CC-6E3F48E42A82} = {DF21B331-8022-4958-AEF7-D7897814038A}
|
||||||
|
{9FBD5BA7-BCE6-48FE-9FB7-396F377D1313} = {DF21B331-8022-4958-AEF7-D7897814038A}
|
||||||
|
{7404A86D-53FA-4B1B-B6FC-D84EB6F5E2D5} = {DF21B331-8022-4958-AEF7-D7897814038A}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
|
@ -0,0 +1,88 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security.Permissions;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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("GNU Getopt Argument Parser")]
|
||||||
|
[assembly: AssemblyDescription("This is a C# port of a Java port of GNU " +
|
||||||
|
"Getopt, a class for parsing command line arguments passed to programs. " +
|
||||||
|
"It is based on the C getopt() functions in glibc 2.0.6 and should " +
|
||||||
|
"parse options in a 100% compatible manner.")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Free Software Foundation, Inc.")]
|
||||||
|
[assembly: AssemblyProduct("GNU Getopt")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright (c) 1987-1997 Free Software " +
|
||||||
|
"Foundation, Inc., Java Port Copyright (c) 1998 by Aaron M. Renn " +
|
||||||
|
"(arenn@urbanophile.com), C#.NET Port of the Java Port Copyright (c) " +
|
||||||
|
"2004 by Klaus Prückl (klaus.prueckl@aon.at)")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 Revision and Build Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("0.9.1.*")]
|
||||||
|
|
||||||
|
//
|
||||||
|
// In order to sign your assembly you must specify a key to use. Refer to the
|
||||||
|
// Microsoft .NET Framework documentation for more information on assembly signing.
|
||||||
|
//
|
||||||
|
// Use the attributes below to control which key is used for signing.
|
||||||
|
//
|
||||||
|
// Notes:
|
||||||
|
// (*) If no key is specified, the assembly is not signed.
|
||||||
|
// (*) KeyName refers to a key that has been installed in the Crypto Service
|
||||||
|
// Provider (CSP) on your machine. KeyFile refers to a file which contains
|
||||||
|
// a key.
|
||||||
|
// (*) If the KeyFile and the KeyName values are both specified, the
|
||||||
|
// following processing occurs:
|
||||||
|
// (1) If the KeyName can be found in the CSP, that key is used.
|
||||||
|
// (2) If the KeyName does not exist and the KeyFile does exist, the key
|
||||||
|
// in the KeyFile is installed into the CSP and used.
|
||||||
|
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
|
||||||
|
// When specifying the KeyFile, the location of the KeyFile should be
|
||||||
|
// relative to the project output directory which is
|
||||||
|
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
|
||||||
|
// located in the project directory, you would specify the AssemblyKeyFile
|
||||||
|
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
|
||||||
|
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
|
||||||
|
// documentation for more information on this.
|
||||||
|
//
|
||||||
|
[assembly:CLSCompliant(true)]
|
||||||
|
[assembly:ComVisible(true)]
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,122 @@
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ProjectType>Local</ProjectType>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{379BC478-7D84-4E0E-A4B8-197905C824AE}</ProjectGuid>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ApplicationIcon>
|
||||||
|
</ApplicationIcon>
|
||||||
|
<AssemblyKeyContainerName>
|
||||||
|
</AssemblyKeyContainerName>
|
||||||
|
<AssemblyName>Gnu.Getopt</AssemblyName>
|
||||||
|
<AssemblyOriginatorKeyFile>
|
||||||
|
</AssemblyOriginatorKeyFile>
|
||||||
|
<DefaultClientScript>JScript</DefaultClientScript>
|
||||||
|
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
|
||||||
|
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
||||||
|
<DelaySign>false</DelaySign>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<RootNamespace>Gnu.Getopt</RootNamespace>
|
||||||
|
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||||
|
<StartupObject>
|
||||||
|
</StartupObject>
|
||||||
|
<FileUpgradeFlags>
|
||||||
|
</FileUpgradeFlags>
|
||||||
|
<OldToolsVersion>0.0</OldToolsVersion>
|
||||||
|
<UpgradeBackupLocation>
|
||||||
|
</UpgradeBackupLocation>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||||
|
<BaseAddress>285212672</BaseAddress>
|
||||||
|
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||||
|
<ConfigurationOverrideFile>
|
||||||
|
</ConfigurationOverrideFile>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DocumentationFile>bin\Debug\Gnu.Getopt.XML</DocumentationFile>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<FileAlignment>4096</FileAlignment>
|
||||||
|
<NoStdLib>false</NoStdLib>
|
||||||
|
<NoWarn>
|
||||||
|
</NoWarn>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<RegisterForComInterop>false</RegisterForComInterop>
|
||||||
|
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||||
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||||
|
<BaseAddress>285212672</BaseAddress>
|
||||||
|
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||||
|
<ConfigurationOverrideFile>
|
||||||
|
</ConfigurationOverrideFile>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<DocumentationFile>bin\Release\Gnu.Getopt.XML</DocumentationFile>
|
||||||
|
<DebugSymbols>false</DebugSymbols>
|
||||||
|
<FileAlignment>4096</FileAlignment>
|
||||||
|
<NoStdLib>false</NoStdLib>
|
||||||
|
<NoWarn>
|
||||||
|
</NoWarn>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<RegisterForComInterop>false</RegisterForComInterop>
|
||||||
|
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||||
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<DebugType>none</DebugType>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System">
|
||||||
|
<Name>System</Name>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="AssemblyInfo.cs">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Getopt.cs">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="LongOpt.cs">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.cs.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.de.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.fr.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.hu.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.ja.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.nl.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.no.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MessagesBundle.resx">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<PreBuildEvent>
|
||||||
|
</PreBuildEvent>
|
||||||
|
<PostBuildEvent>
|
||||||
|
</PostBuildEvent>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,239 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
/* LongOpt.cs -- C#.NET port of Long option object for Getopt
|
||||||
|
/*
|
||||||
|
/* Copyright (c) 1998 by Aaron M. Renn (arenn@urbanophile.com)
|
||||||
|
/* C#.NET Port Copyright (c) 2004 by Klaus Prückl (klaus.prueckl@aon.at)
|
||||||
|
/*
|
||||||
|
/* This program is free software; you can redistribute it and/or modify
|
||||||
|
/* it under the terms of the GNU Library General Public License as published
|
||||||
|
/* by the Free Software Foundation; either version 2 of the License or
|
||||||
|
/* (at your option) any later version.
|
||||||
|
/*
|
||||||
|
/* This program is distributed in the hope that it will be useful, but
|
||||||
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
/* GNU Library General Public License for more details.
|
||||||
|
/*
|
||||||
|
/* You should have received a copy of the GNU Library General Public License
|
||||||
|
/* along with this program; see the file COPYING.LIB. If not, write to
|
||||||
|
/* the Free Software Foundation Inc., 59 Temple Place - Suite 330,
|
||||||
|
/* Boston, MA 02111-1307 USA
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Resources;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Gnu.Getopt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constant enumeration values used for the LongOpt <c>hasArg</c>
|
||||||
|
/// constructor argument.
|
||||||
|
/// </summary>
|
||||||
|
public enum Argument
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This value indicates that the option takes no argument.
|
||||||
|
/// </summary>
|
||||||
|
No = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// This value indicates that the option takes an argument that is
|
||||||
|
/// required.
|
||||||
|
/// </summary>
|
||||||
|
Required = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// This value indicates that the option takes an argument that is
|
||||||
|
/// optional.
|
||||||
|
/// </summary>
|
||||||
|
Optional = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This object represents the definition of a long option in the C# port
|
||||||
|
/// of GNU getopt. An array of LongOpt objects is passed to the
|
||||||
|
/// <see cref="Getopt"/> object to define the list of valid long options
|
||||||
|
/// for a given parsing session. Refer to the <see cref="Getopt"/>
|
||||||
|
/// documentation for details on the format of long options.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="Getopt">Getopt</seealso>
|
||||||
|
/// <author>Aaron M. Renn (arenn@urbanophile.com)</author>
|
||||||
|
/// <author>Klaus Prückl (klaus.prueckl@aon.at)</author>
|
||||||
|
public class LongOpt
|
||||||
|
{
|
||||||
|
#region Instance Variables
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the long option.
|
||||||
|
/// </summary>
|
||||||
|
private string name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the option has no argument, a required argument,
|
||||||
|
/// or an optional argument.
|
||||||
|
/// </summary>
|
||||||
|
private Argument hasArg;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If this variable is not null, then the value stored in <c>val</c>
|
||||||
|
/// is stored here when this long option is encountered. If this is
|
||||||
|
/// null, the value stored in <c>val</c> is treated as the name of an
|
||||||
|
/// equivalent short option.
|
||||||
|
/// </summary>
|
||||||
|
private StringBuilder flag;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The value to store in <c>flag</c> if flag is not null, otherwise
|
||||||
|
/// the equivalent short option character for this long option.
|
||||||
|
/// </summary>
|
||||||
|
private int val;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The localized strings are kept in the resources, which can be
|
||||||
|
/// accessed by the <see cref="ResourceManager"/> class.
|
||||||
|
/// </summary>
|
||||||
|
private ResourceManager resManager = new ResourceManager(
|
||||||
|
"Gnu.Getopt.MessagesBundle", Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current UI culture (set to en-US when posixly correctness is
|
||||||
|
/// enabled).
|
||||||
|
/// </summary>
|
||||||
|
private CultureInfo cultureInfo = CultureInfo.CurrentUICulture;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new LongOpt object with the given parameter values. If the
|
||||||
|
/// value passed as <paramref name="hasArg"/> is not valid, then an
|
||||||
|
/// <see cref="ArgumentException"/> is thrown.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">
|
||||||
|
/// The long option string.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="hasArg">
|
||||||
|
/// Indicates whether the option has no argument
|
||||||
|
/// (<see cref="Argument.No"/>), a required argument
|
||||||
|
/// (<see cref="Argument.Required"/>) or an optional argument
|
||||||
|
/// (<see cref="Argument.Optional"/>).
|
||||||
|
/// </param>
|
||||||
|
/// <param name="flag">
|
||||||
|
/// If non-null, this is a location to store the value of
|
||||||
|
/// <paramref name="val"/> when this option is encountered, otherwise
|
||||||
|
/// <paramref name="val"/> is treated as the equivalent short option
|
||||||
|
/// character.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="val">
|
||||||
|
/// The value to return for this long option, or the equivalent single
|
||||||
|
/// letter option to emulate if flag is null.
|
||||||
|
/// </param>
|
||||||
|
/// <exception cref="System.ArgumentException">
|
||||||
|
/// Is thrown if the <paramref name="hasArg"/> param is not one of
|
||||||
|
/// <see cref="Argument.No"/>, <see cref="Argument.Required"/> or
|
||||||
|
/// <see cref="Argument.Optional"/>.
|
||||||
|
/// </exception>
|
||||||
|
public LongOpt(string name, Argument hasArg, StringBuilder flag,
|
||||||
|
int val)
|
||||||
|
{
|
||||||
|
// Check for application setting "Gnu.PosixlyCorrect" to determine
|
||||||
|
// whether to strictly follow the POSIX standard. This replaces the
|
||||||
|
// "POSIXLY_CORRECT" environment variable in the C version
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if((bool) new AppSettingsReader().GetValue(
|
||||||
|
"Gnu.PosixlyCorrect", typeof(bool)))
|
||||||
|
{
|
||||||
|
this.cultureInfo = new CultureInfo("en-US");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate hasArg
|
||||||
|
if ((hasArg != Argument.No) && (hasArg != Argument.Required) &&
|
||||||
|
(hasArg != Argument.Optional))
|
||||||
|
{
|
||||||
|
object[] msgArgs = new object[]{hasArg};
|
||||||
|
throw new System.ArgumentException(string.Format(
|
||||||
|
this.resManager.GetString("getopt.invalidValue",
|
||||||
|
this.cultureInfo), msgArgs));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store off values
|
||||||
|
this.name = name;
|
||||||
|
this.hasArg = hasArg;
|
||||||
|
this.flag = flag;
|
||||||
|
this.val = val;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the name of this LongOpt as a string
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The name of the long option
|
||||||
|
/// </returns>
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return this.name; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the value set for the <c>hasArg</c> field for this long
|
||||||
|
/// option.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The value of <c>hasArg</c>.
|
||||||
|
/// </returns>
|
||||||
|
public Argument HasArg
|
||||||
|
{
|
||||||
|
get { return this.hasArg; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the value of the <c>flag</c> field for this long option.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The value of <c>flag</c>.
|
||||||
|
/// </returns>
|
||||||
|
public StringBuilder Flag
|
||||||
|
{
|
||||||
|
get { return this.flag; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the value of the <c>val</c> field for this long option.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The value of <c>val</c>.
|
||||||
|
/// </returns>
|
||||||
|
public int Val
|
||||||
|
{
|
||||||
|
get { return this.val; }
|
||||||
|
}
|
||||||
|
} // Class LongOpt
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: volba ''{1}'' je nejednoznaèná</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: volba ''--{1}'' nepøipou¹tí argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: volba ''{1}{2}'' nepøipou¹tí argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: volba ''{1}'' vy¾aduje argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: nepøípustná volba ''--{1}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: nepøípustná volba ''{1}{2}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: nepøípustná volba -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: neplatná volba -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: volba vy¾aduje argument -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>Neplatná hodnota {0} parameteru 'has_arg' </value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: Option ''{1}'' ist zweideutig</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: Option ''--{1}'' erlaubt kein Argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: Option ''{1}{2}'' erlaubt kein Argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: Option ''{1}'' benötigt ein Argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: Unbekannte Option ''--{1}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: Unbekannte Option ''{1}{2}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: Verbotene Option -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: Ungültige Option -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: Option benötigt ein Argument -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>Ungültiger Wert {0} für Parameter 'has_arg' </value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: l'option ''{1}'' est ambiguë</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: l'option ''--{1}'' ne permet pas de paramètre</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: l'option ''{1}{2}'' ne permet pas de paramètre</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: l'option ''{1}'' requiert un paramètre</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: option non reconnue ''--{1}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: option non reconnue ''{1}{2}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: option illégale -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: option invalide -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: cette option requiert un paramètre -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>Valeur invalide {0} pour le paramètre 'has_arg'</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: opció ''{1}'' félreérthetõ</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: opció ''--{1}'' nem enged meg argumentumot</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: opció ''{1}{2}'' nem enged meg argumentumot</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: opció ''{1}'' argumentumot igényel</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: ismeretlen opció ''--{1}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: ismeretlen opció ''{1}{2}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: illegális opció -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: érvénytelen opció -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: az opció argumentumot igényel -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>Érvénytelen érték {0} a következõ paraméterhez 'has_arg' </value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: ''{1}'' \u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u66d6\u6627\u3067\u3059\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: ''--{1}'' \u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u3082\u3061\u307e\u305b\u3093\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: ''{1}{2}'' \u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u3082\u3061\u307e\u305b\u3093\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: ''{1}'' \u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u306f\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u5fc5\u8981\u3067\u3059\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: ''--{1}'' \u306f\u7121\u52b9\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: ''{1}{2}'' \u306f\u7121\u52b9\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: -- {1} \u306f\u4e0d\u6b63\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: -- {1} \u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: -- {1} \u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u306f\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u5fc5\u8981\u3067\u3059\u3002</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>{0} \u306f\u3001'has_arg' \u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u4e0d\u6b63\u306a\u5024\u3067\u3059\u3002</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: optie ''{1}'' is ambigue</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: optie ''--{1}'' staat geen argumenten toe</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: optie ''{1}{2}'' staat geen argumenten toe</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: optie ''{1}'' heeft een argument nodig</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: onbekende optie ''--{1}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: onbekende optie ''{1}{2}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: niet-toegestane optie -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: onjuiste optie -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: optie heeft een argument nodig -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>Ongeldige waarde {0} voor parameter 'has_arg' </value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: flagget ''{1}'' er flertydig</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: flagget ''--{1}'' tillater ikke et argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: flagget ''{1}{2}'' tillater ikke et argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: flagget ''{1}'' krever et argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: ukjent flagg ''--{1}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: ukjent flagg ''{1}{2}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: ugyldig flagg -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: ugyldig flagg -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: flagget krever et argument -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>Ugyldig verdi {0} for parameter 'has_arg' </value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="ResMimeType">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Version">
|
||||||
|
<value>1.0.0.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="Writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="getopt.ambigious">
|
||||||
|
<value>{0}: option ''{1}'' is ambiguous</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments1">
|
||||||
|
<value>{0}: option ''--{1}'' doesn't allow an argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.arguments2">
|
||||||
|
<value>{0}: option ''{1}{2}'' doesn't allow an argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires">
|
||||||
|
<value>{0}: option ''{1}'' requires an argument</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized">
|
||||||
|
<value>{0}: unrecognized option ''--{1}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.unrecognized2">
|
||||||
|
<value>{0}: unrecognized option ''{1}{2}''</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalid">
|
||||||
|
<value>{0}: invalid option -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.illegal">
|
||||||
|
<value>{0}: illegal option -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.requires2">
|
||||||
|
<value>{0}: option requires an argument -- {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="getopt.invalidValue">
|
||||||
|
<value>Invalid value {0} for parameter 'has_arg' </value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.30729</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{859A653A-7728-4F02-BAF2-A5CD8F991916}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>GNU.Gettext</RootNamespace>
|
||||||
|
<AssemblyName>GNU.Gettext</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<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' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="intl.cs" />
|
||||||
|
<Compile Include="msgfmt.cs" />
|
||||||
|
<Compile Include="msgunfmt.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
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("Gettext")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("Gettext")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
|
||||||
|
[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("3be71b7d-867c-46de-bb4d-d12215f0ae67")]
|
||||||
|
|
||||||
|
// 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")]
|
|
@ -0,0 +1,520 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
/* GNU gettext for C#
|
||||||
|
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||||
|
* Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Library General Public License as published
|
||||||
|
* by the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
* USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using the GNU gettext approach, compiled message catalogs are assemblies
|
||||||
|
* containing just one class, a subclass of GettextResourceSet. They are thus
|
||||||
|
* interoperable with standard ResourceManager based code.
|
||||||
|
*
|
||||||
|
* The main differences between the common .NET resources approach and the
|
||||||
|
* GNU gettext approach are:
|
||||||
|
* - In the .NET resource approach, the keys are abstract textual shortcuts.
|
||||||
|
* In the GNU gettext approach, the keys are the English/ASCII version
|
||||||
|
* of the messages.
|
||||||
|
* - In the .NET resource approach, the translation files are called
|
||||||
|
* "Resource.locale.resx" and are UTF-8 encoded XML files. In the GNU gettext
|
||||||
|
* approach, the translation files are called "Resource.locale.po" and are
|
||||||
|
* in the encoding the translator has chosen. There are at least three GUI
|
||||||
|
* translating tools (Emacs PO mode, KDE KBabel, GNOME gtranslator).
|
||||||
|
* - In the .NET resource approach, the function ResourceManager.GetString
|
||||||
|
* returns an empty string or throws an InvalidOperationException when no
|
||||||
|
* translation is found. In the GNU gettext approach, the GetString function
|
||||||
|
* returns the (English) message key in that case.
|
||||||
|
* - In the .NET resource approach, there is no support for plural handling.
|
||||||
|
* In the GNU gettext approach, we have the GetPluralString function.
|
||||||
|
*
|
||||||
|
* To compile GNU gettext message catalogs into C# assemblies, the msgfmt
|
||||||
|
* program can be used.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System; /* String, InvalidOperationException, Console */
|
||||||
|
using System.Globalization; /* CultureInfo */
|
||||||
|
using System.Resources; /* ResourceManager, ResourceSet, IResourceReader */
|
||||||
|
using System.Reflection; /* Assembly, ConstructorInfo */
|
||||||
|
using System.Collections; /* Hashtable, ICollection, IEnumerator, IDictionaryEnumerator */
|
||||||
|
using System.IO; /* Path, FileNotFoundException, Stream */
|
||||||
|
using System.Text; /* StringBuilder */
|
||||||
|
|
||||||
|
namespace GNU.Gettext {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Each instance of this class can be used to lookup translations for a
|
||||||
|
/// given resource name. For each <c>CultureInfo</c>, it performs the lookup
|
||||||
|
/// in several assemblies, from most specific over territory-neutral to
|
||||||
|
/// language-neutral.
|
||||||
|
/// </summary>
|
||||||
|
public class GettextResourceManager : ResourceManager {
|
||||||
|
|
||||||
|
// ======================== Public Constructors ========================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseName">the resource name, also the assembly base
|
||||||
|
/// name</param>
|
||||||
|
public GettextResourceManager (String baseName)
|
||||||
|
: base (baseName, Assembly.GetCallingAssembly(), typeof (GettextResourceSet)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseName">the resource name, also the assembly base
|
||||||
|
/// name</param>
|
||||||
|
public GettextResourceManager (String baseName, Assembly assembly)
|
||||||
|
: base (baseName, assembly, typeof (GettextResourceSet)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== Implementation ========================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads and returns a satellite assembly.
|
||||||
|
/// </summary>
|
||||||
|
// This is like Assembly.GetSatelliteAssembly, but uses resourceName
|
||||||
|
// instead of assembly.GetName().Name, and works around a bug in
|
||||||
|
// mono-0.28.
|
||||||
|
private static Assembly GetSatelliteAssembly (Assembly assembly, String resourceName, CultureInfo culture) {
|
||||||
|
String satelliteExpectedLocation =
|
||||||
|
Path.GetDirectoryName(assembly.Location)
|
||||||
|
+ Path.DirectorySeparatorChar + culture.Name
|
||||||
|
+ Path.DirectorySeparatorChar + resourceName + ".resources.dll";
|
||||||
|
return Assembly.LoadFrom(satelliteExpectedLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads and returns the satellite assembly for a given culture.
|
||||||
|
/// </summary>
|
||||||
|
private Assembly MySatelliteAssembly (CultureInfo culture) {
|
||||||
|
return GetSatelliteAssembly(MainAssembly, BaseName, culture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a resource name to a class name.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>a nonempty string consisting of alphanumerics and underscores
|
||||||
|
/// and starting with a letter or underscore</returns>
|
||||||
|
private static String ConstructClassName (String resourceName) {
|
||||||
|
// We could just return an arbitrary fixed class name, like "Messages",
|
||||||
|
// assuming that every assembly will only ever contain one
|
||||||
|
// GettextResourceSet subclass, but this assumption would break the day
|
||||||
|
// we want to support multi-domain PO files in the same format...
|
||||||
|
bool valid = (resourceName.Length > 0);
|
||||||
|
for (int i = 0; valid && i < resourceName.Length; i++) {
|
||||||
|
char c = resourceName[i];
|
||||||
|
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')
|
||||||
|
|| (i > 0 && c >= '0' && c <= '9')))
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
if (valid)
|
||||||
|
return resourceName;
|
||||||
|
else {
|
||||||
|
// Use hexadecimal escapes, using the underscore as escape character.
|
||||||
|
String hexdigit = "0123456789abcdef";
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
b.Append("__UESCAPED__");
|
||||||
|
for (int i = 0; i < resourceName.Length; i++) {
|
||||||
|
char c = resourceName[i];
|
||||||
|
if (c >= 0xd800 && c < 0xdc00
|
||||||
|
&& i+1 < resourceName.Length
|
||||||
|
&& resourceName[i+1] >= 0xdc00 && resourceName[i+1] < 0xe000) {
|
||||||
|
// Combine two UTF-16 words to a character.
|
||||||
|
char c2 = resourceName[i+1];
|
||||||
|
int uc = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
|
||||||
|
b.Append('_');
|
||||||
|
b.Append('U');
|
||||||
|
b.Append(hexdigit[(uc >> 28) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 24) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 20) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 16) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 12) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 8) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 4) & 0x0f]);
|
||||||
|
b.Append(hexdigit[uc & 0x0f]);
|
||||||
|
i++;
|
||||||
|
} else if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
|
||||||
|
|| (c >= '0' && c <= '9'))) {
|
||||||
|
int uc = c;
|
||||||
|
b.Append('_');
|
||||||
|
b.Append('u');
|
||||||
|
b.Append(hexdigit[(uc >> 12) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 8) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 4) & 0x0f]);
|
||||||
|
b.Append(hexdigit[uc & 0x0f]);
|
||||||
|
} else
|
||||||
|
b.Append(c);
|
||||||
|
}
|
||||||
|
return b.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a resource set for a given culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ArgumentException">
|
||||||
|
/// The expected type name is not valid.
|
||||||
|
/// </exception>
|
||||||
|
/// <exception cref="ReflectionTypeLoadException">
|
||||||
|
/// satelliteAssembly does not contain the expected type.
|
||||||
|
/// </exception>
|
||||||
|
/// <exception cref="NullReferenceException">
|
||||||
|
/// The type has no no-arguments constructor.
|
||||||
|
/// </exception>
|
||||||
|
private static GettextResourceSet InstantiateResourceSet (Assembly satelliteAssembly, String resourceName, CultureInfo culture) {
|
||||||
|
// We expect a class with a culture dependent class name.
|
||||||
|
Type clazz = satelliteAssembly.GetType(ConstructClassName(resourceName)+"_"+culture.Name.Replace('-','_'));
|
||||||
|
// We expect it has a no-argument constructor, and invoke it.
|
||||||
|
ConstructorInfo constructor = clazz.GetConstructor(Type.EmptyTypes);
|
||||||
|
return constructor.Invoke(null) as GettextResourceSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GettextResourceSet[] EmptyResourceSetArray = new GettextResourceSet[0];
|
||||||
|
|
||||||
|
// Cache for already loaded GettextResourceSet cascades.
|
||||||
|
private Hashtable /* CultureInfo -> GettextResourceSet[] */ Loaded = new Hashtable();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the array of <c>GettextResourceSet</c>s for a given culture,
|
||||||
|
/// loading them if necessary, and maintaining the cache.
|
||||||
|
/// </summary>
|
||||||
|
private GettextResourceSet[] GetResourceSetsFor (CultureInfo culture) {
|
||||||
|
//Console.WriteLine(">> GetResourceSetsFor "+culture);
|
||||||
|
// Look up in the cache.
|
||||||
|
GettextResourceSet[] result = Loaded[culture] as GettextResourceSet[];
|
||||||
|
if (result == null) {
|
||||||
|
lock(this) {
|
||||||
|
// Look up again - maybe another thread has filled in the entry
|
||||||
|
// while we slept waiting for the lock.
|
||||||
|
result = Loaded[culture] as GettextResourceSet[];
|
||||||
|
if (result == null) {
|
||||||
|
// Determine the GettextResourceSets for the given culture.
|
||||||
|
if (culture.Parent == null || culture.Equals(CultureInfo.InvariantCulture))
|
||||||
|
// Invariant culture.
|
||||||
|
result = EmptyResourceSetArray;
|
||||||
|
else {
|
||||||
|
// Use a satellite assembly as primary GettextResourceSet, and
|
||||||
|
// the result for the parent culture as fallback.
|
||||||
|
GettextResourceSet[] parentResult = GetResourceSetsFor(culture.Parent);
|
||||||
|
Assembly satelliteAssembly;
|
||||||
|
try {
|
||||||
|
satelliteAssembly = MySatelliteAssembly(culture);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
satelliteAssembly = null;
|
||||||
|
}
|
||||||
|
if (satelliteAssembly != null) {
|
||||||
|
GettextResourceSet satelliteResourceSet;
|
||||||
|
try {
|
||||||
|
satelliteResourceSet = InstantiateResourceSet(satelliteAssembly, BaseName, culture);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.Error.WriteLine(e);
|
||||||
|
Console.Error.WriteLine(e.StackTrace);
|
||||||
|
satelliteResourceSet = null;
|
||||||
|
}
|
||||||
|
if (satelliteResourceSet != null) {
|
||||||
|
result = new GettextResourceSet[1+parentResult.Length];
|
||||||
|
result[0] = satelliteResourceSet;
|
||||||
|
Array.Copy(parentResult, 0, result, 1, parentResult.Length);
|
||||||
|
} else
|
||||||
|
result = parentResult;
|
||||||
|
} else
|
||||||
|
result = parentResult;
|
||||||
|
}
|
||||||
|
// Put the result into the cache.
|
||||||
|
Loaded.Add(culture, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Console.WriteLine("<< GetResourceSetsFor "+culture);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
/// <summary>
|
||||||
|
/// Releases all loaded <c>GettextResourceSet</c>s and their assemblies.
|
||||||
|
/// </summary>
|
||||||
|
// TODO: No way to release an Assembly?
|
||||||
|
public override void ReleaseAllResources () {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the translation of <paramref name="msgid"/> in a given culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgid">the key string to be translated, an ASCII
|
||||||
|
/// string</param>
|
||||||
|
/// <returns>the translation of <paramref name="msgid"/>, or
|
||||||
|
/// <paramref name="msgid"/> if none is found</returns>
|
||||||
|
public override String GetString (String msgid, CultureInfo culture) {
|
||||||
|
foreach (GettextResourceSet rs in GetResourceSetsFor(culture)) {
|
||||||
|
String translation = rs.GetString(msgid);
|
||||||
|
if (translation != null)
|
||||||
|
return translation;
|
||||||
|
}
|
||||||
|
// Fallback.
|
||||||
|
return msgid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the translation of <paramref name="msgid"/> and
|
||||||
|
/// <paramref name="msgidPlural"/> in a given culture, choosing the right
|
||||||
|
/// plural form depending on the number <paramref name="n"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgid">the key string to be translated, an ASCII
|
||||||
|
/// string</param>
|
||||||
|
/// <param name="msgidPlural">the English plural of <paramref name="msgid"/>,
|
||||||
|
/// an ASCII string</param>
|
||||||
|
/// <param name="n">the number, should be >= 0</param>
|
||||||
|
/// <returns>the translation, or <paramref name="msgid"/> or
|
||||||
|
/// <paramref name="msgidPlural"/> if none is found</returns>
|
||||||
|
public virtual String GetPluralString (String msgid, String msgidPlural, long n, CultureInfo culture) {
|
||||||
|
foreach (GettextResourceSet rs in GetResourceSetsFor(culture)) {
|
||||||
|
String translation = rs.GetPluralString(msgid, msgidPlural, n);
|
||||||
|
if (translation != null)
|
||||||
|
return translation;
|
||||||
|
}
|
||||||
|
// Fallback: Germanic plural form.
|
||||||
|
return (n == 1 ? msgid : msgidPlural);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== Public Methods ========================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the translation of <paramref name="msgid"/> in the current
|
||||||
|
/// culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgid">the key string to be translated, an ASCII
|
||||||
|
/// string</param>
|
||||||
|
/// <returns>the translation of <paramref name="msgid"/>, or
|
||||||
|
/// <paramref name="msgid"/> if none is found</returns>
|
||||||
|
public override String GetString (String msgid) {
|
||||||
|
return GetString(msgid, CultureInfo.CurrentUICulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the translation of <paramref name="msgid"/> and
|
||||||
|
/// <paramref name="msgidPlural"/> in the current culture, choosing the
|
||||||
|
/// right plural form depending on the number <paramref name="n"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgid">the key string to be translated, an ASCII
|
||||||
|
/// string</param>
|
||||||
|
/// <param name="msgidPlural">the English plural of <paramref name="msgid"/>,
|
||||||
|
/// an ASCII string</param>
|
||||||
|
/// <param name="n">the number, should be >= 0</param>
|
||||||
|
/// <returns>the translation, or <paramref name="msgid"/> or
|
||||||
|
/// <paramref name="msgidPlural"/> if none is found</returns>
|
||||||
|
public virtual String GetPluralString (String msgid, String msgidPlural, long n) {
|
||||||
|
return GetPluralString(msgid, msgidPlural, n, CultureInfo.CurrentUICulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>
|
||||||
|
/// Each instance of this class encapsulates a single PO file.
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// This API of this class is not meant to be used directly; use
|
||||||
|
/// <c>GettextResourceManager</c> instead.
|
||||||
|
/// </para>
|
||||||
|
/// </summary>
|
||||||
|
// We need this subclass of ResourceSet, because the plural formula must come
|
||||||
|
// from the same ResourceSet as the object containing the plural forms.
|
||||||
|
public class GettextResourceSet : ResourceSet {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new message catalog. When using this constructor, you
|
||||||
|
/// must override the <c>ReadResources</c> method, in order to initialize
|
||||||
|
/// the <c>Table</c> property. The message catalog will support plural
|
||||||
|
/// forms only if the <c>ReadResources</c> method installs values of type
|
||||||
|
/// <c>String[]</c> and if the <c>PluralEval</c> method is overridden.
|
||||||
|
/// </summary>
|
||||||
|
protected GettextResourceSet ()
|
||||||
|
: base (DummyResourceReader) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new message catalog, by reading the string/value pairs from
|
||||||
|
/// the given <paramref name="reader"/>. The message catalog will support
|
||||||
|
/// plural forms only if the reader can produce values of type
|
||||||
|
/// <c>String[]</c> and if the <c>PluralEval</c> method is overridden.
|
||||||
|
/// </summary>
|
||||||
|
public GettextResourceSet (IResourceReader reader)
|
||||||
|
: base (reader) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new message catalog, by reading the string/value pairs from
|
||||||
|
/// the given <paramref name="stream"/>, which should have the format of
|
||||||
|
/// a <c>.resources</c> file. The message catalog will not support plural
|
||||||
|
/// forms.
|
||||||
|
/// </summary>
|
||||||
|
public GettextResourceSet (Stream stream)
|
||||||
|
: base (stream) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new message catalog, by reading the string/value pairs from
|
||||||
|
/// the file with the given <paramref name="fileName"/>. The file should
|
||||||
|
/// be in the format of a <c>.resources</c> file. The message catalog will
|
||||||
|
/// not support plural forms.
|
||||||
|
/// </summary>
|
||||||
|
public GettextResourceSet (String fileName)
|
||||||
|
: base (fileName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the translation of <paramref name="msgid"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgid">the key string to be translated, an ASCII
|
||||||
|
/// string</param>
|
||||||
|
/// <returns>the translation of <paramref name="msgid"/>, or <c>null</c> if
|
||||||
|
/// none is found</returns>
|
||||||
|
// The default implementation essentially does (String)Table[msgid].
|
||||||
|
// Here we also catch the plural form case.
|
||||||
|
public override String GetString (String msgid) {
|
||||||
|
Object value = GetObject(msgid);
|
||||||
|
if (value == null || value is String)
|
||||||
|
return (String)value;
|
||||||
|
else if (value is String[])
|
||||||
|
// A plural form, but no number is given.
|
||||||
|
// Like the C implementation, return the first plural form.
|
||||||
|
return (value as String[])[0];
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException("resource for \""+msgid+"\" in "+GetType().FullName+" is not a string");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the translation of <paramref name="msgid"/>, with possibly
|
||||||
|
/// case-insensitive lookup.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgid">the key string to be translated, an ASCII
|
||||||
|
/// string</param>
|
||||||
|
/// <returns>the translation of <paramref name="msgid"/>, or <c>null</c> if
|
||||||
|
/// none is found</returns>
|
||||||
|
// The default implementation essentially does (String)Table[msgid].
|
||||||
|
// Here we also catch the plural form case.
|
||||||
|
public override String GetString (String msgid, bool ignoreCase) {
|
||||||
|
Object value = GetObject(msgid, ignoreCase);
|
||||||
|
if (value == null || value is String)
|
||||||
|
return (String)value;
|
||||||
|
else if (value is String[])
|
||||||
|
// A plural form, but no number is given.
|
||||||
|
// Like the C implementation, return the first plural form.
|
||||||
|
return (value as String[])[0];
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException("resource for \""+msgid+"\" in "+GetType().FullName+" is not a string");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the translation of <paramref name="msgid"/> and
|
||||||
|
/// <paramref name="msgidPlural"/>, choosing the right plural form
|
||||||
|
/// depending on the number <paramref name="n"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgid">the key string to be translated, an ASCII
|
||||||
|
/// string</param>
|
||||||
|
/// <param name="msgidPlural">the English plural of <paramref name="msgid"/>,
|
||||||
|
/// an ASCII string</param>
|
||||||
|
/// <param name="n">the number, should be >= 0</param>
|
||||||
|
/// <returns>the translation, or <c>null</c> if none is found</returns>
|
||||||
|
public virtual String GetPluralString (String msgid, String msgidPlural, long n) {
|
||||||
|
Object value = GetObject(msgid);
|
||||||
|
if (value == null || value is String)
|
||||||
|
return (String)value;
|
||||||
|
else if (value is String[]) {
|
||||||
|
String[] choices = value as String[];
|
||||||
|
long index = PluralEval(n);
|
||||||
|
return choices[index >= 0 && index < choices.Length ? index : 0];
|
||||||
|
} else
|
||||||
|
throw new InvalidOperationException("resource for \""+msgid+"\" in "+GetType().FullName+" is not a string");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the index of the plural form to be chosen for a given number.
|
||||||
|
/// The default implementation is the Germanic plural formula:
|
||||||
|
/// zero for <paramref name="n"/> == 1, one for <paramref name="n"/> != 1.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual long PluralEval (long n) {
|
||||||
|
return (n == 1 ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the keys of this resource set, i.e. the strings for which
|
||||||
|
/// <c>GetObject()</c> can return a non-null value.
|
||||||
|
/// </summary>
|
||||||
|
public virtual ICollection Keys {
|
||||||
|
get {
|
||||||
|
return Table.Keys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A trivial instance of <c>IResourceReader</c> that does nothing.
|
||||||
|
/// </summary>
|
||||||
|
// Needed by the no-arguments constructor.
|
||||||
|
private static IResourceReader DummyResourceReader = new DummyIResourceReader();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A trivial <c>IResourceReader</c> implementation.
|
||||||
|
/// </summary>
|
||||||
|
class DummyIResourceReader : IResourceReader {
|
||||||
|
|
||||||
|
// Implementation of IDisposable.
|
||||||
|
void System.IDisposable.Dispose () {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementation of IEnumerable.
|
||||||
|
IEnumerator System.Collections.IEnumerable.GetEnumerator () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementation of IResourceReader.
|
||||||
|
void System.Resources.IResourceReader.Close () {
|
||||||
|
}
|
||||||
|
IDictionaryEnumerator System.Resources.IResourceReader.GetEnumerator () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,142 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
/* GNU gettext for C#
|
||||||
|
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||||
|
* Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This program creates a .resources file from a set of key/value pairs given
|
||||||
|
* on standard input.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System; /* String, Console, Exception */
|
||||||
|
using System.IO; /* Stream, BufferedStream, StreamReader */
|
||||||
|
using System.Text; /* StringBuilder, UTF8Encoding */
|
||||||
|
using System.Resources; /* ResourceWriter */
|
||||||
|
|
||||||
|
namespace GNU.Gettext {
|
||||||
|
public class WriteResource {
|
||||||
|
private StreamReader reader;
|
||||||
|
// Read a NUL-terminated UTF-8 encoded string.
|
||||||
|
private String ReadString () {
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
for (;;) {
|
||||||
|
int c = reader.Read();
|
||||||
|
if (c < 0) // EOF?
|
||||||
|
return null;
|
||||||
|
if (c == 0) // End of String?
|
||||||
|
break;
|
||||||
|
b.Append((char)c);
|
||||||
|
}
|
||||||
|
return b.ToString();
|
||||||
|
}
|
||||||
|
// Read all msgid/msgstr pairs, register them in the ResourceWriter,
|
||||||
|
// and write the binary contents to the output stream.
|
||||||
|
private void ReadAllInput (ResourceWriter rw) {
|
||||||
|
for (;;) {
|
||||||
|
String msgid = ReadString();
|
||||||
|
if (msgid == null)
|
||||||
|
break;
|
||||||
|
String msgstr = ReadString();
|
||||||
|
if (msgstr == null)
|
||||||
|
break;
|
||||||
|
rw.AddResource(msgid, msgstr);
|
||||||
|
}
|
||||||
|
rw.Generate();
|
||||||
|
}
|
||||||
|
// Read all msgid/msgstr pairs (each string being NUL-terminated and
|
||||||
|
// UTF-8 encoded) and write the .resources file to the given filename.
|
||||||
|
WriteResource (String filename) {
|
||||||
|
Stream input = new BufferedStream(Console.OpenStandardInput());
|
||||||
|
reader = new StreamReader(input, new UTF8Encoding());
|
||||||
|
if (filename.Equals("-")) {
|
||||||
|
BufferedStream output = new BufferedStream(Console.OpenStandardOutput());
|
||||||
|
// A temporary output stream is needed because ResourceWriter.Generate
|
||||||
|
// expects to be able to seek in the Stream.
|
||||||
|
MemoryStream tmpoutput = new MemoryStream();
|
||||||
|
ResourceWriter rw = new ResourceWriter(tmpoutput);
|
||||||
|
ReadAllInput(rw);
|
||||||
|
#if __CSCC__
|
||||||
|
// Use the ResourceReader to check against pnet-0.6.0 ResourceWriter
|
||||||
|
// bug.
|
||||||
|
try {
|
||||||
|
ResourceReader rr = new ResourceReader(new MemoryStream(tmpoutput.ToArray()));
|
||||||
|
foreach (System.Collections.DictionaryEntry entry in rr);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Exception("class ResourceWriter is buggy", e);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
tmpoutput.WriteTo(output);
|
||||||
|
rw.Close();
|
||||||
|
output.Close();
|
||||||
|
} else {
|
||||||
|
#if __CSCC__
|
||||||
|
MemoryStream tmpoutput = new MemoryStream();
|
||||||
|
ResourceWriter rw = new ResourceWriter(tmpoutput);
|
||||||
|
ReadAllInput(rw);
|
||||||
|
// Use the ResourceReader to check against pnet-0.6.0 ResourceWriter
|
||||||
|
// bug.
|
||||||
|
try {
|
||||||
|
ResourceReader rr = new ResourceReader(new MemoryStream(tmpoutput.ToArray()));
|
||||||
|
foreach (System.Collections.DictionaryEntry entry in rr);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Exception("class ResourceWriter is buggy", e);
|
||||||
|
}
|
||||||
|
BufferedStream output = new BufferedStream(new FileStream(filename, FileMode.Create, FileAccess.Write));
|
||||||
|
tmpoutput.WriteTo(output);
|
||||||
|
rw.Close();
|
||||||
|
output.Close();
|
||||||
|
#else
|
||||||
|
ResourceWriter rw = new ResourceWriter(filename);
|
||||||
|
ReadAllInput(rw);
|
||||||
|
rw.Close();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static int Main (String[] args) {
|
||||||
|
try {
|
||||||
|
new WriteResource(args[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.Error.WriteLine(e);
|
||||||
|
Console.Error.WriteLine(e.StackTrace);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,258 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
/* GNU gettext for C#
|
||||||
|
* Copyright (C) 2003-2004 Free Software Foundation, Inc.
|
||||||
|
* Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This program dumps a GettextResourceSet subclass (in a satellite assembly)
|
||||||
|
* or a .resources file as a PO file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System; /* Object, String, Type, Console, Exception */
|
||||||
|
using System.Reflection; /* Assembly, MethodInfo, ConstructorInfo */
|
||||||
|
using System.Collections; /* Hashtable, DictionaryEntry */
|
||||||
|
using System.IO; /* BufferedStream, StreamWriter, TextWriter, FileNotFoundException, Path */
|
||||||
|
using System.Text; /* StringBuilder, UTF8Encoding */
|
||||||
|
using System.Resources; /* ResourceReader */
|
||||||
|
using GNU.Gettext; /* GettextResourceSet */
|
||||||
|
|
||||||
|
namespace GNU.Gettext {
|
||||||
|
public class DumpResource {
|
||||||
|
private TextWriter Out;
|
||||||
|
private void DumpString (String str) {
|
||||||
|
int n = str.Length;
|
||||||
|
Out.Write('"');
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
char c = str[i];
|
||||||
|
if (c == 0x0008) {
|
||||||
|
Out.Write('\\'); Out.Write('b');
|
||||||
|
} else if (c == 0x000c) {
|
||||||
|
Out.Write('\\'); Out.Write('f');
|
||||||
|
} else if (c == 0x000a) {
|
||||||
|
Out.Write('\\'); Out.Write('n');
|
||||||
|
} else if (c == 0x000d) {
|
||||||
|
Out.Write('\\'); Out.Write('r');
|
||||||
|
} else if (c == 0x0009) {
|
||||||
|
Out.Write('\\'); Out.Write('t');
|
||||||
|
} else if (c == '\\' || c == '"') {
|
||||||
|
Out.Write('\\'); Out.Write(c);
|
||||||
|
} else
|
||||||
|
Out.Write(c);
|
||||||
|
}
|
||||||
|
Out.Write('"');
|
||||||
|
}
|
||||||
|
private void DumpMessage (String msgid, String msgid_plural, Object msgstr) {
|
||||||
|
Out.Write("msgid "); DumpString(msgid); Out.Write('\n');
|
||||||
|
if (msgid_plural != null) {
|
||||||
|
Out.Write("msgid_plural "); DumpString(msgid_plural); Out.Write('\n');
|
||||||
|
for (int i = 0; i < (msgstr as String[]).Length; i++) {
|
||||||
|
Out.Write("msgstr[" + i + "] ");
|
||||||
|
DumpString((msgstr as String[])[i]);
|
||||||
|
Out.Write('\n');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Out.Write("msgstr "); DumpString(msgstr as String); Out.Write('\n');
|
||||||
|
}
|
||||||
|
Out.Write('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- Dumping a GettextResourceSet ----------------
|
||||||
|
|
||||||
|
private void Dump (GettextResourceSet catalog) {
|
||||||
|
MethodInfo pluralMethod =
|
||||||
|
catalog.GetType().GetMethod("GetMsgidPluralTable", Type.EmptyTypes);
|
||||||
|
// Search for the header entry.
|
||||||
|
{
|
||||||
|
Object header_entry = catalog.GetObject("");
|
||||||
|
// If there is no header entry, fake one.
|
||||||
|
// FIXME: This is not needed; right after po_lex_charset_init set
|
||||||
|
// the PO charset to UTF-8.
|
||||||
|
if (header_entry == null)
|
||||||
|
header_entry = "Content-Type: text/plain; charset=UTF-8\n";
|
||||||
|
DumpMessage("", null, header_entry);
|
||||||
|
}
|
||||||
|
// Now the other messages.
|
||||||
|
{
|
||||||
|
Hashtable plural = null;
|
||||||
|
if (pluralMethod != null)
|
||||||
|
plural = pluralMethod.Invoke(catalog, new Object[0]) as Hashtable;
|
||||||
|
foreach (String key in catalog.Keys)
|
||||||
|
if (!"".Equals(key)) {
|
||||||
|
Object value = catalog.GetObject(key);
|
||||||
|
String key_plural =
|
||||||
|
(plural != null && value is String[] ? plural[key] as String : null);
|
||||||
|
DumpMessage(key, key_plural, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Essentially taken from class GettextResourceManager.
|
||||||
|
private static Assembly GetSatelliteAssembly (String baseDirectory, String resourceName, String cultureName) {
|
||||||
|
String satelliteExpectedLocation =
|
||||||
|
baseDirectory
|
||||||
|
+ Path.DirectorySeparatorChar + cultureName
|
||||||
|
+ Path.DirectorySeparatorChar + resourceName + ".resources.dll";
|
||||||
|
return Assembly.LoadFrom(satelliteExpectedLocation);
|
||||||
|
}
|
||||||
|
// Taken from class GettextResourceManager.
|
||||||
|
private static String ConstructClassName (String resourceName) {
|
||||||
|
// We could just return an arbitrary fixed class name, like "Messages",
|
||||||
|
// assuming that every assembly will only ever contain one
|
||||||
|
// GettextResourceSet subclass, but this assumption would break the day
|
||||||
|
// we want to support multi-domain PO files in the same format...
|
||||||
|
bool valid = (resourceName.Length > 0);
|
||||||
|
for (int i = 0; valid && i < resourceName.Length; i++) {
|
||||||
|
char c = resourceName[i];
|
||||||
|
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')
|
||||||
|
|| (i > 0 && c >= '0' && c <= '9')))
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
if (valid)
|
||||||
|
return resourceName;
|
||||||
|
else {
|
||||||
|
// Use hexadecimal escapes, using the underscore as escape character.
|
||||||
|
String hexdigit = "0123456789abcdef";
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
b.Append("__UESCAPED__");
|
||||||
|
for (int i = 0; i < resourceName.Length; i++) {
|
||||||
|
char c = resourceName[i];
|
||||||
|
if (c >= 0xd800 && c < 0xdc00
|
||||||
|
&& i+1 < resourceName.Length
|
||||||
|
&& resourceName[i+1] >= 0xdc00 && resourceName[i+1] < 0xe000) {
|
||||||
|
// Combine two UTF-16 words to a character.
|
||||||
|
char c2 = resourceName[i+1];
|
||||||
|
int uc = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
|
||||||
|
b.Append('_');
|
||||||
|
b.Append('U');
|
||||||
|
b.Append(hexdigit[(uc >> 28) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 24) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 20) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 16) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 12) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 8) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 4) & 0x0f]);
|
||||||
|
b.Append(hexdigit[uc & 0x0f]);
|
||||||
|
i++;
|
||||||
|
} else if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
|
||||||
|
|| (c >= '0' && c <= '9'))) {
|
||||||
|
int uc = c;
|
||||||
|
b.Append('_');
|
||||||
|
b.Append('u');
|
||||||
|
b.Append(hexdigit[(uc >> 12) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 8) & 0x0f]);
|
||||||
|
b.Append(hexdigit[(uc >> 4) & 0x0f]);
|
||||||
|
b.Append(hexdigit[uc & 0x0f]);
|
||||||
|
} else
|
||||||
|
b.Append(c);
|
||||||
|
}
|
||||||
|
return b.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Essentially taken from class GettextResourceManager.
|
||||||
|
private static GettextResourceSet InstantiateResourceSet (Assembly satelliteAssembly, String resourceName, String cultureName) {
|
||||||
|
Type clazz = satelliteAssembly.GetType(ConstructClassName(resourceName)+"_"+cultureName.Replace('-','_'));
|
||||||
|
ConstructorInfo constructor = clazz.GetConstructor(Type.EmptyTypes);
|
||||||
|
return constructor.Invoke(null) as GettextResourceSet;
|
||||||
|
}
|
||||||
|
public DumpResource (String baseDirectory, String resourceName, String cultureName) {
|
||||||
|
// We are only interested in the messages belonging to the locale
|
||||||
|
// itself, not in the inherited messages. Therefore we instantiate just
|
||||||
|
// the GettextResourceSet, not a GettextResourceManager.
|
||||||
|
Assembly satelliteAssembly =
|
||||||
|
GetSatelliteAssembly(baseDirectory, resourceName, cultureName);
|
||||||
|
GettextResourceSet catalog =
|
||||||
|
InstantiateResourceSet(satelliteAssembly, resourceName, cultureName);
|
||||||
|
BufferedStream stream = new BufferedStream(Console.OpenStandardOutput());
|
||||||
|
Out = new StreamWriter(stream, new UTF8Encoding());
|
||||||
|
Dump(catalog);
|
||||||
|
Out.Close();
|
||||||
|
stream.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------- Dumping a .resources file ------------------
|
||||||
|
|
||||||
|
public DumpResource (String filename) {
|
||||||
|
BufferedStream stream = new BufferedStream(Console.OpenStandardOutput());
|
||||||
|
Out = new StreamWriter(stream, new UTF8Encoding());
|
||||||
|
ResourceReader rr;
|
||||||
|
if (filename.Equals("-")) {
|
||||||
|
BufferedStream input = new BufferedStream(Console.OpenStandardInput());
|
||||||
|
// A temporary output stream is needed because ResourceReader expects
|
||||||
|
// to be able to seek in the Stream.
|
||||||
|
byte[] contents;
|
||||||
|
{
|
||||||
|
MemoryStream tmpstream = new MemoryStream();
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
for (;;) {
|
||||||
|
int n = input.Read(buf, 0, 1024);
|
||||||
|
if (n == 0)
|
||||||
|
break;
|
||||||
|
tmpstream.Write(buf, 0, n);
|
||||||
|
}
|
||||||
|
contents = tmpstream.ToArray();
|
||||||
|
tmpstream.Close();
|
||||||
|
}
|
||||||
|
MemoryStream tmpinput = new MemoryStream(contents);
|
||||||
|
rr = new ResourceReader(tmpinput);
|
||||||
|
} else {
|
||||||
|
rr = new ResourceReader(filename);
|
||||||
|
}
|
||||||
|
foreach (DictionaryEntry entry in rr) // uses rr.GetEnumerator()
|
||||||
|
DumpMessage(entry.Key as String, null, entry.Value as String);
|
||||||
|
rr.Close();
|
||||||
|
Out.Close();
|
||||||
|
stream.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
|
public static int Main (String[] args) {
|
||||||
|
try {
|
||||||
|
if (args.Length > 1)
|
||||||
|
new DumpResource(args[0], args[1], args[2]);
|
||||||
|
else
|
||||||
|
new DumpResource(args[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.Error.WriteLine(e);
|
||||||
|
Console.Error.WriteLine(e.StackTrace);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{470FDBA5-04E5-4A9F-80EA-987D1F8D9074}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Gettext.Samples.Console</RootNamespace>
|
||||||
|
<AssemblyName>Gettext.Samples.Console</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<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' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.configuration" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Strings.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Strings.tt</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="Resources\en\Strings.po">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Resources\es\Strings.po">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Resources\fr\Strings.po">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Resources\pt\Strings.po">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Strings.tt">
|
||||||
|
<Generator>TextTemplatingFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Strings.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Core\Gettext.Cs\Gettext.Cs.csproj">
|
||||||
|
<Project>{D8869765-AB47-4C03-B2C5-E5498A55CA79}</Project>
|
||||||
|
<Name>Gettext.Cs</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Gettext.Samples.Console
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
if (SetCultureFromArgs(args))
|
||||||
|
{
|
||||||
|
string translated = Strings.T("Hello world");
|
||||||
|
System.Console.Out.WriteLine(translated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SetCultureFromArgs(string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length == 0 || args[0].Contains("?"))
|
||||||
|
{
|
||||||
|
PrintUsage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var culture = CultureInfo.GetCultureInfo(args[0]);
|
||||||
|
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Console.Error.WriteLine("Error setting culture from argument {0}:\n{1}", args[0], ex.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PrintUsage()
|
||||||
|
{
|
||||||
|
System.Console.Out.WriteLine("Use culture short code as only parameter to view message in that language. Choose from one of the available cultures; localized cultures will fall back to neutral ones, and not available ones will fall back to english.");
|
||||||
|
System.Console.Out.WriteLine();
|
||||||
|
System.Console.Out.WriteLine("Available cultures:");
|
||||||
|
System.Console.Out.WriteLine(" en");
|
||||||
|
System.Console.Out.WriteLine(" es");
|
||||||
|
System.Console.Out.WriteLine(" pt");
|
||||||
|
System.Console.Out.WriteLine(" fr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
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("Gettext.Samples.Console")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("Gettext.Samples.Console")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||||
|
[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("b773169f-8efd-4d1c-b873-625eb1f90c26")]
|
||||||
|
|
||||||
|
// 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")]
|
|
@ -0,0 +1,3 @@
|
||||||
|
#: E:\Gettext\cs-utils\Gettext.CsUtils\Samples\Gettext.Samples.Console\Program.cs:15
|
||||||
|
msgid "Hello world"
|
||||||
|
msgstr ""
|
|
@ -0,0 +1,3 @@
|
||||||
|
#: E:\Gettext\cs-utils\Gettext.CsUtils\Samples\Gettext.Samples.Console\Program.cs:15
|
||||||
|
msgid "Hello world"
|
||||||
|
msgstr "Hola mundo"
|
|
@ -0,0 +1,3 @@
|
||||||
|
#: E:\Gettext\cs-utils\Gettext.CsUtils\Samples\Gettext.Samples.Console\Program.cs:15
|
||||||
|
msgid "Hello world"
|
||||||
|
msgstr "Bonjour tout le monde"
|
|
@ -0,0 +1,3 @@
|
||||||
|
#: E:\Gettext\cs-utils\Gettext.CsUtils\Samples\Gettext.Samples.Console\Program.cs:15
|
||||||
|
msgid "Hello world"
|
||||||
|
msgstr "Olá mundo"
|
|
@ -0,0 +1,168 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <autogenerated>
|
||||||
|
// This code was generated by a tool. Any changes made manually will be lost
|
||||||
|
// the next time this code is regenerated.
|
||||||
|
// </autogenerated>
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Gettext.Samples.Console
|
||||||
|
{
|
||||||
|
public class Strings
|
||||||
|
{
|
||||||
|
private static Object resourceManLock = new Object();
|
||||||
|
private static System.Resources.ResourceManager resourceMan;
|
||||||
|
private static System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
public const string ResourceName = "Strings";
|
||||||
|
|
||||||
|
private static string resourcesDir = GetSetting("ResourcesDir", "Resources");
|
||||||
|
private static string fileFormat = GetSetting("ResourcesFileFormat", "{{culture}}/{{resource}}.po");
|
||||||
|
|
||||||
|
private static string GetSetting(string setting, string defaultValue)
|
||||||
|
{
|
||||||
|
var section = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationManager.GetSection("appSettings");
|
||||||
|
if (section == null) return defaultValue;
|
||||||
|
else return section[setting] ?? defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resources directory used to retrieve files from.
|
||||||
|
/// </summary>
|
||||||
|
public static string ResourcesDirectory
|
||||||
|
{
|
||||||
|
get { return resourcesDir; }
|
||||||
|
set { resourcesDir = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Format of the file based on culture and resource name.
|
||||||
|
/// </summary>
|
||||||
|
public static string FileFormat
|
||||||
|
{
|
||||||
|
get { return fileFormat; }
|
||||||
|
set { fileFormat = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceManager ResourceManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
lock (resourceManLock)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
var directory = resourcesDir;
|
||||||
|
var mgr = new global::Gettext.Cs.GettextResourceManager(ResourceName, directory, fileFormat);
|
||||||
|
resourceMan = mgr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Globalization.CultureInfo Culture
|
||||||
|
{
|
||||||
|
get { return resourceCulture; }
|
||||||
|
set { resourceCulture = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t)
|
||||||
|
{
|
||||||
|
return T(null, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
var translated = ResourceManager.GetString(t, info ?? resourceCulture);
|
||||||
|
return String.IsNullOrEmpty(translated) ? t : translated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
return T(null, t, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
return String.Format(T(info, t), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks a string for future translation, does not translate it now.
|
||||||
|
/// </summary>
|
||||||
|
public static string M(string t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the resource set available for the specified culture.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceSet GetResourceSet(CultureInfo culture)
|
||||||
|
{
|
||||||
|
return ResourceManager.GetResourceSet(culture, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<#@ assembly name="System.Configuration" #>
|
||||||
|
|
||||||
|
<#
|
||||||
|
this.ClassName = "Strings";
|
||||||
|
this.ResourceName = "Strings";
|
||||||
|
this.NamespaceName = "Gettext.Samples.Console";
|
||||||
|
this.DefaultResourceDir = "Resources";
|
||||||
|
#>
|
||||||
|
<#@ include file="..\..\Core\Gettext.Cs\Templates\Strings.tt" #>
|
|
@ -0,0 +1,3 @@
|
||||||
|
#: E:\Gettext\cs-utils\Gettext.CsUtils\Samples\Gettext.Samples.Console\Program.cs:15
|
||||||
|
msgid "Hello world"
|
||||||
|
msgstr ""
|
|
@ -0,0 +1,30 @@
|
||||||
|
rem gettext-cs-utils
|
||||||
|
rem
|
||||||
|
rem Copyright 2011 Manas Technology Solutions
|
||||||
|
rem http://www.manas.com.ar/
|
||||||
|
rem
|
||||||
|
rem This library is free software; you can redistribute it and/or
|
||||||
|
rem modify it under the terms of the GNU Lesser General Public
|
||||||
|
rem License as published by the Free Software Foundation; either
|
||||||
|
rem version 2.1 of the License, or (at your option) any later version.
|
||||||
|
rem
|
||||||
|
rem This library is distributed in the hope that it will be useful,
|
||||||
|
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
rem Lesser General Public License for more details.
|
||||||
|
rem
|
||||||
|
rem You should have received a copy of the GNU Lesser General Public
|
||||||
|
rem License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Setting up global variables...
|
||||||
|
SET path_xgettext=..\..\..\Bin\Gnu.Gettext.Win32\xgettext.exe
|
||||||
|
SET path_output=..\Templates
|
||||||
|
SET file_list=.\..\*.cs
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Generating strings po file...
|
||||||
|
CALL ..\..\..\Scripts\ExtractStrings.bat Strings
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<connectionStrings>
|
||||||
|
<add name="Gettext" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=GettextSample; Integrated Security=SSPI;"/>
|
||||||
|
</connectionStrings>
|
||||||
|
<appSettings>
|
||||||
|
<add key="Gettext.Throw" value="true"/>
|
||||||
|
</appSettings>
|
||||||
|
</configuration>
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{9FBD5BA7-BCE6-48FE-9FB7-396F377D1313}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Gettext.Samples.Database</RootNamespace>
|
||||||
|
<AssemblyName>Gettext.Samples.Database</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<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' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.configuration" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Strings.cs">
|
||||||
|
<DependentUpon>Strings.tt</DependentUpon>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Core\Gettext.Cs\Gettext.Cs.csproj">
|
||||||
|
<Project>{D8869765-AB47-4C03-B2C5-E5498A55CA79}</Project>
|
||||||
|
<Name>Gettext.Cs</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
<None Include="Strings.tt">
|
||||||
|
<Generator>TextTemplatingFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Strings.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
|
@ -0,0 +1,77 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Gettext.Samples.Database
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
if (SetCultureFromArgs(args))
|
||||||
|
{
|
||||||
|
string translated = Strings.T("Hello world");
|
||||||
|
System.Console.Out.WriteLine(translated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SetCultureFromArgs(string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length == 0 || args[0].Contains("?"))
|
||||||
|
{
|
||||||
|
PrintUsage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var culture = CultureInfo.GetCultureInfo(args[0]);
|
||||||
|
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Console.Error.WriteLine("Error setting culture from argument {0}:\n{1}", args[0], ex.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PrintUsage()
|
||||||
|
{
|
||||||
|
System.Console.Out.WriteLine("Use culture short code as only parameter to view message in that language. Choose from one of the available cultures; localized cultures will fall back to neutral ones, and not available ones will fall back to english.");
|
||||||
|
System.Console.Out.WriteLine();
|
||||||
|
System.Console.Out.WriteLine("Available cultures:");
|
||||||
|
System.Console.Out.WriteLine(" en");
|
||||||
|
System.Console.Out.WriteLine(" es");
|
||||||
|
System.Console.Out.WriteLine(" pt");
|
||||||
|
System.Console.Out.WriteLine(" fr");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
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("Gettext.Samples.Database")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("Gettext.Samples.Database")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2010")]
|
||||||
|
[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("4aee2ac6-27d5-4d59-a695-53778e5d56c0")]
|
||||||
|
|
||||||
|
// 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")]
|
|
@ -0,0 +1,147 @@
|
||||||
|
/**
|
||||||
|
* gettext-cs-utils
|
||||||
|
*
|
||||||
|
* Copyright 2011 Manas Technology Solutions
|
||||||
|
* http://www.manas.com.ar/
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <autogenerated>
|
||||||
|
// This code was generated by a tool. Any changes made manually will be lost
|
||||||
|
// the next time this code is regenerated.
|
||||||
|
// </autogenerated>
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Gettext.Samples.Database
|
||||||
|
{
|
||||||
|
public class Strings
|
||||||
|
{
|
||||||
|
private static Object resourceManLock = new Object();
|
||||||
|
private static System.Resources.ResourceManager resourceMan;
|
||||||
|
private static System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
public const string ResourceName = "Strings";
|
||||||
|
|
||||||
|
|
||||||
|
private static string GetSetting(string setting, string defaultValue)
|
||||||
|
{
|
||||||
|
var section = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationManager.GetSection("appSettings");
|
||||||
|
if (section == null) return defaultValue;
|
||||||
|
else return section[setting] ?? defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceManager ResourceManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
lock (resourceManLock)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(resourceMan, null))
|
||||||
|
{
|
||||||
|
var mgr = new global::Gettext.Cs.DatabaseResourceManager("GettextGetResourceSet");
|
||||||
|
resourceMan = mgr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Globalization.CultureInfo Culture
|
||||||
|
{
|
||||||
|
get { return resourceCulture; }
|
||||||
|
set { resourceCulture = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t)
|
||||||
|
{
|
||||||
|
return T(null, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
var translated = ResourceManager.GetString(t, info ?? resourceCulture);
|
||||||
|
return String.IsNullOrEmpty(translated) ? t : translated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
return T(null, t, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string and formats it with the parameters provided; used to mark string for translation as well.
|
||||||
|
/// </summary>
|
||||||
|
public static string T(CultureInfo info, string t, params object[] parameters)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(t)) return t;
|
||||||
|
return String.Format(T(info, t), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks a string for future translation, does not translate it now.
|
||||||
|
/// </summary>
|
||||||
|
public static string M(string t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the resource set available for the specified culture.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Resources.ResourceSet GetResourceSet(CultureInfo culture)
|
||||||
|
{
|
||||||
|
return ResourceManager.GetResourceSet(culture, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<#@ assembly name="System.Configuration" #>
|
||||||
|
|
||||||
|
<#
|
||||||
|
this.ClassName = "Strings";
|
||||||
|
this.ResourceName = "Strings";
|
||||||
|
this.NamespaceName = "Gettext.Samples.Database";
|
||||||
|
this.StoredProcedureName = "GettextGetResourceSet";
|
||||||
|
this.UseDatabase = true;
|
||||||
|
#>
|
||||||
|
<#@ include file="..\..\Core\Gettext.Cs\Templates\Strings.tt" #>
|
|
@ -0,0 +1,3 @@
|
||||||
|
#: E:\Gettext\cs-utils\Gettext.CsUtils\Samples\Gettext.Samples.Console\Program.cs:15
|
||||||
|
msgid "Hello world"
|
||||||
|
msgstr ""
|
|
@ -0,0 +1,3 @@
|
||||||
|
#: E:\Gettext\cs-utils\Gettext.CsUtils\Samples\Gettext.Samples.Console\Program.cs:15
|
||||||
|
msgid "Hello world"
|
||||||
|
msgstr "Hola mundo"
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue