/// <summary> /// Import Vehicle Codes into all Agencies in the system. /// </summary> /// <remarks>TODO: This method does not support Update. This assumes the SystemCodes.UpdateAllAgencies() has run first purging all existing codes.</remarks> public static void ImportIntoAllAgencies(string classicRmsConnectionString) { List <Guid> agencyIds; using (var context = new AdministrationDbContext()) agencyIds = context.Set <Domain.Administration.Aggregates.Agency.Agency>().Select(x => x.Id).ToList(); agencyIds.ForEach(x => ImportIntoAgency(x, classicRmsConnectionString)); }
/// <summary> /// Update the System Codes in All Agencies. /// </summary> public static void UpdateAllAgencies(string classicDatabaseConnectionString) { List <Guid> agencyIds; using (var context = new AdministrationDbContext()) agencyIds = context.Set <Domain.Administration.Aggregates.Agency.Agency>() .Select(x => x.Id).ToList(); agencyIds.ForEach(id => UpdateAgencyCodes(id, classicDatabaseConnectionString)); }
public CodeValue LookupByCode(string code, string category) { var result = _context.Set <Code>() .Where(x => x.CodeSet.Category == category && x.Value == code) .Select(_anonymousCode) .FirstOrDefault(); return(result == null ? null : new CodeValue(result.Code, result.Description)); }
/// <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> /// 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); } }
/// <summary> /// Force EF to generate the Model Metadata. /// </summary> public static void GenerateViews(string viewCachePath, ILog log = null) { // Use the provided ILog instance or create our own. log = log ?? LogProvider.Get(typeof(ContextPreloader)); log.Debug("View Cache Directory set to: {0}", viewCachePath); var admin = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new AdministrationDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\AdministrationDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Agency>().ToString(); timer.Stop(); log.Debug("AdministrationDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var reports = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new ReportsDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\ReportsDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Report>().ToString(); timer.Stop(); log.Debug("ReportsDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var summaries = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new SummariesDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\SummariesDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Summary>().ToString(); timer.Stop(); log.Debug("SummariesDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var recentInfo = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new RecentInfoDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\RecentInfoDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <RecentEvent>().ToString(); timer.Stop(); log.Debug("RecentInfoDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var messaging = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new MessagingDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\MessagingDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <MessageLog>().ToString(); timer.Stop(); log.Debug("MessagingDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var audit = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new AuditDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\AuditDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.AuditEntities.ToString(); timer.Stop(); log.Debug("AuditDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); Task.WaitAll(admin, reports, summaries, recentInfo, messaging, audit); }