/// <summary> /// Update All TriTech Default Templates in the System /// </summary> public static void UpdateAllAgencies() { // Get the list of Agencies in the System. List <Guid> agencyIds; using (var admin = new AdministrationDbContext()) agencyIds = admin.GetEntityQuery <Domain.Administration.Aggregates.Agency.Agency>() .Select(x => x.Id) .ToList(); // We can use the same Metadata Context because we are only reading data. using (var meta = new MetadataDbContext()) { foreach (var agencyId in agencyIds) { // Distribute the work so we do not pay the performance price // of tracking too many entities at the same time. // This is important in systems that have a lot of Agencies. using (var admin = new AdministrationDbContext()) { // Load the Agency var agency = admin.GetAgency(agencyId); // Update the Templates UpdateTriTechDefaultTemplatesInAgency(agency, admin, meta); // Commit the Work admin.Commit(); } } } }
/// <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(); } }
/// <summary> /// Load the Vehicle Codes(VMA and VMO) from Classic RMS into a Web RMS Agency. /// <remarks>TODO: This method does not support Update. This assumes the SystemCodes.UpdateAllAgencies() has run first purging all existing codes.</remarks> /// </summary> public static void ImportIntoAgency(Guid agencyId, string classicRmsConnectionString) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); LoadNcicCodes(classicRmsConnectionString, agency, "VMA", "Vehicle Make", "Category", "Category_desc"); LoadNcicCodes(classicRmsConnectionString, agency, "VMO", "Vehicle Model", "Property_Code", "Property_Code_desc", "VMOTTCH"); context.Commit(); } }
/// <summary> /// Create a Default Officer Role in an Agency /// </summary> public static Guid CreateInAgency(Guid agencyId) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); var role = agency.CreateRole(Name, "Default Officer Role"); ModuleTypeInfo.ReportModules.ForEach(x => role.SetModulePermissions(x, new ModulePermissions(false, true, false, false))); context.Commit(); return(role.Id); } }
/// <summary> /// Re-Import all "System Codes" from a ClassicRMS server into an Agency in WebRMS. /// </summary> public static void UpdateAgencyCodes(Guid agencyId, string classicRmsConnectionString) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); // Remove all existing code sets from the Agency. // TODO: This is in place until we solve the problem of Web getting its codes from Classic. var removedCodes = context.Set <CodeSet>().RemoveRange(agency.RemoveAllCodeSets()); context.Commit(); Log.Info("Purged {0} CodeSets from {1}", removedCodes.Count(), agency.Jurisdiction.Ori); // Load System Codes from Classic LoadSystemCodesFromClassicRms(agency, classicRmsConnectionString); context.Commit(); // Load Dmv Codes from Classic LoadDmvCodesFromClassicRms(agency, classicRmsConnectionString); context.Commit(); } }
/// <summary> /// Update The Implementation Default Templates for all Agencies in the System. /// </summary> /// <param name="implementation">The State Implementation of the System.</param> public static void UpdateAllAgencies(string implementation) { using (var meta = new MetadataDbContext()) using (var admin = new AdministrationDbContext()) { // Install or Update Templates in All Agencies admin.GetEntityQuery <Domain.Administration.Aggregates.Agency.Agency>() .ToList() .ForEach(agency => InstallOrUpdateTemplatesInAgency(agency, implementation, admin, meta)); // Commit the Work admin.Commit(); } }
public void ToRole(Guid roleId) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(_agencyId); var templates = agency.Templates.ToList(); var role = agency.GetRole(roleId); // Assign the role to all available Templates templates.ForEach(t => t.AssignRole(role)); context.Commit(); } }
/// <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); } }
/// <summary> /// Create a Default Admin Role in an Agency. /// /// </summary> public static Guid CreateInAgency(Guid agencyId) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); var role = agency.CreateRole(Name, "Default Administrator Role"); role.SetAgencyPermissions(new AgencyPermissions(true, true, true, true)); // Assign the role to all available Templates var agencyTemplates = agency.Templates.ToList(); agencyTemplates.ForEach(t => t.AssignRole(role)); context.Commit(); return(role.Id); } }
/// <summary> /// Create the Default Workflow for the Agency /// </summary> public static void CreateInAgency(Guid agencyId) { using (var context = new AdministrationDbContext()) { // Find the Agency var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); // Create a New Workflow var defaultWorkflow = agency.CreateWorkflow("Default Workflow", CreateDefaultWorkflowSequence().Serialize()); // Enable the Workflow defaultWorkflow.Enable(); context.Commit(); } }
/// <summary> /// Apply the "Default" settings to an Agency. /// </summary> public static void Apply(Guid agencyId) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); Log.Info("Setting default configuration for " + agency.Jurisdiction.Ori); // Get the Agency's Configuration var config = agency.Configuration; // default setting for number control behavior in incident. config.ReportNumberEqualsCaseNumber = true; context.Commit(); } }
/// <summary> /// Create a Default Supervisor Role in an Agency. /// </summary> public static Guid CreateInAgency(Guid agencyId) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); var role = agency.CreateRole(Name, "Default Supervisor Role"); role.SetAgencyPermissions(new AgencyPermissions(true, false, true, true)); role.SetModulePermissions(ModuleType.Arrest, ModulePermissions.All); role.SetModulePermissions(ModuleType.Case, ModulePermissions.All); // Case doesn't really make sense here. role.SetModulePermissions(ModuleType.FieldInterview, ModulePermissions.All); role.SetModulePermissions(ModuleType.Incident, ModulePermissions.All); context.Commit(); return(role.Id); } }
/// <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> /// 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(); } }
/// <summary> /// Installs the TriTech Default Templates into a specific Agency. /// </summary> public static void Install(Guid agencyId) { using (var admin = new AdministrationDbContext()) using (var meta = new MetadataDbContext()) { var agency = admin.GetAgency(agencyId); if (agency == null) { throw new Exception("Unable to Find Agency [" + agencyId + "]"); } UpdateTriTechDefaultTemplatesInAgency(agency, admin, meta); // Commit the Work admin.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> /// Re-Import all "Agency Settings" from a ClassicRMS server into an Agency in WebRMS. /// </summary> public static void UpdateAgencySettings(Guid agencyId, string classicRmsConnectionString) { using (var context = new AdministrationDbContext()) { var agency = context.Find <Domain.Administration.Aggregates.Agency.Agency>(agencyId); // Remove all existing code sets from the Agency. // TODO: This is in place until we solve the problem of Web getting its codes from Classic. Log.Info("Resetting Agency Settings for jurisdiction {0}", agency.Jurisdiction.Ori); // Load Agency Settings from Classic LoadAgencySettingsFromClassicRms(agency, classicRmsConnectionString); context.Commit(); } }
/// <summary>k /// Create an RMSSystem /// </summary> private static void CreateRmsSystem(string systemName, Version version) { using (var context = new AdministrationDbContext()) { // Create a new RMS System Instance var rmsSystem = new RMSSystem(Guid.Empty, systemName) { Version = version.ToString() }; Log.Info("System: " + rmsSystem.Description); Log.Info("Version: " + rmsSystem.Version); Log.Info("Key: [" + rmsSystem.Id.As64BitString() + "] "); context.Add(rmsSystem); context.Commit(); } }
/// <summary> /// Install the "Implementation Default" Templates in a Specific Agency. /// </summary> /// <param name="agencyId">Id of the Agency to setup templates in.</param> /// <param name="implementation">Implementation of the Templates to Install.</param> public static void Install(Guid agencyId, string implementation) { using (var meta = new MetadataDbContext()) using (var admin = new AdministrationDbContext()) { var agency = admin.GetAgency(agencyId); if (agency == null) { throw new Exception("Agency [" + agencyId + "] not found."); } // Install or Update Templates InstallOrUpdateTemplatesInAgency(agency, implementation, admin, meta); // Commit the Work admin.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(); } }
/// <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(); } }