Permalink
Browse files

sample with NHIbernate.Mapping.Attributes added

  • Loading branch information...
akurdyukov committed Sep 8, 2012
1 parent 8f3a798 commit e6b3e51273600e1de91150952955891e8320e3dd
View
@@ -11,4 +11,6 @@ _ReSharper*
Castle.Facilities.NHibernate.user
* Thumbs.db
*.nupkg
-packages/
+packages/
+*.user
+*.dotCover
@@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{DAFBA7
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.AttrExampleConsoleApp", "src\samples\NHibernate.AttrExampleConsoleApp\NHibernate.AttrExampleConsoleApp.csproj", "{BB3642DF-85D3-4A33-9E11-2AC847DA4DED}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -103,11 +105,32 @@ Global
{9B977E07-808A-4773-B378-EB3665679082}.Release|Mixed Platforms.Build.0 = Release|x86
{9B977E07-808A-4773-B378-EB3665679082}.Release|x86.ActiveCfg = Release|x86
{9B977E07-808A-4773-B378-EB3665679082}.Release|x86.Build.0 = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Debug|x86.ActiveCfg = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Debug|x86.Build.0 = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Debug|Any CPU.ActiveCfg = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Debug|Mixed Platforms.Build.0 = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Debug|x86.ActiveCfg = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Debug|x86.Build.0 = Debug|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Release|Any CPU.ActiveCfg = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Release|Mixed Platforms.ActiveCfg = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Release|Mixed Platforms.Build.0 = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Release|x86.ActiveCfg = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.NET40-Release|x86.Build.0 = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Release|Any CPU.ActiveCfg = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Release|Mixed Platforms.Build.0 = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Release|x86.ActiveCfg = Release|x86
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9B977E07-808A-4773-B378-EB3665679082} = {BF42C45F-BC6F-467D-99C3-D104EF605147}
+ {BB3642DF-85D3-4A33-9E11-2AC847DA4DED} = {BF42C45F-BC6F-467D-99C3-D104EF605147}
EndGlobalSection
EndGlobal
@@ -0,0 +1,34 @@
+using System;
+using NHibernate.Mapping.Attributes;
+
+namespace NHibernate.AttrExampleConsoleApp
+{
+ [Serializable]
+ [Class(Table = "LOGLINES")]
+ public class LogLine
+ {
+ /// <summary>
+ /// Gets the ID of the line in the log.
+ /// </summary>
+ [Id(Name = "Id", Column = "ID")]
+ [Generator(1, Class = "guid.comb")]
+ public virtual Guid Id { get; protected set; }
+
+ /// <summary>
+ /// Gets the log-line.
+ /// </summary>
+ [Property(Column = "LINE", NotNull = true, TypeType = typeof(string))]
+ public virtual string Line { get; protected set; }
+
+ /// <summary> for serialization </summary>
+ [Obsolete("for serialization")]
+ protected LogLine()
+ {
+ }
+
+ public LogLine(string line)
+ {
+ Line = line;
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System;
+using Castle.Transactions;
+
+namespace NHibernate.AttrExampleConsoleApp
+{
+ public class Logger
+ {
+ private readonly Func<ISession> getSession;
+
+ public Logger(Func<ISession> getSession)
+ {
+ this.getSession = getSession;
+ }
+
+ [Transaction]
+ public virtual void WriteToLog(string text)
+ {
+ using (var s = getSession())
+ {
+ s.Save(new LogLine(text));
+ }
+ }
+
+ [Transaction]
+ public virtual void ReadLog(Action<string> reader)
+ {
+ using (var s = getSession())
+ {
+ foreach (var line in s.CreateCriteria<LogLine>().List<LogLine>())
+ {
+ reader(line.Line);
+ }
+ }
+ }
+ }
+}
@@ -0,0 +1,52 @@
+using System;
+using Castle.Facilities.NHibernate;
+using Castle.Transactions;
+using NHibernate.Cfg;
+using NHibernate.Connection;
+using NHibernate.Dialect;
+using NHibernate.Driver;
+using NHibernate.Mapping.Attributes;
+
+namespace NHibernate.AttrExampleConsoleApp
+{
+ internal class NHibInstaller : INHibernateInstaller
+ {
+ public bool IsDefault
+ {
+ get { return true; }
+ }
+
+ public string SessionFactoryKey
+ {
+ get { return "def"; }
+ }
+
+ public Maybe<IInterceptor> Interceptor
+ {
+ get { return Maybe.None<IInterceptor>(); }
+ }
+
+ public Func<Configuration> ConfigBuilder
+ {
+ get
+ {
+ HbmSerializer.Default.Validate = true;
+ Configuration cfg = new Configuration()
+ .DataBaseIntegration(db =>
+ {
+ db.ConnectionString = "Data Source=DataStore.db;Version=3";
+ db.Dialect<SQLiteDialect>();
+ db.Driver<SQLite20Driver>();
+ db.ConnectionProvider<DriverConnectionProvider>();
+ })
+ .AddAssembly(GetType().Assembly)
+ .AddInputStream(HbmSerializer.Default.Serialize(GetType().Assembly));
+ return () => cfg;
+ }
+ }
+
+ public void Registered(ISessionFactory factory)
+ {
+ }
+ }
+}
@@ -0,0 +1,133 @@
+<?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>{BB3642DF-85D3-4A33-9E11-2AC847DA4DED}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NHibernate.AttrExampleConsoleApp</RootNamespace>
+ <AssemblyName>NHibernate.AttrExampleConsoleApp</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </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="Castle.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\Castle.Core.3.1.0\lib\net40-client\Castle.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Facilities.AutoTx, Version=3.2.207.2207, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\Castle.Facilities.AutoTx.3.2.207.2207\lib\net40\Castle.Facilities.AutoTx.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Facilities.FactorySupport, Version=3.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\Castle.FactorySupportFacility.3.1.0\lib\net40\Castle.Facilities.FactorySupport.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Facilities.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\Castle.LoggingFacility.3.1.0\lib\net40\Castle.Facilities.Logging.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Services.Logging.NLogIntegration, Version=3.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\Castle.Core-NLog.3.1.0\lib\net40-client\Castle.Services.Logging.NLogIntegration.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Transactions, Version=3.2.207.2207, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\Castle.Transactions.3.2.207.2207\lib\net40\Castle.Transactions.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Windsor, Version=3.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <HintPath>..\..\..\packages\Castle.Windsor.3.1.0\lib\net40\Castle.Windsor.dll</HintPath>
+ </Reference>
+ <Reference Include="Iesi.Collections">
+ <HintPath>..\..\..\packages\Iesi.Collections.3.2.0.4000\lib\Net35\Iesi.Collections.dll</HintPath>
+ </Reference>
+ <Reference Include="NHibernate">
+ <HintPath>..\..\..\packages\NHibernate.3.3.1.4000\lib\Net35\NHibernate.dll</HintPath>
+ </Reference>
+ <Reference Include="NHibernate.Mapping.Attributes">
+ <HintPath>..\..\..\packages\NHibernate.Mapping.Attributes.3.2.0.0\lib\NHibernate.Mapping.Attributes.dll</HintPath>
+ </Reference>
+ <Reference Include="NLog">
+ <HintPath>..\..\..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Data.SQLite, Version=1.0.82.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\packages\System.Data.SQLite.1.0.82.0\lib\net40\System.Data.SQLite.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Data.SQLite.Linq">
+ <HintPath>..\..\..\packages\System.Data.SQLite.1.0.82.0\lib\net40\System.Data.SQLite.Linq.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Transactions" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="Topshelf, Version=3.0.104.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\packages\Topshelf.3.0.1\lib\net40-full\Topshelf.dll</HintPath>
+ </Reference>
+ <Reference Include="Topshelf.NLog">
+ <HintPath>..\..\..\packages\Topshelf.NLog.3.0.1\lib\net40-full\Topshelf.NLog.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Logger.cs" />
+ <Compile Include="LogLine.cs" />
+ <Compile Include="NHibInstaller.cs" />
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\Castle.Facilities.NHibernate\Castle.Facilities.NHibernate.csproj">
+ <Project>{12598D2B-B68E-4EA7-A7DD-0CC2398CE8B6}</Project>
+ <Name>Castle.Facilities.NHibernate</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="NLog.config">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="x64\SQLite.Interop.dll">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ <Content Include="x86\SQLite.Interop.dll">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.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,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- make sure to set 'Copy To Output Directory' option for this file -->
+ <!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->
+
+ <targets>
+ <target xsi:type="ColoredConsole" name="Console"/>
+ </targets>
+
+ <rules>
+ <logger name="*" writeTo="Console" />
+ </rules>
+</nlog>
Oops, something went wrong.

0 comments on commit e6b3e51

Please sign in to comment.