You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2011/03/31 23:16:49 UTC
svn commit: r1087439 [1/6] - in /avro/trunk: ./ lang/csharp/
lang/csharp/lib/ lang/csharp/lib/main/ lang/csharp/lib/test/
lang/csharp/src/ lang/csharp/src/apache/ lang/csharp/src/apache/codegen/
lang/csharp/src/apache/codegen/Properties/ lang/csharp/sr...
Author: cutting
Date: Thu Mar 31 21:16:28 2011
New Revision: 1087439
URL: http://svn.apache.org/viewvc?rev=1087439&view=rev
Log:
AVRO-533. Add a C# implementation. Contributed by Jeremy Custenborder, Dona Alvarez and thiru.
Added:
avro/trunk/lang/csharp/ (with props)
avro/trunk/lang/csharp/Avro.nunit
avro/trunk/lang/csharp/Avro.sln
avro/trunk/lang/csharp/README
avro/trunk/lang/csharp/build.sh (with props)
avro/trunk/lang/csharp/lib/
avro/trunk/lang/csharp/lib/main/
avro/trunk/lang/csharp/lib/main/Newtonsoft.Json.dll (with props)
avro/trunk/lang/csharp/lib/main/log4net.dll (with props)
avro/trunk/lang/csharp/lib/test/
avro/trunk/lang/csharp/lib/test/nunit.framework.dll (with props)
avro/trunk/lang/csharp/src/
avro/trunk/lang/csharp/src/apache/
avro/trunk/lang/csharp/src/apache/codegen/
avro/trunk/lang/csharp/src/apache/codegen/Avro.codegen.csproj
avro/trunk/lang/csharp/src/apache/codegen/Program.cs
avro/trunk/lang/csharp/src/apache/codegen/Properties/
avro/trunk/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs
avro/trunk/lang/csharp/src/apache/codegen/app.config (with props)
avro/trunk/lang/csharp/src/apache/main/
avro/trunk/lang/csharp/src/apache/main/Avro.main.csproj
avro/trunk/lang/csharp/src/apache/main/CodeGen/
avro/trunk/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenExt.cs
avro/trunk/lang/csharp/src/apache/main/Generic/
avro/trunk/lang/csharp/src/apache/main/Generic/DatumReader.cs
avro/trunk/lang/csharp/src/apache/main/Generic/DatumWriter.cs
avro/trunk/lang/csharp/src/apache/main/Generic/GenericEnum.cs
avro/trunk/lang/csharp/src/apache/main/Generic/GenericFixed.cs
avro/trunk/lang/csharp/src/apache/main/Generic/GenericReader.cs
avro/trunk/lang/csharp/src/apache/main/Generic/GenericRecord.cs
avro/trunk/lang/csharp/src/apache/main/Generic/GenericWriter.cs
avro/trunk/lang/csharp/src/apache/main/IO/
avro/trunk/lang/csharp/src/apache/main/IO/BinaryDecoder.cs
avro/trunk/lang/csharp/src/apache/main/IO/BinaryEncoder.cs
avro/trunk/lang/csharp/src/apache/main/IO/Decoder.cs
avro/trunk/lang/csharp/src/apache/main/IO/Encoder.cs
avro/trunk/lang/csharp/src/apache/main/IO/Resolver.cs
avro/trunk/lang/csharp/src/apache/main/Properties/
avro/trunk/lang/csharp/src/apache/main/Properties/AssemblyInfo.cs
avro/trunk/lang/csharp/src/apache/main/Properties/Settings.Designer.cs
avro/trunk/lang/csharp/src/apache/main/Protocol/
avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs
avro/trunk/lang/csharp/src/apache/main/Protocol/Protocol.cs
avro/trunk/lang/csharp/src/apache/main/Protocol/ProtocolParseException.cs
avro/trunk/lang/csharp/src/apache/main/Schema/
avro/trunk/lang/csharp/src/apache/main/Schema/ArraySchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/AvroException.cs
avro/trunk/lang/csharp/src/apache/main/Schema/AvroTypeException.cs
avro/trunk/lang/csharp/src/apache/main/Schema/EnumSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/Field.cs
avro/trunk/lang/csharp/src/apache/main/Schema/FixedSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/JsonHelper.cs
avro/trunk/lang/csharp/src/apache/main/Schema/MapSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/NamedSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/Property.cs
avro/trunk/lang/csharp/src/apache/main/Schema/RecordSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/Schema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/SchemaName.cs
avro/trunk/lang/csharp/src/apache/main/Schema/SchemaParseException.cs
avro/trunk/lang/csharp/src/apache/main/Schema/UnionSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/UnnamedSchema.cs
avro/trunk/lang/csharp/src/apache/main/Specific/
avro/trunk/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
avro/trunk/lang/csharp/src/apache/main/Specific/SpecificFixed.cs
avro/trunk/lang/csharp/src/apache/main/Specific/SpecificReader.cs
avro/trunk/lang/csharp/src/apache/main/Specific/SpecificRecord.cs
avro/trunk/lang/csharp/src/apache/main/Specific/SpecificWriter.cs
avro/trunk/lang/csharp/src/apache/test/
avro/trunk/lang/csharp/src/apache/test/Avro.test.csproj
avro/trunk/lang/csharp/src/apache/test/CodGen/
avro/trunk/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
avro/trunk/lang/csharp/src/apache/test/Generic/
avro/trunk/lang/csharp/src/apache/test/Generic/GenericTests.cs
avro/trunk/lang/csharp/src/apache/test/IO/
avro/trunk/lang/csharp/src/apache/test/IO/BinaryCodecTests.cs
avro/trunk/lang/csharp/src/apache/test/Properties/
avro/trunk/lang/csharp/src/apache/test/Properties/AssemblyInfo.cs
avro/trunk/lang/csharp/src/apache/test/Protocol/
avro/trunk/lang/csharp/src/apache/test/Protocol/ProtocolTest.cs
avro/trunk/lang/csharp/src/apache/test/Schema/
avro/trunk/lang/csharp/src/apache/test/Schema/AliasTest.cs
avro/trunk/lang/csharp/src/apache/test/Schema/SchemaTests.cs
avro/trunk/lang/csharp/src/apache/test/Specific/
avro/trunk/lang/csharp/src/apache/test/Specific/SpecificTests.cs
Modified:
avro/trunk/CHANGES.txt
avro/trunk/build.sh
avro/trunk/share/rat-excludes.txt
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1087439&r1=1087438&r2=1087439&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Mar 31 21:16:28 2011
@@ -12,6 +12,11 @@ Avro 1.6.0 (unreleased)
Avro 1.5.1 (unreleased)
+ NEW FEATURES
+
+ AVRO-533. Add a C# implementation.
+ (Jeremy Custenborder, Dona Alvarez and thiru)
+
IMPROVEMENTS
AVRO-785. Java: Squash a Velocity warning by upgrading to Velocity 1.7.
Modified: avro/trunk/build.sh
URL: http://svn.apache.org/viewvc/avro/trunk/build.sh?rev=1087439&r1=1087438&r2=1087439&view=diff
==============================================================================
--- avro/trunk/build.sh (original)
+++ avro/trunk/build.sh Thu Mar 31 21:16:28 2011
@@ -44,6 +44,7 @@ case "$target" in
(cd lang/py; ant test)
(cd lang/c; ./build.sh test)
(cd lang/c++; ./build.sh test)
+ (cd lang/csharp; ./build.sh test)
(cd lang/ruby; rake test)
(cd lang/php; ./build.sh test)
@@ -144,6 +145,8 @@ case "$target" in
(cd lang/c++; ./build.sh clean)
+ (cd lang/csharp; ./build.sh clean)
+
(cd lang/ruby; rake clean)
(cd lang/php; ./build.sh clean)
Propchange: avro/trunk/lang/csharp/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Mar 31 21:16:28 2011
@@ -0,0 +1,5 @@
+build
+src/apache/codegen/obj
+src/apache/main/obj
+src/apache/test/obj
+TestResult.xml
Added: avro/trunk/lang/csharp/Avro.nunit
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/Avro.nunit?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/Avro.nunit (added)
+++ avro/trunk/lang/csharp/Avro.nunit Thu Mar 31 21:16:28 2011
@@ -0,0 +1,15 @@
+<NUnitProject>
+ <Settings activeconfig="Release" />
+ <Config name="Debug" binpathtype="Auto">
+ <assembly path="build/test/Debug/Avro.test.dll" />
+ <assembly path="build/test/Debug/Avro.dll" />
+ <assembly path="lib/main/Newtonsoft.Json.dll" />
+ <assembly path="lib/test/nunit.framework.dll" />
+ </Config>
+ <Config name="Release" binpathtype="Auto">
+ <assembly path="build/test/Release/Avro.test.dll" />
+ <assembly path="build/test/Release/Avro.dll" />
+ <assembly path="lib/main/Newtonsoft.Json.dll" />
+ <assembly path="lib/test/nunit.framework.dll" />
+ </Config>
+</NUnitProject>
Added: avro/trunk/lang/csharp/Avro.sln
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/Avro.sln?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/Avro.sln (added)
+++ avro/trunk/lang/csharp/Avro.sln Thu Mar 31 21:16:28 2011
@@ -0,0 +1,55 @@
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+lang/csharp/Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avro.main", "src\apache\main\Avro.main.csproj", "{A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avro.test", "src\apache\test\Avro.test.csproj", "{911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avro.codegen", "src\apache\codegen\Avro.codegen.csproj", "{BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}.Release|x86.ActiveCfg = Release|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {911D56AB-587B-4E5F-B5EA-D47D8A46F1FA}.Release|x86.ActiveCfg = Release|Any CPU
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|x86.ActiveCfg = Debug|x86
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Debug|x86.Build.0 = Debug|x86
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|Mixed Platforms.Build.0 = Release|x86
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|x86.ActiveCfg = Release|x86
+ {BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Added: avro/trunk/lang/csharp/README
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/README?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/README (added)
+++ avro/trunk/lang/csharp/README Thu Mar 31 21:16:28 2011
@@ -0,0 +1,34 @@
+1. Building Avro for .NET
+
+a. Windows
+
+Prerequisites
+ Microsoft Visual C# Express 2010
+
+To build open Avro.sln solution in VC# Express 2010 and build from there.
+
+b. Linux
+
+Prerequisites
+ Mono 2.6 or above.
+
+For Ubuntu Lucid Lynx, mono that comes with it is 2.4. To install mono 2.6
+follow the procedure described at http://badgerports.org/
+
+To build issue the command:
+$ cd lang/csharp
+
+then
+
+$ CONFIGURATION=Release TARGETFRAMEWORKVERSION=3.5 xbuild Avro.sln
+
+or
+
+$ CONFIGURATION=Debug TARGETFRAMEWORKVERSION=3.5 xbuild Avro.sln
+
+2. Unit tests
+
+This is a common procedure for both Windows and Linux.
+
+To run unit-tests, please install NUnit 2.5 or above. From within the NUnit
+GUI, open the project Avro.nunit and run the tests.
Added: avro/trunk/lang/csharp/build.sh
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/build.sh?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/build.sh (added)
+++ avro/trunk/lang/csharp/build.sh Thu Mar 31 21:16:28 2011
@@ -0,0 +1,22 @@
+#!/bin/bash
+set -e # exit on error
+set -x
+
+case "$1" in
+
+ test)
+ CONFIGURATION=Release TARGETFRAMEWORKVERSION=3.5 xbuild
+ nunit-console Avro.nunit
+ ;;
+
+ clean)
+ rm -rf src/apache/{main,test,codegen}/obj
+ rm -rf build
+ ;;
+
+ *)
+ echo "Usage: $0 {test|clean}"
+ exit 1
+esac
+
+exit 0
Propchange: avro/trunk/lang/csharp/build.sh
------------------------------------------------------------------------------
svn:executable = *
Added: avro/trunk/lang/csharp/lib/main/Newtonsoft.Json.dll
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/lib/main/Newtonsoft.Json.dll?rev=1087439&view=auto
==============================================================================
Binary file - no diff available.
Propchange: avro/trunk/lang/csharp/lib/main/Newtonsoft.Json.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: avro/trunk/lang/csharp/lib/main/log4net.dll
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/lib/main/log4net.dll?rev=1087439&view=auto
==============================================================================
Binary file - no diff available.
Propchange: avro/trunk/lang/csharp/lib/main/log4net.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: avro/trunk/lang/csharp/lib/test/nunit.framework.dll
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/lib/test/nunit.framework.dll?rev=1087439&view=auto
==============================================================================
Binary file - no diff available.
Propchange: avro/trunk/lang/csharp/lib/test/nunit.framework.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: avro/trunk/lang/csharp/src/apache/codegen/Avro.codegen.csproj
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/codegen/Avro.codegen.csproj?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/codegen/Avro.codegen.csproj (added)
+++ avro/trunk/lang/csharp/src/apache/codegen/Avro.codegen.csproj Thu Mar 31 21:16:28 2011
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{BF0D313C-1AA3-4900-B277-B0F5F9DDCDA8}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Avro.codegen</RootNamespace>
+ <AssemblyName>avrogen</AssemblyName>
+ <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\..\..\build\codegen\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>none</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>..\..\..\build\codegen\Release\</OutputPath>
+ <DefineConstants>
+ </DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>..\..\..\build\codegen\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <CodeAnalysisLogFile>..\..\..\build\codegen\Debug\avrogen.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+ <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+ <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSetDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+ <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisRuleDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+ <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
+ <OutputPath>..\..\..\build\codegen\Release\</OutputPath>
+ <DefineConstants>
+ </DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>none</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <CodeAnalysisLogFile>..\..\..\build\codegen\Release\avrogen.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+ <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+ <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSetDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+ <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisRuleDirectories>;C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+ <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
+ <OutputPath>..\..\..\build\codegen\Release\</OutputPath>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\main\Avro.main.csproj">
+ <Project>{A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}</Project>
+ <Name>Avro.main</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include=".NETFramework,Version=v3.5,Profile=Client">
+ <Visible>False</Visible>
+ <ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ </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>
Added: avro/trunk/lang/csharp/src/apache/codegen/Program.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/codegen/Program.cs?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/codegen/Program.cs (added)
+++ avro/trunk/lang/csharp/src/apache/codegen/Program.cs Thu Mar 31 21:16:28 2011
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Avro.codegen;
+
+namespace Avro.codegen
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ if (args.Length != 3)
+ {
+ Usage();
+ return;
+ }
+ if (args[0] == "-p")
+ GenProtocol(args[1], args[2]);
+ else if (args[0] == "-s")
+ GenSchema(args[1], args[2]);
+ else
+ Usage();
+ }
+
+ static void Usage()
+ {
+ Console.WriteLine("Usage:\navrogen -p <protocolfile> <outputdir>\navrogen -s <schemafile> <outputdir>");
+ return;
+ }
+
+ static void GenProtocol(string infile, string outdir)
+ {
+ try
+ {
+ string text = System.IO.File.ReadAllText(infile);
+ Protocol protocol = Protocol.Parse(text);
+
+ CodeGen codegen = new CodeGen();
+ codegen.AddProtocol(protocol);
+
+ codegen.GenerateCode();
+ codegen.WriteTypes(outdir);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Exception occurred. " + ex.Message);
+ }
+ }
+
+ static void GenSchema(string infile, string outdir)
+ {
+ try
+ {
+ string text = System.IO.File.ReadAllText(infile);
+ Schema schema = Schema.Parse(text);
+
+ CodeGen codegen = new CodeGen();
+ codegen.AddSchema(schema);
+
+ codegen.GenerateCode();
+ codegen.WriteTypes(outdir);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Exception occurred. " + ex.Message);
+ }
+ }
+
+ }
+}
Added: avro/trunk/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs (added)
+++ avro/trunk/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs Thu Mar 31 21:16:28 2011
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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("Avro.codegen")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Bank of America")]
+[assembly: AssemblyProduct("Avro.codegen")]
+[assembly: AssemblyCopyright("Copyright © Bank of America 2011")]
+[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("3ccfcbf4-bdf9-4f75-8d5a-ab476bb4408f")]
+
+// 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")]
Added: avro/trunk/lang/csharp/src/apache/codegen/app.config
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/codegen/app.config?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/codegen/app.config (added)
+++ avro/trunk/lang/csharp/src/apache/codegen/app.config Thu Mar 31 21:16:28 2011
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
Propchange: avro/trunk/lang/csharp/src/apache/codegen/app.config
------------------------------------------------------------------------------
svn:executable = *
Added: avro/trunk/lang/csharp/src/apache/main/Avro.main.csproj
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/Avro.main.csproj?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/Avro.main.csproj (added)
+++ avro/trunk/lang/csharp/src/apache/main/Avro.main.csproj Thu Mar 31 21:16:28 2011
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{A0A5CA3C-F58C-4D07-98B0-2C7B62AB20F0}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Avro</RootNamespace>
+ <AssemblyName>Avro</AssemblyName>
+ <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\..\..\build\main\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>..\..\..\build\main\Release\</OutputPath>
+ <DefineConstants>
+ </DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="log4net">
+ <HintPath>..\..\..\lib\main\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\..\..\lib\main\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="CodeGen\AvroRuntimeException.cs" />
+ <Compile Include="CodeGen\CodeGen.cs" />
+ <Compile Include="CodeGen\CodeGenException.cs" />
+ <Compile Include="CodeGen\CodeGenExt.cs" />
+ <Compile Include="Generic\DatumReader.cs" />
+ <Compile Include="Generic\DatumWriter.cs" />
+ <Compile Include="Generic\GenericEnum.cs" />
+ <Compile Include="Generic\GenericFixed.cs" />
+ <Compile Include="Generic\GenericReader.cs" />
+ <Compile Include="Generic\GenericRecord.cs" />
+ <Compile Include="Generic\GenericWriter.cs" />
+ <Compile Include="IO\BinaryDecoder.cs" />
+ <Compile Include="IO\BinaryEncoder.cs" />
+ <Compile Include="IO\Decoder.cs" />
+ <Compile Include="IO\Encoder.cs" />
+ <Compile Include="IO\Resolver.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Protocol\Message.cs" />
+ <Compile Include="Protocol\Protocol.cs" />
+ <Compile Include="Protocol\ProtocolParseException.cs" />
+ <Compile Include="Schema\ArraySchema.cs" />
+ <Compile Include="Schema\AvroException.cs" />
+ <Compile Include="Schema\AvroTypeException.cs" />
+ <Compile Include="Schema\EnumSchema.cs" />
+ <Compile Include="Schema\Field.cs" />
+ <Compile Include="Schema\FixedSchema.cs" />
+ <Compile Include="Schema\JsonHelper.cs" />
+ <Compile Include="Schema\MapSchema.cs" />
+ <Compile Include="Schema\NamedSchema.cs" />
+ <Compile Include="Schema\PrimitiveSchema.cs" />
+ <Compile Include="Schema\Property.cs" />
+ <Compile Include="Schema\RecordSchema.cs" />
+ <Compile Include="Schema\Schema.cs" />
+ <Compile Include="Schema\SchemaName.cs" />
+ <Compile Include="Schema\SchemaParseException.cs" />
+ <Compile Include="Schema\UnionSchema.cs" />
+ <Compile Include="Schema\UnnamedSchema.cs" />
+ <Compile Include="Specific\ObjectCreator.cs" />
+ <Compile Include="Specific\SpecificFixed.cs" />
+ <Compile Include="Specific\SpecificReader.cs" />
+ <Compile Include="Specific\SpecificWriter.cs" />
+ <Compile Include="Specific\SpecificRecord.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include=".NETFramework,Version=v3.5">
+ <Visible>False</Visible>
+ <ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ </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>
Added: avro/trunk/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs (added)
+++ avro/trunk/lang/csharp/src/apache/main/CodeGen/AvroRuntimeException.cs Thu Mar 31 21:16:28 2011
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Avro
+{
+ public class AvroRuntimeException : AvroException
+ {
+ public AvroRuntimeException(string s)
+ : base(s)
+ {
+
+ }
+ public AvroRuntimeException(string s, Exception inner)
+ : base(s, inner)
+ {
+
+ }
+ }
+}
Added: avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGen.cs?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGen.cs (added)
+++ avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGen.cs Thu Mar 31 21:16:28 2011
@@ -0,0 +1,645 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using Microsoft.CSharp;
+using System.IO;
+
+namespace Avro
+{
+ public class CodeGen
+ {
+ public CodeCompileUnit CompileUnit { get; private set; }
+ public IList<Schema> Schemas { get; private set; }
+ public IList<Protocol> Protocols { get; private set; }
+ private Dictionary<string, CodeNamespace> namespaceLookup = new Dictionary<string, CodeNamespace>(StringComparer.Ordinal);
+ private CodeGenExt codeGenExt;
+
+ /// <summary>
+ /// Default constructor
+ /// </summary>
+ public CodeGen()
+ {
+ this.Schemas = new List<Schema>();
+ this.Protocols = new List<Protocol>();
+ this.codeGenExt = CodeGenExt.Instance;
+ }
+
+ /// <summary>
+ /// Adds a protocol object to generate code for
+ /// </summary>
+ /// <param name="protocol">protocol object</param>
+ public void AddProtocol(Protocol protocol)
+ {
+ Protocols.Add(protocol);
+ }
+
+ /// <summary>
+ /// Adds a schema object to generate code for
+ /// </summary>
+ /// <param name="schema">schema object</param>
+ public void AddSchema(Schema schema)
+ {
+ Schemas.Add(schema);
+ }
+
+ /// <summary>
+ /// Adds a namespace object for the given name into the dictionary if it doesn't exist yet
+ /// </summary>
+ /// <param name="name">name of namespace</param>
+ /// <returns></returns>
+ private CodeNamespace addNamespace(string name)
+ {
+ if (string.IsNullOrEmpty(name))
+ throw new ArgumentNullException("name", "name cannot be null.");
+
+ CodeNamespace ns = null;
+
+ if (!namespaceLookup.TryGetValue(name, out ns))
+ {
+ ns = new CodeNamespace(codeGenExt.Mangle(name));
+ foreach (CodeNamespaceImport nci in codeGenExt.NamespaceImports)
+ ns.Imports.Add(nci);
+
+ CompileUnit.Namespaces.Add(ns);
+ namespaceLookup.Add(name, ns);
+ }
+ return ns;
+ }
+
+ /// <summary>
+ /// Generates code for the given protocol and schema objects
+ /// </summary>
+ /// <returns>CodeCompileUnit object</returns>
+ public CodeCompileUnit GenerateCode()
+ {
+ CompileUnit = new CodeCompileUnit();
+
+ processSchemas();
+ processProtocols();
+
+ return CompileUnit;
+ }
+
+ /// <summary>
+ /// Generates code for the schema objects
+ /// </summary>
+ private void processSchemas()
+ {
+ foreach (Schema schema in this.Schemas)
+ {
+ SchemaNames names = generateNames(schema);
+ foreach (KeyValuePair<SchemaName, NamedSchema> sn in names)
+ {
+ switch (sn.Value.Tag)
+ {
+ case Schema.Type.Enumeration: processEnum(sn.Value); break;
+ case Schema.Type.Fixed: processFixed(sn.Value); break;
+ case Schema.Type.Record: processRecord(sn.Value); break;
+ case Schema.Type.Error: processRecord(sn.Value); break;
+ default:
+ throw new CodeGenException("Names in schema should only be of type NamedSchema, type found " + sn.Value.Tag);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Generates code for the protocol objects
+ /// </summary>
+ private void processProtocols()
+ {
+ foreach (Protocol protocol in Protocols)
+ {
+ SchemaNames names = generateNames(protocol);
+ foreach (KeyValuePair<SchemaName, NamedSchema> sn in names)
+ {
+ switch (sn.Value.Tag)
+ {
+ case Schema.Type.Enumeration: processEnum(sn.Value); break;
+ case Schema.Type.Fixed: processFixed(sn.Value); break;
+ case Schema.Type.Record: processRecord(sn.Value); break;
+ case Schema.Type.Error: processRecord(sn.Value); break;
+ default:
+ throw new CodeGenException("Names in protocol should only be of type NamedSchema, type found " + sn.Value.Tag);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Generate list of named schemas from given protocol
+ /// </summary>
+ /// <param name="protocol">protocol to process</param>
+ /// <returns></returns>
+ private SchemaNames generateNames(Protocol protocol)
+ {
+ var names = new SchemaNames();
+ foreach (Schema schema in protocol.Types)
+ addName(schema, names);
+ return names;
+ }
+
+ /// <summary>
+ /// Generate list of named schemas from given schema
+ /// </summary>
+ /// <param name="schema">schema to process</param>
+ /// <returns></returns>
+ private SchemaNames generateNames(Schema schema)
+ {
+ var names = new SchemaNames();
+ addName(schema, names);
+ return names;
+ }
+
+ /// <summary>
+ /// Recursively search the given schema for named schemas and adds them to the given container
+ /// </summary>
+ /// <param name="schema">schema object to search</param>
+ /// <param name="names">list of named schemas</param>
+ private void addName(Schema schema, SchemaNames names)
+ {
+ NamedSchema ns = schema as NamedSchema;
+ if (null != ns) if (names.Contains(ns.SchemaName)) return;
+
+ switch (schema.Tag)
+ {
+ case Schema.Type.Null:
+ case Schema.Type.Boolean:
+ case Schema.Type.Int:
+ case Schema.Type.Long:
+ case Schema.Type.Float:
+ case Schema.Type.Double:
+ case Schema.Type.Bytes:
+ case Schema.Type.String:
+ break;
+
+ case Schema.Type.Enumeration:
+ case Schema.Type.Fixed:
+ names.Add(ns);
+ break;
+
+ case Schema.Type.Record:
+ case Schema.Type.Error:
+ var rs = schema as RecordSchema;
+ names.Add(rs);
+ foreach (Field field in rs.Fields)
+ addName(field.Schema, names);
+ break;
+
+ case Schema.Type.Array:
+ var asc = schema as ArraySchema;
+ addName(asc.ItemSchema, names);
+ break;
+
+ case Schema.Type.Map:
+ var ms = schema as MapSchema;
+ addName(ms.ValueSchema, names);
+ break;
+
+ case Schema.Type.Union:
+ var us = schema as UnionSchema;
+ foreach (Schema usc in us.Schemas)
+ addName(usc, names);
+ break;
+
+ default:
+ throw new CodeGenException("Unable to add name for " + schema.Name + " type " + schema.Tag);
+
+ }
+ }
+
+ /// <summary>
+ /// Creates a class declaration for fixed schema
+ /// </summary>
+ /// <param name="schema">fixed schema</param>
+ /// <param name="ns">namespace object</param>
+ private void processFixed(Schema schema)
+ {
+ FixedSchema fixedSchema = schema as FixedSchema;
+ if (null == fixedSchema) throw new CodeGenException("Unable to cast schema into a fixed");
+
+ CodeTypeDeclaration ctd = new CodeTypeDeclaration();
+ ctd.Name = codeGenExt.Mangle(fixedSchema.Name);
+ ctd.IsClass = true;
+ ctd.IsPartial = true;
+ ctd.Attributes = MemberAttributes.Public;
+ ctd.BaseTypes.Add("SpecificFixed");
+
+ // create static schema field
+ createSchemaField(schema, ctd);
+
+ // Add Size field
+ string sizefname = "fixedSize";
+ var ctrfield = new CodeTypeReference(typeof(uint));
+ var codeField = new CodeMemberField(ctrfield, sizefname);
+ codeField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
+ codeField.InitExpression = new CodePrimitiveExpression(fixedSchema.Size);
+ ctd.Members.Add(codeField);
+
+ // Add Size property
+ var fieldRef = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), sizefname);
+ var property = new CodeMemberProperty();
+ property.Attributes = MemberAttributes.Public | MemberAttributes.Static;
+ property.Name = "FixedSize";
+ property.Type = ctrfield;
+ property.GetStatements.Add(new CodeMethodReturnStatement(new CodeTypeReferenceExpression(schema.Name + "." + sizefname)));
+ ctd.Members.Add(property);
+
+ // create constructor to initiate base class SpecificFixed
+ CodeConstructor cc = new CodeConstructor();
+ cc.Attributes = MemberAttributes.Public;
+ cc.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(sizefname));
+ ctd.Members.Add(cc);
+
+ string nspace = fixedSchema.Namespace;
+ if (string.IsNullOrEmpty(nspace))
+ throw new CodeGenException("Namespace required for enum schema " + fixedSchema.Name);
+ CodeNamespace codens = addNamespace(nspace);
+ codens.Types.Add(ctd);
+ }
+
+ /// <summary>
+ /// Creates an enum declaration
+ /// </summary>
+ /// <param name="schema">enum schema</param>
+ /// <param name="ns">namespace</param>
+ private void processEnum(Schema schema)
+ {
+ EnumSchema enumschema = schema as EnumSchema;
+ if (null == enumschema) throw new CodeGenException("Unable to cast schema into an enum");
+
+ CodeTypeDeclaration ctd = new CodeTypeDeclaration(codeGenExt.Mangle(enumschema.Name));
+ ctd.IsEnum = true;
+ ctd.Attributes = MemberAttributes.Public;
+
+ foreach (string symbol in enumschema.Symbols)
+ {
+ if (codeGenExt.ReservedKeywords.Contains(symbol))
+ throw new CodeGenException("Enum symbol " + symbol + " is a C# reserved keyword");
+ CodeMemberField field = new CodeMemberField(typeof(int), symbol);
+ ctd.Members.Add(field);
+ }
+
+ string nspace = enumschema.Namespace;
+ if (string.IsNullOrEmpty(nspace))
+ throw new CodeGenException("Namespace required for enum schema " + enumschema.Name);
+ CodeNamespace codens = addNamespace(nspace);
+
+ codens.Types.Add(ctd);
+ }
+
+ /// <summary>
+ /// Creates a class declaration
+ /// </summary>
+ /// <param name="schema">record schema</param>
+ /// <param name="ns">namespace</param>
+ /// <returns></returns>
+ private CodeTypeDeclaration processRecord(Schema schema)
+ {
+ RecordSchema recordSchema = schema as RecordSchema;
+ if (null == recordSchema) throw new CodeGenException("Unable to cast schema into a record");
+
+ // declare the class
+ var ctd = new CodeTypeDeclaration(codeGenExt.Mangle(recordSchema.Name));
+ ctd.BaseTypes.Add("SpecificRecord");
+ ctd.Attributes = MemberAttributes.Public;
+ ctd.IsClass = true;
+ ctd.IsPartial = true;
+
+ createSchemaField(schema, ctd);
+
+ // declare Get() to be used by the Writer classes
+ var cmmGet = new CodeMemberMethod();
+ cmmGet.Name = "Get";
+ cmmGet.Attributes = MemberAttributes.Public | MemberAttributes.Override;
+ cmmGet.ReturnType = new CodeTypeReference("System.Object");
+ cmmGet.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "fieldPos"));
+ StringBuilder getFieldStmt = new StringBuilder("switch (fieldPos)\n\t\t\t{\n");
+
+ // declare Put() to be used by the Reader classes
+ var cmmPut = new CodeMemberMethod();
+ cmmPut.Name = "Put";
+ cmmPut.Attributes = MemberAttributes.Public | MemberAttributes.Override;
+ cmmPut.ReturnType = new CodeTypeReference(typeof(void));
+ cmmPut.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "fieldPos"));
+ cmmPut.Parameters.Add(new CodeParameterDeclarationExpression("System.Object", "fieldValue"));
+ var putFieldStmt = new StringBuilder("switch (fieldPos)\n\t\t\t{\n");
+
+ foreach (Field field in recordSchema.Fields)
+ {
+ // Determine type of field
+ bool nullibleEnum = false;
+ string baseType = codeGenExt.Mangle(getType(field.Schema, false, ref nullibleEnum));
+ var ctrfield = new CodeTypeReference(baseType);
+
+ // Create field
+ string privFieldName = string.Concat("_", field.Name);
+ var codeField = new CodeMemberField(ctrfield, privFieldName);
+ codeField.Attributes = MemberAttributes.Private;
+
+ // Process field documentation if it exist and add to the field
+ CodeCommentStatement propertyComment = null;
+ if (!string.IsNullOrEmpty(field.Documentation))
+ {
+ propertyComment = createDocComment(field.Documentation);
+ if (null != propertyComment)
+ codeField.Comments.Add(propertyComment);
+ }
+
+ // Add field to class
+ ctd.Members.Add(codeField);
+
+ // Create reference to the field - this.fieldname
+ var fieldRef = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), privFieldName);
+ var mangledName = codeGenExt.Mangle(field.Name);
+
+ // Create field property with get and set methods
+ var property = new CodeMemberProperty();
+ property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
+ property.Name = mangledName;
+ property.Type = ctrfield;
+ property.GetStatements.Add(new CodeMethodReturnStatement(fieldRef));
+ property.SetStatements.Add(new CodeAssignStatement(fieldRef, new CodePropertySetValueReferenceExpression()));
+ if (null != propertyComment)
+ property.Comments.Add(propertyComment);
+
+ // Add field property to class
+ ctd.Members.Add(property);
+
+ // add to Get()
+ getFieldStmt.Append("\t\t\tcase ");
+ getFieldStmt.Append(field.Pos);
+ getFieldStmt.Append(": return this.");
+ getFieldStmt.Append(mangledName);
+ getFieldStmt.Append(";\n");
+
+ // add to Put()
+ putFieldStmt.Append("\t\t\tcase ");
+ putFieldStmt.Append(field.Pos);
+ putFieldStmt.Append(": this.");
+ putFieldStmt.Append(mangledName);
+
+ if (nullibleEnum)
+ {
+ putFieldStmt.Append(" = fieldValue == null ? (");
+ putFieldStmt.Append(baseType);
+ putFieldStmt.Append(")null : (");
+
+ string type = baseType.Remove(0, 16); // remove System.Nullable<
+ type = type.Remove(type.Length - 1); // remove >
+
+ putFieldStmt.Append(type);
+ putFieldStmt.Append(")fieldValue; break;\n");
+ }
+ else
+ {
+ putFieldStmt.Append(" = (");
+ putFieldStmt.Append(baseType);
+ putFieldStmt.Append(")fieldValue; break;\n");
+ }
+ }
+
+ // end switch block for Get()
+ getFieldStmt.Append("\t\t\tdefault: throw new AvroRuntimeException(\"Bad index \" + fieldPos + \" in Get()\");\n\t\t\t}");
+ var cseGet = new CodeSnippetExpression(getFieldStmt.ToString());
+ cmmGet.Statements.Add(cseGet);
+ ctd.Members.Add(cmmGet);
+
+ // end switch block for Put()
+ putFieldStmt.Append("\t\t\tdefault: throw new AvroRuntimeException(\"Bad index \" + fieldPos + \" in Put()\");\n\t\t\t}");
+ var csePut = new CodeSnippetExpression(putFieldStmt.ToString());
+ cmmPut.Statements.Add(csePut);
+ ctd.Members.Add(cmmPut);
+
+ string nspace = recordSchema.Namespace;
+ if (string.IsNullOrEmpty(nspace))
+ throw new CodeGenException("Namespace required for record schema " + recordSchema.Name);
+ CodeNamespace codens = addNamespace(nspace);
+
+ codens.Types.Add(ctd);
+
+ return ctd;
+ }
+
+ /// <summary>
+ /// Gets the string representation of the schema's data type
+ /// </summary>
+ /// <param name="schema">schema</param>
+ /// <param name="nullible">flag to indicate union with null</param>
+ /// <returns></returns>
+ internal static string getType(Schema schema, bool nullible, ref bool nullibleEnum)
+ {
+ switch (schema.Tag)
+ {
+ case Schema.Type.Null:
+ return "System.Object";
+ case Schema.Type.Boolean:
+ if (nullible) return "System.Nullable<bool>";
+ else return typeof(bool).ToString();
+ case Schema.Type.Int:
+ if (nullible) return "System.Nullable<int>";
+ else return typeof(int).ToString();
+ case Schema.Type.Long:
+ if (nullible) return "System.Nullable<long>";
+ else return typeof(long).ToString();
+ case Schema.Type.Float:
+ if (nullible) return "System.Nullable<float>";
+ else return typeof(float).ToString();
+ case Schema.Type.Double:
+ if (nullible) return "System.Nullable<double>";
+ else return typeof(double).ToString();
+
+ case Schema.Type.Bytes:
+ return typeof(byte[]).ToString();
+ case Schema.Type.String:
+ return typeof(string).ToString();
+
+ case Schema.Type.Enumeration:
+ var namedSchema = schema as NamedSchema;
+ if (null == namedSchema)
+ throw new CodeGenException("Unable to cast schema into a named schema");
+ if (nullible)
+ {
+ nullibleEnum = true;
+ return "System.Nullable<" + namedSchema.Fullname + ">";
+ }
+ else return namedSchema.Fullname;
+
+ case Schema.Type.Fixed:
+ case Schema.Type.Record:
+ case Schema.Type.Error:
+ namedSchema = schema as NamedSchema;
+ if (null == namedSchema)
+ throw new CodeGenException("Unable to cast schema into a named schema");
+ return namedSchema.Fullname;
+
+ case Schema.Type.Array:
+ var arraySchema = schema as ArraySchema;
+ if (null == arraySchema)
+ throw new CodeGenException("Unable to cast schema into an array schema");
+
+ return "IList<" + getType(arraySchema.ItemSchema, false, ref nullibleEnum) + ">";
+
+ case Schema.Type.Map:
+ var mapSchema = schema as MapSchema;
+ if (null == mapSchema)
+ throw new CodeGenException("Unable to cast schema into a map schema");
+ return "IDictionary<string," + getType(mapSchema.ValueSchema, false, ref nullibleEnum) + ">";
+
+ case Schema.Type.Union:
+ var unionSchema = schema as UnionSchema;
+ if (null == unionSchema)
+ throw new CodeGenException("Unable to cast schema into a union schema");
+ Schema nullibleType = getNullableType(unionSchema);
+ if (null == nullibleType)
+ return "System.Object";
+ else
+ return getType(nullibleType, true, ref nullibleEnum);
+ }
+ throw new CodeGenException("Unable to generate CodeTypeReference for " + schema.Name + " type " + schema.Tag);
+ }
+
+ /// <summary>
+ /// Gets the schema of a union with null
+ /// </summary>
+ /// <param name="schema">union schema</param>
+ /// <returns>schema that is nullible</returns>
+ public static Schema getNullableType(UnionSchema schema)
+ {
+ Schema ret = null;
+ if (schema.Count == 2)
+ {
+ bool nullable = false;
+ foreach (Schema childSchema in schema.Schemas)
+ {
+ if (childSchema.Tag == Schema.Type.Null)
+ nullable = true;
+ else
+ ret = childSchema;
+ }
+ if (!nullable)
+ ret = null;
+ }
+ return ret;
+ }
+
+ /// <summary>
+ /// Creates the static schema field for class types
+ /// </summary>
+ /// <param name="schema">schema</param>
+ /// <param name="ctd">CodeTypeDeclaration for the class</param>
+ private void createSchemaField(Schema schema, CodeTypeDeclaration ctd)
+ {
+ // create schema field
+ var ctrfield = new CodeTypeReference("Schema");
+ string schemaFname = "_SCHEMA";
+ var codeField = new CodeMemberField(ctrfield, schemaFname);
+ codeField.Attributes = MemberAttributes.Private | MemberAttributes.Static;
+ // create function call Schema.Parse(json)
+ var cpe = new CodePrimitiveExpression(schema.ToString());
+ var cmie = new CodeMethodInvokeExpression(
+ new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(Schema)), "Parse"),
+ new CodeExpression[] { cpe });
+ codeField.InitExpression = cmie;
+ ctd.Members.Add(codeField);
+
+ // create property to get static schema field
+ var property = new CodeMemberProperty();
+ property.Attributes = MemberAttributes.Public | MemberAttributes.Override;
+ property.Name = "Schema";
+ property.Type = ctrfield;
+ property.GetStatements.Add(new CodeMethodReturnStatement(new CodeTypeReferenceExpression(schema.Name + "." + schemaFname)));
+ ctd.Members.Add(property);
+ }
+
+ /// <summary>
+ /// Creates an XML documentation for the given comment
+ /// </summary>
+ /// <param name="comment">comment</param>
+ /// <returns>CodeCommentStatement object</returns>
+ private CodeCommentStatement createDocComment(string comment)
+ {
+ string text = string.Format("<summary>\r\n {0}\r\n </summary>", comment);
+ return new CodeCommentStatement(text, true);
+ }
+
+ /// <summary>
+ /// Writes the generated compile unit into one file
+ /// </summary>
+ /// <param name="outputFile">name of output file to write to</param>
+ public void WriteCompileUnit(string outputFile)
+ {
+ var cscp = new CSharpCodeProvider();
+
+ var opts = new CodeGeneratorOptions();
+ opts.BracingStyle = "C";
+ opts.IndentString = "\t";
+ opts.BlankLinesBetweenMembers = false;
+
+ using (var outfile = new StreamWriter(outputFile))
+ {
+ cscp.GenerateCodeFromCompileUnit(CompileUnit, outfile, opts);
+ }
+ }
+
+ /// <summary>
+ /// Writes each types in each namespaces into individual files
+ /// </summary>
+ /// <param name="outputdir">name of directory to write to</param>
+ public void WriteTypes(string outputdir)
+ {
+ var cscp = new CSharpCodeProvider();
+
+ var opts = new CodeGeneratorOptions();
+ opts.BracingStyle = "C";
+ opts.IndentString = "\t";
+ opts.BlankLinesBetweenMembers = false;
+
+ CodeNamespaceCollection nsc = CompileUnit.Namespaces;
+ for (int i = 0; i < nsc.Count; i++)
+ {
+ var ns = nsc[i];
+
+ string dir = outputdir + "\\" + codeGenExt.UnMangle(ns.Name).Replace('.', '\\');
+ Directory.CreateDirectory(dir);
+
+ var new_ns = new CodeNamespace(ns.Name);
+ new_ns.Comments.Add(this.codeGenExt.FileComment);
+ foreach (CodeNamespaceImport nci in this.codeGenExt.NamespaceImports)
+ new_ns.Imports.Add(nci);
+
+ var types = ns.Types;
+ for (int j = 0; j < types.Count; j++)
+ {
+ var ctd = types[j];
+ string file = dir + "\\" + codeGenExt.UnMangle(ctd.Name) + ".cs";
+ using (var writer = new StreamWriter(file, false))
+ {
+ new_ns.Types.Add(ctd);
+ cscp.GenerateCodeFromNamespace(new_ns, writer, opts);
+ new_ns.Types.Remove(ctd);
+ }
+ }
+ }
+ }
+ }
+}
Added: avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs (added)
+++ avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenException.cs Thu Mar 31 21:16:28 2011
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Avro
+{
+ class CodeGenException : AvroException
+ {
+ public CodeGenException(string s)
+ : base(s)
+ {
+
+ }
+ public CodeGenException(string s, Exception inner)
+ : base(s, inner)
+ {
+
+ }
+ }
+}
Added: avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenExt.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenExt.cs?rev=1087439&view=auto
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenExt.cs (added)
+++ avro/trunk/lang/csharp/src/apache/main/CodeGen/CodeGenExt.cs Thu Mar 31 21:16:28 2011
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.CodeDom;
+
+namespace Avro
+{
+ /// <summary>
+ /// A singleton class containing data used by codegen
+ /// </summary>
+ public sealed class CodeGenExt
+ {
+ private static readonly CodeGenExt instance = new CodeGenExt();
+ public static CodeGenExt Instance { get { return instance; } }
+
+ public CodeNamespaceImport[] NamespaceImports { get; private set; }
+ public CodeCommentStatement FileComment { get; private set; }
+ public HashSet<string> ReservedKeywords { get; private set; }
+ private const char AT = '@';
+ private const char DOT = '.';
+
+ private CodeGenExt()
+ {
+ NamespaceImports = new CodeNamespaceImport[] {
+ new CodeNamespaceImport("System"),
+ new CodeNamespaceImport("System.Collections.Generic"),
+ new CodeNamespaceImport("System.Text"),
+ new CodeNamespaceImport("Avro"),
+ new CodeNamespaceImport("Avro.Specific") };
+
+ FileComment = new CodeCommentStatement(
+@"------------------------------------------------------------------------------
+ <auto-generated>
+ Generated by " + System.AppDomain.CurrentDomain.FriendlyName + ", version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + @"
+ Changes to this file may cause incorrect behavior and will be lost if code
+ is regenerated
+ </auto-generated>
+ ------------------------------------------------------------------------------");
+
+ // Visual Studio 2010 http://msdn.microsoft.com/en-us/library/x53a06bb.aspx
+ ReservedKeywords = new HashSet<string>() {
+ "abstract","as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class",
+ "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event",
+ "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if",
+ "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new",
+ "null", "object", "operator", "out", "override", "params", "private", "protected", "public",
+ "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static",
+ "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong",
+ "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while", "value", "partial" };
+ }
+
+ /// <summary>
+ /// Append @ to all reserved keywords that appear on the given name
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public string Mangle(string name)
+ {
+ var builder = new StringBuilder();
+ string[] names = name.Split(DOT);
+ for (int i = 0; i < names.Length; ++i)
+ {
+ if (ReservedKeywords.Contains(names[i]))
+ builder.Append(AT);
+ builder.Append(names[i]);
+ builder.Append(DOT);
+ }
+ builder.Remove(builder.Length - 1, 1);
+ return builder.ToString();
+ }
+
+ /// <summary>
+ /// Remove all the @
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public string UnMangle(string name)
+ {
+ var builder = new StringBuilder(name.Length);
+ for (int i = 0; i < name.Length; ++i)
+ if (name[i] != AT)
+ builder.Append(name[i]);
+ return builder.ToString();
+ }
+ }
+}