Permalink
Browse files

Add Source code

  • Loading branch information...
1 parent 3052242 commit a9bb1323e99e281fb23cfe3fb07489c28c4c809b @abdullin abdullin committed Aug 28, 2011
Showing with 8,925 additions and 0 deletions.
  1. BIN Sample/Library/MessageContracts.dll
  2. BIN Sample/Library/MessageContracts.pdb
  3. BIN Sample/Library/protobuf-net.dll
  4. BIN Sample/Library/protobuf-net.pdb
  5. +1,572 −0 Sample/Library/protobuf-net.xml
  6. +123 −0 Sample/Sample-1/Contracts.cs
  7. +45 −0 Sample/Sample-1/Contracts.tt
  8. +68 −0 Sample/Sample-1/Program.cs
  9. +68 −0 Sample/Sample-1/Sample-1.csproj
  10. +20 −0 Sample/Sample.sln
  11. +54 −0 Source/CodeDsl.sln
  12. +60 −0 Source/Converter/Converter.csproj
  13. +59 −0 Source/Converter/Program.cs
  14. BIN Source/Library/Antlr3.Runtime.dll
  15. BIN Source/Library/Antlr3.Runtime.pdb
  16. +3,842 −0 Source/Library/Antlr3.Runtime.xml
  17. +14 −0 Source/Library/NUnit.License.txt
  18. BIN Source/Library/nunit.framework.dll
  19. +1 −0 Source/Merge.cmd
  20. +49 −0 Source/MessageContracts.Tests/Class1.cs
  21. +63 −0 Source/MessageContracts.Tests/Lokad.CodeDsl.Tests.csproj
  22. +17 −0 Source/MessageContracts/Context.cs
  23. +18 −0 Source/MessageContracts/Contract.cs
  24. +13 −0 Source/MessageContracts/Errors.cs
  25. +14 −0 Source/MessageContracts/Fragment.cs
  26. +34 −0 Source/MessageContracts/GeneratorUtil.cs
  27. +9 −0 Source/MessageContracts/IGenerateCode.cs
  28. +68 −0 Source/MessageContracts/Lokad.CodeDsl.csproj
  29. +14 −0 Source/MessageContracts/Member.cs
  30. +151 −0 Source/MessageContracts/MessageContractAssembler.cs
  31. +90 −0 Source/MessageContracts/MessageContracts.g
  32. +1,092 −0 Source/MessageContracts/MessageContractsLexer.cs
  33. +1,152 −0 Source/MessageContracts/MessageContractsParser.cs
  34. +183 −0 Source/MessageContracts/TemplatedGenerator.cs
  35. +24 −0 Source/MessageContracts/TextFile1.txt
  36. +1 −0 Source/Tool/.gitignore
  37. +7 −0 Source/Tool/ReadMe.txt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
