Skip to content
Browse files

project start

  • Loading branch information...
1 parent 1c600d6 commit 5c5a5fea1a68777b7cf15a708a133c355fe81209 @akurdyukov committed
View
20 SimpleToDo.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleToDo", "SimpleToDo\SimpleToDo.csproj", "{83E71B0D-37D3-4601-B7E2-552F734D7AC2}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {83E71B0D-37D3-4601-B7E2-552F734D7AC2}.Debug|x86.ActiveCfg = Debug|x86
+ {83E71B0D-37D3-4601-B7E2-552F734D7AC2}.Debug|x86.Build.0 = Debug|x86
+ {83E71B0D-37D3-4601-B7E2-552F734D7AC2}.Release|x86.ActiveCfg = Release|x86
+ {83E71B0D-37D3-4601-B7E2-552F734D7AC2}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
15 SimpleToDo/IToDoDao.cs
@@ -0,0 +1,15 @@
+using System.Collections.Generic;
+
+namespace SimpleToDo
+{
+ /// <summary>
+ /// Interface for DAO
+ /// </summary>
+ public interface IToDoDao
+ {
+ IList<ToDoItem> List();
+ ToDoItem Get(long id);
+ void Save(ToDoItem item);
+ void Remove(ToDoItem item);
+ }
+}
View
46 SimpleToDo/LocalBootstrapper.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Castle.Facilities.AutoTx;
+using Castle.Facilities.NHibernate;
+using Castle.MicroKernel.Registration;
+using Castle.Windsor;
+using Nancy.Bootstrappers.Windsor;
+using Nancy.Conventions;
+using Nancy.Diagnostics;
+
+namespace SimpleToDo
+{
+ public class LocalBootstrapper : WindsorNancyBootstrapper
+ {
+ protected override DiagnosticsConfiguration DiagnosticsConfiguration
+ {
+ get
+ {
+ return new DiagnosticsConfiguration { Password = @"123" };
+ }
+ }
+
+ protected override void ConfigureApplicationContainer(IWindsorContainer container)
+ {
+ base.ConfigureApplicationContainer(container);
+
+ // TODO: install facilities here
+ container
+ .AddFacility<AutoTxFacility>()
+ .Register(
+ Component.For<INHibernateInstaller>().ImplementedBy<NHibInstaller>(),
+ Component.For<IToDoDao>().ImplementedBy<ToDoDao>()
+ )
+ .AddFacility<NHibernateFacility>();
+ }
+
+ protected override void ConfigureConventions(NancyConventions nancyConventions)
+ {
+ base.ConfigureConventions(nancyConventions);
+
+ nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("assets", @"Assets"));
+ }
+ }
+}
View
47 SimpleToDo/MainModule.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Dynamic;
+using Nancy;
+using Nancy.ModelBinding;
+
+namespace SimpleToDo
+{
+ public class MainModule : NancyModule
+ {
+ private readonly IToDoDao dao;
+
+ public MainModule(IToDoDao dao)
+ {
+ this.dao = dao;
+ Get["/"] = RenderMain;
+ Post["/"] = parameters =>
+ {
+ var itemModel = this.Bind<ToDoItemModel>();
+
+ ToDoItem item = new ToDoItem {CreatedAt = DateTime.Now, Name = itemModel.Name};
+ dao.Save(item);
+
+ return RenderMain(null);
+ };
+ Delete["/{id}"] = parameters =>
+ {
+ long id;
+ if (long.TryParse(parameters.id, out id))
+ {
+ var item = dao.Get(id);
+ if (item != null)
+ {
+ dao.Remove(item);
+ }
+ }
+ return RenderMain(null);
+ };
+ }
+
+ private dynamic RenderMain(dynamic parameters)
+ {
+ dynamic model = new ExpandoObject();
+ model.Items = dao.List();
+ return View["index", model];
+ }
+ }
+}
View
66 SimpleToDo/NHibInstaller.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using Castle.Facilities.NHibernate;
+using Castle.Transactions;
+using NHibernate;
+using NHibernate.Cfg;
+using NHibernate.Mapping.Attributes;
+
+namespace SimpleToDo
+{
+ public class NHibInstaller : INHibernateInstaller
+ {
+ private readonly Maybe<IInterceptor> interceptor;
+ private Configuration config;
+
+ public NHibInstaller()
+ {
+ interceptor = Maybe.None<IInterceptor>();
+ }
+
+ public void Registered(ISessionFactory factory)
+ {
+ }
+
+ public bool IsDefault
+ {
+ get { return true; }
+ }
+
+ public string SessionFactoryKey
+ {
+ get { return "default"; }
+ }
+
+ public Maybe<IInterceptor> Interceptor
+ {
+ get { return interceptor; }
+ }
+
+ public Configuration Config
+ {
+ get
+ {
+ if (config == null)
+ {
+ IDictionary<string, string> props = new Dictionary<string, string>()
+ {
+ {"connection.driver_class", "NHibernate.Driver.NpgsqlDriver"},
+ {"connection.connection_string", "Server=10.211.55.2; Port=5432; User Id=test; Password=test; Database=testdb;"},
+ {"dialect", "NHibernate.Dialect.PostgreSQL82Dialect"},
+ {"show_sql", "true"}
+ };
+ HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly(), "schema.hbm.xml");
+ config = new Configuration()
+ .SetProperties(props)
+ .AddInputStream(HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()));
+ }
+ return config;
+ }
+ }
+ }
+}
View
25 SimpleToDo/NLog.config
@@ -0,0 +1,25 @@
+<?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">
+
+ <!--
+ See http://nlog-project.org/wiki/Configuration_file
+ for information on customizing logging rules and outputs.
+ -->
+ <targets>
+ <!-- add your targets here -->
+
+ <!--
+ <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
+ layout="${longdate} ${uppercase:${level}} ${message}" />
+ -->
+ </targets>
+
+ <rules>
+ <!-- add your logging rules here -->
+
+ <!--
+ <logger name="*" minlevel="Trace" writeTo="f" />
+ -->
+ </rules>
+</nlog>
View
2,585 SimpleToDo/NLog.xsd
2,585 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
67 SimpleToDo/Program.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using NLog;
+using Nancy.Hosting.Self;
+
+namespace SimpleToDo
+{
+ class Program
+ {
+ private static readonly Logger logger = LogManager.GetCurrentClassLogger();
+
+ public static int Main(string[] args)
+ {
+ if (args.Length < 1)
+ {
+ Console.WriteLine("Usage: SimpleTodo.exe <url>");
+ return -1;
+ }
+
+ Uri uri;
+ try
+ {
+ uri = new Uri(args[0]);
+ }
+ catch (UriFormatException ex)
+ {
+ Console.WriteLine("Please check URI format in {0}", args[0]);
+ return -1;
+ }
+
+ CancellationTokenSource tokenSource = new CancellationTokenSource();
+ CancellationToken ct = tokenSource.Token;
+
+ var nancyHost = new NancyHost(uri);
+
+ Task nancyTask = new Task(() =>
+ {
+ nancyHost.Start();
+
+ Console.WriteLine("Nancy now listening");
+
+ while (!ct.IsCancellationRequested)
+ {
+ Thread.Sleep(1000);
+ }
+ nancyHost.Stop(); // stop hosting
+ }, tokenSource.Token);
+
+ nancyTask.Start();
+ Console.WriteLine("Server started. Enter 'quit' to stop.");
+
+ var line = Console.ReadLine();
+ while (line != "quit")
+ {
+ line = Console.ReadLine();
+ }
+ tokenSource.Cancel();
+
+ return 0;
+ }
+ }
+}
View
36 SimpleToDo/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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("SimpleToDo")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("SimpleToDo")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[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("9e029649-28e1-4327-b068-1a4328fa4104")]
+
+// 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")]
View
121 SimpleToDo/SimpleToDo.csproj
@@ -0,0 +1,121 @@
+<?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>{83E71B0D-37D3-4601-B7E2-552F734D7AC2}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SimpleToDo</RootNamespace>
+ <AssemblyName>SimpleToDo</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <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="Castle.Core">
+ <HintPath>..\packages\Castle.Core.3.1.0\lib\net40-client\Castle.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Facilities.AutoTx">
+ <HintPath>..\packages\Castle.Facilities.AutoTx.3.2.207.2207\lib\net40\Castle.Facilities.AutoTx.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Facilities.FactorySupport">
+ <HintPath>..\packages\Castle.FactorySupportFacility.3.1.0\lib\net40\Castle.Facilities.FactorySupport.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Facilities.NHibernate">
+ <HintPath>..\lib\Castle.Facilities.NHibernate.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Transactions">
+ <HintPath>..\packages\Castle.Transactions.3.2.207.2207\lib\net40\Castle.Transactions.dll</HintPath>
+ </Reference>
+ <Reference Include="Castle.Windsor">
+ <HintPath>..\packages\Castle.Windsor.3.1.0\lib\net40-client\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="Mono.Security">
+ <HintPath>..\packages\Npgsql.2.0.11\lib\Net40\Mono.Security.dll</HintPath>
+ </Reference>
+ <Reference Include="Nancy">
+ <HintPath>..\packages\Nancy.0.13.0\lib\net40\Nancy.dll</HintPath>
+ </Reference>
+ <Reference Include="Nancy.Bootstrappers.Windsor">
+ <HintPath>..\packages\Nancy.Bootstrappers.Windsor.0.13.0\lib\net40\Nancy.Bootstrappers.Windsor.dll</HintPath>
+ </Reference>
+ <Reference Include="Nancy.Hosting.Self">
+ <HintPath>..\packages\Nancy.Hosting.Self.0.13.0\lib\net40\Nancy.Hosting.Self.dll</HintPath>
+ </Reference>
+ <Reference Include="NHibernate">
+ <HintPath>..\packages\NHibernate.3.3.2.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="Npgsql">
+ <HintPath>..\packages\Npgsql.2.0.11\lib\Net40\Npgsql.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <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" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="IToDoDao.cs" />
+ <Compile Include="LocalBootstrapper.cs" />
+ <Compile Include="MainModule.cs" />
+ <Compile Include="NHibInstaller.cs" />
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ToDoDao.cs" />
+ <Compile Include="ToDoItem.cs" />
+ <Compile Include="ToDoItemModel.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="NLog.config">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ <None Include="app.config" />
+ <None Include="NLog.xsd">
+ <SubType>Designer</SubType>
+ </None>
+ <None Include="packages.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>
View
53 SimpleToDo/ToDoDao.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using Castle.Transactions;
+using NHibernate;
+
+namespace SimpleToDo
+{
+ public class ToDoDao : IToDoDao
+ {
+ private readonly Func<ISession> getSession;
+
+ public ToDoDao(Func<ISession> getSession)
+ {
+ this.getSession = getSession;
+ }
+
+ [Transaction]
+ public IList<ToDoItem> List()
+ {
+ using (var session = getSession())
+ {
+ return session.CreateCriteria(typeof (ToDoItem)).List<ToDoItem>();
+ }
+ }
+
+ [Transaction]
+ public ToDoItem Get(long id)
+ {
+ using (var session = getSession())
+ {
+ return session.Get<ToDoItem>(id);
+ }
+ }
+
+ [Transaction]
+ public void Save(ToDoItem item)
+ {
+ using (var session = getSession())
+ {
+ session.SaveOrUpdate(item);
+ }
+ }
+
+ [Transaction]
+ public void Remove(ToDoItem item)
+ {
+ using (var session = getSession())
+ {
+ session.Delete(item);
+ }
+ }
+ }
+}
View
20 SimpleToDo/ToDoItem.cs
@@ -0,0 +1,20 @@
+using System;
+using NHibernate.Mapping.Attributes;
+
+namespace SimpleToDo
+{
+ [Serializable]
+ [Class(Table = "TODOITEMS")]
+ public class ToDoItem
+ {
+ [Id(0, Column = "ID", Name = "Id")]
+ [Generator(1, Class = "native")]
+ public virtual long Id { get; protected set; }
+
+ [Property(Column = "NAME", NotNull = true)]
+ public virtual string Name { get; set; }
+
+ [Property(Column = "CREATED_AT")]
+ public virtual DateTime CreatedAt { get; set; }
+ }
+}
View
7 SimpleToDo/ToDoItemModel.cs
@@ -0,0 +1,7 @@
+namespace SimpleToDo
+{
+ public class ToDoItemModel
+ {
+ public string Name { get; set; }
+ }
+}
View
3 SimpleToDo/app.config
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
View
17 SimpleToDo/packages.config
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Castle.Core" version="3.1.0" targetFramework="net40-Client" />
+ <package id="Castle.Facilities.AutoTx" version="3.2.207.2207" targetFramework="net40-Client" />
+ <package id="Castle.FactorySupportFacility" version="3.1.0" targetFramework="net40" />
+ <package id="Castle.Transactions" version="3.2.207.2207" targetFramework="net40-Client" />
+ <package id="Castle.Windsor" version="3.1.0" targetFramework="net40-Client" />
+ <package id="Iesi.Collections" version="3.2.0.4000" targetFramework="net40-Client" />
+ <package id="Nancy" version="0.13.0" targetFramework="net40-Client" />
+ <package id="Nancy.Bootstrappers.Windsor" version="0.13.0" targetFramework="net40-Client" />
+ <package id="Nancy.Hosting.Self" version="0.13.0" targetFramework="net40-Client" />
+ <package id="NHibernate" version="3.3.2.4000" targetFramework="net40-Client" />
+ <package id="NHibernate.Mapping.Attributes" version="3.2.0.0" targetFramework="net40-Client" />
+ <package id="NLog" version="2.0.0.2000" targetFramework="net40-Client" />
+ <package id="NLog.Config" version="2.0.0.2000" targetFramework="net40-Client" />
+ <package id="Npgsql" version="2.0.11" targetFramework="net40" />
+</packages>
View
BIN lib/Castle.Facilities.NHibernate.dll
Binary file not shown.

0 comments on commit 5c5a5fe

Please sign in to comment.
Something went wrong with that request. Please try again.