public static RSMDB.Person Select(this Person entity, RSMDB.RSMDataModelDataContext context) { if (entity == null) { return(null); } if (entity.InternalId != 0) { return(context.Persons.FirstOrDefault(x => x.PersonID == entity.InternalId)); } // Missing InternalId - lookup by external Id if (string.IsNullOrWhiteSpace(entity.ExternalId)) { // no id to find return(null); } var findInternalId = context.ExternalApplicationKeys.FirstOrDefault( x => x.EntityType == "Person" && x.ExternalId == entity.ExternalId); return(findInternalId == null ? null : context.Persons.FirstOrDefault(x => x.PersonID == findInternalId.InternalId)); }
/// <summary> /// Adds keys for an external entity to the database. No existence check is performed prior to inserting. /// </summary> /// <param name="from">Entity to add</param> /// <returns></returns> public static Result <ExternalEntity> Add(this ExternalEntity from) { var result = Result <ExternalEntity> .Success(); try { using (var db = new RSMDB.RSMDataModelDataContext()) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, TransactionTimeout)) { if (from.KeysAdded == DateTime.MinValue) { from.KeysAdded = DateTime.Now; } var row = from.InsertKeys(db); if (row == null) { return(result.Fail("Add external entity keys failed")); } result.Entity = new ExternalEntity(); result.Entity = row.ToModel(result.Entity); transaction.Complete(); } } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Add external entity keys failed {0}", e.ToString())); } return(result); }
public static Result <AccessLog> Get(this AccessLog from, SelectKeys keyType = SelectKeys.External) { var result = Result <AccessLog> .Success(); var keys = (from as ExternalEntity).GetKeys(keyType); if (keys.Failed) { return(result.Merge(keys)); } try { keys.Entity.MapKeys(from); using (var db = new RSMDB.RSMDataModelDataContext()) { var row = from.Select(db); if (row == null) { return(result.Fail("AccessLog not found")); } result.Entity = row.ToModel(); keys.Entity.MapKeys(result.Entity); } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Get AccessLog failed. {0}", e.ToString())); } return(result); }
/// <summary> /// Search by specific criteria and optional date range on when Added. /// </summary> /// <param name="criteria">Fields considered: ExternalSystemId, EntityType</param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public static Result <List <ExternalEntity> > SearchKeys(this ExternalEntity criteria, DateTime?from = null, DateTime?to = null) { var result = new Result <List <ExternalEntity> >(); try { using (var db = new RSMDB.RSMDataModelDataContext()) { var type = Enum.GetName(typeof(EntityType), criteria.EntityType); var rows = criteria.SearchKeys(db, x => x.SystemId == criteria.ExternalSystemId && x.EntityType == type && (from == null || x.Added > from) && (to == null || x.Added < to)); result.Entity = rows.Select(x => x.ToModel <ExternalEntity>()).ToList(); } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Get AccessLog failed. {0}", e.ToString())); } return(result); }
public void TrackExportAccessHistory_Execute() { Task task = null; Result <string> result = Result <string> .Success(); var taskName = "TrackExportTest"; using (var context = new RSMDB.RSMDataModelDataContext()) { LoadTrackExportTestData(context, taskName); } try { task = Task.Create(taskName, new ServiceProfile()); var export = task as RSM.Integration.Track.Export.AccessEvents; result = export.Execute(null); } catch (Exception e) { Assert.Fail("Test exception! {0}", e.ToString()); } Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); }
public void Person_Get_External() { var externalId = "50"; var id = 1; var person = DataFactory.CreatePerson("John", "Smith", "middle"); using (var context = new RSMDB.RSMDataModelDataContext()) { context.Persons.InsertOnSubmit(person); context.SubmitChanges(); id = person.PersonID; var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); } var criteria = new Person { EntityType = EntityType.Person, ExternalSystemId = S2In.Id, ExternalId = externalId }; var result = criteria.Get(); Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); Assert.IsNotNull(result.Entity, "Missing entity"); Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity"); Assert.IsTrue(result.Entity.EntityType == EntityType.Person, "EntityType mismatch"); Assert.IsTrue((result.Entity as ExternalEntity).InternalId == id, "Incorrect id for entity"); }
public void TrackExportAccessHistory_CreateTask() { using (var context = new RSMDB.RSMDataModelDataContext()) { var setting = context.Settings.First(x => x.Id == StageData.Settings.TrackExportRepeat.Id); setting.Value = "true"; setting = context.Settings.First(x => x.Id == StageData.Settings.TrackExportRepeatInterval.Id); setting.Value = "12"; context.SubmitChanges(); } Task task = null; try { task = Task.Create("TrackExport", new ServiceProfile()); } catch (Exception e) { Assert.Fail("Create task failed! {0}", e.ToString()); } Assert.IsNotNull(task, "Missing task object"); Assert.IsTrue(task.ActivityName == "AccessEvents", "Wrong activity name {0}", task.ActivityName); Assert.IsTrue(task.Name == "TrackExport", "Wrong task name {0}", task.Name); Assert.IsTrue(task.Profile.Schedule.Repeat, "Repeat should be true"); Assert.IsTrue(task.Profile.Schedule.RepeatInterval.TotalMinutes == 12, "Wrong repeat interval {0}", task.Profile.Schedule.RepeatInterval.TotalMinutes); }
public void LubrizolEmployeeImport_Execute_NoStub() { const string taskName = "LubrizolImport"; var result = Result <string> .Success(); using (var context = new RSMDB.RSMDataModelDataContext()) { //Load settings. //Includes a field level filter on LoadLubrizolImportTestData(context, taskName); CreateTestPerson(context, "System", "", "Administrator", "_1", S2In); CreateTestPerson(context, "Chris", "", "Milum", "_2", S2In); } try { var task = Task.Create(taskName, new ServiceProfile()); var import = task as Integration.Lubrizol.Employees; result = import.Execute(null); } catch (Exception e) { Assert.Fail("Test exception! {0}", e.ToString()); } Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); }
public static void LoadS2ImportTestData(RSMDB.RSMDataModelDataContext context, string prefix) { var s2 = context.ExternalSystems.FirstOrDefault(x => x.Id == S2In.Id); var factory = new StageFactory(context); factory.createSetting(s2, prefix, S2Import.Repeat); factory.createSetting(s2, prefix, S2Import.RepeatInterval, "3"); factory.createSetting(s2, prefix, S2Import.LastAccessed); factory.createSetting(s2, prefix, S2Import.PersonImport, "true"); factory.createSetting(s2, prefix, S2Import.ServiceAddress, "http://localhost"); factory.createSetting(s2, prefix, S2Import.ServiceAccount, "asdfasasdfasd"); factory.createSetting(s2, prefix, S2Import.ServicePassword, "admin"); var location = factory.createLocation("Location1", action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Location, "Location1", s2.Id, location.LocationID); var portal = factory.createPortal("Portal1", location.LocationID, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Portal, "Portal1", s2.Id, portal.Id); var reader = factory.createReader("Reader1", portal.Id, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Reader, "Reader1", s2.Id, reader.Id); context.SubmitChanges(); }
/// <summary> /// Get External entity keys. /// </summary> /// <param name="from"></param> /// <param name="keyType"><typeparamref name="SelectKeys"/></param> /// <param name="replace">If true, criteria entity will be replaced with values retrieved.</param> /// <returns></returns> public static Result <ExternalEntity> GetKeys(this ExternalEntity from, SelectKeys keyType = SelectKeys.External, bool replace = false) { var result = Result <ExternalEntity> .Success(); try { using (var db = new RSMDB.RSMDataModelDataContext()) { var row = keyType == SelectKeys.External ? from.SelectExternal(db) : from.Select(db); if (row == null) { return(result.Fail("ExternalEntity not found", "NotFound")); } Debug.Assert(row.ExternalSystem != null, "ExternalSystem instance was not fetched!"); result.Entity = row.ToModel <ExternalEntity>(replace ? from : null); } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Get ExternalEntity failed. {0}", e.ToString())); } return(result); }
public void LubrizolEmployeeImport_CreateTask() { using (var context = new RSMDB.RSMDataModelDataContext()) { var name = string.Format("{0}.{1}", LubrizolImport.DefaultPrefix, LubrizolImport.Repeat.Name); var setting = context.Settings.First(x => x.Name == name); setting.Value = "false"; name = string.Format("{0}.{1}", LubrizolImport.DefaultPrefix, LubrizolImport.RepeatInterval.Name); setting = context.Settings.First(x => x.Name == name); setting.Value = "30"; context.SubmitChanges(); } Task task = null; try { task = Task.Create("LubrizolIn", new ServiceProfile()); } catch (Exception e) { Assert.Fail("Create task failed! {0}", e.ToString()); } Assert.IsNotNull(task, "Missing task object"); Assert.IsTrue(task.ActivityName == "LubrizolImport", "Wrong activity name {0}", task.ActivityName); Assert.IsTrue(task.Name == "LubrizolIn", "Wrong task name {0}", task.Name); Assert.IsTrue(!task.Profile.Schedule.Repeat, "Repeat should be false"); Assert.IsTrue(task.Profile.Schedule.RepeatInterval.TotalMinutes == 30, "Wrong repeat interval {0}", task.Profile.Schedule.RepeatInterval.TotalMinutes); }
public Person CreateTestPerson(RSMDB.RSMDataModelDataContext context, string firstName, string middleName, string lastName, string employeeId, ExternalSystem system, Bitmap imageFile = null) { var key = context.ExternalApplicationKeys.FirstOrDefault(x => x.EntityType == "Person" && x.ExternalId == employeeId); if (key != null) { DeleteTestPerson(context, employeeId, system); } var person = StageFactory.CreatePerson(firstName, lastName, middleName); if (imageFile != null) { var ms = new MemoryStream(); imageFile.Save(ms, ImageFormat.Jpeg); person.Image = ms.ToArray(); } context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var modelPerson = person.ToModel(); var keys = StageFactory.CreateExternalApplicationKey(EntityType.Person, employeeId, system.Id, person.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); keys.ToModel(modelPerson); return(modelPerson); }
public static Result <List <ExternalEntity> > PushList(this ExternalEntity src, ExternalEntity to) { var result = new Result <List <ExternalEntity> >(); if (src.EntityType != to.EntityType) { return(result.Fail("cannot derive a push list on different entity types.")); } if (src.ExternalSystemId == to.ExternalSystemId) { return(result.Fail("cannot derive a push list from the same system.")); } try { using (var db = new RSMDB.RSMDataModelDataContext()) { var type = Enum.GetName(typeof(EntityType), src.EntityType); var toQuery = db.ExternalApplicationKeys.Where(k => k.EntityType == type && k.SystemId == to.ExternalSystemId); var srcQuery = db.ExternalApplicationKeys.Where(k => k.EntityType == type && k.SystemId == src.ExternalSystemId); var rows = srcQuery.Where(s => !toQuery.Any(t => t.ExternalId == s.ExternalId)); result.Entity = rows.Select(x => x.ToModel <ExternalEntity>(null)).ToList(); } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Get push list failed. {0}", e.ToString())); } return(result); }
public static void LoadS2ImportTestData(RSMDB.RSMDataModelDataContext context, string prefix) { var s2 = context.ExternalSystems.FirstOrDefault(x => x.Id == S2In.Id); var factory = new StageFactory(context); //factory.createSetting(1001, string.Format("{0}.Repeat", prefix), "Allow S2 import task to repeat.", "true", 0, false, InputTypes.Checkbox, s2); //factory.createSetting(1002, string.Format("{0}.RepeatInterval", prefix), "S2 import repeat interval in minutes.", "3", 0, false, InputTypes.Text, s2); //factory.createSetting(1003, string.Format("{0}.LastAccessEvent", prefix), "Date time on last S2 record imported.", "", 0, false, InputTypes.Text, s2); //factory.createSetting(1004, string.Format("{0}.PersonImport", prefix), "Allow importing of People from S2.", "true", 0, false, InputTypes.Checkbox, s2); //factory.createSetting(1005, string.Format("{0}.ServiceAddress", prefix), "Appliance Address", "http://localhost", 2, true, InputTypes.Text, s2); //factory.createSetting(1006, string.Format("{0}.ServiceAccount", prefix), "S2 Service User Id", "asdfasasdfasd", 3, true, InputTypes.Text, s2); //factory.createSetting(1007, string.Format("{0}.ServicePassword", prefix), "S2 Service Password", "admin", 4, true, InputTypes.Password, s2); //factory.createSetting(1007, string.Format("{0}.ServicePassword", prefix), "S2 Service Password", "admin", 4, true, InputTypes.Password, s2); var location = factory.createLocation(name: "Location1", id: 1, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Location, "Location1", s2.Id, location.LocationID); var portal = factory.createPortal("Portal1", location.LocationID, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Portal, "Portal1", s2.Id, portal.Id); var reader = factory.createReader("Reader1", portal.Id, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Reader, "Reader1", s2.Id, reader.Id); context.SubmitChanges(); }
public static Result <ExternalEntity> MostRecent(this ExternalEntity criteria, DateTime?from = null, DateTime?to = null) { var result = new Result <ExternalEntity>(); try { using (var db = new RSMDB.RSMDataModelDataContext()) { var type = Enum.GetName(typeof(EntityType), criteria.EntityType); var rows = criteria.SearchKeys(db, x => x.SystemId == criteria.ExternalSystemId && x.EntityType == type && (from == null || x.Added > from) && (to == null || x.Added < to)).OrderByDescending(o => o.Added); result.Entity = rows.Select(x => x.ToModel <ExternalEntity>()).FirstOrDefault(); if (result.Entity == null) { return(result.Fail("most recent external entity not found.")); } } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Get AccessLog failed. {0}", e.ToString())); } return(result); }
public void Person_Add() { var externalId = "50"; var criteria = new Person { EntityType = EntityType.Person, ExternalSystemId = S2In.Id, ExternalId = externalId, FirstName = "FirstName", LastName = "Last", Added = DateTime.Now, udf4 = "Contractor company A" }; var result = criteria.Add(); Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); Assert.IsNotNull(result.Entity, "Missing entity"); Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity"); Assert.IsTrue(result.Entity.EntityType == EntityType.Person, "EntityType mismatch"); Assert.IsTrue(result.Entity.InternalId > 0, "Invalid id"); using (var context = new RSMDB.RSMDataModelDataContext()) { var keys = context.ExternalApplicationKeys.FirstOrDefault(x => x.ExternalId == externalId && x.SystemId == S2In.Id && x.EntityType == Enum.GetName(typeof(EntityType), EntityType.Person)); Assert.IsNotNull(keys, "Keys not created"); var row = context.Persons.FirstOrDefault(x => x.PersonID == keys.InternalId); Assert.IsNotNull(row, "Person not created"); } }
public void ExternalEntity_Get_Internal() { var externalId = "50"; var id = 1; var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, id); using (var context = new RSMDB.RSMDataModelDataContext()) { context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); } var criteria = new ExternalEntity { EntityType = EntityType.Person, ExternalSystemId = S2In.Id, InternalId = id }; var result = criteria.GetKeys(SelectKeys.Internal); Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); Assert.IsNotNull(result.Entity, "Missing entity"); Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity"); Assert.IsTrue(result.Entity.EntityType == EntityType.Person, "EntityType mismatch"); }
public void AccessLog_Get_External() { var externalId = "Access50"; var id = 1; var locationId = 1; using (var context = new RSMDB.RSMDataModelDataContext()) { var person = DataFactory.CreatePerson("first", "last", "middle"); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var keys = DataFactory.CreateExternalApplicationKey(EntityType.Person, externalId, S2In.Id, person.PersonID); context.ExternalApplicationKeys.InsertOnSubmit(keys); var location = DataFactory.CreateLocation("Location1"); context.Locations.InsertOnSubmit(location); context.SubmitChanges(); locationId = location.LocationID; var portal = DataFactory.CreatePortal("Portal1", locationId); context.Portals.InsertOnSubmit(portal); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Portal, externalId, S2In.Id, portal.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); var reader = DataFactory.CreateReader("Reader50", portal.Id); context.Readers.InsertOnSubmit(reader); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.Reader, externalId, S2In.Id, reader.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); var access = DataFactory.CreateAccessHistory("Access50", person.PersonID, portal.Id, reader.Id, 30); context.AccessHistories.InsertOnSubmit(access); context.SubmitChanges(); keys = DataFactory.CreateExternalApplicationKey(EntityType.AccessLog, externalId, S2In.Id, access.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); id = access.Id; } var criteria = new AccessLog { EntityType = EntityType.AccessLog, ExternalSystemId = S2In.Id, ExternalId = externalId }; var result = criteria.Get(); Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); Assert.IsNotNull(result.Entity, "Missing entity"); Assert.IsNotNull(result.Entity.ExternalSystem, "Missing ExternalSystem entity"); Assert.IsTrue(result.Entity.EntityType == EntityType.AccessLog, "EntityType mismatch"); Assert.IsTrue((result.Entity as ExternalEntity).InternalId == id, "Incorrect id for entity"); }
private void CallLubrizolExport_Click(object sender, EventArgs e) { const string taskName = "LubrizolExport"; const string employee1 = "TEST_1"; const string employee2 = "TEST_2"; Configuration.SaveConfigValue("ServiceId", "6"); Configuration.SaveConfigValue("ServiceName", "R1SM.LubrizolExport"); Configuration.SaveConfigValue("Description", "Performs export operations for R1SM's SharePoint integration."); Configuration.SaveConfigValue("Task1", "LubrizolExport"); var result = Result <string> .Success(); using (var context = new RSMDB.RSMDataModelDataContext()) { CreateTestPerson(context, StageData.People.R1Person1.FirstName, StageData.People.R1Person1.MiddleName, StageData.People.R1Person1.LastName, employee1, S2In, RSM.Service.Library.Tests.Properties.Resources.BadPiggies); CreateTestPerson(context, StageData.People.R1Person2.FirstName, StageData.People.R1Person2.MiddleName, StageData.People.R1Person2.LastName, employee2, S2In, RSM.Service.Library.Tests.Properties.Resources.AngryBirdsRed); } using (var context = new LubrizolData()) { CreateTestEmployee(context, StageData.People.R1Person1.FirstName, StageData.People.R1Person1.MiddleName, StageData.People.R1Person1.LastName, employee1, "Active"); CreateTestEmployee(context, StageData.People.R1Person2.FirstName, StageData.People.R1Person2.MiddleName, StageData.People.R1Person2.LastName, employee2, "Inactive"); } try { var task = Task.Create(taskName, new ServiceProfile()); var import = task as RSM.Integration.Lubrizol.Export.People; result = import.Execute(null); txtOutput.Text += Environment.NewLine + string.Format(result.Message); } catch (Exception ex) { txtOutput.Text += Environment.NewLine + string.Format("Test exception! {0}", ex.ToString()); } // Clean out test data using (var context = new RSMDB.RSMDataModelDataContext()) { DeleteTestPerson(context, employee1, S2In); DeleteTestPerson(context, employee2, S2In); } using (var context = new LubrizolData()) { DeleteTestEmployee(context, employee1); DeleteTestEmployee(context, employee2); } }
public void LubrizolEmployeeImport_Execute() { var taskName = "LubrizolImportAPIStub"; RSMModel.Person modelPerson; using (var context = new RSMDB.RSMDataModelDataContext()) { //Load settings. //Includes a field level filter on LoadLubrizolImportTestData(context, taskName); //Create an existing person that will be updated var person = StageFactory.CreatePerson("OrigFirst2", "OrigLast", "OrigMid"); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); modelPerson = person.ToModel(); var keys = StageFactory.CreateExternalApplicationKey(EntityType.Person, "2", S2In.Id, person.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); keys.ToModel(modelPerson); } Task task = null; Result <string> result = Result <string> .Success(); try { task = Task.Create(taskName, new ServiceProfile()); var import = task as RSM.Integration.S2.Import.People; result = import.Execute(null); } catch (Exception e) { Assert.Fail("Test exception! {0}", e.ToString()); } Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); using (var context = new RSMDB.RSMDataModelDataContext()) { var newPerson = context.Persons.FirstOrDefault(x => x.PersonID == modelPerson.InternalId); Assert.IsTrue(newPerson.MiddleName == modelPerson.MiddleName, "Middle name updated but not in field list to update."); Assert.IsTrue(newPerson.FirstName != modelPerson.FirstName, "First name should have been updated."); Assert.IsTrue(newPerson.Image != modelPerson.Image, "Image should have been updated."); var newKeys = context.ExternalApplicationKeys.FirstOrDefault(x => x.ExternalId == modelPerson.ExternalId && x.InternalId == modelPerson.InternalId && x.SystemId == modelPerson.ExternalSystemId && x.EntityType == Enum.GetName(typeof(EntityType), EntityType.Person)); Assert.IsTrue(newKeys.ExternalEntityLastUpdated != null, "ExternalEntityLastUpdated should have been updated."); Assert.IsTrue(context.Persons.FirstOrDefault(x => x.UDF4 == null || x.UDF4.Length == 0) == null, "There should be no records with an empty UDF4 field due to field filter."); } }
public static void LoadTrackExportTestData(RSMDB.RSMDataModelDataContext context, string prefix) { var s2 = context.ExternalSystems.FirstOrDefault(x => x.Id == S2In.Id); var trackOut = context.ExternalSystems.FirstOrDefault(x => x.Id == TrackOut.Id); var factory = new StageFactory(context); factory.createSetting(trackOut, prefix, TrackExport.Repeat); factory.createSetting(trackOut, prefix, TrackExport.RepeatInterval); factory.createSetting(trackOut, prefix, TrackExport.LastAccessEvent); factory.createSetting(trackOut, prefix, TrackExport.PersonExport); factory.createSetting(trackOut, prefix, TrackExport.ServiceAddress, "http://localhost:8088/mockACS2TrackWebSvcSoap12"); factory.createSetting(trackOut, prefix, TrackExport.Account); factory.createSetting(trackOut, prefix, TrackExport.Password); factory.createSetting(trackOut, prefix, TrackExport.SourceSystem, s2.Id.ToString()); factory.createSetting(trackOut, prefix, TrackExport.LocationExport); factory.createSetting(trackOut, prefix, TrackExport.AccessExport); factory.createSetting(trackOut, prefix, TrackExport.EventCode); factory.createSetting(trackOut, prefix, TrackExport.SysId); factory.createSetting(trackOut, prefix, TrackExport.DataSource); factory.createSetting(trackOut, prefix, TrackExport.CompanyExport); var location = factory.createLocation("Location1", action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Location, "Location1", s2.Id, location.LocationID); factory.createExternalApplicationKey(EntityType.Location, "1", trackOut.Id, location.LocationID); var portal = factory.createPortal("Portal 1001", location.LocationID, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Portal, "1001", s2.Id, portal.Id); var reader = factory.createReader("Reader1", portal.Id, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Reader, "Reader1", s2.Id, reader.Id); var person = factory.createPerson("Jane", "Smith", null, UDFs: new Dictionary <int, string> { { 4, "Contractor Co1" } }, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Person, "Person1", s2.Id, person.Id); var start = DateTime.Now; for (var i = 0; i < 5; i++) { var extId = string.Format("access{0}", i); var access = factory.createAccessHistory(extId, person.Id, portal.Id, reader.Id, (int)AccessType.Valid, accessed: start.Subtract(TimeSpan.FromMinutes(i)), action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.AccessLog, extId, s2.Id, access.Id); } context.SubmitChanges(); }
public virtual void Initialize() { Cleanup(); using (var context = new RSMDB.RSMDataModelDataContext()) { var sysList = new List <RSMDB.ExternalSystem>() { StageFactory.CreateExternalSystem(1, Constants.R1SMSystemName, RSMDB.ExternalSystemDirection.None), StageFactory.CreateExternalSystem(2, "S2 Import", RSMDB.ExternalSystemDirection.Incoming), StageFactory.CreateExternalSystem(3, "Track", RSMDB.ExternalSystemDirection.Outgoing), StageFactory.CreateExternalSystem(4, "S2 Export", RSMDB.ExternalSystemDirection.Outgoing), StageFactory.CreateExternalSystem(5, "PeopleSoft", RSMDB.ExternalSystemDirection.Incoming), }; var settingsList = new List <RSMDB.Setting>() { StageFactory.CreateSetting(1, "RuleEngineAllow", "Allow the R1SM rule engine to assign roles.", "false", 0, true, InputTypes.Checkbox, sysList[0]), StageFactory.CreateSetting(2, "JobCodesFirst", "Show job codes before job titles when editing rules.", "false", 1, true, InputTypes.Checkbox, sysList[0]), StageFactory.CreateSetting(3, "RequireAccessApproval", "Require approval of changes made by the rule engine", "false", 2, false, InputTypes.Checkbox, sysList[0]), StageFactory.CreateSetting(4, "AdminPass", "New Admin Password", "Testing", 3, true, InputTypes.Password, sysList[0]), StageFactory.CreateSetting(5, "LevelImport", "Allow importing of levels from S2.", "false", 1, true, InputTypes.Text, sysList[1]), StageFactory.CreateSetting(6, "S2Import.ServiceAddress", "Appliance Address", "http://localhost", 2, true, InputTypes.Text, sysList[1]), StageFactory.CreateSetting(7, "S2Import.PersonImport", "Allow importing of People from S2.", "true", 0, true, InputTypes.Checkbox, sysList[1]), StageFactory.CreateSetting(8, "TrackExport.PersonExport", "Allow exporting of People to Track", "true", 0, true, InputTypes.Checkbox, sysList[2]), StageFactory.CreateSetting(9, "TrackExport.LocationExport", "Allow exporting of Locations to Track", "true", 1, true, InputTypes.Checkbox, sysList[2]), StageFactory.CreateSetting(10, "TrackExport.AccessExport", "Allow exporting of Access History to Track", "true", 2, true, InputTypes.Checkbox, sysList[2]), StageFactory.CreateSetting(11, "S2Import.ServiceAccount", "S2 Service User Id", "asdfasasdfasd", 3, true, InputTypes.Text, sysList[1]), StageFactory.CreateSetting(12, "S2Import.ServicePassword", "S2 Service Password", "admin", 4, true, InputTypes.Password, sysList[1]), StageFactory.CreateSetting(13, "PersonExport", "Allow exporting of user data and roles to S2", "false", 0, false, InputTypes.Checkbox, sysList[1]), StageFactory.CreateSetting(14, "S2Import.Repeat", "Allow S2 import task to repeat.", "true", 0, false, InputTypes.Checkbox, sysList[1]), StageFactory.CreateSetting(15, "S2Import.RepeatInterval", "S2 import repeat interval in minutes.", "3", 0, false, InputTypes.Text, sysList[1]), StageFactory.CreateSetting(16, "S2Import.LastAccessEvent", "Date time of last access record imported from S2.", "", 0, false, InputTypes.Text, sysList[1]), StageFactory.CreateSetting(17, "TrackExport.ServiceAddress", "Appliance Address", "http://localhost", 2, true, InputTypes.Text, sysList[2]), StageFactory.CreateSetting(18, "TrackExport.ServiceAccount", "Track Service User Id", "asdfasasdfasd", 3, true, InputTypes.Text, sysList[2]), StageFactory.CreateSetting(19, "TrackExport.ServicePassword", "Track Service Password", "admin", 4, true, InputTypes.Password, sysList[2]), StageFactory.CreateSetting(20, "TrackExport.LastAccessEvent", "Date time of last access record exported to Track.", "", 0, false, InputTypes.Text, sysList[2]), StageFactory.CreateSetting(21, "TrackExport.SourceSystem", "System whose data will be exported to Track.", "", 0, false, InputTypes.Text, sysList[2]), StageFactory.CreateSetting(22, "TrackExport.Repeat", "Allow Track export task to repeat.", "true", 0, false, InputTypes.Checkbox, sysList[2]), StageFactory.CreateSetting(23, "TrackExport.RepeatInterval", "Track export repeat interval in minutes.", "3", 0, false, InputTypes.Text, sysList[2]), StageFactory.CreateSetting(24, "TrackExport.LastAccessEvent", "Date time of last access record exported to Track.", "", 0, false, InputTypes.Text, sysList[2]), StageFactory.CreateSetting(25, "S2Import.Contractors", "Comma delimited list of contractors to get from S2.", "S & B,Mustang", 0, false, InputTypes.Text, sysList[1]), }; context.ExternalSystems.InsertAllOnSubmit(sysList); context.Settings.InsertAllOnSubmit(settingsList); context.SubmitChanges(); } }
public static void LoadTrackExportTestData(RSMDB.RSMDataModelDataContext context, string prefix) { var s2 = context.ExternalSystems.FirstOrDefault(x => x.Id == S2In.Id); var trackOut = context.ExternalSystems.FirstOrDefault(x => x.Id == TrackOut.Id); var factory = new StageFactory(context); factory.createSetting(1001, string.Format("{0}.Repeat", prefix), "Allow task to repeat.", "true", 0, false, InputTypes.Checkbox, trackOut); factory.createSetting(1002, string.Format("{0}.RepeatInterval", prefix), "repeat interval in minutes.", "3", 0, false, InputTypes.Text, trackOut); factory.createSetting(1003, string.Format("{0}.LastAccessEvent", prefix), "Date time on last record exported.", "", 0, false, InputTypes.Text, trackOut); factory.createSetting(1004, string.Format("{0}.PersonExport", prefix), "Allow export of People.", "true", 0, false, InputTypes.Checkbox, trackOut); factory.createSetting(1005, string.Format("{0}.ServiceAddress", prefix), "Appliance Address", "http://localhost:8088/mockACS2TrackWebSvcSoap12", 2, true, InputTypes.Text, trackOut); factory.createSetting(1006, string.Format("{0}.ServiceAccount", prefix), "Service User Id", "asdfasasdfasd", 3, true, InputTypes.Text, trackOut); factory.createSetting(1007, string.Format("{0}.ServicePassword", prefix), "Service Password", "admin", 4, true, InputTypes.Password, trackOut); factory.createSetting(1008, string.Format("{0}.SourceSystem", prefix), "System whose data will be exported to Track.", s2.Id.ToString(), 0, false, InputTypes.Text, trackOut); factory.createSetting(1009, string.Format("{0}.LocationExport", prefix), "Allow exporting of Locations to Track", "true", 1, true, InputTypes.Checkbox, trackOut); factory.createSetting(10010, string.Format("{0}.AccessExport", prefix), "Allow exporting of Access History to Track", "true", 2, true, InputTypes.Checkbox, trackOut); factory.createSetting(10011, string.Format("{0}.EventCode", prefix), "Event Code value for export to Track.", "8", 0, false, InputTypes.Text, trackOut); factory.createSetting(10012, string.Format("{0}.SysId", prefix), "System Id value for export to Track.", "1", 0, false, InputTypes.Text, trackOut); factory.createSetting(10013, string.Format("{0}.DataSource", prefix), "DataSource value for export to Track.", "TSTLBZDB", 0, false, InputTypes.Text, trackOut); factory.createSetting(10014, string.Format("{0}.CompanyExport", prefix), "Allow exporting of Companies to Track", "true", 1, true, InputTypes.Checkbox, trackOut); var location = factory.createLocation("Location1", action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Location, "Location1", s2.Id, location.LocationID); factory.createExternalApplicationKey(EntityType.Location, "1", trackOut.Id, location.LocationID); var portal = factory.createPortal("Portal 1001", location.LocationID, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Portal, "1001", s2.Id, portal.Id); var reader = factory.createReader("Reader1", portal.Id, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Reader, "Reader1", s2.Id, reader.Id); var person = factory.createPerson("Jane", "Smith", null, UDFs: new Dictionary <int, string> { { 4, "Contractor Co1" } }, action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.Person, "Person1", s2.Id, person.Id); var start = DateTime.Now; for (var i = 0; i < 5; i++) { var extId = string.Format("access{0}", i); var access = factory.createAccessHistory(extId, person.Id, portal.Id, reader.Id, (int)AccessType.Valid, accessed: start.Subtract(TimeSpan.FromMinutes(i)), action: EntityAction.InsertAndSubmit); factory.createExternalApplicationKey(EntityType.AccessLog, extId, s2.Id, access.Id); } context.SubmitChanges(); }
public virtual void Cleanup() { using (var context = new RSMDB.RSMDataModelDataContext()) { context.AccessHistories.DeleteAllOnSubmit(context.AccessHistories); context.ExternalApplicationKeys.DeleteAllOnSubmit(context.ExternalApplicationKeys); context.Readers.DeleteAllOnSubmit(context.Readers); context.Portals.DeleteAllOnSubmit(context.Portals); context.Locations.DeleteAllOnSubmit(context.Locations); context.Persons.DeleteAllOnSubmit(context.Persons); context.Settings.DeleteAllOnSubmit(context.Settings); context.ExternalSystems.DeleteAllOnSubmit(context.ExternalSystems); context.SubmitChanges(); } }
public static Result <AccessLog> Add(this AccessLog from) { var result = Result <AccessLog> .Success(); var exists = from.Get(); if (exists.Succeeded) { exists.Set(ResultType.Warning, "AccessLog already exists {0}", from.InternalId.ToString()); return(exists); } try { using (var db = new RSMDB.RSMDataModelDataContext()) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, TransactionTimeout)) { var row = from.Insert(db); if (row == null) { return(result.Fail("Add AccessLog failed")); } from.InternalId = row.Id; from.KeysAdded = DateTime.Now; var keys = (from as ExternalEntity).InsertKeys(db); if (row == null || keys == null) { return(result.Fail("Add AccessLog failed")); } result.Entity = row.ToModel(); keys.ToModel(result.Entity); transaction.Complete(); } } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Add AccessLog failed. {0}", e.ToString())); } return(result); }
public static Result <List <Person> > Search(this Person criteria, DateTime?updatedFrom = null) { var result = new Result <List <Person> >(); try { using (var db = new RSMDB.RSMDataModelDataContext()) { var where = criteria.Search(db, x => true); if (updatedFrom != null) { where = where.Where(x => x.LastUpdated > updatedFrom); } if (criteria.ExternalSystemId != 0) { var type = Enum.GetName(typeof(EntityType), EntityType.Person); where = where.Where(x => db.ExternalApplicationKeys.Any(k => k.InternalId == x.PersonID && k.SystemId == criteria.ExternalSystemId && k.EntityType == type)); } where = where.OrderBy(x => x.LastUpdated); result.Entity = where.Select(x => x.ToModel(null)).ToList(); if (criteria.ExternalSystemId != 0) { //hydrate the keys foreach (var entity in result.Entity) { // Add the missing External Key to the entity entity.ExternalSystemId = criteria.ExternalSystemId; ((ExternalEntity)entity).GetKeys(SelectKeys.Internal, true); } } } } catch (Exception e) { return(result.Set(ResultType.TechnicalError, e, "Search people failed. {0}", e.ToString())); } return(result); }
public Person CreateTestPerson(RSMDB.RSMDataModelDataContext context, string firstName, string middleName, string lastName, string employeeId, ExternalSystem system) { var person = StageFactory.CreatePerson(firstName, lastName, middleName); context.Persons.InsertOnSubmit(person); context.SubmitChanges(); var modelPerson = person.ToModel(); var keys = StageFactory.CreateExternalApplicationKey(EntityType.Person, employeeId, system.Id, person.Id); context.ExternalApplicationKeys.InsertOnSubmit(keys); context.SubmitChanges(); keys.ToModel(modelPerson); return(modelPerson); }
public static RSMDB.Person Update(this Person entity, RSMDB.RSMDataModelDataContext context, bool overrideLastUpdate = true) { var row = Select(entity, context); if (row == null) { return(null); } row.LastUpdated = overrideLastUpdate ? DateTime.Now : entity.LastUpdated; row.FirstName = entity.FirstName; row.LastName = entity.LastName; row.MiddleName = entity.MiddleName; row.Active = entity.Active; row.UDF1 = entity.udf1; row.UDF2 = entity.udf2; row.UDF3 = entity.udf3; row.UDF4 = entity.udf4; row.UDF5 = entity.udf5; row.UDF6 = entity.udf6; row.UDF7 = entity.udf7; row.UDF8 = entity.udf8; row.UDF9 = entity.udf9; row.UDF10 = entity.udf10; row.UDF11 = entity.udf11; row.UDF12 = entity.udf12; row.UDF13 = entity.udf13; row.UDF14 = entity.udf14; row.UDF15 = entity.udf15; row.UDF16 = entity.udf16; row.UDF17 = entity.udf17; row.UDF18 = entity.udf18; row.UDF19 = entity.udf19; row.UDF20 = entity.udf20; row.BadgeNumber = entity.BadgeNumber; if (entity.Image != null) { row.Image = entity.Image; } context.SubmitChanges(); return(row); }
public void S2ImportAccessHistory_Execute() { var taskName = "S2ImportAccessAPIStub"; var lastLogId = 0; using (var context = new RSMDB.RSMDataModelDataContext()) { LoadS2ImportTestData(context, taskName); lastLogId = context.LogEntries.Any() ? context.LogEntries.Max(x => x.ID) : 0; } Task task = null; Result <string> result = Result <string> .Success(); try { task = Task.Create(taskName, new ServiceProfile(), "S2Import"); var import = task as RSM.Integration.S2.Import.AccessHistory; result = import.Execute(null); } catch (Exception e) { Assert.Fail("Test exception! {0}", e.ToString()); } Assert.IsNotNull(result, "Missing results"); Assert.IsTrue(result.Succeeded, result.ToString()); using (var context = new RSMDB.RSMDataModelDataContext()) { var histories = context.AccessHistories; // 1 for Mustang Filter, 1 for S & B Filter Assert.IsTrue(histories.Count() == 2, "Incorrect number of access logs imported."); var logs = context.LogEntries.Where(x => x.ID > lastLogId); Assert.IsTrue(logs.Any(x => x.Message.Contains("BadPerson")), "Invalid person logged."); Assert.IsTrue(logs.Any(x => x.Message.Contains("BadPortal")), "Invalid portal logged."); Assert.IsTrue(logs.Any(x => x.Message.Contains("BadReader")), "Invalid reader logged."); } }
public static RSMDB.AccessHistory Insert(this AccessLog entity, RSMDB.RSMDataModelDataContext context) { var row = new RSMDB.AccessHistory { PersonId = entity.PersonId, PortalId = entity.PortalId, ReaderId = entity.ReaderId, Reason = entity.Reason, Type = entity.AccessType, Accessed = entity.Accessed, }; context.AccessHistories.InsertOnSubmit(row); context.SubmitChanges(); return(row); }