@@ -0,0 +1,123 @@
+using System;
+using ProtoBuf;
+
+namespace Sample
+{
+
+ [ProtoContract]
+ public sealed class SecurityDetails
+ {
+ [ProtoMember(1)] public readonly Guid UserId;
+ [ProtoMember(2)] public readonly string UserName;
+ [ProtoMember(3)] public readonly string Rule;
+ private SecurityDetails () {}
+ public SecurityDetails (Guid userId, string userName, string rule)
+ {
+ UserId = userId;
+ UserName = userName;
+ Rule = rule;
+ }
+ }
+
+ [ProtoContract]
+ public sealed class SecurityRequest
+ {
+ [ProtoMember(1)] public readonly Guid UserId;
+ private SecurityRequest () {}
+ public SecurityRequest (Guid userId)
+ {
+ UserId = userId;
+ }
+ }
+
+ [ProtoContract]
+ public sealed class CreateProject : ICommand
+ {
+ [ProtoMember(1)] public readonly Guid ProjectId;
+ [ProtoMember(2)] public readonly string Name;
+ [ProtoMember(3)] public readonly int Rank;
+ [ProtoMember(4)] public readonly SecurityRequest Request;
+ private CreateProject () {}
+ public CreateProject (Guid projectId, string name, int rank, SecurityRequest request)
+ {
+ ProjectId = projectId;
+ Name = name;
+ Rank = rank;
+ Request = request;
+ }
+ }
+
+ [ProtoContract]
+ public sealed class ProjectCreated : IEvent
+ {
+ [ProtoMember(1)] public readonly Guid ProjectId;
+ [ProtoMember(2)] public readonly string Name;
+ [ProtoMember(3)] public readonly int Rank;
+ [ProtoMember(4)] public readonly SecurityDetails Security;
+ private ProjectCreated () {}
+ public ProjectCreated (Guid projectId, string name, int rank, SecurityDetails security)
+ {
+ ProjectId = projectId;
+ Name = name;
+ Rank = rank;
+ Security = security;
+ }
+ }
+
+ [ProtoContract]
+ public sealed class RenameProject : ICommand
+ {
+ [ProtoMember(1)] public readonly Guid ProjectId;
+ [ProtoMember(2)] public readonly string Name;
+ [ProtoMember(3)] public readonly SecurityRequest Request;
+ private RenameProject () {}
+ public RenameProject (Guid projectId, string name, SecurityRequest request)
+ {
+ ProjectId = projectId;
+ Name = name;
+ Request = request;
+ }
+ }
+
+ [ProtoContract]
+ public sealed class ProjectRenamed : IEvent
+ {
+ [ProtoMember(1)] public readonly Guid ProjectId;
+ [ProtoMember(2)] public readonly string Name;
+ [ProtoMember(3)] public readonly SecurityDetails Security;
+ private ProjectRenamed () {}
+ public ProjectRenamed (Guid projectId, string name, SecurityDetails security)
+ {
+ ProjectId = projectId;
+ Name = name;
+ Security = security;
+ }
+ }
+
+ [ProtoContract]
+ public sealed class DeleteProject : ICommand
+ {
+ [ProtoMember(1)] public readonly Guid ProjectId;
+ [ProtoMember(2)] public readonly SecurityRequest Request;
+ private DeleteProject () {}
+ public DeleteProject (Guid projectId, SecurityRequest request)
+ {
+ ProjectId = projectId;
+ Request = request;
+ }
+ }
+
+ [ProtoContract]
+ public sealed class ProjectDeleted : IEvent
+ {
+ [ProtoMember(1)] public readonly Guid ProjectId;
+ [ProtoMember(2)] public readonly SecurityDetails Security;
+ private ProjectDeleted () {}
+ public ProjectDeleted (Guid projectId, SecurityDetails security)
+ {
+ ProjectId = projectId;
+ Security = security;
+ }
+ }
+
+}
@@ -0,0 +1,45 @@
+<#@ template language="C#" #>
+<#@ assembly name="$(SolutionDir)\Library\MessageContracts.dll" #>
+<#@ import namespace="MessageContracts" #>
+using System;
+using ProtoBuf;
+
+namespace Sample
+{
+ <# var generator = new WriteForProtoBufNet();
+ var dsl = @"
+
+// this is the reference implementation of running on-the-fly DSL in Visual Studio
+// edit this file and hit Ctrl+S to see the changes propagate to Contracts.cs
+// Run to reflect upon the generated contracts
+// use ReSharper with Solution-wide analysis for better experience (or AutoTest)
+
+// works best for CQRS projects and event sourcing.
+
+// check out sources and implement your own generator similar to
+// WriteForProtoBufNet to create your own serialization flavour
+
+
+
+// generic contracts
+SecurityDetails(Guid UserId, string UserName, string Rule)
+SecurityRequest(Guid UserId)
+
+// common fragments
+let projectId = Guid ProjectId;
+let name = string Name;
+let security = SecurityDetails Security;
+let auth = SecurityRequest Request;
+
+// projects
+CreateProject? (projectId, name, int Rank, auth)
+ProjectCreated! (projectId, name, int Rank, security)
+
+RenameProject? (projectId, name, auth)
+ProjectRenamed! (projectId, name, security)
+
+DeleteProject? (projectId, auth)
+ProjectDeleted! (projectId, security)
+ "; #>
+ <#= GeneratorUtil.Build(dsl, generator) #>
+}
@@ -0,0 +1,68 @@
+using System;
+using System.Linq;
+using System.Reflection;
+
+namespace Sample
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine(
+ @"
+Mercenary Sample
+----------------
+
+This is sample of streamlined contract generator in action. Stop the console and try editing 'contracts.tt' to force Visual Studio to regenerate C# contracts files.
+
+Best works with the latest ReSharper (and solution-wide analysis), Autotest.NET or any equivalent. They will pick up changes without recomipling code in Visual Studio!
+
+See http://abdullin.com/on/mercenary for additional details.
+
+PS: New BSD license (c) 2010 Lokad, Rinat Abdullin (basically, do what you want license)
+
+Press any key to continue...
+");
+
+ Console.ReadKey(true);
+
+
+ var types = Assembly
+ .GetExecutingAssembly()
+ .GetExportedTypes()
+ .Where(t => typeof (IMessage).IsAssignableFrom(t))
+ .Where(t => !t.IsAbstract);
+
+ foreach (var type in types)
+ {
+ Console.WriteLine(type.Name);
+
+ foreach (var member in type.GetFields())
+ {
+ Console.WriteLine(" {0}: {1}", member.FieldType.Name, member.Name);
+ }
+ foreach (var member in type.GetProperties())
+ {
+ Console.WriteLine(" {0}: {1}", member.PropertyType.Name, member.Name);
+ }
+ Console.WriteLine();
+ }
+
+
+ Console.WriteLine("Press any key to close");
+ Console.ReadKey(true);
+ }
+ }
+
+ public interface IMessage
+ {
+ }
+
+ public interface ICommand : IMessage
+ {
+ }
+
+ public interface IEvent : IMessage
+ {
+ }
+}
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{CF5667D4-9D1D-46BF-9744-5FBE880CACDE}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Sample</RootNamespace>
+ <AssemblyName>Sample</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="protobuf-net">
+ <HintPath>..\Library\protobuf-net.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Contracts.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Contracts.tt</DependentUpon>
+ </Compile>
+ <Compile Include="Program.cs" />
+
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Contracts.tt">
+ <Generator>TextTemplatingFileGenerator</Generator>
+ <LastGenOutput>Contracts.cs</LastGenOutput>
+ </None>
+ </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>
View
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample-1", "Sample-1\Sample-1.csproj", "{CF5667D4-9D1D-46BF-9744-5FBE880CACDE}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {CF5667D4-9D1D-46BF-9744-5FBE880CACDE}.Debug|x86.ActiveCfg = Debug|x86
+ {CF5667D4-9D1D-46BF-9744-5FBE880CACDE}.Debug|x86.Build.0 = Debug|x86
+ {CF5667D4-9D1D-46BF-9744-5FBE880CACDE}.Release|x86.ActiveCfg = Release|x86
+ {CF5667D4-9D1D-46BF-9744-5FBE880CACDE}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
@@ -0,0 +1,54 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lokad.CodeDsl", "MessageContracts\Lokad.CodeDsl.csproj", "{B93B4F62-E2B9-432A-864B-8AD40EAEB176}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Converter", "Converter\Converter.csproj", "{AE78747E-1ABB-4654-B19F-C889AE013696}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lokad.CodeDsl.Tests", "MessageContracts.Tests\Lokad.CodeDsl.Tests.csproj", "{D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}"
+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
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {B93B4F62-E2B9-432A-864B-8AD40EAEB176}.Release|x86.ActiveCfg = Release|Any CPU
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Debug|x86.ActiveCfg = Debug|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Debug|x86.Build.0 = Debug|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Release|Any CPU.ActiveCfg = Release|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Release|Mixed Platforms.Build.0 = Release|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Release|x86.ActiveCfg = Release|x86
+ {AE78747E-1ABB-4654-B19F-C889AE013696}.Release|x86.Build.0 = Release|x86
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {D20B805F-A0E7-4CA3-AE9C-EFE4285B24E8}.Release|x86.ActiveCfg = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Oops, something went wrong.

0 comments on commit a9bb132

Please sign in to comment.