Skip to content

Instantly share code, notes, and snippets.

@manadart
Created October 25, 2011 13:41
Show Gist options
  • Save manadart/1312760 to your computer and use it in GitHub Desktop.
Save manadart/1312760 to your computer and use it in GitHub Desktop.
Quick and nasty example of instantiation and use of the new GT APM.
using System.Configuration;
using GeomaticTechnologies.Databases;
using GeomaticTechnologies.Security.Apm;
using GeomaticTechnologies.Security.Apm.ClauseGenerators;
using GeomaticTechnologies.Security.Apm.DataServices;
using TinyIoC;
namespace NewApmDemo
{
public static class IoC
{
public static void BootStrap()
{
InitDatabase();
var container = TinyIoCContainer.Current;
container.Register(Database.GetDatabase());
container.Register<IApmDataService, DbDirect>();
container.Register<IApmClauseGenerator, ApmSqlClauseGenerator>();
container.Register<ApmUserAuthorisation>();
}
public static ApmUserAuthorisation GetApmGood(string userId)
{
var apm = TinyIoCContainer.Current.Resolve<ApmUserAuthorisation>();
apm.Initialise(userId);
return apm;
}
public static ApmUserAuthorisation GetApmBad(string userId)
{
InitDatabase();
var ds = new DbDirect(Database.GetDatabase());
var cg = new ApmSqlClauseGenerator();
var apm = new ApmUserAuthorisation(ds, cg);
apm.Initialise(userId);
return apm;
}
private static void InitDatabase()
{
var connectConfig = ConfigurationManager.ConnectionStrings["demo"];
Database.SetDefault(connectConfig.ProviderName, connectConfig.ConnectionString);
}
}
}
using System;
using System.Windows.Forms;
namespace NewApmDemo
{
static class Program
{
[STAThread]
static void Main()
{
IoC.BootStrap();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Demo());
}
}
}
using System;
using System.Windows.Forms;
using GeomaticTechnologies.Security.Apm;
namespace NewApmDemo
{
public partial class Demo : Form
{
private ApmUserAuthorisation _apm;
public Demo() { InitializeComponent(); }
private void btnApm_Click(object sender, EventArgs e)
{
_apm = IoC.GetApmGood(txtUserId.Text);
MessageBox.Show("Initialised");
}
private void btnT1Ts45_Click(object sender, EventArgs e)
{
MessageBox.Show(_apm.Validate(1, 45).ToString()); // Returns False.
}
private void btnTierAspPageTierSetEditGmu_Click(object sender, EventArgs e)
{
MessageBox.Show(_apm.Validate("ASP Page", "EditGMU.aspx").ToString()); // Returns True.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment