public override CommandExecutionResult Execute() { try { using (var adminContext = new AdministrationDbContext()) { var system = adminContext.GetSystemInstance(); Log.Info(system.Description); var agencies = adminContext.GetSystemInstance() .Agencies .Select(a => new { a.Name, a.Jurisdiction.Ori }) .ToList(); foreach (var agency in agencies) { Log.Info("[{0}]\t{1}", agency.Ori, agency.Name); } } } catch (Exception ex) { return(CommandExecutionResult.Exception(ex)); } return(CommandExecutionResult.Ok()); }
public override CommandExecutionResult Execute() { var ctx = new AdministrationDbContext(); var rmsSystem = ctx.GetSystemInstance(); var sysAdmin = rmsSystem.FindIdentity("sys_admin"); if (Password != null) { if (string.IsNullOrWhiteSpace(Password)) { return(CommandExecutionResult.Fail("Password cannot be blank")); } sysAdmin.SetPassword(Password); } if (Enable) { sysAdmin.MakeActive(); } if (Disable) { sysAdmin.MakeActive(false); } ctx.SaveChanges(); return(CommandExecutionResult.Ok()); }
/// <summary> /// Provides the roles needed for the user to interact with the STS. /// </summary> public IEnumerable <string> GetRoles(string userName) { var roles = new List <string>(); using (var context = new AdministrationDbContext() as IAdministrationUnitOfWork) { var rmsSystem = context.GetSystemInstance(); var identity = rmsSystem.FindIdentity(userName); if (identity == null) { return(roles); } if (identity.IsActive) // the user can request a token ( We may need to look closer at this ) { roles.Add(IdentityServerUsersRole); } if (identity.IsAdministrator) // the user can administer the STS ( Should Interface Accounts be able to do this? ) { roles.Add(IdentityServerAdministratorsRole); } } return(roles); }
/// <summary> /// Import any Agency Specific Violation Codes /// </summary> /// <param name="agencyId">Id of the Agency to Import Codes for.</param> /// <param name="classicRmsConnectionString">Connection string to the Classic RMS Database.</param> public static void ImportAgencyViolationCodes(Guid agencyId, string classicRmsConnectionString) { using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); ImportAgencyViolationsFromClassicRms(rmsSystem, agencyId, classicRmsConnectionString); context.Commit(); } }
public static void Setup() { using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); rmsSystem.Settings["TODO"] = "There are currently no Default System Configurations."; context.Commit(); } }
public override CommandExecutionResult Execute() { using (var ctx = new AdministrationDbContext()) { var rmsSystem = ctx.GetSystemInstance(); var sysInfo = "Description: " + rmsSystem.Description + Environment.NewLine + "Key: [" + rmsSystem.Id.As64BitString() + "]" + Environment.NewLine + "Version: " + rmsSystem.Version + Environment.NewLine; return(CommandExecutionResult.Ok(sysInfo)); } }
/// <summary> /// Update the Agency Specific Violation Codes for all Agencies in the system. /// </summary> /// <remarks>TODO: We are assuming the update process has purged all existing Violations.</remarks> public static void UpdateAllAgencies(string classicRmsConnectionString) { using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); var agencyIds = rmsSystem.Agencies.Select(x => x.Id).ToList(); foreach (var agencyId in agencyIds) { ImportAgencyViolationsFromClassicRms(rmsSystem, agencyId, classicRmsConnectionString); } context.Commit(); } }
/// <summary> /// Setup the Classic Integration Role in the Agency. /// </summary> /// <param name="agencyId">Id of the Agency to Create the Role in.</param> /// <returns>Id of the new Role.</returns> public static Guid Setup(Guid agencyId) { using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); var etlAccount = rmsSystem.FindIdentity(ClassicIntegrationAccount.Username); var agency = rmsSystem.GetAgency(agencyId); var etlRole = CreateInAgency(agency); etlAccount.AssignRole(etlRole); SetupRolePermissions(etlRole); context.Commit(); return(etlRole.Id); } }
private void button1_Click(object sender, EventArgs e) { var metadataContext = new MetadataDbContext(); var adminContext = new AdministrationDbContext(); foreach (var agency in adminContext.GetSystemInstance().Agencies) { foreach (var contract in metadataContext.GetEntityQuery <DataEntryContract>()) { TemplateFactory.Create(agency, contract); } } adminContext.SaveChanges(); }
/// <summary> /// Import ImageInfo codes from the ClassicRMS database into the RMSSystem instance. /// </summary> public static void ImportFromClassicRms(string classicRmsConnectionString) { // TODO: Until Codes are managed in Web we must purge everytime we update from Classic. Purge(); using (var context = new AdministrationDbContext()) { // Get the RMSSystem Instance var rmsSystem = context.GetSystemInstance(); // Load the SMT Codes into the RMSSystem LoadSMTCodes(rmsSystem); // Save any Changes context.Commit(); } }
/// <summary> /// Setup any Default Accounts in the new RMSSystem /// </summary> public static void SetupDefaultAccounts( ) { Log.Info("Setting up default accounts"); using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); // Setup System Admin Account SysAdminAccount.Setup(rmsSystem); // Setup Classic Integration Account ClassicIntegrationAccount.Setup(rmsSystem); context.Commit(); } }
/// <summary> /// Register the Default Modules with the RMSSystem. /// </summary> public static void Register() { Log.Info("Registering Default Modules"); using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); // TODO: Look into seeding more detailed information into the Resources table.(ModuleTypeInfo) var moduleTypes = ModuleTypeInfo.AllModules; moduleTypes.ForEach(moduleType => rmsSystem.CreateResource(moduleType, moduleType.GetDescription())); context.Commit(); } }
private static void LoadUcrCodes(string classicRmsConnectionString) { using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); using (var conn = new SqlConnection(classicRmsConnectionString)) { conn.Open(); using (var ucrCodesData = new DataSet()) { const string ucrSelect = "SELECT DISTINCT [Ucr_Code_Link],[UCR_Code],[Description],[OK_Incident],[OK_Arrest],[In_Summary],[Off_Group] ,[UCR_Class],[UCR_Sub_Class], [Crime_Part] FROM [VSI_SYSTEM].[dbo].[UCR_Code]"; using (var adapter = new SqlDataAdapter(ucrSelect, conn)) adapter.Fill(ucrCodesData, "UCRCodes"); Log.Info("Importing {0} UCR Codes", ucrCodesData.Tables["UCRCodes"].Rows.Count); foreach (DataRow ucrCodeRow in ucrCodesData.Tables["UCRCodes"].Rows) { // Find or create UCR Code record var classicId = Convert.ToInt32(ucrCodeRow["Ucr_Code_Link"].ToString()); var value = ucrCodeRow["UCR_Code"] as string; var description = ucrCodeRow["Description"] as string; var incident = Convert.ToBoolean(ucrCodeRow["OK_Incident"].ToString()); var arrest = Convert.ToBoolean(ucrCodeRow["OK_Arrest"].ToString()); var summary = Convert.ToBoolean(ucrCodeRow["In_Summary"].ToString()); var offGroup = ucrCodeRow["Off_Group"] as string; var ucrClass = ucrCodeRow["UCR_Class"] as string; var ucrSubClass = ucrCodeRow["UCR_Sub_Class"] as string; var crimePart = ucrCodeRow["Crime_Part"] as string; rmsSystem.CreateUcrCode(classicId, value, description, incident, arrest, summary, offGroup, ucrClass, ucrSubClass, crimePart); } } } context.Commit(); } }
public IEnumerable <Claim> GetClaims(ClaimsPrincipal principal, RequestDetails requestDetails) { using (var context = new AdministrationDbContext() as IAdministrationUnitOfWork) { var rmsSystem = context.GetSystemInstance(); var userName = principal.Identity.Name; var identity = rmsSystem.FindIdentity(userName); var claims = new List <Claim>(from c in principal.Claims select c); if (identity == null) { throw new Exception("Username was not found."); } claims.Add(new Claim(ClaimTypes.Sid, identity.Id.ToString())); claims.Add(new Claim(ClaimTypes.Email, identity.EmailAddress ?? String.Empty)); var @interface = identity as Interface; if (@interface != null) // description is name for an interface { claims.Add(new Claim(ClaimTypes.GivenName, @interface.Description ?? String.Empty)); } var user = identity as User; if (user != null) { claims.Add(new Claim(ClaimTypes.GivenName, user.FullName ?? String.Empty)); claims.Add(new Claim(ClaimTypes.PrimaryGroupSid, user.PrimaryAgencyId.ToString())); } var systemAccount = identity as SystemAccount; if (systemAccount != null) { claims.Add(new Claim(ClaimTypes.GivenName, systemAccount.Username)); } return(claims); } }
/// <summary> /// Performs user credentials validation. /// </summary> public bool ValidateUser(string userName, string password) { // Nothing to Check if (string.IsNullOrEmpty(userName)) { return(false); } using (var context = new AdministrationDbContext() as IAdministrationUnitOfWork) { var rmsSystem = context.GetSystemInstance(); var loginResult = rmsSystem.Login(userName, password); context.Commit(); // TODO: At some point if the audit is moved back into the application stack we will need messaging to coordinate the audit of the login. // Audit the Result AuditResult(userName, loginResult); return(loginResult.Success); } }
private static Guid CreateAgency(string name, string ori) { using (var context = new AdministrationDbContext()) { // Get the RMSSystem Instance var rmsSystem = context.GetSystemInstance(); // Create a New Agency var agency = rmsSystem.CreateAgency(name, ori); // Activate the Agency agency.MakeActive(); // Licensing Stuff (Not really used yet) LicenseDefaultModules(rmsSystem, agency); // Save context.Commit(); return(agency.Id); } }
private static void ImportNcicCodes(string classicRmsConnectionString) { using (var context = new AdministrationDbContext()) using (var conn = new SqlConnection(classicRmsConnectionString)) { var rmsSystem = context.GetSystemInstance(); conn.Open(); using (var ncicCodesData = new DataSet()) { const string ncicSelect = "SELECT DISTINCT [NCIC_Code_Validation_Link], [Category], [Code], [Description], [Code_Name], [Global] ,[Code_Length], [InActive] FROM [VSI_SYSTEM].[dbo].[NCIC_Code_Validation] WHERE Category = 'SCA'"; using (var adapter = new SqlDataAdapter(ncicSelect, conn)) adapter.Fill(ncicCodesData, "NCICCodes"); Log.Info("Importing {0} NCIC Codes for Scars/Marks", ncicCodesData.Tables["NCICCodes"].Rows.Count); foreach (DataRow ncicCodeRow in ncicCodesData.Tables["NCICCodes"].Rows) { // Find or create UCR Code record var classicId = Convert.ToInt32(ncicCodeRow["NCIC_Code_Validation_Link"].ToString()); var category = ncicCodeRow["Category"] as string; var code = ncicCodeRow["Code"] as string; var description = ncicCodeRow["Description"] as string; var codeName = ncicCodeRow["Code_Name"] as string; var global = ncicCodeRow["Global"] as bool?; var codeLength = ncicCodeRow["Code_Length"] as int?; var inActive = ncicCodeRow["InActive"] as bool?; rmsSystem.CreateNCICCode(classicId, category, code, description, codeName, global, codeLength, inActive); } } context.Commit(); } }
/// <summary> /// Create the "Developer" user in an Agency. /// Also assign the user to all roles in the system. /// </summary> /// <param name="homeAgencyId">Id of the Agency the developer account belongs to.</param> /// <returns></returns> public static Guid CreateInAgency(Guid homeAgencyId) { Log.Info("Creating Developer User Account"); using (var context = new AdministrationDbContext()) { var rmsSystem = context.GetSystemInstance(); var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(homeAgencyId); // Create the User Account var devUser = rmsSystem.CreateUserAccount(UniqueId, agency, Username, "developer"); devUser.FirstName = "Evolution"; devUser.LastName = "Developer"; // Find all Roles in the System except the "etl" role. var roles = context.Set <Role>() .Where(x => x.Name != ClassicIntegrationRole.Name).ToList(); // Assign the developer account to all roles in the System. roles.ForEach(role => devUser.AssignRole(role)); // Create an Officer for the developer account var devOfficer = agency.CreateOfficerFromUser(devUser); devOfficer.OfficerId = "47"; devOfficer.IncludeInOfficerDropdown = true; // Activate the user devUser.MakeActive(); // Make the user a system Administrator. devUser.MakeAdministrator(); context.Commit(); return(devUser.Id); } }
private static void LoadViolationCodes(string classicRmsConnectionString) { // call Safe Get(), eat exception and set default value of UCR. using (var context = new AdministrationDbContext()) using (var conn = new SqlConnection(classicRmsConnectionString)) { var rmsSystem = context.GetSystemInstance(); conn.Open(); using (var ucrCodesData = new DataSet()) { const string violationSelect = "SELECT DISTINCT [VC].[Violation_Code_Link], [VC].[Code], [VC].[Description], [VC].[Statute], [VC].[Statute_Description], " + "ISNULL([VC].[UCR_Code],'') UCR_Code, IsNull([VC].[UCR_Category],'') UCR_Category, IsNull([UC].[Description],'') UCR_Description, [VC].[Type_Statute], [VC].[Level_Degree], [VC].[State_Code], [VC].[NCIC_Code], " + "[VC].[Effective_Date],[VC].[Repeal_Date], ISNULL([VC].[Citation],0) Citation, ISNULL([VC].[Warrant],0) Warrant, ISNULL([VC].[Arrest],0) Arrest, " + " ISNULL([VC].[Violation_Hierarchy],0) Violation_Hierarchy, ISNULL([VC].[Incident],0) Incident, ISNULL([VC].[Jail],0) Jail," + " ISNULL([VC].[Inactive],0) Inactive, ISNULL([VC].[Reportable],0) Reportable " + " FROM [VSI_SYSTEM].[dbo].[Violation_Code] [VC] " + "LEFT OUTER JOIN [VSI_SYSTEM].[dbo].[UCR_Code] [UC] " + "ON [VC].[UCR_Code] = [UC].[UCR_Code] " + " WHERE ISNULL([VC].[JURISDICTION],'ALL') = 'ALL'"; using (var adapter = new SqlDataAdapter(violationSelect, conn)) adapter.Fill(ucrCodesData, "ViolationCodes"); var guid = Guid.Empty; Log.Info("Importing {0} Violation Codes", ucrCodesData.Tables["ViolationCodes"].Rows.Count); foreach (DataRow violationCodeRow in ucrCodesData.Tables["ViolationCodes"].Rows) { // Find or create UCR Code record var classicId = Convert.ToInt32(violationCodeRow["Violation_Code_Link"].ToString()); var code = violationCodeRow["Code"] as string; var violationDescription = violationCodeRow["Description"] as string; var violationHierarchy = violationCodeRow["Violation_Hierarchy"].ToString(); var statute = violationCodeRow["Statute"] as string; var statuteDescription = violationCodeRow["Statute_Description"] as string; var ucrCode = violationCodeRow["UCR_Code"] as string; var ucrCategory = violationCodeRow["UCR_Category"] as string; var ucrDescription = violationCodeRow["UCR_Description"] as string; var typeStatute = violationCodeRow["Type_Statute"] as string; var levelDegree = violationCodeRow["Level_Degree"] as string; var stateCode = violationCodeRow["State_Code"] as string; var ncicCode = violationCodeRow["NCIC_Code"] as string; var effectiveDatestr = violationCodeRow["Effective_Date"] as string; var effectiveDate = String.IsNullOrEmpty(effectiveDatestr) ? DateTime.Now.AddYears(-100) : Convert.ToDateTime(effectiveDatestr); var repealDatestr = violationCodeRow["Repeal_Date"] as string; var repealDate = String.IsNullOrEmpty(repealDatestr) ? DateTime.Now.AddYears(100) : Convert.ToDateTime(repealDatestr); var citation = Convert.ToBoolean(violationCodeRow["Citation"].ToString()); var warrant = Convert.ToBoolean(violationCodeRow["Warrant"].ToString()); var arrest = Convert.ToBoolean(violationCodeRow["Arrest"].ToString()); var incident = Convert.ToBoolean(violationCodeRow["Incident"].ToString()); var jail = Convert.ToBoolean(violationCodeRow["Jail"].ToString()); var inactive = Convert.ToBoolean(violationCodeRow["Inactive"].ToString()); var reportable = Convert.ToBoolean(violationCodeRow["Reportable"].ToString()); statute = String.IsNullOrEmpty(statute) ? "" : statute; statuteDescription = String.IsNullOrEmpty(statuteDescription) ? "" : statuteDescription; ucrCode = String.IsNullOrEmpty(ucrCode) ? "" : ucrCode; ucrDescription = String.IsNullOrEmpty(ucrDescription) ? "" : ucrDescription; code = String.IsNullOrEmpty(code) ? "" : code; var statuteDefinition = String.Format("{0} {1} {2} {3} {4}", statute, statuteDescription, ucrCode, ucrDescription, code); var filterCode = String.IsNullOrEmpty(ucrCode) ? "" : ucrCode; var filterDesc = String.IsNullOrEmpty(ucrDescription) ? "" : ucrDescription; var filter = new CodeValue { Code = filterCode, Description = filterDesc }; rmsSystem.CreateViolationCode(guid, classicId, code, violationDescription, reportable, ucrCode, ucrCategory, statute, statuteDescription, violationHierarchy, typeStatute, levelDegree, stateCode, ncicCode, effectiveDate, repealDate, inactive, incident, citation, arrest, warrant, jail, statuteDefinition, filter); } } context.Commit(); } }