Skip to content

Commit

Permalink
starting to add some app stuff to configure database connection, etc.…
Browse files Browse the repository at this point in the history
… recreated database to ensure it works correctly
  • Loading branch information
Derick Bailey committed Nov 4, 2009
1 parent 5f0bfc2 commit a5a0624
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 8 deletions.
Binary file modified db/security.s3db
Binary file not shown.
20 changes: 20 additions & 0 deletions src/Security.Repository/RepoConfig.cs
@@ -0,0 +1,20 @@
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Cfg;
using UoW;
using UoW.NHibernate;

namespace Security.Repository
{
public static class RepoConfig
{
public static IUnitOfWorkConfiguration GetConfiguration()
{
Configuration config = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.UsingFile("security.s3db"))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<SecurityRepository>()).BuildConfiguration();

return new NHibernateConfig(() => config, new StructureMapRepositoryFactory(), new ThreadStaticUnitOfWorkStorage());
}
}
}
2 changes: 2 additions & 0 deletions src/Security.Repository/Security.Repository.csproj
Expand Up @@ -90,6 +90,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RepoConfig.cs" />
<Compile Include="SecurityRepository.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Security\Security.csproj">
Expand Down
33 changes: 33 additions & 0 deletions src/Security.Repository/SecurityRepository.cs
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.SqlCommand;
using UoW.NHibernate;

namespace Security.Repository
{
public class SecurityRepository: NHibernateRepository, ISecurityRepository
{
public IList<Permission> GetPermissionsForUserActivity(User user, string activity)
{
ICriterion userIdMatches = Restrictions.Eq("Id", user.Id);
ICriterion activityNameMatches = Restrictions.Eq("Name", activity);
ICriterion userIdAliasMatches = Restrictions.Eq("u.Id", user.Id);

DetachedCriteria groupPermissionCriteria = DetachedCriteria.For<Permission>()
.SetProjection(Projections.Property("Role"))
.CreateCriteria("Role").CreateCriteria("Users").Add(userIdMatches);
ICriterion groupSubquery = Subqueries.PropertyIn("Role", groupPermissionCriteria);

DetachedCriteria permissionCriteria = DetachedCriteria.For<Permission>()
.CreateAlias("User", "u", JoinType.LeftOuterJoin)
.Add(Restrictions.Or(userIdAliasMatches, groupSubquery));
permissionCriteria.CreateCriteria("Activity").Add(activityNameMatches);

ICriteria executableCriteria = permissionCriteria.GetExecutableCriteria(Session);
IList<Permission> permissions = executableCriteria.List<Permission>();

return permissions;
}
}
}
6 changes: 6 additions & 0 deletions src/Security.Specs/Security.Specs.csproj
Expand Up @@ -66,6 +66,12 @@
<Name>Security</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\db\security.s3db">
<Link>security.s3db</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</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.
Expand Down
6 changes: 4 additions & 2 deletions src/Security.TestApp/Program.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Security.Repository;
using UoW;

namespace Security.TestApp
{
Expand All @@ -13,6 +13,8 @@ static class Program
[STAThread]
static void Main()
{
UnitOfWork.Configure(RepoConfig.GetConfiguration());

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Expand Down
62 changes: 62 additions & 0 deletions src/Security.TestApp/Security.TestApp.csproj
Expand Up @@ -31,10 +31,50 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Antlr3.Runtime, Version=3.1.0.39271, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Castle.DynamicProxy2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Castle.DynamicProxy2.dll</HintPath>
</Reference>
<Reference Include="FluentNHibernate, Version=1.0.0.593, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\log4net.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nhibernate\NHibernate.ByteCode.Castle.dll</HintPath>
</Reference>
<Reference Include="StructureMap, Version=2.5.3.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\StructureMap.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.SQLite, Version=1.0.60.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\database\System.Data.SQLite.DLL</HintPath>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
Expand All @@ -46,6 +86,14 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="UoW, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\database\UoW.dll</HintPath>
</Reference>
<Reference Include="UoW.NHibernate, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\database\UoW.NHibernate.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
Expand All @@ -65,6 +113,10 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Content Include="..\..\db\security.s3db">
<Link>security.s3db</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -75,6 +127,16 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Security.Repository\Security.Repository.csproj">
<Project>{8B2A0EEB-AF7C-4B51-8182-1D2A83A5E362}</Project>
<Name>Security.Repository</Name>
</ProjectReference>
<ProjectReference Include="..\Security\Security.csproj">
<Project>{5C6820F1-F420-4FD9-99DE-70BE667E7DC9}</Project>
<Name>Security</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
10 changes: 5 additions & 5 deletions src/Security/Permission.cs
Expand Up @@ -2,14 +2,14 @@
{
public class Permission
{
public virtual int Id{ get; set; }
public int Id{ get; set; }

public virtual bool IsAllowed { get; set; }
public bool IsAllowed { get; set; }

public virtual Activity Activity { get; set; }
public Activity Activity { get; set; }

public virtual User User { get; set; }
public User User { get; set; }

public virtual Role Group { get; set; }
public Role Role { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Security/User.cs
Expand Up @@ -2,6 +2,6 @@ namespace Security
{
public class User
{
int Id { get; set; }
public int Id { get; set; }
}
}

0 comments on commit a5a0624

Please sign in to comment.