public void TestRelationsApi() { var masterService = new ServiceLocatorMaster(SuperAdminContext); var standardIds = new List <Guid> { new Guid("6A59A66C-6EC0-11DF-AB2D-366B9DFF4B22"), new Guid("cdff6dc0-416f-457c-90cc-ba148f926b9d"), new Guid("c5e3b333-bcec-41fc-82dc-d49b648d3b13"), new Guid("39eb58bf-b931-48d0-b129-11f1f836552d"), new Guid("c5e3b333-bcec-41fc-82dc-d49b648d3b13"), new Guid("c8487c0c-92c7-4eb2-b976-52d16c861cf7"), new Guid("4f1047f3-51ac-401d-b231-f5c87afe2de8"), new Guid("08bd11c1-2102-43f7-9d9f-9dd96dd594f0"), new Guid("fb78924e-6d25-49f4-b05c-176b0be371c9"), new Guid("be60a98c-a875-44b2-abf0-40105151ffd3") }; var startTime = DateTime.Now; var relations = Task.Run(() => masterService.AcademicBenchmarkService.GetListOfStandardRelations(standardIds)).Result; var delta = DateTime.Now - startTime; Debug.WriteLine(delta); foreach (var rel in relations) { Debug.WriteLine($"{rel?.Derivatives?.Count} --- {rel?.Origins?.Count} --- {rel?.RelatedDerivatives?.Count}"); } }
public void Resync(string tableName) { Log.LogInfo("start resync"); connectorLocator = ConnectorLocator.Create(ConnectionInfo.SisUserName, ConnectionInfo.SisPassword, ConnectionInfo.SisUrl); ServiceLocatorMaster = new ServiceLocatorMaster(sysadminCntx); ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null); Log.LogInfo("download data to resync"); context = new SyncContext(connectorLocator.ApiVersion); var tablesToResync = new List <string> { tableName, nameof(Gender), // We need this tables for mappers nameof(SpEdStatus) // inside StudentAdapter/Selector }; var toSync = context.TablesToSync; var results = new List <SyncResultBase <SyncModel> >(); foreach (var table in toSync) { var type = context.Types[table.Key]; SyncResultBase <SyncModel> res; var resType = (typeof(SyncResult <>)).MakeGenericType(type); if (tablesToResync.Contains(table.Key)) { Log.LogInfo("Start downloading " + table.Key); res = (SyncResultBase <SyncModel>)connectorLocator.SyncConnector.GetDiff(type, null); Log.LogInfo("Table downloaded: " + table.Key + " " + res.RowCount); } else { res = (SyncResultBase <SyncModel>)Activator.CreateInstance(resType, new object[0]); } if (table.Key == tableName) //resync table { object o = resType.GetProperty("Rows").GetValue(res); resType.GetProperty("Updated").SetValue(res, o); resType.GetProperty("Inserted").SetValue(res, null); resType.GetProperty("Deleted").SetValue(res, null); resType.GetProperty("Rows").SetValue(res, null); } results.Add(res); } foreach (var syncResultBase in results) { context.SetResult(syncResultBase); } if (!ServiceLocatorSchool.Context.DistrictId.HasValue) { throw new Exception("District id should be defined for import"); } DoRegularSync(false); }
public static IServiceLocatorMaster CreateMasterSysAdmin() { var admin = new User { Id = Guid.Empty, Login = "******", LoginInfo = new UserLoginInfo() }; var context = new UserContext(admin, CoreRoles.SUPER_ADMIN_ROLE, null, null, null, null, null); var serviceLocator = new ServiceLocatorMaster(context); return(serviceLocator); }
public void ResyncAfterRestore() { Log.LogInfo("start resync after sti DB restore"); ServiceLocatorMaster = new ServiceLocatorMaster(sysadminCntx); ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null); if (!ServiceLocatorSchool.Context.DistrictId.HasValue) { throw new Exception("District id should be defined for import"); } var d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value); connectorLocator = ConnectorLocator.Create(ConnectionInfo.SisUserName, ConnectionInfo.SisPassword, ConnectionInfo.SisUrl); Log.LogInfo("remove district last sync label"); d.LastSync = null; ServiceLocatorMaster.DistrictService.Update(d); Log.LogInfo("performing before restore preparation"); ServiceLocatorMaster.DbMaintenanceService.BeforeSisRestore(d.Id); ServiceLocatorSchool.DbMaintenanceService.BeforeSisRestore(); Log.LogInfo("download data to restore"); DownloadSyncData(); Log.LogInfo("remove user records"); var all = ServiceLocatorMaster.UserService.GetAll(districtId); var allIds = new HashSet <int>(all.Select(x => x.SisUserId.Value)); var newUsers = new List <StiConnector.SyncModel.User>(); var rows = context.GetSyncResult <StiConnector.SyncModel.User>().Rows; foreach (var r in rows) { if (!allIds.Contains(r.UserID)) { newUsers.Add(r); } } context.GetSyncResult <StiConnector.SyncModel.User>().Inserted = null; context.GetSyncResult <StiConnector.SyncModel.User>().Rows = newUsers.ToArray(); context.GetSyncResult <StiConnector.SyncModel.User>().Updated = null; context.GetSyncResult <StiConnector.SyncModel.User>().Deleted = null; Log.LogInfo("do initial sync"); DoInitialSync(); d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value); Log.LogInfo("performing after restore preparation"); var logs = ServiceLocatorMaster.DbMaintenanceService.AfterSisRestore(d.Id); ServiceLocatorSchool.DbMaintenanceService.AfterSisRestore(); foreach (var restoreLogItem in logs) { Log.LogWarning(restoreLogItem.Msg); } Log.LogInfo("updating district last sync"); UpdateDistrictLastSync(d, true); CreateUserLoginInfos(); Log.LogInfo("resync after sti DB restore is completed"); }
public static IServiceLocatorSchool CreateSchoolLocator(UserContext context) { IServiceLocatorSchool locator; if (context != null && DemoUserService.IsDemoUser(context)) { locator = CreateDemoSchoolLocator(context); } else { var masterLocator = new ServiceLocatorMaster(context); locator = new ServiceLocatorSchool(masterLocator); } return(locator); }
public void Import() { Log.LogInfo("start import"); ServiceLocatorMaster = new ServiceLocatorMaster(sysadminCntx); ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null); if (!ServiceLocatorSchool.Context.DistrictId.HasValue) { throw new Exception("District id should be defined for import"); } var d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value); try { connectorLocator = ConnectorLocator.Create(ConnectionInfo.SisUserName, ConnectionInfo.SisPassword, ConnectionInfo.SisUrl); Log.LogInfo("download data to sync"); DownloadSyncData(); if (d.LastSync.HasValue) { DoRegularSync(true); } else { DoInitialSync(); } Log.LogInfo("updating district last sync"); d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value); UpdateDistrictLastSync(d, true); } catch (Exception) { UpdateDistrictLastSync(d, false); throw; } Log.LogInfo("process pictures"); ProcessPictures(); Log.LogInfo("setting link status"); var importedSchoolIds = context.GetSyncResult <School>().All.Select(x => x.SchoolID); foreach (var importedSchoolId in importedSchoolIds) { connectorLocator.LinkConnector.CompleteSync(importedSchoolId); } CreateUserLoginInfos(); Log.LogInfo("import is completed"); }
private void DoRegularSync(bool updateVersions) { ServiceLocatorMaster = new ImportServiceLocatorMaster(sysadminCntx); ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null); var masterDb = (ImportDbService)ServiceLocatorMaster.DbService; var schoolDb = (ImportDbService)ServiceLocatorSchool.SchoolDbService; Log.LogInfo("begin master transaction"); masterDb.BeginTransaction(); Log.LogInfo("begin school transaction"); schoolDb.BeginTransaction(); var t1 = new Thread(PingConnection); var t2 = new Thread(PingConnection); t1.Start(masterDb); t2.Start(schoolDb); bool schoolCommited = false; try { SyncDb(updateVersions); Log.LogInfo("commit school db"); schoolDb.CommitAll(); schoolCommited = true; Log.LogInfo("commit master db"); masterDb.CommitAll(); } catch (Exception ex) { Log.LogException(ex, districtId.ToString(), taskId.ToString()); if (!schoolCommited) { Log.LogError("rollback school db"); schoolDb.Rollback(); } else { Log.LogError("!!!!!!!!school is commited but master is going to rollback!!!!!!!!!!!!!!!!!!!!!"); } //TODO..... Log.LogError("rollback master db"); masterDb.Rollback(); throw; } finally { try { t1.Abort(); t2.Abort(); } catch (Exception ex) { Trace.TraceError(ex.Message); } } schoolDb.Dispose(); masterDb.Dispose(); ServiceLocatorMaster = new ServiceLocatorMaster(sysadminCntx); ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null); }