private void Execute(IModelDatabaseMaintanance databaseMaintanance, Action <Session, string> action) { using (var objectSpace = Application.CreateObjectSpace()){ var isObjectFitForCriteria = IsObjectFitForCriteria(databaseMaintanance, objectSpace); if ((isObjectFitForCriteria.HasValue && isObjectFitForCriteria.Value)) { var parser = new ConnectionStringParser(Application.ConnectionString); var database = parser.GetPartByName("Initial Catalog"); action(objectSpace.Session(), database); } } }
private Task BackupTask(string database, IModelDatabaseMaintanance databaseMaintanance) { return(Task.Factory.StartNew(() => { try{ var dateTime = DateTime.Now.ToString("yyyy.MMMM.dd-HH.mm.ss"); string text = $@"BACKUP DATABASE [{database}] TO DISK = N'{databaseMaintanance.BackupDirectory}\{database}-{dateTime }.bak' WITH NOFORMAT, NOINIT, NAME = N'{database}-Full Database Backup on {dateTime}', SKIP, NOREWIND, NOUNLOAD, STATS = 10"; ExecuteNonQuery(text, databaseMaintanance.BackupTimeout); } catch (Exception e) { Tracing.Tracer.LogError(e); } }, TaskCreationOptions.LongRunning | TaskCreationOptions.AttachedToParent)); }
private bool?IsObjectFitForCriteria(IModelDatabaseMaintanance databaseMaintanance, IObjectSpace objectSpace) { var user = objectSpace.GetObject(SecuritySystem.CurrentUser); CriteriaOperator criteriaOperator; var typeInfo = databaseMaintanance.UserModelClass?.TypeInfo; var targetObjectType = typeInfo?.Type; using (objectSpace.CreateParseCriteriaScope()){ criteriaOperator = CriteriaWrapper.ParseCriteriaWithReadOnlyParameters(databaseMaintanance.UserCriteria, targetObjectType); } var fit = objectSpace.GetExpressionEvaluator(new EvaluatorContextDescriptorDefault(typeInfo == null?typeof(object):targetObjectType), criteriaOperator).Fit(typeInfo == null?new object():user); return(fit); }
public static IModelList <IModelClass> Get_UserClasses(IModelDatabaseMaintanance databaseMaintanance) { return(databaseMaintanance.ModelClasses(typeof(ISecurityUser))); }
public static IModelClass Get_UserModelClass(IModelDatabaseMaintanance databaseMaintanance) { return(databaseMaintanance.ModelClasses(typeof(ISecurityUser)).FirstOrDefault()); }