public IEntity CreateSuspendedTask(BackgroundTask task) { var suspendedTask = Entity.Create(SuspendedTaskType); var context = task.Context; if (context.Identity != null && context.Identity.Id != 0) { var primaryUser = Entity.Get <UserAccount>(context.Identity.Id); if (primaryUser != null) { suspendedTask.GetRelationships(SuspendedTask.StIdentity_Field).Add(primaryUser); } } if (context.SecondaryIdentity != null && context.SecondaryIdentity.Id != 0) { var secondaryUser = Entity.Get <UserAccount>(context.SecondaryIdentity.Id); if (secondaryUser != null) { suspendedTask.GetRelationships(SuspendedTask.StSecondaryIdentity_Field).Add(secondaryUser); } } suspendedTask.SetField(SuspendedTask.StCulture_Field, task.Context.Culture); suspendedTask.SetField(SuspendedTask.StTimezone_Field, task.Context.TimeZone); T taskParam = task.GetData <T>(); AnnotateSuspendedTask(suspendedTask, taskParam); return(suspendedTask); }
public bool Handle(BackgroundTask task, BackgroundTaskService.BackgroundTaskLog log) { bool res = true; try { var data = task.GetData <DatabaseUpdateTaskData>(); var sl = ServiceLocatorFactory.CreateMasterSysAdmin(); var districts = sl.DistrictService.GetDistricts(); var masterSqls = data.Sqls.Where(x => x.RunOnMaster).ToList(); var districtSqls = data.Sqls.Where(x => !x.RunOnMaster).ToList(); using (var uow = new UnitOfWork(Settings.MasterConnectionString, true)) { foreach (var updateSql in masterSqls) { var cmd = uow.GetTextCommandWithParams(updateSql.Sql, new Dictionary <string, object>()); cmd.CommandTimeout = Settings.DbUpdateTimeout; cmd.ExecuteNonQuery(); } uow.Commit(); } foreach (var dbServer in Settings.ChalkableSchoolDbServers) { using (var uow = new UnitOfWork(Settings.GetSchoolTemplateConnectionString(dbServer), true)) { foreach (var updateSql in districtSqls) { var cmd = uow.GetTextCommandWithParams(updateSql.Sql, new Dictionary <string, object>()); cmd.CommandTimeout = Settings.DbUpdateTimeout; cmd.ExecuteNonQuery(); } uow.Commit(); } } var runer = new AllSchoolRunner <IEnumerable <UpdateSql> >(); if (!runer.Run(districts, districtSqls, log, ExecSql, task1 => AllSchoolRunner <IEnumerable <UpdateSql> > .TaskStatusEnum.Completed)) { res = false; } } catch (Exception ex) { while (ex != null) { log.LogError("Error during database update"); log.LogError(ex.Message); log.LogError(ex.StackTrace); ex = ex.InnerException; } res = false; } return(res); }
public bool Handle(BackgroundTask task, BackgroundTaskService.BackgroundTaskLog log) { var data = task.GetData <ReportProcessingTaskData>(); var sl = ServiceLocatorFactory.CreateSchoolLocator(data.UserContext); string appRoot = Environment.GetEnvironmentVariable("RoleRoot"); data.ReportInputModel.DefaultDataPath = Path.Combine(appRoot + @"\", @"approot\"); sl.ReportService.GenerateReportCard(data.ReportInputModel); return(true); }
public bool Handle(BackgroundTask task, BackgroundTaskService.BackgroundTaskLog log) { var sl = ServiceLocatorFactory.CreateMasterSysAdmin(); var data = task.GetData <PictureImportTaskData>(); var district = sl.DistrictService.GetByIdOrNull(data.DistrictId); var connectorLocator = ConnectorLocator.Create(district.SisUserName, district.SisPassword, district.SisUrl); foreach (var person in data.PersonIds) { var content = connectorLocator.UsersConnector.GetPhoto(person); if (content != null) { sl.PersonPictureService.UploadPicture(data.DistrictId, person, content); } else { sl.PersonPictureService.DeletePicture(data.DistrictId, person); } } return(true); }
public bool Handle(BackgroundTask task, BackgroundTaskService.BackgroundTaskLog log) { var sl = ServiceLocatorFactory.CreateMasterSysAdmin(); var data = task.GetData <DatabaseBackupRestoreTaskData>(); if (data.BackupMaster) { var c = new SqlConnection(sl.Context.MasterConnectionString); var t = new AllSchoolRunner <long> .Task { Database = c.Database, Server = c.DataSource, Data = data.Time, Success = false, Completed = false }; if (backup) { AllSchoolRunner <long> .Run(new List <AllSchoolRunner <long> .Task> { t }, x => BackupHelper.DoExport(x.Data, x.Server, x.Database), CheckStatus); } else { AllSchoolRunner <long> .Run(new List <AllSchoolRunner <long> .Task> { t }, Restore, CheckStatus); } if (!t.Success) { log.LogError($"Db {actionName} error: Master Database"); if (t.ErrorMessage != null) { log.LogError(t.ErrorMessage); } return(false); } } string[] serversForTemplateDbs = Settings.ChalkableSchoolDbServers; if (backup) { serversForTemplateDbs = serversForTemplateDbs.Take(1).ToArray(); } foreach (var dbServer in serversForTemplateDbs) { var c = new SqlConnection(Settings.GetSchoolTemplateConnectionString(dbServer)); var t = new AllSchoolRunner <long> .Task { Database = c.Database, Server = c.DataSource, Data = data.Time, Success = false, Completed = false }; if (backup) { AllSchoolRunner <long> .Run(new List <AllSchoolRunner <long> .Task> { t }, x => BackupHelper.DoExport(x.Data, x.Server, x.Database), CheckStatus); } else { AllSchoolRunner <long> .Run(new List <AllSchoolRunner <long> .Task> { t }, Restore, CheckStatus); } if (!t.Success) { log.LogError(string.Format("Db {0} error: Template Database", actionName)); if (t.ErrorMessage != null) { log.LogError(t.ErrorMessage); } return(false); } } var schools = sl.DistrictService.GetDistricts(); var runer = new AllSchoolRunner <long>(); bool res; if (backup) { res = runer.Run(schools, data.Time, log, t => BackupHelper.DoExport(t.Data, t.Server, t.Database), CheckStatus); } else { res = runer.Run(schools, data.Time, log, Restore, CheckStatus); } return(res); }
/// <summary> /// /// </summary> /// <param name="data"></param> public void HandleTask(BackgroundTask task) { var value = task.GetData <T>(); HandleTask(value); }